File tree Expand file tree Collapse file tree 2 files changed +26
-9
lines changed Expand file tree Collapse file tree 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)
229229 */
230230 public static function getNodeName ($ path )
231231 {
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 );
233241 }
234242
235243 /**
Original file line number Diff line number Diff line change @@ -249,21 +249,30 @@ public function testGetParentPathRoot()
249249 $ this ->assertEquals ('/ ' , PathHelper::getParentPath ('/ ' ));
250250 }
251251
252- // getNodeName tests
253-
254- public function testGetNodeName ()
252+ public function provideGetNodeName ()
255253 {
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+ );
257259 }
258260
259- public function testGetNodeNameNamespaced ()
261+ /**
262+ * @dataProvider provideGetNodeName
263+ */
264+ public function testGetNodeName ($ path , $ expected = null )
260265 {
261- $ this ->assertEquals (' ns:child ' , PathHelper::getNodeName (' /parent/ns:child ' ));
266+ $ this ->assertEquals ($ expected , PathHelper::getNodeName ($ path ));
262267 }
263268
264- public function testGetNodeNameRoot ()
269+ /**
270+ * @expectedException PHPCR\RepositoryException
271+ * @expectedExceptionMessage must be an absolute path
272+ */
273+ public function testGetNodeNameMustBeAbsolute ()
265274 {
266- $ this -> assertEquals ( '' , PathHelper::getNodeName ('/ ' ) );
275+ PathHelper::getNodeName ('foobar ' );
267276 }
268277
269278 public function testGetPathDepth ()
You can’t perform that action at this time.
0 commit comments