@@ -22,7 +22,12 @@ abstract class PhpcrRepositoryTestCase extends RepositoryTestCase
22
22
/**
23
23
* @var SessionInterface
24
24
*/
25
- protected $ session ;
25
+ private $ session ;
26
+
27
+ /**
28
+ * @var NodeInterface
29
+ */
30
+ private $ baseNode ;
26
31
27
32
protected function setUp ()
28
33
{
@@ -34,21 +39,21 @@ protected function setUp()
34
39
$ rootNode = $ this ->session ->getRootNode ();
35
40
36
41
// the resource repository is based at "/test"
37
- $ node = $ rootNode ->addNode ('/test ' );
38
-
39
- $ sub1 = $ node ->addNode ('node-1 ' );
40
- $ sub1 ->addNode ('node-1-1 ' );
41
- $ sub1 ->addNode ('node-1-2 ' );
42
- $ node ->addNode ('node-2 ' );
43
-
44
- $ this ->session ->save ();
42
+ $ this ->baseNode = $ rootNode ->addNode ('/test ' );
45
43
}
46
44
47
45
/**
48
46
* @dataProvider provideGet
49
47
*/
50
48
public function testGet ($ path , $ expectedName )
51
49
{
50
+ $ sub1 = $ this ->baseNode ->addNode ('node-1 ' );
51
+ $ sub1 ->addNode ('node-1-1 ' );
52
+ $ sub1 ->addNode ('node-1-2 ' );
53
+ $ this ->baseNode ->addNode ('node-2 ' );
54
+ $ this ->session ->save ();
55
+
56
+ $ this ->session ->save ();
52
57
$ res = $ this ->getRepository ()->get ($ path );
53
58
$ this ->assertNotNull ($ res );
54
59
$ payload = $ res ->getPayload ();
@@ -73,6 +78,12 @@ public function provideGet()
73
78
*/
74
79
public function testFind ($ pattern , $ nbResults )
75
80
{
81
+ $ sub1 = $ this ->baseNode ->addNode ('node-1 ' );
82
+ $ sub1 ->addNode ('node-1-1 ' );
83
+ $ sub1 ->addNode ('node-1-2 ' );
84
+ $ this ->baseNode ->addNode ('node-2 ' );
85
+ $ this ->session ->save ();
86
+
76
87
$ res = $ this ->getRepository ()->find ($ pattern );
77
88
$ this ->assertCount ($ nbResults , $ res );
78
89
}
@@ -90,6 +101,12 @@ public function provideFind()
90
101
*/
91
102
public function testMove ($ sourcePath , $ targetPath , $ expectedPaths )
92
103
{
104
+ $ sub1 = $ this ->baseNode ->addNode ('node-1 ' );
105
+ $ sub1 ->addNode ('node-1-1 ' );
106
+ $ sub1 ->addNode ('node-1-2 ' );
107
+ $ this ->baseNode ->addNode ('node-2 ' );
108
+ $ this ->session ->save ();
109
+
93
110
$ expectedNbMoved = count ($ expectedPaths );
94
111
95
112
$ nbMoved = $ this ->getRepository ()->move ($ sourcePath , $ targetPath );
@@ -121,6 +138,12 @@ public function provideMove()
121
138
*/
122
139
public function testRemove ($ path , $ expectedRemovedPaths )
123
140
{
141
+ $ sub1 = $ this ->baseNode ->addNode ('node-1 ' );
142
+ $ sub1 ->addNode ('node-1-1 ' );
143
+ $ sub1 ->addNode ('node-1-2 ' );
144
+ $ this ->baseNode ->addNode ('node-2 ' );
145
+ $ this ->session ->save ();
146
+
124
147
$ expectedNbRemoved = count ($ expectedRemovedPaths );
125
148
$ nbRemoved = $ this ->getRepository ()->remove ($ path );
126
149
$ this ->assertEquals ($ expectedNbRemoved , $ nbRemoved );
@@ -144,4 +167,44 @@ public function provideRemove()
144
167
['/node-1/* ' , ['/test/node-1-1 ' , '/test/node-1-2 ' ]],
145
168
];
146
169
}
170
+
171
+ /**
172
+ * @dataProvider provideReorder
173
+ */
174
+ public function testReorder ($ path , $ index , $ newOrder )
175
+ {
176
+ $ this ->baseNode ->addNode ('node-1 ' );
177
+ $ this ->baseNode ->addNode ('node-2 ' );
178
+ $ this ->baseNode ->addNode ('node-3 ' );
179
+ $ this ->session ->save ();
180
+
181
+ $ this ->getRepository ()->reorder ($ path , $ index );
182
+
183
+ $ node = $ this ->session ->getNode ('/test ' .$ path );
184
+ $ parent = $ node ->getParent ();
185
+ $ nodeNames = $ parent ->getNodeNames ();
186
+ $ this ->assertEquals ($ newOrder , iterator_to_array ($ nodeNames ));
187
+ }
188
+
189
+ public function provideReorder ()
190
+ {
191
+ return [
192
+ ['/node-1 ' , 1 , ['node-2 ' , 'node-1 ' , 'node-3 ' ]],
193
+ ['/node-1 ' , 2 , ['node-2 ' , 'node-3 ' , 'node-1 ' ]],
194
+ ['/node-1 ' , 0 , ['node-1 ' , 'node-2 ' , 'node-3 ' ]],
195
+ ['/node-3 ' , 0 , ['node-3 ' , 'node-1 ' , 'node-2 ' ]],
196
+ ['/node-1 ' , 66 , ['node-2 ' , 'node-3 ' , 'node-1 ' ]],
197
+ ];
198
+ }
199
+
200
+ /**
201
+ * It should throw an exception if the reorder index is less than zero.
202
+ *
203
+ * @expectedException \InvalidArgumentException
204
+ * @expectedExceptionMessage Reorder position cannot be negative, got: -5
205
+ */
206
+ public function testReorderNegative ()
207
+ {
208
+ $ this ->getRepository ()->reorder ('/foo ' , -5 );
209
+ }
147
210
}
0 commit comments