|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
declare(strict_types=1); |
|
4
|
|
|
|
|
5
|
|
|
namespace StefanoTreeTest\Integration\Adapter; |
|
6
|
|
|
|
|
7
|
|
|
use StefanoTree\NestedSet\Adapter\AdapterInterface as TreeAdapterInterface; |
|
8
|
|
|
use StefanoTreeTest\IntegrationTestCase; |
|
9
|
|
|
|
|
10
|
|
|
abstract class AdapterJoinTableTestAbstract extends IntegrationTestCase |
|
11
|
|
|
{ |
|
12
|
|
|
/** |
|
13
|
|
|
* @var TreeAdapterInterface |
|
14
|
|
|
*/ |
|
15
|
|
|
protected $adapter; |
|
16
|
|
|
|
|
17
|
|
|
protected function setUp() |
|
18
|
|
|
{ |
|
19
|
|
|
$this->adapter = $this->getAdapter(); |
|
20
|
|
|
|
|
21
|
|
|
parent::setUp(); |
|
22
|
|
|
} |
|
23
|
|
|
|
|
24
|
|
|
protected function tearDown() |
|
25
|
|
|
{ |
|
26
|
|
|
$this->adapter = null; |
|
27
|
|
|
parent::tearDown(); |
|
28
|
|
|
} |
|
29
|
|
|
|
|
30
|
|
|
/** |
|
31
|
|
|
* @return TreeAdapterInterface |
|
32
|
|
|
*/ |
|
33
|
|
|
abstract protected function getAdapter(); |
|
34
|
|
|
|
|
35
|
|
|
protected function getDataSet() |
|
36
|
|
|
{ |
|
37
|
|
|
return $this->createMySQLXMLDataSet(__DIR__.'/_files/adapter/join_table/initDataSet.xml'); |
|
38
|
|
|
} |
|
39
|
|
|
|
|
40
|
|
|
public function testGetNode() |
|
41
|
|
|
{ |
|
42
|
|
|
$nodes = $this->adapter |
|
43
|
|
|
->getDescendants(10); |
|
44
|
|
|
|
|
45
|
|
|
$expected = array( |
|
46
|
|
|
array( |
|
47
|
|
|
'tree_traversal_id' => 10, |
|
48
|
|
|
'name' => null, |
|
49
|
|
|
'lft' => 5, |
|
50
|
|
|
'rgt' => 6, |
|
51
|
|
|
'parent_id' => 9, |
|
52
|
|
|
'level' => 4, |
|
53
|
|
|
'scope' => 1, |
|
54
|
|
|
'metadata' => 'meta-10', |
|
55
|
|
|
), |
|
56
|
|
|
); |
|
57
|
|
|
$this->assertEquals($expected, $nodes); |
|
58
|
|
|
} |
|
59
|
|
|
|
|
60
|
|
|
public function testGetAncestors() |
|
61
|
|
|
{ |
|
62
|
|
|
$nodes = $this->adapter |
|
63
|
|
|
->getAncestors(10, 2, 1); |
|
64
|
|
|
|
|
65
|
|
|
$expected = array( |
|
66
|
|
|
array( |
|
67
|
|
|
'tree_traversal_id' => 8, |
|
68
|
|
|
'name' => null, |
|
69
|
|
|
'lft' => 3, |
|
70
|
|
|
'rgt' => 8, |
|
71
|
|
|
'parent_id' => 7, |
|
72
|
|
|
'level' => 2, |
|
73
|
|
|
'scope' => 1, |
|
74
|
|
|
'metadata' => null, |
|
75
|
|
|
), |
|
76
|
|
|
array( |
|
77
|
|
|
'tree_traversal_id' => 9, |
|
78
|
|
|
'name' => null, |
|
79
|
|
|
'lft' => 4, |
|
80
|
|
|
'rgt' => 7, |
|
81
|
|
|
'parent_id' => 8, |
|
82
|
|
|
'level' => 3, |
|
83
|
|
|
'scope' => 1, |
|
84
|
|
|
'metadata' => 'meta-9', |
|
85
|
|
|
), |
|
86
|
|
|
); |
|
87
|
|
|
$this->assertEquals($expected, $nodes); |
|
88
|
|
|
} |
|
89
|
|
|
|
|
90
|
|
|
public function testGetDescendants() |
|
91
|
|
|
{ |
|
92
|
|
|
$nodes = $this->adapter |
|
93
|
|
|
->getDescendants(2, 1, 1, 4); |
|
94
|
|
|
|
|
95
|
|
|
$expected = array( |
|
96
|
|
|
array( |
|
97
|
|
|
'tree_traversal_id' => 3, |
|
98
|
|
|
'name' => null, |
|
99
|
|
|
'lft' => 3, |
|
100
|
|
|
'rgt' => 4, |
|
101
|
|
|
'parent_id' => 2, |
|
102
|
|
|
'level' => 2, |
|
103
|
|
|
'scope' => 2, |
|
104
|
|
|
'metadata' => null, |
|
105
|
|
|
), |
|
106
|
|
|
array( |
|
107
|
|
|
'tree_traversal_id' => 5, |
|
108
|
|
|
'name' => null, |
|
109
|
|
|
'lft' => 7, |
|
110
|
|
|
'rgt' => 8, |
|
111
|
|
|
'parent_id' => 2, |
|
112
|
|
|
'level' => 2, |
|
113
|
|
|
'scope' => 2, |
|
114
|
|
|
'metadata' => null, |
|
115
|
|
|
), |
|
116
|
|
|
); |
|
117
|
|
|
$this->assertEquals($expected, $nodes); |
|
118
|
|
|
} |
|
119
|
|
|
|
|
120
|
|
|
public function testGetChildrenNodeInfo() |
|
121
|
|
|
{ |
|
122
|
|
|
$nodes = $this->adapter |
|
123
|
|
|
->getChildrenNodeInfo(2); |
|
124
|
|
|
|
|
125
|
|
|
$this->assertEquals(3, count($nodes)); |
|
126
|
|
|
} |
|
127
|
|
|
|
|
128
|
|
|
public function testGetNodeInfo() |
|
129
|
|
|
{ |
|
130
|
|
|
$nodeInfo = $this->adapter |
|
131
|
|
|
->getNodeInfo(2); |
|
132
|
|
|
|
|
133
|
|
|
$this->assertEquals($nodeInfo->getId(), 2); |
|
134
|
|
|
$this->assertEquals($nodeInfo->getParentId(), 1); |
|
135
|
|
|
$this->assertEquals($nodeInfo->getLeft(), 2); |
|
136
|
|
|
$this->assertEquals($nodeInfo->getRight(), 9); |
|
137
|
|
|
$this->assertEquals($nodeInfo->getLevel(), 1); |
|
138
|
|
|
$this->assertEquals($nodeInfo->getScope(), 2); |
|
139
|
|
|
} |
|
140
|
|
|
} |
|
141
|
|
|
|