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