From: <chr...@us...> - 2006-05-12 22:15:15
|
Revision: 858 Author: chromatic Date: 2006-05-12 15:14:57 -0700 (Fri, 12 May 2006) ViewCVS: http://svn.sourceforge.net/everydevel/?rev=858&view=rev Log Message: ----------- r16660@windwheel: chromatic | 2006-05-12 15:14:48 -0700 Ported tests for location node to the new style. Modified Paths: -------------- trunk/ebase/MANIFEST trunk/ebase/lib/Everything/Node/location.pm trunk/ebase/t/Node/location.t Added Paths: ----------- trunk/ebase/lib/Everything/Node/Test/location.pm Property Changed: ---------------- trunk/ebase/ Property changes on: trunk/ebase ___________________________________________________________________ Name: svk:merge - a6810612-c0f9-0310-9d3e-a9e4af8c5745:/ebase/offline:16553 + a6810612-c0f9-0310-9d3e-a9e4af8c5745:/ebase/offline:16660 Modified: trunk/ebase/MANIFEST =================================================================== --- trunk/ebase/MANIFEST 2006-05-09 23:42:55 UTC (rev 857) +++ trunk/ebase/MANIFEST 2006-05-12 22:14:57 UTC (rev 858) @@ -89,6 +89,7 @@ lib/Everything/Node/workspace.pm lib/Everything/Node/Test/dbtable.pm lib/Everything/Node/Test/htmlcode.pm +lib/Everything/Node/Test/location.pm lib/Everything/Node/Test/node.pm lib/Everything/Node/Test/nodeball.pm lib/Everything/Node/Test/nodegroup.pm Added: trunk/ebase/lib/Everything/Node/Test/location.pm =================================================================== --- trunk/ebase/lib/Everything/Node/Test/location.pm (rev 0) +++ trunk/ebase/lib/Everything/Node/Test/location.pm 2006-05-12 22:14:57 UTC (rev 858) @@ -0,0 +1,110 @@ +package Everything::Node::Test::location; + +use strict; +use warnings; + +use base 'Everything::Node::Test::node'; +use Test::More; +use SUPER; +*Everything::Node::location::SUPER = \&UNIVERSAL::SUPER; + +sub test_nuke :Test( +8 ) +{ + my $self = shift; + my $node = $self->{node}; + my $db = $self->{mock_db}; + + $db->set_true( 'sqlUpdate' ); + $self->SUPER(); + + $node->set_series( SUPER => -1, 0, 1 ); + $db->clear(); + + $node->{node_id} = 'node_id'; + $node->{loc_location} = 'loc_location'; + + is( $node->nuke( 'user' ), -1, + 'nuke() should return result of SUPER() call' ); + + my ($method, $args) = $node->next_call(); + is( $args->[1], 'user', '... passing user to parent method' ); + + isnt( $db->next_call(), 'sqlUpdate', + '... not calling sqlUpdate() if SUPER() call fails' ); + + $node->nuke( 'user' ); + isnt( $db->next_call(), 'sqlUpdate', + '... or if SUPER() returns invalid node_id' ); + + $node->nuke( 'user'); + ($method, $args) = $db->next_call(); + + is( $method, 'sqlUpdate', + '... but should call sqlUpdate() if SUPER() call succeeds' ); + is( $args->[1], 'node', '... updating node table' ); + is( $args->[2]{loc_location}, 'loc_location', 'updating loc_location' ); + is( $args->[3], 'loc_location=node_id', '... matching node_id' ); +} + +sub test_list_nodes :Test( 5 ) +{ + my $self = shift; + my $node = $self->{node}; + + $node->set_always( listNodesWhere => 'lnw' ); + + my $result = $node->listNodes( 'full_flag' ); + my ($method, $args) = $node->next_call(); + + is( $method, 'listNodesWhere', 'listNodes() should call listNodesWhere()' ); + is( $args->[1], '', '... with no WHERE clause' ); + is( $args->[2], '', '... with no ORDER clause' ); + is( $args->[3], 'full_flag', '... passing the full flag' ); + is( $result, 'lnw', '... and returning the results' ); +} + + +sub test_list_nodes_where :Test( 11 ) +{ + my $self = shift; + my $node = $self->{node}; + my $db = $self->{mock_db}; + + $db->set_false( 'sqlSelectMany' ); + $node->{node_id} = 'node_id'; + + $node->listNodesWhere( 'where', 'an order' ); + my ($method, $args) = $db->next_call(); + + is( $method, 'sqlSelectMany', 'listNodesWhere() should fetch nodes' ); + like( $args->[3], qr/^where loc_loca/, '... adding passed where clause' ); + is( $args->[4], 'an order', '... using passed order clause' ); + + $node->listNodesWhere(); + ($method, $args) = $db->next_call(); + + like( $args->[3], qr/^ loc_loca/, + '... but should use default where clause' ); + is( $args->[4], 'order by title', '... and default order clause' ); + + $db->set_series( fetchrow => 1, 2, undef, 1 ) + ->set_series( sqlSelectMany => undef, $db, $db ) + ->set_true( qw( getRef finish )); + + is( @{ $node->listNodesWhere( '', '', '') }, 0, + '... returning empty array ref without nodes in location' ); + + my $nodes = $node->listNodesWhere( '', '' ); + is( @$nodes, 2, '... returning array ref of found nodes' ); + is( join( '', @$nodes ), '12', '... and the right nodes' ); + ok( !( grep { $_ eq 'getRef' } map { scalar $db->next_call() } 1 .. 5 ), + '... but should not call getRef on nodes without full flag' ); + + $node->listNodesWhere( '', '', 1 ); + ok( ( grep { $_ eq 'getRef' } map { scalar $db->next_call() } 1 .. 5 ), + '... and should call getRef on nodes with full flag' ); + + is( $db->next_call(), 'finish', '... and should finish() cursor' ); +} + +1; Property changes on: trunk/ebase/lib/Everything/Node/Test/location.pm ___________________________________________________________________ Name: svn:mime-type + text/plain; charset=UTF-8 Name: svn:eol-style + native Modified: trunk/ebase/lib/Everything/Node/location.pm =================================================================== --- trunk/ebase/lib/Everything/Node/location.pm 2006-05-09 23:42:55 UTC (rev 857) +++ trunk/ebase/lib/Everything/Node/location.pm 2006-05-12 22:14:57 UTC (rev 858) @@ -23,9 +23,9 @@ sub nuke { my ( $this, $USER ) = @_; - my $id = $$this{node_id}; - my $parentLoc = $$this{loc_location}; - my $result = $this->SUPER(); + my $id = $this->{node_id}; + my $parentLoc = $this->{loc_location}; + my $result = $this->SUPER( $USER ); if ( $result > 0 ) { @@ -33,7 +33,7 @@ # Set all the nodes that were in this location to be in the # parent location... deleting a location does not delete all # the nodes inside of it. - $$this{DB}->sqlUpdate( "node", { loc_location => $parentLoc }, + $this->{DB}->sqlUpdate( "node", { loc_location => $parentLoc }, "loc_location=$id" ); } @@ -97,16 +97,16 @@ my ( $this, $where, $order, $full ) = @_; $where ||= ''; $order ||= "order by title"; - $where .= " loc_location='$$this{node_id}'"; + $where .= " loc_location='$this->{node_id}'"; my @nodes; if ( my $csr = - $$this{DB}->sqlSelectMany( "node_id", "node", $where, $order ) ) + $this->{DB}->sqlSelectMany( "node_id", "node", $where, $order ) ) { while ( my $id = $csr->fetchrow() ) { - $$this{DB}->getRef($id) if ($full); + $this->{DB}->getRef($id) if ($full); push @nodes, $id; } Modified: trunk/ebase/t/Node/location.t =================================================================== --- trunk/ebase/t/Node/location.t 2006-05-09 23:42:55 UTC (rev 857) +++ trunk/ebase/t/Node/location.t 2006-05-12 22:14:57 UTC (rev 858) @@ -1,113 +1,4 @@ -#!/usr/bin/perl +#! perl -use strict; -use warnings; - -use vars '$AUTOLOAD'; - -BEGIN -{ - chdir 't' if -d 't'; - use lib 'lib'; -} - -use FakeNode; -use Test::More tests => 23; - -my $module = 'Everything::Node::location'; -use_ok( $module ) or exit; - -ok( $module->isa( 'Everything::Node::node' ), 'location should extend node' ); - -can_ok( $module, 'dbtables' ); -my @tables = $module->dbtables(); -is_deeply( \@tables, [ 'node' ], 'dbtables() should return node tables' ); - -my $node = FakeNode->new(); - -# nuke() -$node->{_subs}{SUPER} = [ -1, 0, 1 ]; -$node->{DB} = $node; -$node->{node_id} = 'node_id'; -$node->{loc_location} = 'loc_location'; - -is( nuke($node), -1, 'nuke() should return result of SUPER() call' ); -is( $node->{_calls}->[-1][0], - 'SUPER', '... should not call sqlUpdate() if SUPER() call fails' ); - -nuke($node); -is( $node->{_calls}->[-1][0], - 'SUPER', '... or if SUPER() returns invalid node_id' ); - -nuke($node); -my $call = $node->{_calls}->[-1]; -is( $call->[0], 'sqlUpdate', - '... should call sqlUpdate() if SUPER() call succeeds' ); -is( $call->[1], 'node', '... updating node table' ); -is( $call->[2]{loc_location}, 'loc_location', 'updating loc_location' ); -is( $call->[3], 'loc_location=node_id', '... matching node_id' ); - -# listNodes() -$node->{_calls} = []; -$node->{node_id} = 'node_id'; -$node->{_subs} = { - fetchrow => [ 1, 2, undef, 1 ], - sqlSelectMany => [ undef, $node, $node ], -}; - -local *FakeNode::listNodesWhere; -*FakeNode::listNodesWhere = \&Everything::Node::location::listNodesWhere; - -is( scalar @{ listNodes($node) }, - 0, 'listNodes() should return empty array ref with no nodes in location' ); -like( - join( ' ', @{ $node->{_calls}[0] } ), - qr/sqlSelectMany.+location='node_id'/, - '... should call sqlSelectMany() to find its nodes' -); - -$node->{_calls} = []; -my $nodes = listNodes($node); -is( scalar @$nodes, 2, '... should return array ref of found nodes' ); -is( join( '', @$nodes ), '12', '... and the right nodes' ); -ok( - !( grep { $_->[0] eq 'getRef' } @{ $node->{_calls} } ), - '... but should not call getRef on nodes without full flag' -); - -$node->{_calls} = []; -listNodes( $node, 1 ); -ok( - ( grep { $_->[0] eq 'getRef' } @{ $node->{_calls} } ), - '... and should call getRef on nodes with full flag' -); -is( $node->{_calls}[-1][0], 'finish', '... and should finish() cursor' ); - -# listNodesWhere() -$node->{_calls} = []; -listNodesWhere( $node, 'where', 'an order' ); -$call = $node->{_calls}[0]; -is( $call->[0], 'sqlSelectMany', 'listNodesWhere should fetch nodes' ); -like( $call->[3], qr/^where loc_loca/, '... adding any passed where clause' ); -is( $call->[4], 'an order', '... and using any passed order clause' ); - -listNodesWhere($node); -$call = $node->{_calls}[1]; -like( $call->[3], qr/^ loc_loca/, '... but should use default where clause' ); -is( $call->[4], 'order by title', '... and default order clause' ); - -sub AUTOLOAD -{ - return if $AUTOLOAD =~ /DESTROY$/; - - no strict 'refs'; - $AUTOLOAD =~ s/^main:://; - - my $sub = "Everything::Node::location::$AUTOLOAD"; - - if ( defined &{$sub} ) - { - *{$AUTOLOAD} = \&{$sub}; - goto &{$sub}; - } -} +use Everything::Node::Test::location; +Everything::Node::Test::location->runtests(); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |