These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more
1 | <?php |
||
2 | /** |
||
3 | * @link https://github.com/paulzi/yii2-materialized-path |
||
4 | * @copyright Copyright (c) 2015 PaulZi <[email protected]> |
||
5 | * @license MIT (https://github.com/paulzi/yii2-materialized-path/blob/master/LICENSE) |
||
6 | */ |
||
7 | |||
8 | namespace paulzi\materializedPath\tests; |
||
9 | |||
10 | use paulzi\materializedPath\tests\migrations\TestMigration; |
||
11 | use paulzi\materializedPath\tests\models\AttributeModeNode; |
||
12 | use paulzi\materializedPath\tests\models\MultipleTreeNode; |
||
13 | use paulzi\materializedPath\tests\models\Node; |
||
14 | use Yii; |
||
15 | |||
16 | /** |
||
17 | * @author PaulZi <[email protected]> |
||
18 | */ |
||
19 | class MaterializedPathBehaviorTestCase extends BaseTestCase |
||
20 | { |
||
21 | View Code Duplication | public function testGetParents() |
|
22 | { |
||
23 | $data = [1, 3]; |
||
24 | $this->assertEquals($data, array_map(function ($value) { return $value->id; }, Node::findOne(9)->parents)); |
||
25 | $this->assertEquals($data, array_map(function ($value) { return $value->id; }, AttributeModeNode::findOne(9)->parents)); |
||
26 | $this->assertEquals($data, array_map(function ($value) { return $value->id; }, MultipleTreeNode::findOne(9)->parents)); |
||
27 | |||
28 | $data = [17]; |
||
29 | $this->assertEquals($data, array_map(function ($value) { return $value->id; }, Node::findOne(24)->getParents(1)->all())); |
||
30 | $this->assertEquals($data, array_map(function ($value) { return $value->id; }, AttributeModeNode::findOne(24)->getParents(1)->all())); |
||
31 | $this->assertEquals($data, array_map(function ($value) { return $value->id; }, MultipleTreeNode::findOne(24)->getParents(1)->all())); |
||
32 | } |
||
33 | |||
34 | View Code Duplication | public function testGetParent() |
|
35 | { |
||
36 | $data = 15; |
||
37 | $this->assertEquals($data, Node::findOne(18)->parent->id); |
||
38 | $this->assertEquals($data, AttributeModeNode::findOne(18)->parent->id); |
||
39 | $this->assertEquals($data, MultipleTreeNode::findOne(18)->parent->id); |
||
40 | |||
41 | $data = null; |
||
42 | $this->assertEquals($data, Node::findOne(1)->getParent()->one()); |
||
43 | $this->assertEquals($data, AttributeModeNode::findOne(1)->getParent()->one()); |
||
44 | $this->assertEquals($data, MultipleTreeNode::findOne(1)->getParent()->one()); |
||
45 | } |
||
46 | |||
47 | public function testGetRoot() |
||
48 | { |
||
49 | $data = 1; |
||
50 | $this->assertEquals($data, Node::findOne(12)->root->id); |
||
51 | $this->assertEquals($data, AttributeModeNode::findOne(12)->root->id); |
||
52 | $this->assertEquals($data, MultipleTreeNode::findOne(12)->root->id); |
||
53 | |||
54 | $data = 1; |
||
55 | $this->assertEquals($data, Node::findOne(1)->getRoot()->one()->id); |
||
56 | $this->assertEquals($data, AttributeModeNode::findOne(1)->getRoot()->one()->id); |
||
57 | $this->assertEquals($data, MultipleTreeNode::findOne(1)->getRoot()->one()->id); |
||
58 | } |
||
59 | |||
60 | public function testGetDescendants() |
||
61 | { |
||
62 | $data = [2, 3, 4, 5, 8, 11, 12, 6, 9, 10, 7, 13]; |
||
63 | $this->assertEquals($data, array_map(function ($value) { return $value->id; }, Node::findOne(1)->descendants)); |
||
64 | $this->assertEquals($data, array_map(function ($value) { return $value->id; }, AttributeModeNode::findOne(1)->descendants)); |
||
65 | $this->assertEquals($data, array_map(function ($value) { return $value->id; }, MultipleTreeNode::findOne(1)->descendants)); |
||
66 | |||
67 | $data = [14, 15, 16, 17]; |
||
68 | $this->assertEquals($data, array_map(function ($value) { return $value->id; }, Node::findOne(14)->getDescendants(1, true)->all())); |
||
69 | $this->assertEquals($data, array_map(function ($value) { return $value->id; }, AttributeModeNode::findOne(14)->getDescendants(1, true)->all())); |
||
70 | $this->assertEquals($data, array_map(function ($value) { return $value->id; }, MultipleTreeNode::findOne(14)->getDescendants(1, true)->all())); |
||
71 | } |
||
72 | |||
73 | View Code Duplication | public function testGetChildren() |
|
74 | { |
||
75 | $data = [24, 25, 26]; |
||
76 | $this->assertEquals($data, array_map(function ($value) { return $value->id; }, Node::findOne(17)->children)); |
||
77 | $this->assertEquals($data, array_map(function ($value) { return $value->id; }, AttributeModeNode::findOne(17)->children)); |
||
78 | $this->assertEquals($data, array_map(function ($value) { return $value->id; }, MultipleTreeNode::findOne(17)->children)); |
||
79 | |||
80 | $data = []; |
||
81 | $this->assertEquals($data, array_map(function ($value) { return $value->id; }, Node::findOne(13)->getChildren()->all())); |
||
82 | $this->assertEquals($data, array_map(function ($value) { return $value->id; }, AttributeModeNode::findOne(13)->getChildren()->all())); |
||
83 | $this->assertEquals($data, array_map(function ($value) { return $value->id; }, MultipleTreeNode::findOne(13)->getChildren()->all())); |
||
84 | } |
||
85 | |||
86 | public function testGetLeaves() |
||
87 | { |
||
88 | $data = [18, 21, 24, 25, 19, 22, 23, 20, 26]; |
||
89 | $this->assertEquals($data, array_map(function ($value) { return $value->id; }, Node::findOne(14)->leaves)); |
||
90 | $this->assertEquals($data, array_map(function ($value) { return $value->id; }, AttributeModeNode::findOne(14)->leaves)); |
||
91 | $this->assertEquals($data, array_map(function ($value) { return $value->id; }, MultipleTreeNode::findOne(14)->leaves)); |
||
92 | |||
93 | $data = []; |
||
94 | $this->assertEquals($data, array_map(function ($value) { return $value->id; }, Node::findOne(14)->getLeaves(1)->all())); |
||
95 | $this->assertEquals($data, array_map(function ($value) { return $value->id; }, AttributeModeNode::findOne(14)->getLeaves(1)->all())); |
||
96 | $this->assertEquals($data, array_map(function ($value) { return $value->id; }, MultipleTreeNode::findOne(14)->getLeaves(1)->all())); |
||
97 | } |
||
98 | |||
99 | View Code Duplication | public function testGetPrev() |
|
100 | { |
||
101 | $data = 12; |
||
102 | $this->assertEquals($data, Node::findOne(13)->prev->id); |
||
103 | $this->assertEquals($data, AttributeModeNode::findOne(13)->prev->id); |
||
104 | $this->assertEquals($data, MultipleTreeNode::findOne(13)->prev->id); |
||
105 | |||
106 | $data = null; |
||
107 | $this->assertEquals($data, Node::findOne(15)->getPrev()->one()); |
||
108 | $this->assertEquals($data, AttributeModeNode::findOne(15)->getPrev()->one()); |
||
109 | $this->assertEquals($data, MultipleTreeNode::findOne(15)->getPrev()->one()); |
||
110 | } |
||
111 | |||
112 | View Code Duplication | public function testGetNext() |
|
113 | { |
||
114 | $data = 23; |
||
115 | $this->assertEquals($data, Node::findOne(22)->next->id); |
||
116 | $this->assertEquals($data, AttributeModeNode::findOne(22)->next->id); |
||
117 | $this->assertEquals($data, MultipleTreeNode::findOne(22)->next->id); |
||
118 | |||
119 | $data = null; |
||
120 | $this->assertEquals($data, Node::findOne(4)->getNext()->one()); |
||
121 | $this->assertEquals($data, AttributeModeNode::findOne(4)->getNext()->one()); |
||
122 | $this->assertEquals($data, MultipleTreeNode::findOne(4)->getNext()->one()); |
||
123 | } |
||
124 | |||
125 | public function testGetParentPath() |
||
126 | { |
||
127 | $this->assertEquals('1/2', Node::findOne(7)->getParentPath()); |
||
128 | $this->assertEquals(null, AttributeModeNode::findOne(1)->getParentPath()); |
||
129 | $this->assertEquals(['r', 'n1'], MultipleTreeNode::findOne(7)->getParentPath(true)); |
||
130 | $this->assertEquals([], Node::findOne(14)->getParentPath(true)); |
||
131 | } |
||
132 | |||
133 | public function testPopulateTree() |
||
134 | { |
||
135 | $node = Node::findOne(4); |
||
136 | $node->populateTree(); |
||
137 | $this->assertEquals(true, $node->isRelationPopulated('children')); |
||
138 | $this->assertEquals(true, $node->children[0]->isRelationPopulated('children')); |
||
139 | $this->assertEquals(11, $node->children[0]->id); |
||
140 | |||
141 | $node = AttributeModeNode::findOne(4); |
||
142 | $node->populateTree(1); |
||
143 | $this->assertEquals(true, $node->isRelationPopulated('children')); |
||
144 | $this->assertEquals(false, $node->children[0]->isRelationPopulated('children')); |
||
145 | $this->assertEquals(11, $node->children[0]->id); |
||
146 | |||
147 | $node = MultipleTreeNode::findOne(19); |
||
148 | $node->populateTree(); |
||
149 | $this->assertEquals(true, $node->isRelationPopulated('children')); |
||
150 | } |
||
151 | |||
152 | View Code Duplication | public function testIsRoot() |
|
153 | { |
||
154 | $this->assertTrue(Node::findOne(1)->isRoot()); |
||
155 | $this->assertFalse(Node::findOne(3)->isRoot()); |
||
156 | |||
157 | $this->assertTrue(AttributeModeNode::findOne(1)->isRoot()); |
||
158 | $this->assertFalse(AttributeModeNode::findOne(3)->isRoot()); |
||
159 | |||
160 | $this->assertTrue(MultipleTreeNode::findOne(1)->isRoot()); |
||
161 | $this->assertFalse(MultipleTreeNode::findOne(3)->isRoot()); |
||
162 | } |
||
163 | |||
164 | public function testIsChildOf() |
||
165 | { |
||
166 | $this->assertTrue(Node::findOne(10)->isChildOf(Node::findOne(1))); |
||
0 ignored issues
–
show
|
|||
167 | $this->assertTrue(Node::findOne(5)->isChildOf(Node::findOne(2))); |
||
0 ignored issues
–
show
The call to
Node::findOne() has too many arguments starting with 2 .
This check compares calls to functions or methods with their respective definitions. If the call has more arguments than are defined, it raises an issue. If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress. In this case you can add the
Loading history...
|
|||
168 | $this->assertFalse(Node::findOne(9)->isChildOf(Node::findOne(12))); |
||
0 ignored issues
–
show
The call to
Node::findOne() has too many arguments starting with 12 .
This check compares calls to functions or methods with their respective definitions. If the call has more arguments than are defined, it raises an issue. If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress. In this case you can add the
Loading history...
|
|||
169 | $this->assertFalse(Node::findOne(9)->isChildOf(Node::findOne(10))); |
||
0 ignored issues
–
show
The call to
Node::findOne() has too many arguments starting with 10 .
This check compares calls to functions or methods with their respective definitions. If the call has more arguments than are defined, it raises an issue. If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress. In this case you can add the
Loading history...
|
|||
170 | $this->assertFalse(Node::findOne(9)->isChildOf(Node::findOne(9))); |
||
171 | $this->assertFalse(Node::findOne(9)->isChildOf(Node::findOne(16))); |
||
0 ignored issues
–
show
The call to
Node::findOne() has too many arguments starting with 16 .
This check compares calls to functions or methods with their respective definitions. If the call has more arguments than are defined, it raises an issue. If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress. In this case you can add the
Loading history...
|
|||
172 | |||
173 | $this->assertTrue(AttributeModeNode::findOne(10)->isChildOf(AttributeModeNode::findOne(1))); |
||
0 ignored issues
–
show
The call to
AttributeModeNode::findOne() has too many arguments starting with 1 .
This check compares calls to functions or methods with their respective definitions. If the call has more arguments than are defined, it raises an issue. If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress. In this case you can add the
Loading history...
|
|||
174 | $this->assertTrue(AttributeModeNode::findOne(5)->isChildOf(AttributeModeNode::findOne(2))); |
||
0 ignored issues
–
show
The call to
AttributeModeNode::findOne() has too many arguments starting with 2 .
This check compares calls to functions or methods with their respective definitions. If the call has more arguments than are defined, it raises an issue. If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress. In this case you can add the
Loading history...
|
|||
175 | $this->assertFalse(AttributeModeNode::findOne(9)->isChildOf(AttributeModeNode::findOne(12))); |
||
0 ignored issues
–
show
The call to
AttributeModeNode::findOne() has too many arguments starting with 12 .
This check compares calls to functions or methods with their respective definitions. If the call has more arguments than are defined, it raises an issue. If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress. In this case you can add the
Loading history...
|
|||
176 | $this->assertFalse(AttributeModeNode::findOne(9)->isChildOf(AttributeModeNode::findOne(10))); |
||
0 ignored issues
–
show
The call to
AttributeModeNode::findOne() has too many arguments starting with 10 .
This check compares calls to functions or methods with their respective definitions. If the call has more arguments than are defined, it raises an issue. If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress. In this case you can add the
Loading history...
|
|||
177 | $this->assertFalse(AttributeModeNode::findOne(9)->isChildOf(AttributeModeNode::findOne(9))); |
||
178 | $this->assertFalse(AttributeModeNode::findOne(9)->isChildOf(AttributeModeNode::findOne(16))); |
||
0 ignored issues
–
show
The call to
AttributeModeNode::findOne() has too many arguments starting with 16 .
This check compares calls to functions or methods with their respective definitions. If the call has more arguments than are defined, it raises an issue. If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress. In this case you can add the
Loading history...
|
|||
179 | |||
180 | $this->assertTrue(MultipleTreeNode::findOne(10)->isChildOf(MultipleTreeNode::findOne(1))); |
||
0 ignored issues
–
show
The call to
MultipleTreeNode::findOne() has too many arguments starting with 1 .
This check compares calls to functions or methods with their respective definitions. If the call has more arguments than are defined, it raises an issue. If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress. In this case you can add the
Loading history...
|
|||
181 | $this->assertTrue(MultipleTreeNode::findOne(5)->isChildOf(MultipleTreeNode::findOne(2))); |
||
0 ignored issues
–
show
The call to
MultipleTreeNode::findOne() has too many arguments starting with 2 .
This check compares calls to functions or methods with their respective definitions. If the call has more arguments than are defined, it raises an issue. If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress. In this case you can add the
Loading history...
|
|||
182 | $this->assertFalse(MultipleTreeNode::findOne(9)->isChildOf(MultipleTreeNode::findOne(12))); |
||
0 ignored issues
–
show
The call to
MultipleTreeNode::findOne() has too many arguments starting with 12 .
This check compares calls to functions or methods with their respective definitions. If the call has more arguments than are defined, it raises an issue. If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress. In this case you can add the
Loading history...
|
|||
183 | $this->assertFalse(MultipleTreeNode::findOne(9)->isChildOf(MultipleTreeNode::findOne(10))); |
||
0 ignored issues
–
show
The call to
MultipleTreeNode::findOne() has too many arguments starting with 10 .
This check compares calls to functions or methods with their respective definitions. If the call has more arguments than are defined, it raises an issue. If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress. In this case you can add the
Loading history...
|
|||
184 | $this->assertFalse(MultipleTreeNode::findOne(9)->isChildOf(MultipleTreeNode::findOne(9))); |
||
185 | $this->assertFalse(MultipleTreeNode::findOne(9)->isChildOf(MultipleTreeNode::findOne(16))); |
||
0 ignored issues
–
show
The call to
MultipleTreeNode::findOne() has too many arguments starting with 16 .
This check compares calls to functions or methods with their respective definitions. If the call has more arguments than are defined, it raises an issue. If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress. In this case you can add the
Loading history...
|
|||
186 | } |
||
187 | |||
188 | View Code Duplication | public function testIsLeaf() |
|
189 | { |
||
190 | $this->assertTrue(Node::findOne(5)->isLeaf()); |
||
191 | $this->assertFalse(Node::findOne(2)->isLeaf()); |
||
192 | |||
193 | $this->assertTrue(AttributeModeNode::findOne(5)->isLeaf()); |
||
194 | $this->assertFalse(AttributeModeNode::findOne(2)->isLeaf()); |
||
195 | |||
196 | $this->assertTrue(MultipleTreeNode::findOne(5)->isLeaf()); |
||
197 | $this->assertFalse(MultipleTreeNode::findOne(2)->isLeaf()); |
||
198 | } |
||
199 | |||
200 | public function testMakeRootInsert() |
||
201 | { |
||
202 | (new TestMigration())->up(); |
||
203 | $dataSet = new ArrayDataSet(require(__DIR__ . '/data/empty.php')); |
||
204 | $this->getDatabaseTester()->setDataSet($dataSet); |
||
205 | $this->getDatabaseTester()->onSetUp(); |
||
206 | |||
207 | $node = new Node(['slug' => 'r']); |
||
208 | $this->assertTrue($node->makeRoot()->save()); |
||
209 | |||
210 | $node = new AttributeModeNode(['slug' => 'r']); |
||
211 | $this->assertTrue($node->makeRoot()->save()); |
||
212 | |||
213 | $node = new MultipleTreeNode(['slug' => 'r']); |
||
214 | $this->assertTrue($node->makeRoot()->save()); |
||
215 | |||
216 | $node = new MultipleTreeNode([ |
||
217 | 'slug' => 'r', |
||
218 | 'tree' => 100, |
||
219 | ]); |
||
220 | $this->assertTrue($node->makeRoot()->save()); |
||
221 | |||
222 | $dataSet = $this->getConnection()->createDataSet(['tree', 'attribute_mode_tree', 'multiple_tree']); |
||
223 | $expectedDataSet = new ArrayDataSet(require(__DIR__ . '/data/test-make-root-insert.php')); |
||
224 | $this->assertDataSetsEqual($expectedDataSet, $dataSet); |
||
225 | } |
||
226 | |||
227 | public function testMakeRootUpdate() |
||
228 | { |
||
229 | $node = Node::findOne(9); |
||
230 | $this->assertTrue($node->makeRoot()->save()); |
||
231 | |||
232 | $node = AttributeModeNode::findOne(15); |
||
233 | $this->assertTrue($node->makeRoot()->save()); |
||
234 | |||
235 | $node = MultipleTreeNode::findOne(17); |
||
236 | $this->assertTrue($node->makeRoot()->save()); |
||
237 | |||
238 | $dataSet = $this->getConnection()->createDataSet(['tree', 'attribute_mode_tree', 'multiple_tree']); |
||
239 | $expectedDataSet = new ArrayDataSet(require(__DIR__ . '/data/test-make-root-update.php')); |
||
240 | $this->assertDataSetsEqual($expectedDataSet, $dataSet); |
||
241 | } |
||
242 | |||
243 | View Code Duplication | public function testPrependToInsertInNoEmpty() |
|
244 | { |
||
245 | $node = new Node(['slug' => 'new']); |
||
246 | $this->assertTrue($node->prependTo(Node::findOne(1))->save()); |
||
247 | |||
248 | $node = new AttributeModeNode(['slug' => 'new']); |
||
249 | $this->assertTrue($node->prependTo(AttributeModeNode::findOne(1))->save()); |
||
250 | |||
251 | $node = new MultipleTreeNode(['slug' => 'new']); |
||
252 | $this->assertTrue($node->prependTo(MultipleTreeNode::findOne(1))->save()); |
||
253 | |||
254 | $dataSet = $this->getConnection()->createDataSet(['tree', 'attribute_mode_tree', 'multiple_tree']); |
||
255 | $expectedDataSet = new ArrayDataSet(require(__DIR__ . '/data/test-prepend-to-insert-in-no-empty.php')); |
||
256 | $this->assertDataSetsEqual($expectedDataSet, $dataSet); |
||
257 | } |
||
258 | |||
259 | View Code Duplication | public function testPrependToInsertInEmpty() |
|
260 | { |
||
261 | $node = new Node(['slug' => 'new']); |
||
262 | $this->assertTrue($node->prependTo(Node::findOne(22))->save()); |
||
263 | |||
264 | $node = new AttributeModeNode(['slug' => 'new']); |
||
265 | $this->assertTrue($node->prependTo(AttributeModeNode::findOne(22))->save()); |
||
266 | |||
267 | $node = new MultipleTreeNode(['slug' => 'new']); |
||
268 | $this->assertTrue($node->prependTo(MultipleTreeNode::findOne(22))->save()); |
||
269 | |||
270 | $dataSet = $this->getConnection()->createDataSet(['tree', 'attribute_mode_tree', 'multiple_tree']); |
||
271 | $expectedDataSet = new ArrayDataSet(require(__DIR__ . '/data/test-prepend-to-insert-in-empty.php')); |
||
272 | $this->assertDataSetsEqual($expectedDataSet, $dataSet); |
||
273 | } |
||
274 | |||
275 | View Code Duplication | public function testPrependToUpdateSameNode() |
|
276 | { |
||
277 | $node = Node::findOne(4); |
||
278 | $this->assertTrue($node->prependTo(Node::findOne(1))->save()); |
||
279 | |||
280 | $node = AttributeModeNode::findOne(4); |
||
281 | $this->assertTrue($node->prependTo(AttributeModeNode::findOne(1))->save()); |
||
282 | |||
283 | $node = MultipleTreeNode::findOne(4); |
||
284 | $this->assertTrue($node->prependTo(MultipleTreeNode::findOne(1))->save()); |
||
285 | |||
286 | $dataSet = $this->getConnection()->createDataSet(['tree', 'attribute_mode_tree', 'multiple_tree']); |
||
287 | $expectedDataSet = new ArrayDataSet(require(__DIR__ . '/data/test-prepend-to-update-same-node.php')); |
||
288 | $this->assertDataSetsEqual($expectedDataSet, $dataSet); |
||
289 | } |
||
290 | |||
291 | View Code Duplication | public function testPrependToUpdateDeep() |
|
292 | { |
||
293 | $node = Node::findOne(16); |
||
294 | $this->assertTrue($node->prependTo(Node::findOne(19))->save()); |
||
295 | |||
296 | $node = AttributeModeNode::findOne(16); |
||
297 | $this->assertTrue($node->prependTo(AttributeModeNode::findOne(19))->save()); |
||
298 | |||
299 | $node = MultipleTreeNode::findOne(16); |
||
300 | $this->assertTrue($node->prependTo(MultipleTreeNode::findOne(19))->save()); |
||
301 | |||
302 | $dataSet = $this->getConnection()->createDataSet(['tree', 'attribute_mode_tree', 'multiple_tree']); |
||
303 | $expectedDataSet = new ArrayDataSet(require(__DIR__ . '/data/test-prepend-to-update-deep.php')); |
||
304 | $this->assertDataSetsEqual($expectedDataSet, $dataSet); |
||
305 | } |
||
306 | |||
307 | View Code Duplication | public function testPrependToUpdateOut() |
|
308 | { |
||
309 | $node = Node::findOne(12); |
||
310 | $this->assertTrue($node->prependTo(Node::findOne(1))->save()); |
||
311 | |||
312 | $node = AttributeModeNode::findOne(12); |
||
313 | $this->assertTrue($node->prependTo(AttributeModeNode::findOne(1))->save()); |
||
314 | |||
315 | $node = MultipleTreeNode::findOne(12); |
||
316 | $this->assertTrue($node->prependTo(MultipleTreeNode::findOne(1))->save()); |
||
317 | |||
318 | $dataSet = $this->getConnection()->createDataSet(['tree', 'attribute_mode_tree', 'multiple_tree']); |
||
319 | $expectedDataSet = new ArrayDataSet(require(__DIR__ . '/data/test-prepend-to-update-out.php')); |
||
320 | $this->assertDataSetsEqual($expectedDataSet, $dataSet); |
||
321 | } |
||
322 | |||
323 | View Code Duplication | public function testPrependToUpdateAnotherTree() |
|
324 | { |
||
325 | $node = Node::findOne(17); |
||
326 | $this->assertTrue($node->prependTo(Node::findOne(2))->save()); |
||
327 | |||
328 | $node = AttributeModeNode::findOne(17); |
||
329 | $this->assertTrue($node->prependTo(AttributeModeNode::findOne(2))->save()); |
||
330 | |||
331 | $node = MultipleTreeNode::findOne(17); |
||
332 | $this->assertTrue($node->prependTo(MultipleTreeNode::findOne(2))->save()); |
||
333 | |||
334 | $dataSet = $this->getConnection()->createDataSet(['tree', 'attribute_mode_tree', 'multiple_tree']); |
||
335 | $expectedDataSet = new ArrayDataSet(require(__DIR__ . '/data/test-prepend-to-update-another-tree.php')); |
||
336 | $this->assertDataSetsEqual($expectedDataSet, $dataSet); |
||
337 | } |
||
338 | |||
339 | View Code Duplication | public function testPrependToUpdateSelf() |
|
340 | { |
||
341 | $node = Node::findOne(2); |
||
342 | $this->assertTrue($node->prependTo(Node::findOne(1))->save()); |
||
343 | |||
344 | $node = AttributeModeNode::findOne(2); |
||
345 | $this->assertTrue($node->prependTo(AttributeModeNode::findOne(1))->save()); |
||
346 | |||
347 | $node = MultipleTreeNode::findOne(2); |
||
348 | $this->assertTrue($node->prependTo(MultipleTreeNode::findOne(1))->save()); |
||
349 | |||
350 | $dataSet = $this->getConnection()->createDataSet(['tree', 'attribute_mode_tree', 'multiple_tree']); |
||
351 | $expectedDataSet = new ArrayDataSet(require(__DIR__ . '/data/data.php')); |
||
352 | $this->assertDataSetsEqual($expectedDataSet, $dataSet); |
||
353 | } |
||
354 | |||
355 | /** |
||
356 | * @expectedException \yii\base\Exception |
||
357 | */ |
||
358 | public function testPrependToInsertExceptionIsRaisedWhenTargetIsNewRecord() |
||
359 | { |
||
360 | $node = new Node(['slug' => 'new']); |
||
361 | $node->prependTo(new Node())->save(); |
||
362 | } |
||
363 | |||
364 | /** |
||
365 | * @expectedException \yii\base\Exception |
||
366 | */ |
||
367 | public function testPrependToUpdateExceptionIsRaisedWhenTargetIsNewRecord() |
||
368 | { |
||
369 | $node = Node::findOne(2); |
||
370 | $node->prependTo(new Node())->save(); |
||
371 | } |
||
372 | |||
373 | /** |
||
374 | * @expectedException \yii\base\Exception |
||
375 | */ |
||
376 | public function testPrependToUpdateExceptionIsRaisedWhenTargetIsSame() |
||
377 | { |
||
378 | $node = Node::findOne(3); |
||
379 | $node->prependTo(Node::findOne(3))->save(); |
||
380 | } |
||
381 | |||
382 | /** |
||
383 | * @expectedException \yii\base\Exception |
||
384 | */ |
||
385 | public function testPrependToUpdateExceptionIsRaisedWhenTargetIsChild() |
||
386 | { |
||
387 | $node = Node::findOne(17); |
||
388 | $node->prependTo(Node::findOne(24))->save(); |
||
389 | } |
||
390 | |||
391 | View Code Duplication | public function testAppendToInsertInNoEmpty() |
|
392 | { |
||
393 | $node = new Node(['slug' => 'new']); |
||
394 | $this->assertTrue($node->appendTo(Node::findOne(1))->save()); |
||
395 | |||
396 | $node = new AttributeModeNode(['slug' => 'new']); |
||
397 | $this->assertTrue($node->appendTo(AttributeModeNode::findOne(1))->save()); |
||
398 | |||
399 | $node = new MultipleTreeNode(['slug' => 'new']); |
||
400 | $this->assertTrue($node->appendTo(MultipleTreeNode::findOne(1))->save()); |
||
401 | |||
402 | $dataSet = $this->getConnection()->createDataSet(['tree', 'attribute_mode_tree', 'multiple_tree']); |
||
403 | $expectedDataSet = new ArrayDataSet(require(__DIR__ . '/data/test-append-to-insert-in-no-empty.php')); |
||
404 | $this->assertDataSetsEqual($expectedDataSet, $dataSet); |
||
405 | } |
||
406 | |||
407 | View Code Duplication | public function testAppendToInsertInEmpty() |
|
408 | { |
||
409 | $node = new Node(['slug' => 'new']); |
||
410 | $this->assertTrue($node->appendTo(Node::findOne(22))->save()); |
||
411 | |||
412 | $node = new AttributeModeNode(['slug' => 'new']); |
||
413 | $this->assertTrue($node->appendTo(AttributeModeNode::findOne(22))->save()); |
||
414 | |||
415 | $node = new MultipleTreeNode(['slug' => 'new']); |
||
416 | $this->assertTrue($node->appendTo(MultipleTreeNode::findOne(22))->save()); |
||
417 | |||
418 | $dataSet = $this->getConnection()->createDataSet(['tree', 'attribute_mode_tree', 'multiple_tree']); |
||
419 | $expectedDataSet = new ArrayDataSet(require(__DIR__ . '/data/test-append-to-insert-in-empty.php')); |
||
420 | $this->assertDataSetsEqual($expectedDataSet, $dataSet); |
||
421 | } |
||
422 | |||
423 | View Code Duplication | public function testAppendToUpdateSameNode() |
|
424 | { |
||
425 | $node = Node::findOne(2); |
||
426 | $this->assertTrue($node->appendTo(Node::findOne(1))->save()); |
||
427 | |||
428 | $node = AttributeModeNode::findOne(2); |
||
429 | $this->assertTrue($node->appendTo(AttributeModeNode::findOne(1))->save()); |
||
430 | |||
431 | $node = MultipleTreeNode::findOne(2); |
||
432 | $this->assertTrue($node->appendTo(MultipleTreeNode::findOne(1))->save()); |
||
433 | |||
434 | $dataSet = $this->getConnection()->createDataSet(['tree', 'attribute_mode_tree', 'multiple_tree']); |
||
435 | $expectedDataSet = new ArrayDataSet(require(__DIR__ . '/data/test-append-to-update-same-node.php')); |
||
436 | $this->assertDataSetsEqual($expectedDataSet, $dataSet); |
||
437 | } |
||
438 | |||
439 | View Code Duplication | public function testAppendToUpdateDeep() |
|
440 | { |
||
441 | $node = Node::findOne(16); |
||
442 | $this->assertTrue($node->appendTo(Node::findOne(19))->save()); |
||
443 | |||
444 | $node = AttributeModeNode::findOne(16); |
||
445 | $this->assertTrue($node->appendTo(AttributeModeNode::findOne(19))->save()); |
||
446 | |||
447 | $node = MultipleTreeNode::findOne(16); |
||
448 | $this->assertTrue($node->appendTo(MultipleTreeNode::findOne(19))->save()); |
||
449 | |||
450 | $dataSet = $this->getConnection()->createDataSet(['tree', 'attribute_mode_tree', 'multiple_tree']); |
||
451 | $expectedDataSet = new ArrayDataSet(require(__DIR__ . '/data/test-append-to-update-deep.php')); |
||
452 | $this->assertDataSetsEqual($expectedDataSet, $dataSet); |
||
453 | } |
||
454 | |||
455 | View Code Duplication | public function testAppendToUpdateOut() |
|
456 | { |
||
457 | $node = Node::findOne(12); |
||
458 | $this->assertTrue($node->appendTo(Node::findOne(1))->save()); |
||
459 | |||
460 | $node = AttributeModeNode::findOne(12); |
||
461 | $this->assertTrue($node->appendTo(AttributeModeNode::findOne(1))->save()); |
||
462 | |||
463 | $node = MultipleTreeNode::findOne(12); |
||
464 | $this->assertTrue($node->appendTo(MultipleTreeNode::findOne(1))->save()); |
||
465 | |||
466 | $dataSet = $this->getConnection()->createDataSet(['tree', 'attribute_mode_tree', 'multiple_tree']); |
||
467 | $expectedDataSet = new ArrayDataSet(require(__DIR__ . '/data/test-append-to-update-out.php')); |
||
468 | $this->assertDataSetsEqual($expectedDataSet, $dataSet); |
||
469 | } |
||
470 | |||
471 | View Code Duplication | public function testAppendToUpdateAnotherTree() |
|
472 | { |
||
473 | $node = Node::findOne(17); |
||
474 | $this->assertTrue($node->appendTo(Node::findOne(2))->save()); |
||
475 | |||
476 | $node = AttributeModeNode::findOne(17); |
||
477 | $this->assertTrue($node->appendTo(AttributeModeNode::findOne(2))->save()); |
||
478 | |||
479 | $node = MultipleTreeNode::findOne(17); |
||
480 | $this->assertTrue($node->appendTo(MultipleTreeNode::findOne(2))->save()); |
||
481 | |||
482 | $dataSet = $this->getConnection()->createDataSet(['tree', 'attribute_mode_tree', 'multiple_tree']); |
||
483 | $expectedDataSet = new ArrayDataSet(require(__DIR__ . '/data/test-append-to-update-another-tree.php')); |
||
484 | $this->assertDataSetsEqual($expectedDataSet, $dataSet); |
||
485 | } |
||
486 | |||
487 | View Code Duplication | public function testAppendToUpdateSelf() |
|
488 | { |
||
489 | $node = Node::findOne(4); |
||
490 | $this->assertTrue($node->appendTo(Node::findOne(1))->save()); |
||
491 | |||
492 | $node = AttributeModeNode::findOne(4); |
||
493 | $this->assertTrue($node->appendTo(AttributeModeNode::findOne(1))->save()); |
||
494 | |||
495 | $node = MultipleTreeNode::findOne(4); |
||
496 | $this->assertTrue($node->appendTo(MultipleTreeNode::findOne(1))->save()); |
||
497 | |||
498 | $dataSet = $this->getConnection()->createDataSet(['tree', 'attribute_mode_tree', 'multiple_tree']); |
||
499 | $expectedDataSet = new ArrayDataSet(require(__DIR__ . '/data/data.php')); |
||
500 | $this->assertDataSetsEqual($expectedDataSet, $dataSet); |
||
501 | } |
||
502 | |||
503 | /** |
||
504 | * @expectedException \yii\base\Exception |
||
505 | */ |
||
506 | public function testAppendToInsertExceptionIsRaisedWhenTargetIsNewRecord() |
||
507 | { |
||
508 | $node = new Node(['slug' => 'new']); |
||
509 | $node->appendTo(new Node())->save(); |
||
510 | } |
||
511 | |||
512 | /** |
||
513 | * @expectedException \yii\base\Exception |
||
514 | */ |
||
515 | public function testAppendToUpdateExceptionIsRaisedWhenTargetIsNewRecord() |
||
516 | { |
||
517 | $node = Node::findOne(2); |
||
518 | $node->appendTo(new Node())->save(); |
||
519 | } |
||
520 | |||
521 | /** |
||
522 | * @expectedException \yii\base\Exception |
||
523 | */ |
||
524 | public function testAppendToUpdateExceptionIsRaisedWhenTargetIsSame() |
||
525 | { |
||
526 | $node = Node::findOne(3); |
||
527 | $node->appendTo(Node::findOne(3))->save(); |
||
528 | } |
||
529 | |||
530 | /** |
||
531 | * @expectedException \yii\base\Exception |
||
532 | */ |
||
533 | public function testAppendToUpdateExceptionIsRaisedWhenTargetIsChild() |
||
534 | { |
||
535 | $node = Node::findOne(17); |
||
536 | $node->appendTo(Node::findOne(24))->save(); |
||
537 | } |
||
538 | |||
539 | View Code Duplication | public function testInsertBeforeInsertNoGap() |
|
540 | { |
||
541 | $node = new Node(['slug' => 'new']); |
||
542 | $this->assertTrue($node->insertBefore(Node::findOne(4))->save()); |
||
543 | |||
544 | $node = new AttributeModeNode(['slug' => 'new']); |
||
545 | $this->assertTrue($node->insertBefore(AttributeModeNode::findOne(4))->save()); |
||
546 | |||
547 | $node = new MultipleTreeNode(['slug' => 'new']); |
||
548 | $this->assertTrue($node->insertBefore(MultipleTreeNode::findOne(4))->save()); |
||
549 | |||
550 | $dataSet = $this->getConnection()->createDataSet(['tree', 'attribute_mode_tree', 'multiple_tree']); |
||
551 | $expectedDataSet = new ArrayDataSet(require(__DIR__ . '/data/test-insert-before-insert-no-gap.php')); |
||
552 | $this->assertDataSetsEqual($expectedDataSet, $dataSet); |
||
553 | } |
||
554 | |||
555 | View Code Duplication | public function testInsertBeforeInsertGap() |
|
556 | { |
||
557 | $node = new Node(['slug' => 'new']); |
||
558 | $this->assertTrue($node->insertBefore(Node::findOne(10))->save()); |
||
559 | |||
560 | $node = new AttributeModeNode(['slug' => 'new']); |
||
561 | $this->assertTrue($node->insertBefore(AttributeModeNode::findOne(10))->save()); |
||
562 | |||
563 | $node = new MultipleTreeNode(['slug' => 'new']); |
||
564 | $this->assertTrue($node->insertBefore(MultipleTreeNode::findOne(10))->save()); |
||
565 | |||
566 | $dataSet = $this->getConnection()->createDataSet(['tree', 'attribute_mode_tree', 'multiple_tree']); |
||
567 | $expectedDataSet = new ArrayDataSet(require(__DIR__ . '/data/test-insert-before-insert-gap.php')); |
||
568 | $this->assertDataSetsEqual($expectedDataSet, $dataSet); |
||
569 | } |
||
570 | |||
571 | View Code Duplication | public function testInsertBeforeInsertBegin() |
|
572 | { |
||
573 | $node = new Node(['slug' => 'new']); |
||
574 | $this->assertTrue($node->insertBefore(Node::findOne(24))->save()); |
||
575 | |||
576 | $node = new AttributeModeNode(['slug' => 'new']); |
||
577 | $this->assertTrue($node->insertBefore(AttributeModeNode::findOne(24))->save()); |
||
578 | |||
579 | $node = new MultipleTreeNode(['slug' => 'new']); |
||
580 | $this->assertTrue($node->insertBefore(MultipleTreeNode::findOne(24))->save()); |
||
581 | |||
582 | $dataSet = $this->getConnection()->createDataSet(['tree', 'attribute_mode_tree', 'multiple_tree']); |
||
583 | $expectedDataSet = new ArrayDataSet(require(__DIR__ . '/data/test-insert-before-insert-begin.php')); |
||
584 | $this->assertDataSetsEqual($expectedDataSet, $dataSet); |
||
585 | } |
||
586 | |||
587 | |||
588 | View Code Duplication | public function testInsertBeforeUpdateSameNode() |
|
589 | { |
||
590 | $node = Node::findOne(2); |
||
591 | $this->assertTrue($node->insertBefore(Node::findOne(4))->save()); |
||
592 | |||
593 | $node = AttributeModeNode::findOne(2); |
||
594 | $this->assertTrue($node->insertBefore(AttributeModeNode::findOne(4))->save()); |
||
595 | |||
596 | $node = MultipleTreeNode::findOne(2); |
||
597 | $this->assertTrue($node->insertBefore(MultipleTreeNode::findOne(4))->save()); |
||
598 | |||
599 | $dataSet = $this->getConnection()->createDataSet(['tree', 'attribute_mode_tree', 'multiple_tree']); |
||
600 | $expectedDataSet = new ArrayDataSet(require(__DIR__ . '/data/test-insert-before-update-same-node.php')); |
||
601 | $this->assertDataSetsEqual($expectedDataSet, $dataSet); |
||
602 | } |
||
603 | |||
604 | View Code Duplication | public function testInsertBeforeUpdateNext() |
|
605 | { |
||
606 | $node = Node::findOne(3); |
||
607 | $this->assertTrue($node->insertBefore(Node::findOne(4))->save()); |
||
608 | |||
609 | $node = AttributeModeNode::findOne(3); |
||
610 | $this->assertTrue($node->insertBefore(AttributeModeNode::findOne(4))->save()); |
||
611 | |||
612 | $node = MultipleTreeNode::findOne(3); |
||
613 | $this->assertTrue($node->insertBefore(MultipleTreeNode::findOne(4))->save()); |
||
614 | |||
615 | $dataSet = $this->getConnection()->createDataSet(['tree', 'attribute_mode_tree', 'multiple_tree']); |
||
616 | $expectedDataSet = new ArrayDataSet(require(__DIR__ . '/data/data.php')); |
||
617 | $this->assertDataSetsEqual($expectedDataSet, $dataSet); |
||
618 | } |
||
619 | |||
620 | View Code Duplication | public function testInsertBeforeUpdateAnotherTree() |
|
621 | { |
||
622 | $node = Node::findOne(14); |
||
623 | $this->assertTrue($node->insertBefore(Node::findOne(10))->save()); |
||
624 | |||
625 | $node = AttributeModeNode::findOne(14); |
||
626 | $this->assertTrue($node->insertBefore(AttributeModeNode::findOne(10))->save()); |
||
627 | |||
628 | $node = MultipleTreeNode::findOne(14); |
||
629 | $this->assertTrue($node->insertBefore(MultipleTreeNode::findOne(10))->save()); |
||
630 | |||
631 | $dataSet = $this->getConnection()->createDataSet(['tree', 'attribute_mode_tree', 'multiple_tree']); |
||
632 | $expectedDataSet = new ArrayDataSet(require(__DIR__ . '/data/test-insert-before-update-another-tree.php')); |
||
633 | $this->assertDataSetsEqual($expectedDataSet, $dataSet); |
||
634 | } |
||
635 | |||
636 | /** |
||
637 | * @expectedException \yii\base\Exception |
||
638 | */ |
||
639 | public function testInsertBeforeInsertExceptionIsRaisedWhenTargetIsNewRecord() |
||
640 | { |
||
641 | $node = new Node(['slug' => 'new']); |
||
642 | $node->insertBefore(new Node())->save(); |
||
643 | } |
||
644 | |||
645 | /** |
||
646 | * @expectedException \yii\base\Exception |
||
647 | */ |
||
648 | public function testInsertBeforeInsertExceptionIsRaisedWhenTargetIsRoot() |
||
649 | { |
||
650 | $node = new Node(['name' => 'new']); |
||
651 | $node->insertBefore(Node::findOne(1))->save(); |
||
652 | } |
||
653 | |||
654 | /** |
||
655 | * @expectedException \yii\base\Exception |
||
656 | */ |
||
657 | public function testInsertBeforeUpdateExceptionIsRaisedWhenTargetIsSame() |
||
658 | { |
||
659 | $node = Node::findOne(3); |
||
660 | $node->insertBefore(Node::findOne(3))->save(); |
||
661 | } |
||
662 | |||
663 | /** |
||
664 | * @expectedException \yii\base\Exception |
||
665 | */ |
||
666 | public function testInsertBeforeUpdateExceptionIsRaisedWhenTargetIsChild() |
||
667 | { |
||
668 | $node = Node::findOne(17); |
||
669 | $node->insertBefore(Node::findOne(24))->save(); |
||
670 | } |
||
671 | |||
672 | View Code Duplication | public function testInsertAfterInsertNoGap() |
|
673 | { |
||
674 | $node = new Node(['slug' => 'new']); |
||
675 | $this->assertTrue($node->insertAfter(Node::findOne(2))->save()); |
||
676 | |||
677 | $node = new AttributeModeNode(['slug' => 'new']); |
||
678 | $this->assertTrue($node->insertAfter(AttributeModeNode::findOne(2))->save()); |
||
679 | |||
680 | $node = new MultipleTreeNode(['slug' => 'new']); |
||
681 | $this->assertTrue($node->insertAfter(MultipleTreeNode::findOne(2))->save()); |
||
682 | |||
683 | $dataSet = $this->getConnection()->createDataSet(['tree', 'attribute_mode_tree', 'multiple_tree']); |
||
684 | $expectedDataSet = new ArrayDataSet(require(__DIR__ . '/data/test-insert-after-insert-no-gap.php')); |
||
685 | $this->assertDataSetsEqual($expectedDataSet, $dataSet); |
||
686 | } |
||
687 | |||
688 | View Code Duplication | public function testInsertAfterInsertGap() |
|
689 | { |
||
690 | $node = new Node(['slug' => 'new']); |
||
691 | $this->assertTrue($node->insertAfter(Node::findOne(11))->save()); |
||
692 | |||
693 | $node = new AttributeModeNode(['slug' => 'new']); |
||
694 | $this->assertTrue($node->insertAfter(AttributeModeNode::findOne(11))->save()); |
||
695 | |||
696 | $node = new MultipleTreeNode(['slug' => 'new']); |
||
697 | $this->assertTrue($node->insertAfter(MultipleTreeNode::findOne(11))->save()); |
||
698 | |||
699 | $dataSet = $this->getConnection()->createDataSet(['tree', 'attribute_mode_tree', 'multiple_tree']); |
||
700 | $expectedDataSet = new ArrayDataSet(require(__DIR__ . '/data/test-insert-after-insert-gap.php')); |
||
701 | $this->assertDataSetsEqual($expectedDataSet, $dataSet); |
||
702 | } |
||
703 | |||
704 | View Code Duplication | public function testInsertAfterInsertEnd() |
|
705 | { |
||
706 | $node = new Node(['slug' => 'new']); |
||
707 | $this->assertTrue($node->insertAfter(Node::findOne(23))->save()); |
||
708 | |||
709 | $node = new AttributeModeNode(['slug' => 'new']); |
||
710 | $this->assertTrue($node->insertAfter(AttributeModeNode::findOne(23))->save()); |
||
711 | |||
712 | $node = new MultipleTreeNode(['slug' => 'new']); |
||
713 | $this->assertTrue($node->insertAfter(MultipleTreeNode::findOne(23))->save()); |
||
714 | |||
715 | $dataSet = $this->getConnection()->createDataSet(['tree', 'attribute_mode_tree', 'multiple_tree']); |
||
716 | $expectedDataSet = new ArrayDataSet(require(__DIR__ . '/data/test-insert-after-insert-end.php')); |
||
717 | $this->assertDataSetsEqual($expectedDataSet, $dataSet); |
||
718 | } |
||
719 | |||
720 | View Code Duplication | public function testInsertAfterUpdateSameNode() |
|
721 | { |
||
722 | $node = Node::findOne(4); |
||
723 | $this->assertTrue($node->insertAfter(Node::findOne(2))->save()); |
||
724 | |||
725 | $node = AttributeModeNode::findOne(4); |
||
726 | $this->assertTrue($node->insertAfter(AttributeModeNode::findOne(2))->save()); |
||
727 | |||
728 | $node = MultipleTreeNode::findOne(4); |
||
729 | $this->assertTrue($node->insertAfter(MultipleTreeNode::findOne(2))->save()); |
||
730 | |||
731 | $dataSet = $this->getConnection()->createDataSet(['tree', 'attribute_mode_tree', 'multiple_tree']); |
||
732 | $expectedDataSet = new ArrayDataSet(require(__DIR__ . '/data/test-insert-after-update-same-node.php')); |
||
733 | $this->assertDataSetsEqual($expectedDataSet, $dataSet); |
||
734 | } |
||
735 | |||
736 | View Code Duplication | public function testInsertAfterUpdatePrev() |
|
737 | { |
||
738 | $node = Node::findOne(3); |
||
739 | $this->assertTrue($node->insertAfter(Node::findOne(2))->save()); |
||
740 | |||
741 | $node = AttributeModeNode::findOne(3); |
||
742 | $this->assertTrue($node->insertAfter(AttributeModeNode::findOne(2))->save()); |
||
743 | |||
744 | $node = MultipleTreeNode::findOne(3); |
||
745 | $this->assertTrue($node->insertAfter(MultipleTreeNode::findOne(2))->save()); |
||
746 | |||
747 | $dataSet = $this->getConnection()->createDataSet(['tree', 'attribute_mode_tree', 'multiple_tree']); |
||
748 | $expectedDataSet = new ArrayDataSet(require(__DIR__ . '/data/data.php')); |
||
749 | $this->assertDataSetsEqual($expectedDataSet, $dataSet); |
||
750 | } |
||
751 | |||
752 | View Code Duplication | public function testInsertAfterUpdateAnotherTree() |
|
753 | { |
||
754 | $node = Node::findOne(14); |
||
755 | $this->assertTrue($node->insertAfter(Node::findOne(11))->save()); |
||
756 | |||
757 | $node = AttributeModeNode::findOne(14); |
||
758 | $this->assertTrue($node->insertAfter(AttributeModeNode::findOne(11))->save()); |
||
759 | |||
760 | $node = MultipleTreeNode::findOne(14); |
||
761 | $this->assertTrue($node->insertAfter(MultipleTreeNode::findOne(11))->save()); |
||
762 | |||
763 | $dataSet = $this->getConnection()->createDataSet(['tree', 'attribute_mode_tree', 'multiple_tree']); |
||
764 | $expectedDataSet = new ArrayDataSet(require(__DIR__ . '/data/test-insert-after-update-another-tree.php')); |
||
765 | $this->assertDataSetsEqual($expectedDataSet, $dataSet); |
||
766 | } |
||
767 | |||
768 | /** |
||
769 | * @expectedException \yii\base\Exception |
||
770 | */ |
||
771 | public function testInsertAfterInsertExceptionIsRaisedWhenTargetIsNewRecord() |
||
772 | { |
||
773 | $node = new Node(['slug' => 'new']); |
||
774 | $node->insertAfter(new Node())->save(); |
||
775 | } |
||
776 | |||
777 | /** |
||
778 | * @expectedException \yii\base\Exception |
||
779 | */ |
||
780 | public function testInsertAfterInsertExceptionIsRaisedWhenTargetIsRoot() |
||
781 | { |
||
782 | $node = new Node(['slug' => 'new']); |
||
783 | $node->insertAfter(Node::findOne(1))->save(); |
||
784 | } |
||
785 | |||
786 | /** |
||
787 | * @expectedException \yii\base\Exception |
||
788 | */ |
||
789 | public function testInsertAfterUpdateExceptionIsRaisedWhenTargetIsSame() |
||
790 | { |
||
791 | $node = Node::findOne(3); |
||
792 | $node->insertAfter(Node::findOne(3))->save(); |
||
793 | } |
||
794 | |||
795 | /** |
||
796 | * @expectedException \yii\base\Exception |
||
797 | */ |
||
798 | public function testInsertAfterUpdateExceptionIsRaisedWhenTargetIsChild() |
||
799 | { |
||
800 | $node = Node::findOne(17); |
||
801 | $node->insertAfter(Node::findOne(24))->save(); |
||
802 | } |
||
803 | |||
804 | View Code Duplication | public function testDelete() |
|
805 | { |
||
806 | $this->assertEquals(1, Node::findOne(3)->delete()); |
||
807 | |||
808 | $this->assertEquals(1, AttributeModeNode::findOne(3)->delete()); |
||
809 | |||
810 | $this->assertEquals(1, MultipleTreeNode::findOne(3)->delete()); |
||
811 | |||
812 | $dataSet = $this->getConnection()->createDataSet(['tree', 'attribute_mode_tree', 'multiple_tree']); |
||
813 | $expectedDataSet = new ArrayDataSet(require(__DIR__ . '/data/test-delete.php')); |
||
814 | $this->assertDataSetsEqual($expectedDataSet, $dataSet); |
||
815 | } |
||
816 | |||
817 | /** |
||
818 | * @expectedException \yii\base\Exception |
||
819 | */ |
||
820 | public function testDeleteRoot() |
||
821 | { |
||
822 | Node::findOne(1)->delete(); |
||
823 | } |
||
824 | |||
825 | /** |
||
826 | * @expectedException \yii\base\Exception |
||
827 | */ |
||
828 | public function testDeleteExceptionIsRaisedWhenNodeIsNewRecord() |
||
829 | { |
||
830 | $node = new Node(['slug' => 'new']); |
||
831 | $node->delete(); |
||
832 | } |
||
833 | |||
834 | View Code Duplication | public function testDeleteWithChildren() |
|
835 | { |
||
836 | $this->assertEquals(4, Node::findOne(3)->deleteWithChildren()); |
||
837 | |||
838 | $this->assertEquals(4, AttributeModeNode::findOne(3)->deleteWithChildren()); |
||
839 | |||
840 | $this->assertEquals(4, MultipleTreeNode::findOne(3)->deleteWithChildren()); |
||
841 | |||
842 | $dataSet = $this->getConnection()->createDataSet(['tree', 'attribute_mode_tree', 'multiple_tree']); |
||
843 | $expectedDataSet = new ArrayDataSet(require(__DIR__ . '/data/test-delete-with-children.php')); |
||
844 | $this->assertDataSetsEqual($expectedDataSet, $dataSet); |
||
845 | } |
||
846 | |||
847 | View Code Duplication | public function testDeleteWithChildrenRoot() |
|
848 | { |
||
849 | $this->assertEquals(13, Node::findOne(1)->deleteWithChildren()); |
||
850 | |||
851 | $this->assertEquals(13, AttributeModeNode::findOne(1)->deleteWithChildren()); |
||
852 | |||
853 | $this->assertEquals(13, MultipleTreeNode::findOne(1)->deleteWithChildren()); |
||
854 | |||
855 | $dataSet = $this->getConnection()->createDataSet(['tree', 'attribute_mode_tree', 'multiple_tree']); |
||
856 | $expectedDataSet = new ArrayDataSet(require(__DIR__ . '/data/test-delete-with-children-root.php')); |
||
857 | $this->assertDataSetsEqual($expectedDataSet, $dataSet); |
||
858 | } |
||
859 | |||
860 | /** |
||
861 | * @expectedException \yii\base\Exception |
||
862 | */ |
||
863 | public function testDeleteWithChildrenExceptionIsRaisedWhenNodeIsNewRecord() |
||
864 | { |
||
865 | $node = new Node(['slug' => 'new']); |
||
866 | $node->deleteWithChildren(); |
||
867 | } |
||
868 | |||
869 | public function testReorderChildren() |
||
870 | { |
||
871 | $this->assertEquals(true, Node::findOne(4)->reorderChildren(true) > 0); |
||
872 | |||
873 | $this->assertEquals(true, MultipleTreeNode::findOne(4)->reorderChildren(false) > 0); |
||
874 | |||
875 | $dataSet = $this->getConnection()->createDataSet(['tree', 'attribute_mode_tree', 'multiple_tree']); |
||
876 | $expectedDataSet = new ArrayDataSet(require(__DIR__ . '/data/test-reorder-children.php')); |
||
877 | $this->assertDataSetsEqual($expectedDataSet, $dataSet); |
||
878 | } |
||
879 | |||
880 | /** |
||
881 | * @expectedException \yii\base\NotSupportedException |
||
882 | */ |
||
883 | public function testExceptionIsRaisedWhenInsertIsCalled() |
||
884 | { |
||
885 | $node = new Node(['slug' => 'new']); |
||
886 | $node->insert(); |
||
887 | } |
||
888 | |||
889 | public function testUpdate() |
||
890 | { |
||
891 | $node = Node::findOne(3); |
||
892 | $node->slug = 'update'; |
||
893 | $this->assertEquals(1, $node->update()); |
||
894 | } |
||
895 | |||
896 | } |
This check compares calls to functions or methods with their respective definitions. If the call has more arguments than are defined, it raises an issue.
If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress.
In this case you can add the
@ignore
PhpDoc annotation to the duplicate definition and it will be ignored.