From 34abbe7f6ba24b5afd9ccc51f360ed33aaba9999 Mon Sep 17 00:00:00 2001 From: Gunnar Wrobel Date: Thu, 11 Nov 2010 21:37:52 +0100 Subject: [PATCH] Fix dealing with top level files with doc role. --- .../Components/Pear/Package/Filelist/Default.php | 6 +- .../Pear/Package/Filelist/DefaultTest.php | 124 +++++++++++++++++++++ 2 files changed, 129 insertions(+), 1 deletion(-) create mode 100644 components/test/Components/Unit/Components/Pear/Package/Filelist/DefaultTest.php diff --git a/components/lib/Components/Pear/Package/Filelist/Default.php b/components/lib/Components/Pear/Package/Filelist/Default.php index 335753e17..1f9625094 100644 --- a/components/lib/Components/Pear/Package/Filelist/Default.php +++ b/components/lib/Components/Pear/Package/Filelist/Default.php @@ -65,7 +65,11 @@ class Components_Pear_Package_Filelist_Default if (!isset($file['attribs'])) { continue; } - $components = explode('/', $file['attribs']['name'], 2); + if (strpos($file['attribs']['name'], '/') !== false) { + $components = explode('/', $file['attribs']['name'], 2); + } else { + $components = array('', $file['attribs']['name']); + } $role = isset($file['attribs']['role']) ? $file['attribs']['role'] : ''; switch ($role) { case 'horde': diff --git a/components/test/Components/Unit/Components/Pear/Package/Filelist/DefaultTest.php b/components/test/Components/Unit/Components/Pear/Package/Filelist/DefaultTest.php new file mode 100644 index 000000000..60a112bb5 --- /dev/null +++ b/components/test/Components/Unit/Components/Pear/Package/Filelist/DefaultTest.php @@ -0,0 +1,124 @@ + + * @license http://www.fsf.org/copyleft/lgpl.html LGPL + * @link http://pear.horde.org/index.php?package=Components + */ + +/** + * Prepare the test setup. + */ +require_once dirname(__FILE__) . '/../../../../../Autoload.php'; + + //@require_once 'PEAR/Validate.php'; + +/** + * Test the handling of file lists. + * + * Copyright 2010 The Horde Project (http://www.horde.org/) + * + * See the enclosed file COPYING for license information (LGPL). If you + * did not receive this file, see http://www.fsf.org/copyleft/lgpl.html. + * + * @category Horde + * @package Components + * @subpackage UnitTests + * @author Gunnar Wrobel + * @license http://www.fsf.org/copyleft/lgpl.html LGPL + * @link http://pear.horde.org/index.php?package=Components + */ +class Components_Unit_Components_Pear_Package_Filelist_DefaultTest +extends PHPUnit_Framework_TestCase +{ + public function setUp() + { + if (!defined('PEAR_VALIDATE_INSTALLING')) { + define('PEAR_VALIDATE_INSTALLING', 1); + define('PEAR_VALIDATE_NORMAL', 3); + } + } + + /** + * @dataProvider provideFiles + */ + public function testInstall($role, $name, $as) + { + $package = $this->_getPackage(array('role' => $role, 'name' => $name)); + $package->expects($this->once()) + ->method('addInstallAs') + ->with($name, $as); + $this->_getFilelist($package)->update(); + } + + public function testEmpty() + { + $list = array('dir' => array('file' => array(array()))); + $package = $this->getMock('PEAR_PackageFile_v2_rw', array(), array(), '', false, false); + $package->expects($this->once()) + ->method('getContents') + ->will($this->returnValue($list)); + $package->expects($this->never()) + ->method('addUsesRole'); + $this->_getFilelist($package)->update(); + } + + public function testNewHordeRole() + { + $package = $this->_getPackage(array('role' => 'horde', 'name' => 'a')); + $package->expects($this->once()) + ->method('addUsesRole') + ->with('horde', 'Role', 'pear.horde.org'); + $this->_getFilelist($package)->update(); + } + + public function testPreviousHordeRole() + { + $package = $this->_getPackage(array('role' => 'horde', 'name' => 'a')); + $package->expects($this->once()) + ->method('getUsesRole') + ->will($this->returnValue(array('role' => 'horde'))); + $package->expects($this->never()) + ->method('addUsesRole'); + $this->_getFilelist($package)->update(); + } + + private function _getPackage(array $contents) + { + $list = array('dir' => array('file' => array(array('attribs' => $contents)))); + $package = $this->getMock('PEAR_PackageFile_v2_rw', array(), array(), '', false, false); + $package->expects($this->once()) + ->method('getContents') + ->will($this->returnValue($list)); + return $package; + } + + private function _getFilelist(PEAR_PackageFile_v2_rw $package) + { + return new Components_Pear_Package_Filelist_Default($package); + } + + public function provideFiles() + { + return array( + array('horde', 'a', 'a'), + array('doc', 'doc/a', 'a'), + array('doc', 'README', 'README'), + array('test', 'test/AllTest.php', 'AllTest.php'), + array('script', 'script/something.php', 'something'), + array('script', 'bin/runthis', 'runthis'), + array('php', 'lib/Library.php', 'Library.php'), + array('php', 'view.php', 'view.php'), + array('data', 'data/table.sql', 'table.sql'), + array('data', 'locale/de.mo', 'locale/de.mo'), + array('data', 'migration/Horde/Alarm/1_horde_alarms_table.php', 'Horde/Alarm/migration/1_horde_alarms_table.php'), + array('data', 'somedata', 'somedata'), + ); + } +} \ No newline at end of file -- 2.11.0