2012-06-06 01:00:57 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
/*
|
|
|
|
* This file is part of Composer.
|
|
|
|
*
|
|
|
|
* (c) Nils Adermann <naderman@naderman.de>
|
|
|
|
* Jordi Boggiano <j.boggiano@seld.be>
|
|
|
|
*
|
|
|
|
* For the full copyright and license information, please view the LICENSE
|
|
|
|
* file that was distributed with this source code.
|
|
|
|
*/
|
|
|
|
|
|
|
|
namespace Composer\Test\Downloader;
|
|
|
|
|
|
|
|
use Composer\Downloader\PearPackageExtractor;
|
|
|
|
|
|
|
|
class PearPackageExtractorTest extends \PHPUnit_Framework_TestCase
|
|
|
|
{
|
|
|
|
public function testShouldExtractPackage_1_0()
|
|
|
|
{
|
2015-06-03 08:17:09 +00:00
|
|
|
$state = libxml_disable_entity_loader(true);
|
|
|
|
|
2012-06-06 01:00:57 +00:00
|
|
|
$extractor = $this->getMockForAbstractClass('Composer\Downloader\PearPackageExtractor', array(), '', false);
|
|
|
|
$method = new \ReflectionMethod($extractor, 'buildCopyActions');
|
|
|
|
$method->setAccessible(true);
|
|
|
|
|
2012-06-27 05:27:01 +00:00
|
|
|
$fileActions = $method->invoke($extractor, __DIR__ . '/Fixtures/Package_v1.0', array('php' => '/'), array());
|
2012-06-06 01:00:57 +00:00
|
|
|
|
2015-06-03 08:17:09 +00:00
|
|
|
libxml_disable_entity_loader($state);
|
|
|
|
|
2012-06-06 01:00:57 +00:00
|
|
|
$expectedFileActions = array(
|
2014-10-17 17:46:01 +00:00
|
|
|
'Gtk.php' => array(
|
2012-06-06 01:00:57 +00:00
|
|
|
'from' => 'PEAR_Frontend_Gtk-0.4.0/Gtk.php',
|
|
|
|
'to' => 'PEAR/Frontend/Gtk.php',
|
2012-06-27 05:27:01 +00:00
|
|
|
'role' => 'php',
|
|
|
|
'tasks' => array(),
|
2012-06-06 01:00:57 +00:00
|
|
|
),
|
2014-10-17 17:46:01 +00:00
|
|
|
'Gtk/Config.php' => array(
|
2012-06-06 01:00:57 +00:00
|
|
|
'from' => 'PEAR_Frontend_Gtk-0.4.0/Gtk/Config.php',
|
|
|
|
'to' => 'PEAR/Frontend/Gtk/Config.php',
|
2012-06-27 05:27:01 +00:00
|
|
|
'role' => 'php',
|
|
|
|
'tasks' => array(),
|
2012-06-06 01:00:57 +00:00
|
|
|
),
|
2014-10-17 17:46:01 +00:00
|
|
|
'Gtk/xpm/black_close_icon.xpm' => array(
|
2012-06-06 01:00:57 +00:00
|
|
|
'from' => 'PEAR_Frontend_Gtk-0.4.0/Gtk/xpm/black_close_icon.xpm',
|
|
|
|
'to' => 'PEAR/Frontend/Gtk/xpm/black_close_icon.xpm',
|
2012-06-27 05:27:01 +00:00
|
|
|
'role' => 'php',
|
|
|
|
'tasks' => array(),
|
2012-06-06 01:00:57 +00:00
|
|
|
)
|
|
|
|
);
|
|
|
|
$this->assertSame($expectedFileActions, $fileActions);
|
|
|
|
}
|
|
|
|
|
|
|
|
public function testShouldExtractPackage_2_0()
|
|
|
|
{
|
2015-06-03 08:17:09 +00:00
|
|
|
$state = libxml_disable_entity_loader(true);
|
|
|
|
|
2012-06-06 01:00:57 +00:00
|
|
|
$extractor = $this->getMockForAbstractClass('Composer\Downloader\PearPackageExtractor', array(), '', false);
|
|
|
|
$method = new \ReflectionMethod($extractor, 'buildCopyActions');
|
|
|
|
$method->setAccessible(true);
|
|
|
|
|
2012-06-27 05:27:01 +00:00
|
|
|
$fileActions = $method->invoke($extractor, __DIR__ . '/Fixtures/Package_v2.0', array('php' => '/'), array());
|
2012-06-06 01:00:57 +00:00
|
|
|
|
2015-06-03 08:17:09 +00:00
|
|
|
libxml_disable_entity_loader($state);
|
|
|
|
|
2012-06-06 01:00:57 +00:00
|
|
|
$expectedFileActions = array(
|
2014-10-17 17:46:01 +00:00
|
|
|
'URL.php' => array(
|
2012-06-06 01:00:57 +00:00
|
|
|
'from' => 'Net_URL-1.0.15/URL.php',
|
|
|
|
'to' => 'Net/URL.php',
|
2012-06-27 05:27:01 +00:00
|
|
|
'role' => 'php',
|
|
|
|
'tasks' => array(),
|
2012-06-06 01:00:57 +00:00
|
|
|
)
|
|
|
|
);
|
|
|
|
$this->assertSame($expectedFileActions, $fileActions);
|
|
|
|
}
|
2012-06-15 01:30:08 +00:00
|
|
|
|
|
|
|
public function testShouldExtractPackage_2_1()
|
|
|
|
{
|
2015-06-03 08:17:09 +00:00
|
|
|
$state = libxml_disable_entity_loader(true);
|
|
|
|
|
2012-06-15 01:30:08 +00:00
|
|
|
$extractor = $this->getMockForAbstractClass('Composer\Downloader\PearPackageExtractor', array(), '', false);
|
|
|
|
$method = new \ReflectionMethod($extractor, 'buildCopyActions');
|
|
|
|
$method->setAccessible(true);
|
|
|
|
|
2012-06-27 05:27:01 +00:00
|
|
|
$fileActions = $method->invoke($extractor, __DIR__ . '/Fixtures/Package_v2.1', array('php' => '/', 'script' => '/bin'), array());
|
2012-06-15 01:30:08 +00:00
|
|
|
|
2015-06-03 08:17:09 +00:00
|
|
|
libxml_disable_entity_loader($state);
|
|
|
|
|
2012-06-15 01:30:08 +00:00
|
|
|
$expectedFileActions = array(
|
2014-10-17 17:46:01 +00:00
|
|
|
'php/Zend/Authentication/Storage/StorageInterface.php' => array(
|
2012-06-15 01:30:08 +00:00
|
|
|
'from' => 'Zend_Authentication-2.0.0beta4/php/Zend/Authentication/Storage/StorageInterface.php',
|
|
|
|
'to' => '/php/Zend/Authentication/Storage/StorageInterface.php',
|
2012-06-27 05:27:01 +00:00
|
|
|
'role' => 'php',
|
|
|
|
'tasks' => array(),
|
2012-06-15 01:30:08 +00:00
|
|
|
),
|
2014-10-17 17:46:01 +00:00
|
|
|
'php/Zend/Authentication/Result.php' => array(
|
2012-06-15 01:30:08 +00:00
|
|
|
'from' => 'Zend_Authentication-2.0.0beta4/php/Zend/Authentication/Result.php',
|
|
|
|
'to' => '/php/Zend/Authentication/Result.php',
|
2012-06-27 05:27:01 +00:00
|
|
|
'role' => 'php',
|
|
|
|
'tasks' => array(),
|
|
|
|
),
|
|
|
|
'php/Test.php' => array (
|
|
|
|
'from' => 'Zend_Authentication-2.0.0beta4/php/Test.php',
|
|
|
|
'to' => '/php/Test.php',
|
|
|
|
'role' => 'script',
|
|
|
|
'tasks' => array (
|
|
|
|
array (
|
|
|
|
'from' => '@version@',
|
|
|
|
'to' => 'version',
|
|
|
|
)
|
|
|
|
)
|
|
|
|
),
|
2014-10-17 17:46:01 +00:00
|
|
|
'renamedFile.php' => array(
|
2012-06-27 05:27:01 +00:00
|
|
|
'from' => 'Zend_Authentication-2.0.0beta4/renamedFile.php',
|
|
|
|
'to' => 'correctFile.php',
|
|
|
|
'role' => 'php',
|
|
|
|
'tasks' => array(),
|
|
|
|
),
|
2012-06-15 01:30:08 +00:00
|
|
|
);
|
|
|
|
$this->assertSame($expectedFileActions, $fileActions);
|
|
|
|
}
|
2012-06-27 05:27:01 +00:00
|
|
|
|
|
|
|
public function testShouldPerformReplacements()
|
|
|
|
{
|
|
|
|
$from = tempnam(sys_get_temp_dir(), 'pear-extract');
|
|
|
|
$to = $from.'-to';
|
|
|
|
|
|
|
|
$original = 'replaced: @placeholder@; not replaced: @another@; replaced again: @placeholder@';
|
|
|
|
$expected = 'replaced: value; not replaced: @another@; replaced again: value';
|
|
|
|
|
|
|
|
file_put_contents($from, $original);
|
|
|
|
|
|
|
|
$extractor = new PearPackageExtractor($from);
|
|
|
|
$method = new \ReflectionMethod($extractor, 'copyFile');
|
|
|
|
$method->setAccessible(true);
|
|
|
|
|
|
|
|
$method->invoke($extractor, $from, $to, array(array('from' => '@placeholder@', 'to' => 'variable')), array('variable' => 'value'));
|
|
|
|
$result = file_get_contents($to);
|
|
|
|
|
|
|
|
unlink($to);
|
|
|
|
unlink($from);
|
|
|
|
|
|
|
|
$this->assertEquals($expected, $result);
|
|
|
|
}
|
2012-06-06 01:00:57 +00:00
|
|
|
}
|