From: <pau...@us...> - 2006-09-22 12:13:37
|
Revision: 911 http://svn.sourceforge.net/everydevel/?rev=911&view=rev Author: paul_the_nomad Date: 2006-09-22 05:13:25 -0700 (Fri, 22 Sep 2006) Log Message: ----------- Move XML.t tests to Unit tests for XML.pm Modified Paths: -------------- trunk/ebase/t/Everything/Auth.t trunk/ebase/t/Everything/XML.t Added Paths: ----------- trunk/ebase/lib/Everything/Test/XML.pm Added: trunk/ebase/lib/Everything/Test/XML.pm =================================================================== --- trunk/ebase/lib/Everything/Test/XML.pm (rev 0) +++ trunk/ebase/lib/Everything/Test/XML.pm 2006-09-22 12:13:25 UTC (rev 911) @@ -0,0 +1,144 @@ +package Everything::Test::XML; + +use strict; +use Test::More; +use Test::MockObject; +use SUPER; + +use base 'Everything::Test'; + +sub startup : Test(startup => +0) { + my $self = shift; + my $mock = Test::MockObject->new; + + $self->{le} = []; + $mock->fake_module( 'Everything', + logErrors => sub { push @{ $self->{le} }, [@_] } ); + $mock->fake_module('XML::DOM'); + + $self->SUPER; + $self->{mock} = $mock; + +} + +sub test_readtag : Test(1) { + my $self = shift; + my $package = $self->{class}; + can_ok( $package, 'readTag' ); + +} + +sub test_initXMLParser : Test(2) { + my $self = shift; + my $package = $self->{class}; + + can_ok( $package, 'initXMLParser' ); + my $unfixed = Everything::XML::_unfixed(); + $unfixed->{foo} = 'bar'; + Everything::XML::initXMLParser(); + is( keys( %{ Everything::XML::_unfixed() } ), + 0, 'initXMLParser() should clear unfixed keys' ); +} + +sub test_fix_nodes : Test(7) { + my $self = shift; + my $package = $self->{class}; + my $mock = $self->{mock}; + + can_ok( $package, 'fixNodes' ); + + my ( @gn, @gnret ); + + no strict 'refs'; + local *{ __PACKAGE__ . '::fixNodes' }; + *{ __PACKAGE__ . '::fixNodes' } = \&{ $self->{class} . '::fixNodes' }; + local *{ __PACKAGE__ . '::_unfixed' }; + *{ __PACKAGE__ . '::_unfixed' } = \&{ $self->{class} . '::_unfixed' }; + use strict 'refs'; + + local *Everything::XML::getNode; + *Everything::XML::getNode = sub { + push @gn, [@_]; + return shift @gnret; + }; + + my $unfixed = _unfixed(); + $unfixed->{foo} = 'bar'; + + fixNodes(0); + is( @{ $self->{le} }, + 0, 'fixNodes() should log nothing unless error flag is set' ); + + fixNodes(1); + is( @{ $self->{le} }, 1, '... but should log with error flag' ); + + @gnret = ($mock) x 4; + + $mock->set_series( applyXMLFix => 1, 0, 1 )->set_true('commitXMLFixes') + ->clear(); + $unfixed->{foo} = [ 1, 2 ]; + + fixNodes('printflag'); + my ( $method, $args ) = $mock->next_call(); + is( $method, 'applyXMLFix', '... calling applyXMLFix() for all unfixed' ); + is( join( '-', @$args ), + "$mock-1-printflag", '... with fix and print error' ); + is_deeply( $unfixed, { foo => [1] }, '... saving only unfixed nodes' ); + + $mock->clear(); + + $unfixed = { bar => [] }; + fixNodes('printflag'); + is( $mock->next_call(2), 'commitXMLFixes', '... committing fixes' ); + +} + +sub test_xml2node : Test(1) { + my $self = shift; + my $package = $self->{class}; + can_ok( $package, 'xml2node' ); +} + +sub test_xmlfile2node : Test(1) { + my $self = shift; + my $package = $self->{class}; + can_ok( $package, 'xmlfile2node' ); +} + +sub test_gen_basic_tag : Test(1) { + my $self = shift; + my $package = $self->{class}; + can_ok( $package, 'genBasicTag' ); +} + +sub test_parse_basic_tag : Test(1) { + my $self = shift; + my $package = $self->{class}; + can_ok( $package, 'parseBasicTag' ); +} + +sub test_path_xml_where : Test(1) { + my $self = shift; + my $package = $self->{class}; + can_ok( $package, 'patchXMLwhere' ); +} + +sub test_make_xml_safe : Test(1) { + my $self = shift; + my $package = $self->{class}; + can_ok( $package, 'makeXmlSafe' ); +} + +sub test_unmake_xml_safe : Test(1) { + my $self = shift; + my $package = $self->{class}; + can_ok( $package, 'unMakeXmlSafe' ); +} + +sub test_get_field_type : Test(1) { + my $self = shift; + my $package = $self->{class}; + can_ok( $package, 'getFieldType' ); +} + +1; Property changes on: trunk/ebase/lib/Everything/Test/XML.pm ___________________________________________________________________ Name: svn:mime-type + text/plain Name: svn:eol-style + native Modified: trunk/ebase/t/Everything/Auth.t =================================================================== --- trunk/ebase/t/Everything/Auth.t 2006-09-22 11:28:01 UTC (rev 910) +++ trunk/ebase/t/Everything/Auth.t 2006-09-22 12:13:25 UTC (rev 911) @@ -4,40 +4,3 @@ Everything::Test::Auth->runtests; -__END__ - - -# BEGIN -# { -# chdir 't' if -d 't'; -# unshift @INC, '../lib', '../blib/lib', 'lib'; -# } - -# use strict; -# use File::Path; -# use File::Spec; - -# use Test::More tests => 32; - -# use Test::Exception; -# use Test::MockObject; - -my ( $result, $method, $args, @le ); - - - -can_ok( $package, 'generateSession' ); -my $mock = Test::MockObject->new(); -$mock->{options} = { guest_user => 'guest' }; -$mock->set_always( getVars => 'vars' ); - -$db->set_false('getNode')->clear(); - -throws_ok { Everything::Auth::generateSession($mock) } qr/Unable to get user!/, - 'generateSession() should die with no user'; -( $method, $args ) = $db->next_call(); -is( $method, 'getNode', '... so should fetch a user given none' ); -is( $args->[1], 'guest', '... using guest user option' ); - -my @results = Everything::Auth::generateSession( $mock, $mock ); -is_deeply( \@results, [ $mock, 'vars' ], '... returning user and user vars' ); Modified: trunk/ebase/t/Everything/XML.t =================================================================== --- trunk/ebase/t/Everything/XML.t 2006-09-22 11:28:01 UTC (rev 910) +++ trunk/ebase/t/Everything/XML.t 2006-09-22 12:13:25 UTC (rev 911) @@ -1,92 +1,6 @@ #!/usr/bin/perl -w -use strict; +use Everything::Test::XML; -BEGIN -{ - chdir 't' if -d 't'; - unshift @INC, '../blib/lib', 'lib/', '..'; -} +Everything::Test::XML->runtests; -use strict; -use vars qw( $AUTOLOAD ); - -use Test::More tests => 19; -use Test::MockObject; - -my $mock = Test::MockObject->new(); - -my ( $method, $args, $results, @le ); - -$mock->fake_module( 'Everything', logErrors => sub { push @le, [@_] } ); -$mock->fake_module('XML::DOM'); - -my $package = 'Everything::XML'; -use_ok($package) or exit; - -sub AUTOLOAD -{ - $AUTOLOAD =~ s/main:://; - if ( my $sub = $package->can($AUTOLOAD) ) - { - no strict 'refs'; - *{$AUTOLOAD} = $sub; - goto &$AUTOLOAD; - } -} - -can_ok( $package, 'readTag' ); - -can_ok( $package, 'initXMLParser' ); -my $unfixed = _unfixed(); -$unfixed->{foo} = 'bar'; -initXMLParser(); -is( keys( %{ _unfixed() } ), 0, 'initXMLParser() should clear unfixed keys' ); - -can_ok( $package, 'fixNodes' ); -{ - my ( @gn, @gnret ); - - local *Everything::XML::getNode; - *Everything::XML::getNode = sub { - push @gn, [@_]; - return shift @gnret; - }; - - my $unfixed = _unfixed(); - $unfixed->{foo} = 'bar'; - - fixNodes(0); - is( @le, 0, 'fixNodes() should log nothing unless error flag is set' ); - - fixNodes(1); - is( @le, 1, '... but should log with error flag' ); - - @gnret = ($mock) x 4; - - $mock->set_series( applyXMLFix => 1, 0, 1 )->set_true('commitXMLFixes') - ->clear(); - $unfixed->{foo} = [ 1, 2 ]; - - fixNodes('printflag'); - ( $method, $args ) = $mock->next_call(); - is( $method, 'applyXMLFix', '... calling applyXMLFix() for all unfixed' ); - is( join( '-', @$args ), - "$mock-1-printflag", '... with fix and print error' ); - is_deeply( $unfixed, { foo => [1] }, '... saving only unfixed nodes' ); - - $mock->clear(); - - $unfixed = { bar => [] }; - fixNodes('printflag'); - is( $mock->next_call(2), 'commitXMLFixes', '... committing fixes' ); -} - -can_ok( $package, 'xml2node' ); -can_ok( $package, 'xmlfile2node' ); -can_ok( $package, 'genBasicTag' ); -can_ok( $package, 'parseBasicTag' ); -can_ok( $package, 'patchXMLwhere' ); -can_ok( $package, 'makeXmlSafe' ); -can_ok( $package, 'unMakeXmlSafe' ); -can_ok( $package, 'getFieldType' ); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |