Added more testing for the package.xml update module. Fixed install location for...
authorGunnar Wrobel <p@rdus.de>
Tue, 12 Oct 2010 20:15:42 +0000 (22:15 +0200)
committerGunnar Wrobel <p@rdus.de>
Wed, 13 Oct 2010 19:14:43 +0000 (21:14 +0200)
12 files changed:
components/TODO
components/lib/Components/Pear/Package.php
components/lib/Components/Runner/PearPackageXml.php
components/test/Components/Integration/Components/Module/PearPackageXmlTest.php
components/test/Components/StoryTestCase.php
components/test/Components/fixture/simple/js/test.js [new file with mode: 0644]
components/test/Components/fixture/simple/lib/Stays.php [new file with mode: 0644]
components/test/Components/fixture/simple/migration/test.sql [new file with mode: 0644]
components/test/Components/fixture/simple/package.xml
components/test/Components/fixture/simple/script/other_script [new file with mode: 0644]
components/test/Components/fixture/simple/script/script.php [new file with mode: 0644]
components/test/Components/fixture/simple/script/shell_script.sh [new file with mode: 0644]

index c43f3eb..af335f0 100644 (file)
@@ -4,8 +4,6 @@
 
  - Document usage
 
- - Fix variable replacements when updating the package.xml
-
  - Do the distribution runner.
 
  - Add module for generating component documentation.
index 05de3bd..fcf7bd0 100644 (file)
@@ -216,6 +216,9 @@ class Components_Pear_Package
         $contents = $contents['dir']['file'];
         $taskfiles = array();
         foreach ($contents as $file) {
+            if (!isset($file['attribs'])) {
+                continue;
+            }
             $atts = $file['attribs'];
             unset($file['attribs']);
             if (count($file)) {
@@ -247,8 +250,8 @@ class Components_Pear_Package
                         $logger,
                         ''
                     );
-                    switch ($tag) {
-                    case 'replace':
+                    switch ($taskname) {
+                    case 'PEAR_Task_Replace_rw':
                         $task->setInfo(
                             $raw['attribs']['from'],
                             $raw['attribs']['to'],
@@ -256,7 +259,7 @@ class Components_Pear_Package
                         );
                         break;
                     default:
-                        throw new Components_Exceptions(
+                        throw new Components_Exception(
                             sprintf('Unsupported task type %s!', $tag)
                         );
                     }
@@ -316,7 +319,7 @@ class Components_Pear_Package
                 break;
             case 'script':
                 $filename = basename($file['attribs']['name']);
-                if (substr($filename, strlen($filename) - 4)) {
+                if (substr($filename, strlen($filename) - 4) == '.php') {
                     $filename = substr($filename, 0, strlen($filename) - 4);
                 }
                 $package->addInstallAs(
index 7d9d35b..708e5d8 100644 (file)
@@ -61,6 +61,8 @@ class Components_Runner_PearPackageXml
     public function run()
     {
         $arguments = $this->_config->getArguments();
+        $options = $this->_config->getOptions();
+
         if (isset($options['pearrc'])) {
             $package = $this->_factory->createPackageForInstallLocation(
                 $arguments[0] . '/package.xml',
@@ -72,7 +74,6 @@ class Components_Runner_PearPackageXml
             );
         }
 
-        $options = $this->_config->getOptions();
         if (!empty($options['packagexml'])) {
             $package->printUpdatedPackageFile();
         }
index e7d78ea..f0582b3 100644 (file)
@@ -98,11 +98,44 @@ extends Components_StoryTestCase
     public function thePOptionProvidesAnUpdatedPackageXml()
     {
         $this->given('the default Components setup')
-            ->when('calling the package with the packagexml option and a Horde element')
+            ->when('calling the package with the packagexml option and a Horde component')
             ->then('the new package.xml of the Horde element will be printed.');
     }
 
     /**
+     * @scenario
+     */
+    public function thePOptionWithThePearrcOptionProvidesAnUpdatedPackageXml()
+    {
+        $this->given('the default Components setup')
+            ->when('calling the package with the pearrc, the packagexml option, and a Horde component')
+            ->then('the new package.xml of the Horde element will be printed.');
+    }
+
+    /**
+     * @scenario
+     */
+    public function thePOptionProvidesAnUpdatedPackageXmlWhichRetainsReplaceTasks()
+    {
+        $this->given('the default Components setup')
+            ->when('calling the package with the packagexml option and a Horde component')
+            ->then('the new package.xml of the Horde component will retain all "replace" tasks.');
+    }
+
+    /**
+     * @scenario
+     */
+    public function thePOptionProvidesAnUpdatedPackageXmlWithDefaultInstallLocations()
+    {
+        $this->given('the default Components setup')
+            ->when('calling the package with the packagexml option and a Horde component')
+            ->then('the new package.xml will install java script files in a default location')
+            ->and('the new package.xml will install migration files in a default location')
+            ->and('the new package.xml will install script files in a default location');
+    }
+
+
+    /**
      * @todo Test (and fix) the reactions to three more scenarios:
      *  - invalid XML in the package.xml (e.g. tag missing)
      *  - empty file list
index 6fab17d..39929a1 100644 (file)
@@ -76,7 +76,7 @@ extends PHPUnit_Extensions_Story_TestCase
             );
             $world['output'] = $this->_callStrictComponents();
             break;
-        case 'calling the package with the packagexml option and a Horde element':
+        case 'calling the package with the packagexml option and a Horde component':
             $_SERVER['argv'] = array(
                 'horde-components',
                 '--packagexml',
@@ -84,6 +84,15 @@ extends PHPUnit_Extensions_Story_TestCase
             );
             $world['output'] = $this->_callUnstrictComponents();
             break;
+        case 'calling the package with the pearrc, the packagexml option, and a Horde component':
+            $_SERVER['argv'] = array(
+                'horde-components',
+                '--pearrc=' . $this->_getTemporaryDirectory() . DIRECTORY_SEPARATOR . '.pearrc',
+                '--packagexml',
+                dirname(__FILE__) . '/fixture/simple'
+            );
+            $world['output'] = $this->_callUnstrictComponents();
+            break;
         case 'calling the package with the packagexml option and the path':
             $_SERVER['argv'] = array(
                 'horde-components',
@@ -232,6 +241,38 @@ extends PHPUnit_Extensions_Story_TestCase
                 $world['output']
             );
             break;
+        case 'the new package.xml of the Horde component will retain all "replace" tasks.':
+            $this->assertRegExp(
+                '#<tasks:replace from="@data_dir@" to="data_dir" type="pear-config" />#',
+                $world['output']
+            );
+            break;
+        case 'the new package.xml will install java script files in a default location':
+            $this->assertRegExp(
+                '#<install as="js/test.js" name="js/test.js" />#',
+                $world['output']
+            );
+            break;
+        case 'the new package.xml will install migration files in a default location':
+            $this->assertRegExp(
+                '#<install as="migration/test.sql" name="migration/test.sql" />#',
+                $world['output']
+            );
+            break;
+        case 'the new package.xml will install script files in a default location':
+            $this->assertRegExp(
+                '#<install as="other_script" name="script/other_script" />#',
+                $world['output']
+            );
+            $this->assertRegExp(
+                '#<install as="shell_script.sh" name="script/shell_script.sh" />#',
+                $world['output']
+            );
+            $this->assertRegExp(
+                '#<install as="script" name="script/script.php" />#',
+                $world['output']
+            );
+            break;
         case 'a new PEAR configuration file will be installed':
             $this->assertTrue(
                 file_exists($this->_temp_dir . DIRECTORY_SEPARATOR . '.pearrc')
diff --git a/components/test/Components/fixture/simple/js/test.js b/components/test/Components/fixture/simple/js/test.js
new file mode 100644 (file)
index 0000000..792d600
--- /dev/null
@@ -0,0 +1 @@
+#
diff --git a/components/test/Components/fixture/simple/lib/Stays.php b/components/test/Components/fixture/simple/lib/Stays.php
new file mode 100644 (file)
index 0000000..b3d9bbc
--- /dev/null
@@ -0,0 +1 @@
+<?php
diff --git a/components/test/Components/fixture/simple/migration/test.sql b/components/test/Components/fixture/simple/migration/test.sql
new file mode 100644 (file)
index 0000000..792d600
--- /dev/null
@@ -0,0 +1 @@
+#
index 2a539f4..267aae2 100644 (file)
@@ -28,6 +28,9 @@
   <dir baseinstalldir="/" name="/">
    <dir name="lib">
     <file name="Old.php" role="php" />
+    <file name="Stays.php" role="php">
+      <tasks:replace from="@data_dir@" to="data_dir" type="pear-config" />
+    </file>
    </dir> <!-- /lib -->
   </dir> <!-- / -->
  </contents>
@@ -44,6 +47,7 @@
  <phprelease>
   <filelist>
    <install as="Old.php" name="lib/Old.php" />
+   <install as="Stays.php" name="lib/Stays.php" />
   </filelist>
  </phprelease>
  <changelog>
diff --git a/components/test/Components/fixture/simple/script/other_script b/components/test/Components/fixture/simple/script/other_script
new file mode 100644 (file)
index 0000000..c8ff8c2
--- /dev/null
@@ -0,0 +1,2 @@
+#!/usr/bin/env php
+<?php
diff --git a/components/test/Components/fixture/simple/script/script.php b/components/test/Components/fixture/simple/script/script.php
new file mode 100644 (file)
index 0000000..c8ff8c2
--- /dev/null
@@ -0,0 +1,2 @@
+#!/usr/bin/env php
+<?php
diff --git a/components/test/Components/fixture/simple/script/shell_script.sh b/components/test/Components/fixture/simple/script/shell_script.sh
new file mode 100644 (file)
index 0000000..7f3915b
--- /dev/null
@@ -0,0 +1 @@
+#!/usr/bin/bash