Renamed Positional to Ordered and added tests for Ordered.
[dbsrgits/DBIx-Class-Tree.git] / t / lib / TreeTest.pm
index 95a0dec..137ea17 100644 (file)
@@ -8,7 +8,11 @@ use TreeTest::Schema;
 our $NODE_COUNT = 80;
 
 sub count_tests {
-    return 11;
+    my $count = 11;
+    if( TreeTest::Schema::Node->can('position_column') ){
+        $count ++;
+    }
+    return $count;
 }
 
 sub run_tests {
@@ -41,6 +45,21 @@ sub run_tests {
     $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' );
+
+    if( TreeTest::Schema::Node->can('position_column') ){
+        ok( check_positions(scalar $root->children()), 'positions are correct' );
+    }
+}
+
+sub check_positions {
+    my $nodes = shift;
+    my $position = 0;
+    while (my $node = $nodes->next()) {
+        $position ++;
+        return 0 if ($node->position() != $position);
+        return 0 if ( !check_positions(scalar $node->children()) );
+    }
+    return 1;
 }
 
 1;