@@ -8,82 +8,54 @@ class PathHelperTest extends \PHPUnit_Framework_TestCase
8
8
{
9
9
// assertValidPath tests
10
10
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
-
44
11
/**
45
- * @expectedException \PHPCR\RepositoryException
12
+ * @dataProvider dataproviderValidAbsolutePaths
46
13
*/
47
- public function testAssertValidPathNotAbsolute ( )
14
+ public function testAssertValidAbsolutePath ( $ path , $ destination = false )
48
15
{
49
- PathHelper::assertValidAbsolutePath (' parent ' );
16
+ $ this -> assertTrue ( PathHelper::assertValidAbsolutePath ($ path , $ destination ) );
50
17
}
51
18
52
- /**
53
- * @expectedException \PHPCR\RepositoryException
54
- */
55
- public function testAssertValidPathDouble ()
19
+ public function dataproviderValidAbsolutePaths ()
56
20
{
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
+ );
66
29
}
67
30
68
31
/**
32
+ * @dataProvider dataproviderInvalidAbsolutePaths
69
33
* @expectedException \PHPCR\RepositoryException
70
34
*/
71
- public function testAssertValidPathSelf ( )
35
+ public function testAssertInvalidAbsolutePath ( $ path , $ destination = false )
72
36
{
73
- PathHelper::assertValidAbsolutePath (' /parent/./child ' );
37
+ PathHelper::assertValidAbsolutePath ($ path , $ destination );
74
38
}
75
39
76
40
/**
77
- * @expectedException \PHPCR\RepositoryException
41
+ * @dataProvider dataproviderInvalidAbsolutePaths
78
42
*/
79
- public function testAssertValidPathTrailing ( )
43
+ public function testAssertInvalidAbsolutePathNoThrow ( $ path , $ destination = false )
80
44
{
81
- PathHelper::assertValidAbsolutePath (' /parent/child/ ' );
45
+ $ this -> assertFalse ( PathHelper::assertValidAbsolutePath ($ path , $ destination , false ) );
82
46
}
83
47
84
- public function testAssertValidPathNoThrow ()
48
+ public function dataproviderInvalidAbsolutePaths ()
85
49
{
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
+ );
87
59
}
88
60
89
61
// assertValidLocalName tests
@@ -99,35 +71,22 @@ public function testAssertValidLocalNameRootnode()
99
71
}
100
72
101
73
/**
74
+ * @dataProvider dataproviderInvalidLocalNames
102
75
* @expectedException \PHPCR\RepositoryException
103
76
*/
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 )
113
78
{
114
- $ this -> assertTrue ( PathHelper::assertValidLocalName (' /path ' ) );
79
+ PathHelper::assertValidLocalName ($ name );
115
80
}
116
81
117
- /**
118
- * @expectedException \PHPCR\RepositoryException
119
- */
120
- public function testAssertValidLocalNameSelf ()
82
+ public function dataproviderInvalidLocalNames ()
121
83
{
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
+ );
131
90
}
132
91
133
92
// normalizePath tests
@@ -151,17 +110,6 @@ public static function dataproviderNormalizePath()
151
110
);
152
111
}
153
112
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
-
165
113
/**
166
114
* @dataProvider dataproviderNormalizePathInvalid
167
115
* @expectedException \PHPCR\RepositoryException
@@ -179,6 +127,17 @@ public function testNormalizePathInvalidNoThrow($input)
179
127
$ this ->assertFalse (PathHelper::normalizePath ($ input , true , false ));
180
128
}
181
129
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
+
182
141
// absolutizePath tests
183
142
184
143
/**
@@ -229,27 +188,35 @@ public static function dataproviderAbsolutizePathInvalid()
229
188
230
189
// getParentPath tests
231
190
232
- public function testGetParentPath ()
191
+ /**
192
+ * @dataProvider dataproviderParentPath
193
+ */
194
+ public function testGetParentPath ($ path , $ parent )
233
195
{
234
- $ this ->assertEquals (' / parent' , PathHelper::getParentPath (' /parent/child ' ));
196
+ $ this ->assertEquals ($ parent , PathHelper::getParentPath ($ path ));
235
197
}
236
198
237
- public function testGetParentPathNamespaced ()
199
+ public function dataproviderParentPath ()
238
200
{
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
+ );
240
207
}
241
208
242
- public function testGetParentPathNodeAtRoot ()
243
- {
244
- $ this ->assertEquals ('/ ' , PathHelper::getParentPath ('/parent ' ));
245
- }
209
+ // getNodeName tests
246
210
247
- public function testGetParentPathRoot ()
211
+ /**
212
+ * @dataProvider dataproviderGetNodeName
213
+ */
214
+ public function testGetNodeName ($ path , $ expected = null )
248
215
{
249
- $ this ->assertEquals (' / ' , PathHelper::getParentPath ( ' / ' ));
216
+ $ this ->assertEquals ($ expected , PathHelper::getNodeName ( $ path ));
250
217
}
251
218
252
- public function provideGetNodeName ()
219
+ public function dataproviderGetNodeName ()
253
220
{
254
221
return array (
255
222
array ('/parent/child ' , 'child ' ),
@@ -259,27 +226,31 @@ public function provideGetNodeName()
259
226
}
260
227
261
228
/**
262
- * @dataProvider provideGetNodeName
229
+ * @expectedException \PHPCR\RepositoryException
230
+ * @expectedExceptionMessage must be an absolute path
263
231
*/
264
- public function testGetNodeName ( $ path , $ expected = null )
232
+ public function testGetNodeNameMustBeAbsolute ( )
265
233
{
266
- $ this -> assertEquals ( $ expected , PathHelper::getNodeName ($ path ) );
234
+ PathHelper::getNodeName (' foobar ' );
267
235
}
268
236
237
+ // getPathDepth tests
238
+
269
239
/**
270
- * @expectedException PHPCR\RepositoryException
271
- * @expectedExceptionMessage must be an absolute path
240
+ * @dataProvider dataproviderPathDepth
272
241
*/
273
- public function testGetNodeNameMustBeAbsolute ( )
242
+ public function testGetPathDepth ( $ path , $ depth )
274
243
{
275
- PathHelper::getNodeName ( ' foobar ' );
244
+ $ this -> assertEquals ( $ depth , PathHelper::getPathDepth ( $ path ) );
276
245
}
277
246
278
- public function testGetPathDepth ()
247
+ public function dataproviderPathDepth ()
279
248
{
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
+ );
284
255
}
285
256
}
0 commit comments