Skip to content

cleanup the path helper test #122

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Sep 2, 2014
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
197 changes: 84 additions & 113 deletions tests/PHPCR/Tests/Util/PathHelperTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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
Expand All @@ -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

/**
Expand Down Expand Up @@ -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'),
Expand All @@ -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),
);
}
}