From 2ee4b8861cea2e9fa713e769b2ec723988ffa63d Mon Sep 17 00:00:00 2001 From: Jakub Zalas Date: Fri, 6 Apr 2012 23:05:31 +0100 Subject: [PATCH] [Filesystem] Added unit tests for makePathRelative method. --- .../Filesystem/Tests/FilesystemTest.php | 31 +++++++++++++++++++ 1 file changed, 31 insertions(+) diff --git a/src/Symfony/Component/Filesystem/Tests/FilesystemTest.php b/src/Symfony/Component/Filesystem/Tests/FilesystemTest.php index 05f429fe20..367c83ea2e 100644 --- a/src/Symfony/Component/Filesystem/Tests/FilesystemTest.php +++ b/src/Symfony/Component/Filesystem/Tests/FilesystemTest.php @@ -410,6 +410,37 @@ class FilesystemTest extends \PHPUnit_Framework_TestCase $this->assertEquals($file, readlink($link)); } + /** + * @dataProvider provideAbsolutePaths + */ + public function testMakePathRelative($endPath, $startPath, $expectedPath) + { + $path = $this->filesystem->makePathRelative($endPath, $startPath); + + $this->assertEquals($expectedPath, $path); + } + + /** + * @return array + */ + public function provideAbsolutePaths() + { + $paths = array( + array('/var/lib/symfony/src/Symfony/', '/var/lib/symfony/src/Symfony/Component', '../'), + array('var/lib/symfony/', 'var/lib/symfony/src/Symfony/Component', '../../../'), + array('/usr/lib/symfony/', '/var/lib/symfony/src/Symfony/Component', '../../../../../../usr/lib/symfony/') + ); + + // fix directory separator + foreach ($paths as $i => $pathItems) { + foreach ($pathItems as $k => $path) { + $paths[$i][$k] = str_replace('/', DIRECTORY_SEPARATOR, $path); + } + } + + return $paths; + } + /** * Returns file permissions as three digits (i.e. 755) *