Skip to content

Commit

Permalink
Merge pull request #147 from davidverholen/master
Browse files Browse the repository at this point in the history
 solves #146
  • Loading branch information
Flyingmana committed Dec 11, 2014
2 parents e0c8e4a + a8f771d commit 32a1048
Show file tree
Hide file tree
Showing 2 changed files with 77 additions and 23 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -604,41 +604,54 @@ public function annoy(IOInterface $io)
}

/**
* join 2 paths
* joinFilePath
*
* @param $path1
* @param $path2
* @param $delimiter
* @param bool $prependDelimiter
* @param string $additionalPrefix
* joins 2 Filepaths and replaces the Directory Separators
* with the Systems Directory Separator
*
* @internal param $url1
* @internal param $url2
* @param $path1
* @param $path2
*
* @return string
*/
protected function joinPath($path1, $path2, $delimiter, $prependDelimiter = false, $additionalPrefix = '')
public function joinFilePath($path1, $path2)
{
$prefix = $additionalPrefix . $prependDelimiter ? $delimiter : '';

return $prefix . join(
$delimiter,
array(
explode($path1, $delimiter),
explode($path2, $delimiter)
$prefix = $this->startsWithDs($path1) ? DIRECTORY_SEPARATOR : '';
$suffix = $this->endsWithDs($path2) ? DIRECTORY_SEPARATOR : '';

return $prefix . implode(
DIRECTORY_SEPARATOR,
array_merge(
preg_split('/\\\|\//', $path1, null, PREG_SPLIT_NO_EMPTY),
preg_split('/\\\|\//', $path2, null, PREG_SPLIT_NO_EMPTY)
)
);
) . $suffix;
}

/**
* @param $path1
* @param $path2
* startsWithDs
*
* @return string
* @param $path
*
* @return bool
*/
protected function startsWithDs($path)
{
return strrpos($path, '/', -strlen($path)) !== FALSE
|| strrpos($path, '\\', -strlen($path)) !== FALSE;
}

/**
* endsWithDs
*
* @param $path
*
* @return bool
*/
protected function joinFilePath($path1, $path2)
protected function endsWithDs($path)
{
return $this->joinPath($path1, $path2, DIRECTORY_SEPARATOR, true);
return strpos($path, '/', strlen($path) - 1) !== FALSE
|| strpos($path, '\\', strlen($path) - 1) !== FALSE;
}

/**
Expand Down
43 changes: 42 additions & 1 deletion tests/MagentoHackathon/Composer/Magento/ModuleInstallerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
class ModuleInstallerTest extends \PHPUnit_Framework_TestCase
{
/**
* @var Installer
* @var ModuleInstaller
*/
protected $object;

Expand Down Expand Up @@ -239,6 +239,30 @@ public function parserTypeProvider()
* translations are specified.
*/

/**
* joinFilePathsProvider
*
* @return array
*/
public function joinFilePathsProvider()
{
$ds = DIRECTORY_SEPARATOR;
return array(
array('app/etc/', '/modules', 'app'.$ds.'etc'.$ds.'modules'),
array('app/etc/', 'modules', 'app'.$ds.'etc'.$ds.'modules'),
array('app/etc', 'modules', 'app'.$ds.'etc'.$ds.'modules'),
array('/app/etc', '/modules', $ds.'app'.$ds.'etc'.$ds.'modules'),
array('/app/etc/', '/modules', $ds.'app'.$ds.'etc'.$ds.'modules'),
array('/app/etc', 'modules/', $ds.'app'.$ds.'etc'.$ds.'modules'.$ds),
array('app\\etc\\', '\\modules', 'app'.$ds.'etc'.$ds.'modules'),
array('app\\etc\\', 'modules', 'app'.$ds.'etc'.$ds.'modules'),
array('app\\etc', 'modules', 'app'.$ds.'etc'.$ds.'modules'),
array('\\app\\etc', '\\modules', $ds.'app'.$ds.'etc'.$ds.'modules'),
array('\\app\\etc\\', '\\modules', $ds.'app'.$ds.'etc'.$ds.'modules'),
array('\\app\\etc', 'modules\\', $ds.'app'.$ds.'etc'.$ds.'modules'.$ds)
);
}

protected function createPathMappingTranslationMock()
{
return $this->createPackageMock(
Expand Down Expand Up @@ -345,5 +369,22 @@ public function testMediaPathMappingTranslation2()
$this->assertContains(array('src2/media/images', './media/examplename_images'), $mappings);
}

/**
* testJoinFilePaths
*
* @param $path1
* @param $path2
* @param $expected
*
* @return void
*
* @dataProvider joinFilePathsProvider
* @covers MagentoHackathon\Composer\Magento\Installer\ModuleInstaller::joinFilePaths
*/
public function testJoinFilePaths($path1, $path2, $expected)
{
$this->assertEquals($expected, $this->object->joinFilePath($path1, $path2));
}

}

0 comments on commit 32a1048

Please sign in to comment.