From 83662862d586f7ec2f54d68448bed52614e5ba50 Mon Sep 17 00:00:00 2001 From: Gunnar Wrobel
Date: Tue, 12 Oct 2010 22:15:42 +0200
Subject: [PATCH] Added more testing for the package.xml update module. Fixed
install location for scripts.
---
components/TODO | 2 -
components/lib/Components/Pear/Package.php | 11 ++++--
.../lib/Components/Runner/PearPackageXml.php | 3 +-
.../Components/Module/PearPackageXmlTest.php | 35 +++++++++++++++++-
components/test/Components/StoryTestCase.php | 43 +++++++++++++++++++++-
.../test/Components/fixture/simple/js/test.js | 1 +
.../test/Components/fixture/simple/lib/Stays.php | 1 +
.../Components/fixture/simple/migration/test.sql | 1 +
.../test/Components/fixture/simple/package.xml | 4 ++
.../Components/fixture/simple/script/other_script | 2 +
.../Components/fixture/simple/script/script.php | 2 +
.../fixture/simple/script/shell_script.sh | 1 +
12 files changed, 97 insertions(+), 9 deletions(-)
create mode 100644 components/test/Components/fixture/simple/js/test.js
create mode 100644 components/test/Components/fixture/simple/lib/Stays.php
create mode 100644 components/test/Components/fixture/simple/migration/test.sql
create mode 100644 components/test/Components/fixture/simple/script/other_script
create mode 100644 components/test/Components/fixture/simple/script/script.php
create mode 100644 components/test/Components/fixture/simple/script/shell_script.sh
diff --git a/components/TODO b/components/TODO
index c43f3eb1a..af335f0e3 100644
--- a/components/TODO
+++ b/components/TODO
@@ -4,8 +4,6 @@
- Document usage
- - Fix variable replacements when updating the package.xml
-
- Do the distribution runner.
- Add module for generating component documentation.
diff --git a/components/lib/Components/Pear/Package.php b/components/lib/Components/Pear/Package.php
index 05de3bdc9..fcf7bd019 100644
--- a/components/lib/Components/Pear/Package.php
+++ b/components/lib/Components/Pear/Package.php
@@ -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(
diff --git a/components/lib/Components/Runner/PearPackageXml.php b/components/lib/Components/Runner/PearPackageXml.php
index 7d9d35bf0..708e5d8b7 100644
--- a/components/lib/Components/Runner/PearPackageXml.php
+++ b/components/lib/Components/Runner/PearPackageXml.php
@@ -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();
}
diff --git a/components/test/Components/Integration/Components/Module/PearPackageXmlTest.php b/components/test/Components/Integration/Components/Module/PearPackageXmlTest.php
index e7d78eab5..f0582b392 100644
--- a/components/test/Components/Integration/Components/Module/PearPackageXmlTest.php
+++ b/components/test/Components/Integration/Components/Module/PearPackageXmlTest.php
@@ -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
diff --git a/components/test/Components/StoryTestCase.php b/components/test/Components/StoryTestCase.php
index 6fab17d5b..39929a133 100644
--- a/components/test/Components/StoryTestCase.php
+++ b/components/test/Components/StoryTestCase.php
@@ -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(
+ '#