From: Gunnar Wrobel Date: Thu, 8 Jul 2010 09:33:41 +0000 (+0200) Subject: Reactivate testing and make the basic filter test work again. X-Git-Url: https://git.internetallee.de/?a=commitdiff_plain;h=1cb16470064ec65628126759405dee73a96308ef;p=horde.git Reactivate testing and make the basic filter test work again. --- diff --git a/framework/Kolab_Filter/lib/Horde/Kolab/Filter/Base.php b/framework/Kolab_Filter/lib/Horde/Kolab/Filter/Base.php index 66ea6334a..f16784715 100644 --- a/framework/Kolab_Filter/lib/Horde/Kolab/Filter/Base.php +++ b/framework/Kolab_Filter/lib/Horde/Kolab/Filter/Base.php @@ -3,9 +3,6 @@ * @package Kolab_Filter */ -/** Load the Filter libraries */ -require_once dirname(__FILE__) . '/Response.php'; - /** * A basic definition for a PHP based postfix filter. * @@ -76,6 +73,12 @@ class Horde_Kolab_Filter_Base */ var $_sasl_username; + public function __construct() + { + $GLOBALS['injector'] = $injector = new Horde_Injector(new Horde_Injector_TopLevel()); + $injector->setInstance('Horde_Log_Logger', new Horde_Core_Log_Logger(new Horde_Log_Handler_Mock())); + } + /** * Initialize the class. */ @@ -98,7 +101,7 @@ class Horde_Kolab_Filter_Base { /* Setup the temporary storage */ $result = $this->_initTmp(); - if (is_a($result, 'PEAR_Error')) { + if ($result instanceOf PEAR_Error) { return $result; } @@ -208,9 +211,14 @@ class Horde_Kolab_Filter_Base } if (empty($values['recipient'])) { - $msg = 'Please provide one or more recipients.' - . "\n\n" . $p->getUsage(); - return PEAR::raiseError($msg, OUT_STDOUT | EX_USAGE); + throw new Horde_Kolab_Filter_Exception( + sprintf( + "Please provide one or more recipients.\n\n%s", + $p->getUsage() + ), + Horde_Kolab_Filter_Exception::OUT_STDOUT | + Horde_Kolab_Filter_Exception::EX_USAGE + ); } $this->_sender = strtolower($values['sender']); diff --git a/framework/Kolab_Filter/test/Horde/Kolab/Filter/AllTests.php b/framework/Kolab_Filter/test/Horde/Kolab/Filter/AllTests.php new file mode 100644 index 000000000..66b842c36 --- /dev/null +++ b/framework/Kolab_Filter/test/Horde/Kolab/Filter/AllTests.php @@ -0,0 +1,87 @@ + + * @license http://www.fsf.org/copyleft/lgpl.html LGPL + * @link http://pear.horde.org/index.php?package=Kolab_Storage + */ + +/** + * Define the main method + */ +if (!defined('PHPUnit_MAIN_METHOD')) { + define('PHPUnit_MAIN_METHOD', 'Horde_Kolab_Storage_AllTests::main'); +} + +/** + * Prepare the test setup. + */ +require_once 'Horde/Test/AllTests.php'; + +/** + * @package Horde_Kolab_Storage + * @subpackage UnitTests + */ +class Horde_Kolab_Storage_AllTests extends Horde_Test_AllTests +{ + /** + * Main entry point for running the suite. + */ + public static function main($package = null, $file = null) + { + if ($package) { + self::$_package = $package; + } + if ($file) { + self::$_file = $file; + } + + PHPUnit_TextUI_TestRunner::run(self::suite()); + } + + /** + * Collect the unit tests of this directory into a new suite. + * + * @return PHPUnit_Framework_TestSuite The test suite. + */ + public static function suite() + { + return self::detectTestFixture(Horde_Test_AllTests::suite()); + } + + /** + * Detect if test configuration is available for the server integration + * tests. + * + * @param PHPUnit_Framework_TestSuite $suite The current test suite. + */ + public static function detectTestFixture(PHPUnit_Framework_TestSuite $suite) + { + $config = getenv('KOLAB_STORAGE_TEST_CONFIG'); + if ($config === false) { + $config = dirname(__FILE__) . '/conf.php'; + } + if (file_exists($config)) { + require $config; + if (isset($conf['kolab']['storage']['test'])) { + $fixture = new stdClass; + $fixture->conf = $conf['kolab']['storage']['test']; + $fixture->drivers = array(); + $suite->setSharedFixture($fixture); + } + } + return $suite; + } +} + +Horde_Kolab_Storage_AllTests::init('Horde_Kolab_Storage', __FILE__); + +if (PHPUnit_MAIN_METHOD == 'Horde_Kolab_Storage_AllTests::main') { + Horde_Kolab_Storage_AllTests::main(); +} diff --git a/framework/Kolab_Filter/test/Horde/Kolab/Filter/Autoload.php b/framework/Kolab_Filter/test/Horde/Kolab/Filter/Autoload.php new file mode 100644 index 000000000..d92650cea --- /dev/null +++ b/framework/Kolab_Filter/test/Horde/Kolab/Filter/Autoload.php @@ -0,0 +1,38 @@ + + * @license http://www.fsf.org/copyleft/lgpl.html LGPL + * @link http://pear.horde.org/index.php?package=Kolab_Filter + */ + +if (!spl_autoload_functions()) { + spl_autoload_register( + create_function( + '$class', + '$filename = str_replace(array(\'::\', \'_\'), \'/\', $class);' + . '$err_mask = E_ALL ^ E_WARNING;' + . '$oldErrorReporting = error_reporting($err_mask);' + . 'include "$filename.php";' + . 'error_reporting($oldErrorReporting);' + ) + ); +} + +/** Catch strict standards */ +error_reporting(E_ALL | E_STRICT); + + +/** Load the basic test definition */ +require_once dirname(__FILE__) . '/StoryTestCase.php'; diff --git a/framework/Kolab_Filter/test/Horde/Kolab/Filter/FilterTest.php b/framework/Kolab_Filter/test/Horde/Kolab/Filter/FilterTest.php index a399dfe35..634f41b77 100644 --- a/framework/Kolab_Filter/test/Horde/Kolab/Filter/FilterTest.php +++ b/framework/Kolab_Filter/test/Horde/Kolab/Filter/FilterTest.php @@ -2,17 +2,20 @@ /** * Test the base filter class within the Kolab filter implementation. * - * @package Horde_Kolab_Filter + * PHP version 5 + * + * @category Kolab + * @package Kolab_Filter + * @subpackage UnitTests + * @author Gunnar Wrobel + * @license http://www.fsf.org/copyleft/lgpl.html LGPL + * @link http://pear.horde.org/index.php?package=Kolab_Filter */ /** - * We need the unit test framework + * Prepare the test setup. */ -require_once 'PHPUnit/Framework.php'; -require_once 'PHPUnit/Extensions/OutputTestCase.php'; - -require_once 'Horde.php'; -require_once 'Horde/Kolab/Filter/Incoming.php'; +require_once dirname(__FILE__) . '/Autoload.php'; /** * Test the filter class. @@ -22,8 +25,12 @@ require_once 'Horde/Kolab/Filter/Incoming.php'; * See the enclosed file COPYING for license information (LGPL). If you * did not receive this file, see http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. * - * @author Gunnar Wrobel - * @package Horde_Kolab_Filter + * @category Kolab + * @package Kolab_Filter + * @subpackage UnitTests + * @author Gunnar Wrobel + * @license http://www.fsf.org/copyleft/lgpl.html LGPL + * @link http://pear.horde.org/index.php?package=Kolab_Filter */ class Horde_Kolab_Filter_FilterTest extends PHPUnit_Framework_TestCase { @@ -49,10 +56,12 @@ class Horde_Kolab_Filter_FilterTest extends PHPUnit_Framework_TestCase $_SERVER['argv'] = array($_SERVER['argv'][0]); $parser = &new Horde_Kolab_Filter_Incoming(); $inh = fopen(dirname(__FILE__) . '/fixtures/tiny.eml', 'r'); - $result = $parser->parse($inh, 'echo'); - - $this->assertTrue(is_a($result, 'PEAR_Error')); - - $this->assertContains('Please provide one or more recipients.', $result->getMessage()); + try { + $result = $parser->parse($inh, 'echo'); + } catch (Horde_Kolab_Filter_Exception $e) { + $this->assertContains('Please provide one or more recipients.', $e->getMessage()); + return; + } + $this->assertFail('No exception!'); } } diff --git a/framework/Kolab_Filter/test/Horde/Kolab/Filter/StoryTestCase.php b/framework/Kolab_Filter/test/Horde/Kolab/Filter/StoryTestCase.php new file mode 100644 index 000000000..6b6c285e3 --- /dev/null +++ b/framework/Kolab_Filter/test/Horde/Kolab/Filter/StoryTestCase.php @@ -0,0 +1,90 @@ + + * @license http://www.fsf.org/copyleft/lgpl.html LGPL + * @link http://pear.horde.org/index.php?package=Kolab_Filter + */ + +/** + * Base for scenario based testing of this package. + * + * Copyright 2010 Klarälvdalens Datakonsult AB + * + * 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 Kolab + * @package Kolab_Filter + * @subpackage UnitTests + * @author Gunnar Wrobel + * @license http://www.fsf.org/copyleft/lgpl.html LGPL + * @link http://pear.horde.org/index.php?package=Kolab_Filter + */ +class Horde_Kolab_Filter_StoryTestCase +extends PHPUnit_Extensions_Story_TestCase +{ + /** + * Handle a "given" step. + * + * @param array &$world Joined "world" of variables. + * @param string $action The description of the step. + * @param array $arguments Additional arguments to the step. + * + * @return mixed The outcome of the step. + */ + public function runGiven(&$world, $action, $arguments) + { + switch($action) { + case 'that no Kolab server configuration file can be found': + break; + default: + return $this->notImplemented($action); + } + } + + /** + * Handle a "when" step. + * + * @param array &$world Joined "world" of variables. + * @param string $action The description of the step. + * @param array $arguments Additional arguments to the step. + * + * @return mixed The outcome of the step. + */ + public function runWhen(&$world, $action, $arguments) + { + switch($action) { + case 'reading the configuration': + break; + default: + return $this->notImplemented($action); + } + } + + /** + * Handle a "then" step. + * + * @param array &$world Joined "world" of variables. + * @param string $action The description of the step. + * @param array $arguments Additional arguments to the step. + * + * @return mixed The outcome of the step. + */ + public function runThen(&$world, $action, $arguments) + { + switch($action) { + case 'the Config Object will throw an exception of type': + break; + default: + return $this->notImplemented($action); + } + } + +} \ No newline at end of file