X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=blobdiff_plain;f=t%2Flib%2FTreeTest.pm;h=7af89b30803d690138af2d9c2753ff679058b359;hb=3c94ae56c4e2a8553d44944a111f479b0a87ff7d;hp=a3054cbd522eb73d750ad8cdee463564f282ad7c;hpb=c0d76c37162678a26ce56f769aa98e3cf1ae11c1;p=dbsrgits%2FDBIx-Class-Tree.git diff --git a/t/lib/TreeTest.pm b/t/lib/TreeTest.pm index a3054cb..7af89b3 100644 --- a/t/lib/TreeTest.pm +++ b/t/lib/TreeTest.pm @@ -3,12 +3,13 @@ use strict; use warnings; use Test::More; +use Test::Exception; use TreeTest::Schema; our $NODE_COUNT = 80; sub count_tests { - my $count = 22; + my $count = 17; if( TreeTest::Schema::Node->can('position_column') ){ $count ++; } @@ -27,6 +28,7 @@ sub run_tests { my $node = $nodes->create({ name=>'child' }); $node->parent( $parent_id ); } + ok( ($nodes->count()==81), 'correct number of nodes in random tree' ); ok( ($nodes->find(3)->children->count()==7), 'node 3 has correct number of children' ); ok( ($nodes->find(22)->children->count()==3), 'node 22 has correct number of children' ); @@ -38,52 +40,29 @@ sub run_tests { ok( ($nodes->find(22)->children->count()==2), 'node 22 has correct number of children' ); ok( ($nodes->find(22)->siblings->count()==3), 'node 22 has correct number of siblings' ); - $nodes->find(22)->add_child( $nodes->find(3) ); + $nodes->find(22)->attach_child( $nodes->find(3) ); ok( ($nodes->find(22)->children->count()==3), 'node 22 has correct number of children' ); ok( ($nodes->find(22)->siblings->count()==2), 'node 22 has correct number of siblings' ); - $nodes->find(22)->add_sibling( $nodes->find(3) ); + $nodes->find(22)->attach_sibling( $nodes->find(3) ); ok( ($nodes->find(22)->children->count()==2), 'node 22 has correct number of children' ); ok( ($nodes->find(22)->siblings->count()==3), 'node 22 has correct number of siblings' ); ok( ($nodes->find(22)->parents->count()==1), 'node 22 has correct number of parents' ); ok( (($nodes->find(22)->parents->all())[0]->id()==$nodes->find(22)->parent->id()), 'node 22 parent matches parents' ); + my @ancestors = $nodes->find(44)->ancestors(); + ok( scalar(@ancestors)==8, 'node 44 has correct number of ancestors' ); + ok( $ancestors[0]->id == $nodes->find(44)->parent_id, 'node 44\'s first ancestor is its parent' ); + ok( $ancestors[-1]->name eq 'root', 'node 44\'s last ancestor is root' ); + if( TreeTest::Schema::Node->can('position_column') ){ ok( check_positions(scalar $root->children()), 'positions are correct' ); } - #$nodes->delete; - $schema = TreeTest::Schema->connect(); - $nodes = $schema->resultset('Node'); - $root = $nodes->create({ name=>'root' }); - @parents = ( - 1,1,3,2,3,3,6,6,2,5,3,5,12,1 - ); - foreach my $parent_id (@parents) { - my $node = $nodes->create({ name=>'child' }); - $node->parent( $parent_id ); - } - - ok ($nodes->find(1)->descendents == 14, 'root node has 14 descendents'); - ok ($nodes->find(2)->descendents == 4, 'node 2 has 4 descendents'); - ok ($nodes->find(6)->descendents == 2, 'node 6 has 2 descendents'); - ok ($nodes->find(10)->descendents == 0, 'node 10 has no descendents'); - - $nodes->find(2)->pharaoh_delete; - ok ($nodes->find(1)->descendents == 9, 'root node has 9 descendents after pharaohing node 2'); - - ok ($nodes->find(3)->children == 4, 'node 3 has 4 children'); - $nodes->find(6)->grandmother_delete; - ok ($nodes->find(3)->children == 5, 'node 3 has 5 children after node 6 dies'); - - $nodes->find(3)->replace_with_and_delete($nodes->find(12)); - ok ($nodes->find(12)->children == 5, 'node 12 has 5 children after taking over from node 3'); - ok ($nodes->find(7)->parent->id == 12, 'node 7\'s parent is node 12'); - - - - + lives_and ( sub { + is( $nodes->find(3)->copy({name => 'special'})->name,'special','copy test'); + }, 'copy does not throw'); } sub check_positions {