@@ -8,82 +8,54 @@ class PathHelperTest extends \PHPUnit_Framework_TestCase
88{
99 // assertValidPath tests
1010
11- public function testAssertValidPath ()
12- {
13- $ this ->assertTrue (PathHelper::assertValidAbsolutePath ('/parent/child ' ));
14- }
15-
16- public function testAssertValidPathRoot ()
17- {
18- $ this ->assertTrue (PathHelper::assertValidAbsolutePath ('/ ' ));
19- }
20-
21- public function testAssertValidPathNamespaced ()
22- {
23- $ this ->assertTrue (PathHelper::assertValidAbsolutePath ('/jcr:foo_/b-a/0^.txt ' ));
24- }
25-
26- public function testAssertValidPathIndexed ()
27- {
28- $ this ->assertTrue (PathHelper::assertValidAbsolutePath ('/parent[7]/child ' ));
29- }
30-
31- public function testAssertValidPathIndexedAtEnd ()
32- {
33- $ this ->assertTrue (PathHelper::assertValidAbsolutePath ('/parent[7]/child[3] ' ));
34- }
35-
36- /**
37- * @expectedException \PHPCR\RepositoryException
38- */
39- public function testAssertValidTargetPathNoIndex ()
40- {
41- PathHelper::assertValidAbsolutePath ('/parent/child[7] ' , true );
42- }
43-
4411 /**
45- * @expectedException \PHPCR\RepositoryException
12+ * @dataProvider dataproviderValidAbsolutePaths
4613 */
47- public function testAssertValidPathNotAbsolute ( )
14+ public function testAssertValidAbsolutePath ( $ path , $ destination = false )
4815 {
49- PathHelper::assertValidAbsolutePath (' parent ' );
16+ $ this -> assertTrue ( PathHelper::assertValidAbsolutePath ($ path , $ destination ) );
5017 }
5118
52- /**
53- * @expectedException \PHPCR\RepositoryException
54- */
55- public function testAssertValidPathDouble ()
19+ public function dataproviderValidAbsolutePaths ()
5620 {
57- PathHelper::assertValidAbsolutePath ('/parent//child ' );
58- }
59-
60- /**
61- * @expectedException \PHPCR\RepositoryException
62- */
63- public function testAssertValidPathParent ()
64- {
65- PathHelper::assertValidAbsolutePath ('/parent/../child ' );
21+ return array (
22+ array ('/parent/child ' ),
23+ array ('/ ' ),
24+ array ('/jcr:foo_/b-a/0^.txt ' ),
25+ array ('/parent[7]/child ' ),
26+ array ('/parent[7]/child ' , true ), // index is allowed in destination parent path, only not in last element
27+ array ('/parent[7]/child[3] ' ),
28+ );
6629 }
6730
6831 /**
32+ * @dataProvider dataproviderInvalidAbsolutePaths
6933 * @expectedException \PHPCR\RepositoryException
7034 */
71- public function testAssertValidPathSelf ( )
35+ public function testAssertInvalidAbsolutePath ( $ path , $ destination = false )
7236 {
73- PathHelper::assertValidAbsolutePath (' /parent/./child ' );
37+ PathHelper::assertValidAbsolutePath ($ path , $ destination );
7438 }
7539
7640 /**
77- * @expectedException \PHPCR\RepositoryException
41+ * @dataProvider dataproviderInvalidAbsolutePaths
7842 */
79- public function testAssertValidPathTrailing ( )
43+ public function testAssertInvalidAbsolutePathNoThrow ( $ path , $ destination = false )
8044 {
81- PathHelper::assertValidAbsolutePath (' /parent/child/ ' );
45+ $ this -> assertFalse ( PathHelper::assertValidAbsolutePath ($ path , $ destination , false ) );
8246 }
8347
84- public function testAssertValidPathNoThrow ()
48+ public function dataproviderInvalidAbsolutePaths ()
8549 {
86- $ this ->assertFalse (PathHelper::assertValidAbsolutePath ('parent ' , false , false ));
50+ return array (
51+ array ('/parent/child[7] ' , true ), // destination last element with index
52+ array ('parent ' ), // not absolute
53+ array ('/parent//child ' ),
54+ array ('// ' ),
55+ array ('/parent/../child ' ),
56+ array ('/parent/./child ' ),
57+ array ('/parent/child/ ' ),
58+ );
8759 }
8860
8961 // assertValidLocalName tests
@@ -99,35 +71,22 @@ public function testAssertValidLocalNameRootnode()
9971 }
10072
10173 /**
74+ * @dataProvider dataproviderInvalidLocalNames
10275 * @expectedException \PHPCR\RepositoryException
10376 */
104- public function testAssertValidLocalNameNamespaced ()
105- {
106- $ this ->assertTrue (PathHelper::assertValidLocalName ('jcr:nodename ' ));
107- }
108-
109- /**
110- * @expectedException \PHPCR\RepositoryException
111- */
112- public function testAssertValidLocalNamePath ()
77+ public function testAssertInvalidLocalName ($ name )
11378 {
114- $ this -> assertTrue ( PathHelper::assertValidLocalName (' /path ' ) );
79+ PathHelper::assertValidLocalName ($ name );
11580 }
11681
117- /**
118- * @expectedException \PHPCR\RepositoryException
119- */
120- public function testAssertValidLocalNameSelf ()
82+ public function dataproviderInvalidLocalNames ()
12183 {
122- PathHelper::assertValidLocalName ('. ' );
123- }
124-
125- /**
126- * @expectedException \PHPCR\RepositoryException
127- */
128- public function testAssertValidLocalNameParent ()
129- {
130- PathHelper::assertValidLocalName ('.. ' );
84+ return array (
85+ array ('jcr:nodename ' ),
86+ array ('/path ' ),
87+ array ('. ' ),
88+ array ('.. ' )
89+ );
13190 }
13291
13392 // normalizePath tests
@@ -151,17 +110,6 @@ public static function dataproviderNormalizePath()
151110 );
152111 }
153112
154- public static function dataproviderNormalizePathInvalid ()
155- {
156- return array (
157- array ('foo/bar ' ),
158- array ('bar ' ),
159- array ('/foo/bar/ ' ),
160- array ('' ),
161- array (new \stdClass ()),
162- );
163- }
164-
165113 /**
166114 * @dataProvider dataproviderNormalizePathInvalid
167115 * @expectedException \PHPCR\RepositoryException
@@ -179,6 +127,17 @@ public function testNormalizePathInvalidNoThrow($input)
179127 $ this ->assertFalse (PathHelper::normalizePath ($ input , true , false ));
180128 }
181129
130+ public static function dataproviderNormalizePathInvalid ()
131+ {
132+ return array (
133+ array ('foo/bar ' ),
134+ array ('bar ' ),
135+ array ('/foo/bar/ ' ),
136+ array ('' ),
137+ array (new \stdClass ()),
138+ );
139+ }
140+
182141 // absolutizePath tests
183142
184143 /**
@@ -229,27 +188,35 @@ public static function dataproviderAbsolutizePathInvalid()
229188
230189 // getParentPath tests
231190
232- public function testGetParentPath ()
191+ /**
192+ * @dataProvider dataproviderParentPath
193+ */
194+ public function testGetParentPath ($ path , $ parent )
233195 {
234- $ this ->assertEquals (' / parent' , PathHelper::getParentPath (' /parent/child ' ));
196+ $ this ->assertEquals ($ parent , PathHelper::getParentPath ($ path ));
235197 }
236198
237- public function testGetParentPathNamespaced ()
199+ public function dataproviderParentPath ()
238200 {
239- $ this ->assertEquals ('/jcr:parent ' , PathHelper::getParentPath ('/jcr:parent/ns:child ' ));
201+ return array (
202+ array ('/parent/child ' , '/parent ' ),
203+ array ('/jcr:parent/ns:child ' , '/jcr:parent ' ),
204+ array ('/child ' , '/ ' ),
205+ array ('/ ' , '/ ' ),
206+ );
240207 }
241208
242- public function testGetParentPathNodeAtRoot ()
243- {
244- $ this ->assertEquals ('/ ' , PathHelper::getParentPath ('/parent ' ));
245- }
209+ // getNodeName tests
246210
247- public function testGetParentPathRoot ()
211+ /**
212+ * @dataProvider dataproviderGetNodeName
213+ */
214+ public function testGetNodeName ($ path , $ expected = null )
248215 {
249- $ this ->assertEquals (' / ' , PathHelper::getParentPath ( ' / ' ));
216+ $ this ->assertEquals ($ expected , PathHelper::getNodeName ( $ path ));
250217 }
251218
252- public function provideGetNodeName ()
219+ public function dataproviderGetNodeName ()
253220 {
254221 return array (
255222 array ('/parent/child ' , 'child ' ),
@@ -259,27 +226,31 @@ public function provideGetNodeName()
259226 }
260227
261228 /**
262- * @dataProvider provideGetNodeName
229+ * @expectedException \PHPCR\RepositoryException
230+ * @expectedExceptionMessage must be an absolute path
263231 */
264- public function testGetNodeName ( $ path , $ expected = null )
232+ public function testGetNodeNameMustBeAbsolute ( )
265233 {
266- $ this -> assertEquals ( $ expected , PathHelper::getNodeName ($ path ) );
234+ PathHelper::getNodeName (' foobar ' );
267235 }
268236
237+ // getPathDepth tests
238+
269239 /**
270- * @expectedException PHPCR\RepositoryException
271- * @expectedExceptionMessage must be an absolute path
240+ * @dataProvider dataproviderPathDepth
272241 */
273- public function testGetNodeNameMustBeAbsolute ( )
242+ public function testGetPathDepth ( $ path , $ depth )
274243 {
275- PathHelper::getNodeName ( ' foobar ' );
244+ $ this -> assertEquals ( $ depth , PathHelper::getPathDepth ( $ path ) );
276245 }
277246
278- public function testGetPathDepth ()
247+ public function dataproviderPathDepth ()
279248 {
280- $ this ->assertEquals (0 , PathHelper::getPathDepth ('/ ' ));
281- $ this ->assertEquals (1 , PathHelper::getPathDepth ('/foo ' ));
282- $ this ->assertEquals (2 , PathHelper::getPathDepth ('/foo/bar ' ));
283- $ this ->assertEquals (2 , PathHelper::getPathDepth ('/foo/bar/ ' ));
249+ return array (
250+ array ('/ ' , 0 ),
251+ array ('/foo ' , 1 ),
252+ array ('/foo/bar ' , 2 ),
253+ array ('/foo/bar/ ' , 2 ),
254+ );
284255 }
285256}
0 commit comments