@@ 40-61 (lines=22) @@ | ||
37 | $this->assertEquals($descendants[5]->primaryKey,7); |
|
38 | } |
|
39 | ||
40 | public function testChildren() |
|
41 | { |
|
42 | // single root |
|
43 | $nestedSet=NestedSet::model()->findByPk(1); |
|
44 | $this->assertTrue($nestedSet instanceof NestedSet); |
|
45 | $children=$nestedSet->children()->findAll(); |
|
46 | $this->assertEquals(count($children),2); |
|
47 | foreach($children as $child) |
|
48 | $this->assertTrue($child instanceof NestedSet); |
|
49 | $this->assertEquals($children[0]->primaryKey,2); |
|
50 | $this->assertEquals($children[1]->primaryKey,5); |
|
51 | ||
52 | // many roots |
|
53 | $nestedSet=NestedSetWithManyRoots::model()->findByPk(1); |
|
54 | $this->assertTrue($nestedSet instanceof NestedSetWithManyRoots); |
|
55 | $children=$nestedSet->children()->findAll(); |
|
56 | $this->assertEquals(count($children),2); |
|
57 | foreach($children as $child) |
|
58 | $this->assertTrue($child instanceof NestedSetWithManyRoots); |
|
59 | $this->assertEquals($children[0]->primaryKey,2); |
|
60 | $this->assertEquals($children[1]->primaryKey,5); |
|
61 | } |
|
62 | ||
63 | public function testAncestors() |
|
64 | { |
|
@@ 63-84 (lines=22) @@ | ||
60 | $this->assertEquals($children[1]->primaryKey,5); |
|
61 | } |
|
62 | ||
63 | public function testAncestors() |
|
64 | { |
|
65 | // single root |
|
66 | $nestedSet=NestedSet::model()->findByPk(7); |
|
67 | $this->assertTrue($nestedSet instanceof NestedSet); |
|
68 | $ancestors=$nestedSet->ancestors()->findAll(); |
|
69 | $this->assertEquals(count($ancestors),2); |
|
70 | foreach($ancestors as $ancestor) |
|
71 | $this->assertTrue($ancestor instanceof NestedSet); |
|
72 | $this->assertEquals($ancestors[0]->primaryKey,1); |
|
73 | $this->assertEquals($ancestors[1]->primaryKey,5); |
|
74 | ||
75 | // many roots |
|
76 | $nestedSet=NestedSetWithManyRoots::model()->findByPk(7); |
|
77 | $this->assertTrue($nestedSet instanceof NestedSetWithManyRoots); |
|
78 | $ancestors=$nestedSet->ancestors()->findAll(); |
|
79 | $this->assertEquals(count($ancestors),2); |
|
80 | foreach($ancestors as $ancestor) |
|
81 | $this->assertTrue($ancestor instanceof NestedSetWithManyRoots); |
|
82 | $this->assertEquals($ancestors[0]->primaryKey,1); |
|
83 | $this->assertEquals($ancestors[1]->primaryKey,5); |
|
84 | } |
|
85 | ||
86 | public function testRoots() |
|
87 | { |