Fix dealing with top level files with doc role.
authorGunnar Wrobel <p@rdus.de>
Thu, 11 Nov 2010 20:37:52 +0000 (21:37 +0100)
committerGunnar Wrobel <p@rdus.de>
Thu, 11 Nov 2010 21:31:13 +0000 (22:31 +0100)
components/lib/Components/Pear/Package/Filelist/Default.php
components/test/Components/Unit/Components/Pear/Package/Filelist/DefaultTest.php [new file with mode: 0644]

index 335753e..1f96250 100644 (file)
@@ -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 (file)
index 0000000..60a112b
--- /dev/null
@@ -0,0 +1,124 @@
+<?php
+/**
+ * Test the handling of file lists.
+ *
+ * PHP version 5
+ *
+ * @category   Horde
+ * @package    Components
+ * @subpackage UnitTests
+ * @author     Gunnar Wrobel <wrobel@pardus.de>
+ * @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 <wrobel@pardus.de>
+ * @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