From f9cd62ae120f196e6d1612e983a2055bc867aeed Mon Sep 17 00:00:00 2001 From: David Buchmann Date: Mon, 1 Sep 2014 20:39:33 +0200 Subject: [PATCH] cleanup the path helper test --- tests/PHPCR/Tests/Util/PathHelperTest.php | 197 +++++++++------------- 1 file changed, 84 insertions(+), 113 deletions(-) diff --git a/tests/PHPCR/Tests/Util/PathHelperTest.php b/tests/PHPCR/Tests/Util/PathHelperTest.php index 3be5f7e..f7808ac 100644 --- a/tests/PHPCR/Tests/Util/PathHelperTest.php +++ b/tests/PHPCR/Tests/Util/PathHelperTest.php @@ -8,82 +8,54 @@ class PathHelperTest extends \PHPUnit_Framework_TestCase { // assertValidPath tests - public function testAssertValidPath() - { - $this->assertTrue(PathHelper::assertValidAbsolutePath('/parent/child')); - } - - public function testAssertValidPathRoot() - { - $this->assertTrue(PathHelper::assertValidAbsolutePath('/')); - } - - public function testAssertValidPathNamespaced() - { - $this->assertTrue(PathHelper::assertValidAbsolutePath('/jcr:foo_/b-a/0^.txt')); - } - - public function testAssertValidPathIndexed() - { - $this->assertTrue(PathHelper::assertValidAbsolutePath('/parent[7]/child')); - } - - public function testAssertValidPathIndexedAtEnd() - { - $this->assertTrue(PathHelper::assertValidAbsolutePath('/parent[7]/child[3]')); - } - - /** - * @expectedException \PHPCR\RepositoryException - */ - public function testAssertValidTargetPathNoIndex() - { - PathHelper::assertValidAbsolutePath('/parent/child[7]', true); - } - /** - * @expectedException \PHPCR\RepositoryException + * @dataProvider dataproviderValidAbsolutePaths */ - public function testAssertValidPathNotAbsolute() + public function testAssertValidAbsolutePath($path, $destination = false) { - PathHelper::assertValidAbsolutePath('parent'); + $this->assertTrue(PathHelper::assertValidAbsolutePath($path, $destination)); } - /** - * @expectedException \PHPCR\RepositoryException - */ - public function testAssertValidPathDouble() + public function dataproviderValidAbsolutePaths() { - PathHelper::assertValidAbsolutePath('/parent//child'); - } - - /** - * @expectedException \PHPCR\RepositoryException - */ - public function testAssertValidPathParent() - { - PathHelper::assertValidAbsolutePath('/parent/../child'); + return array( + array('/parent/child'), + array('/'), + array('/jcr:foo_/b-a/0^.txt'), + array('/parent[7]/child'), + array('/parent[7]/child', true), // index is allowed in destination parent path, only not in last element + array('/parent[7]/child[3]'), + ); } /** + * @dataProvider dataproviderInvalidAbsolutePaths * @expectedException \PHPCR\RepositoryException */ - public function testAssertValidPathSelf() + public function testAssertInvalidAbsolutePath($path, $destination = false) { - PathHelper::assertValidAbsolutePath('/parent/./child'); + PathHelper::assertValidAbsolutePath($path, $destination); } /** - * @expectedException \PHPCR\RepositoryException + * @dataProvider dataproviderInvalidAbsolutePaths */ - public function testAssertValidPathTrailing() + public function testAssertInvalidAbsolutePathNoThrow($path, $destination = false) { - PathHelper::assertValidAbsolutePath('/parent/child/'); + $this->assertFalse(PathHelper::assertValidAbsolutePath($path, $destination, false)); } - public function testAssertValidPathNoThrow() + public function dataproviderInvalidAbsolutePaths() { - $this->assertFalse(PathHelper::assertValidAbsolutePath('parent', false, false)); + return array( + array('/parent/child[7]', true), // destination last element with index + array('parent'), // not absolute + array('/parent//child'), + array('//'), + array('/parent/../child'), + array('/parent/./child'), + array('/parent/child/'), + ); } // assertValidLocalName tests @@ -99,35 +71,22 @@ public function testAssertValidLocalNameRootnode() } /** + * @dataProvider dataproviderInvalidLocalNames * @expectedException \PHPCR\RepositoryException */ - public function testAssertValidLocalNameNamespaced() - { - $this->assertTrue(PathHelper::assertValidLocalName('jcr:nodename')); - } - - /** - * @expectedException \PHPCR\RepositoryException - */ - public function testAssertValidLocalNamePath() + public function testAssertInvalidLocalName($name) { - $this->assertTrue(PathHelper::assertValidLocalName('/path')); + PathHelper::assertValidLocalName($name); } - /** - * @expectedException \PHPCR\RepositoryException - */ - public function testAssertValidLocalNameSelf() + public function dataproviderInvalidLocalNames() { - PathHelper::assertValidLocalName('.'); - } - - /** - * @expectedException \PHPCR\RepositoryException - */ - public function testAssertValidLocalNameParent() - { - PathHelper::assertValidLocalName('..'); + return array( + array('jcr:nodename'), + array('/path'), + array('.'), + array('..') + ); } // normalizePath tests @@ -151,17 +110,6 @@ public static function dataproviderNormalizePath() ); } - public static function dataproviderNormalizePathInvalid() - { - return array( - array('foo/bar'), - array('bar'), - array('/foo/bar/'), - array(''), - array(new \stdClass()), - ); - } - /** * @dataProvider dataproviderNormalizePathInvalid * @expectedException \PHPCR\RepositoryException @@ -179,6 +127,17 @@ public function testNormalizePathInvalidNoThrow($input) $this->assertFalse(PathHelper::normalizePath($input, true, false)); } + public static function dataproviderNormalizePathInvalid() + { + return array( + array('foo/bar'), + array('bar'), + array('/foo/bar/'), + array(''), + array(new \stdClass()), + ); + } + // absolutizePath tests /** @@ -229,27 +188,35 @@ public static function dataproviderAbsolutizePathInvalid() // getParentPath tests - public function testGetParentPath() + /** + * @dataProvider dataproviderParentPath + */ + public function testGetParentPath($path, $parent) { - $this->assertEquals('/parent', PathHelper::getParentPath('/parent/child')); + $this->assertEquals($parent, PathHelper::getParentPath($path)); } - public function testGetParentPathNamespaced() + public function dataproviderParentPath() { - $this->assertEquals('/jcr:parent', PathHelper::getParentPath('/jcr:parent/ns:child')); + return array( + array('/parent/child', '/parent'), + array('/jcr:parent/ns:child', '/jcr:parent'), + array('/child', '/'), + array('/', '/'), + ); } - public function testGetParentPathNodeAtRoot() - { - $this->assertEquals('/', PathHelper::getParentPath('/parent')); - } + // getNodeName tests - public function testGetParentPathRoot() + /** + * @dataProvider dataproviderGetNodeName + */ + public function testGetNodeName($path, $expected = null) { - $this->assertEquals('/', PathHelper::getParentPath('/')); + $this->assertEquals($expected, PathHelper::getNodeName($path)); } - public function provideGetNodeName() + public function dataproviderGetNodeName() { return array( array('/parent/child', 'child'), @@ -259,27 +226,31 @@ public function provideGetNodeName() } /** - * @dataProvider provideGetNodeName + * @expectedException \PHPCR\RepositoryException + * @expectedExceptionMessage must be an absolute path */ - public function testGetNodeName($path, $expected = null) + public function testGetNodeNameMustBeAbsolute() { - $this->assertEquals($expected, PathHelper::getNodeName($path)); + PathHelper::getNodeName('foobar'); } + // getPathDepth tests + /** - * @expectedException PHPCR\RepositoryException - * @expectedExceptionMessage must be an absolute path + * @dataProvider dataproviderPathDepth */ - public function testGetNodeNameMustBeAbsolute() + public function testGetPathDepth($path, $depth) { - PathHelper::getNodeName('foobar'); + $this->assertEquals($depth, PathHelper::getPathDepth($path)); } - public function testGetPathDepth() + public function dataproviderPathDepth() { - $this->assertEquals(0, PathHelper::getPathDepth('/')); - $this->assertEquals(1, PathHelper::getPathDepth('/foo')); - $this->assertEquals(2, PathHelper::getPathDepth('/foo/bar')); - $this->assertEquals(2, PathHelper::getPathDepth('/foo/bar/')); + return array( + array('/', 0), + array('/foo', 1), + array('/foo/bar', 2), + array('/foo/bar/', 2), + ); } }