@@ -22,7 +22,12 @@ abstract class PhpcrRepositoryTestCase extends RepositoryTestCase
2222 /**
2323 * @var SessionInterface
2424 */
25- protected $ session ;
25+ private $ session ;
26+
27+ /**
28+ * @var NodeInterface
29+ */
30+ private $ baseNode ;
2631
2732 protected function setUp ()
2833 {
@@ -34,21 +39,21 @@ protected function setUp()
3439 $ rootNode = $ this ->session ->getRootNode ();
3540
3641 // 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 ' );
4543 }
4644
4745 /**
4846 * @dataProvider provideGet
4947 */
5048 public function testGet ($ path , $ expectedName )
5149 {
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 ();
5257 $ res = $ this ->getRepository ()->get ($ path );
5358 $ this ->assertNotNull ($ res );
5459 $ payload = $ res ->getPayload ();
@@ -73,6 +78,12 @@ public function provideGet()
7378 */
7479 public function testFind ($ pattern , $ nbResults )
7580 {
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+
7687 $ res = $ this ->getRepository ()->find ($ pattern );
7788 $ this ->assertCount ($ nbResults , $ res );
7889 }
@@ -90,6 +101,12 @@ public function provideFind()
90101 */
91102 public function testMove ($ sourcePath , $ targetPath , $ expectedPaths )
92103 {
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+
93110 $ expectedNbMoved = count ($ expectedPaths );
94111
95112 $ nbMoved = $ this ->getRepository ()->move ($ sourcePath , $ targetPath );
@@ -121,6 +138,12 @@ public function provideMove()
121138 */
122139 public function testRemove ($ path , $ expectedRemovedPaths )
123140 {
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+
124147 $ expectedNbRemoved = count ($ expectedRemovedPaths );
125148 $ nbRemoved = $ this ->getRepository ()->remove ($ path );
126149 $ this ->assertEquals ($ expectedNbRemoved , $ nbRemoved );
@@ -144,4 +167,44 @@ public function provideRemove()
144167 ['/node-1/* ' , ['/test/node-1-1 ' , '/test/node-1-2 ' ]],
145168 ];
146169 }
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+ }
147210}
0 commit comments