File tree 2 files changed +26
-9
lines changed 2 files changed +26
-9
lines changed Original file line number Diff line number Diff line change @@ -229,7 +229,15 @@ public static function getParentPath($path)
229
229
*/
230
230
public static function getNodeName ($ path )
231
231
{
232
- return substr ($ path , strrpos ($ path , '/ ' ) + 1 );
232
+ $ strrpos = strrpos ($ path , '/ ' );
233
+
234
+ if (false === $ strrpos ) {
235
+ self ::error (sprintf (
236
+ 'Path "%s" must be an absolute path ' , $ path
237
+ ), true );
238
+ }
239
+
240
+ return substr ($ path , $ strrpos + 1 );
233
241
}
234
242
235
243
/**
Original file line number Diff line number Diff line change @@ -249,21 +249,30 @@ public function testGetParentPathRoot()
249
249
$ this ->assertEquals ('/ ' , PathHelper::getParentPath ('/ ' ));
250
250
}
251
251
252
- // getNodeName tests
253
-
254
- public function testGetNodeName ()
252
+ public function provideGetNodeName ()
255
253
{
256
- $ this ->assertEquals ('child ' , PathHelper::getNodeName ('/parent/child ' ));
254
+ return array (
255
+ array ('/parent/child ' , 'child ' ),
256
+ array ('/parent/ns:child ' , 'ns:child ' ),
257
+ array ('/ ' , '' ),
258
+ );
257
259
}
258
260
259
- public function testGetNodeNameNamespaced ()
261
+ /**
262
+ * @dataProvider provideGetNodeName
263
+ */
264
+ public function testGetNodeName ($ path , $ expected = null )
260
265
{
261
- $ this ->assertEquals (' ns:child ' , PathHelper::getNodeName (' /parent/ns:child ' ));
266
+ $ this ->assertEquals ($ expected , PathHelper::getNodeName ($ path ));
262
267
}
263
268
264
- public function testGetNodeNameRoot ()
269
+ /**
270
+ * @expectedException PHPCR\RepositoryException
271
+ * @expectedExceptionMessage must be an absolute path
272
+ */
273
+ public function testGetNodeNameMustBeAbsolute ()
265
274
{
266
- $ this -> assertEquals ( '' , PathHelper::getNodeName ('/ ' ) );
275
+ PathHelper::getNodeName ('foobar ' );
267
276
}
268
277
269
278
public function testGetPathDepth ()
You can’t perform that action at this time.
0 commit comments