From e048653b52aad13b5964e1626192ffee2211870b Mon Sep 17 00:00:00 2001 From: Andreas Gohr Date: Tue, 17 Apr 2012 15:38:03 +0200 Subject: moved functions and classes out of bootstrap There's still more that I'd like to moved out. bootstrap should not contain any logic but only call the appropriate functions for setup the test environment. --- _testing/bootstrap.php | 163 +++-------------------------------------- _testing/core/DokuWikiTest.php | 52 +++++++++++++ _testing/core/TestRequest.php | 67 +++++++++++++++++ _testing/core/TestUtils.php | 52 +++++++++++++ 4 files changed, 182 insertions(+), 152 deletions(-) create mode 100644 _testing/core/DokuWikiTest.php create mode 100644 _testing/core/TestRequest.php create mode 100644 _testing/core/TestUtils.php diff --git a/_testing/bootstrap.php b/_testing/bootstrap.php index 6ea2c2661..b4356fa7c 100644 --- a/_testing/bootstrap.php +++ b/_testing/bootstrap.php @@ -1,58 +1,16 @@ read())) { - if ($entry == '.' || $entry == '..') { - continue; - } - rcopy($newdestdir, $source.'/'.$entry); - } - $dh->close(); - } -} - -// helper for recursive rmdir()/unlink() -function rdelete($target) { - if (!is_dir($target)) { - unlink($target); - } else { - $dh = dir($target); - while (false !== ($entry = $dh->read())) { - if ($entry == '.' || $entry == '..') { - continue; - } - rdelete("$target/$entry"); - } - $dh->close(); - rmdir($target); - } -} - -// helper to append text to a file -function fappend($file, $text) { - $fh = fopen($file, 'a'); - fwrite($fh, $text); - fclose($fh); -} - -// if someone really wants a special handling during tests -define('DOKU_UNITTEST', true); +// backward compatibility to old test suite define('SIMPLE_TEST', true); // basic behaviours @@ -117,12 +75,12 @@ mkdir(TMP_DIR); // cleanup dir after exit register_shutdown_function(function() { - rdelete(TMP_DIR); + TestUtils::rdelete(TMP_DIR); }); // populate default dirs -rcopy(TMP_DIR, dirname(__FILE__).'/conf'); -rcopy(TMP_DIR, dirname(__FILE__).'/data'); +TestUtils::rcopy(TMP_DIR, dirname(__FILE__).'/conf'); +TestUtils::rcopy(TMP_DIR, dirname(__FILE__).'/data'); // disable all non-default plugins by default $dh = dir(DOKU_INC.'lib/plugins/'); @@ -139,7 +97,7 @@ while (false !== ($entry = $dh->read())) { if (!in_array($plugin, $default_plugins)) { // disable this plugin - fappend(DOKU_CONF.'plugins.local.php', "\$plugins['$plugin'] = 0;\n"); + TestUtils::fappend(DOKU_CONF.'plugins.local.php', "\$plugins['$plugin'] = 0;\n"); } } $dh->close(); @@ -163,103 +121,4 @@ function ob_start_callback($buffer) { $output_buffer .= $buffer; } -// Helper class to provide basic functionality for tests -abstract class DokuWikiTest extends PHPUnit_Framework_TestCase { - // nothing for now, makes migration easy - - function setUp() { - // reload config - global $conf, $config_cascade; - $conf = array(); - foreach (array('default','local','protected') as $config_group) { - if (empty($config_cascade['main'][$config_group])) continue; - foreach ($config_cascade['main'][$config_group] as $config_file) { - if (@file_exists($config_file)) { - include($config_file); - } - } - } - - // reload license config - global $license; - $license = array(); - - // load the license file(s) - foreach (array('default','local') as $config_group) { - if (empty($config_cascade['license'][$config_group])) continue; - foreach ($config_cascade['license'][$config_group] as $config_file) { - if(@file_exists($config_file)){ - include($config_file); - } - } - } - - // make real paths and check them - init_paths(); - init_files(); - - // reset loaded plugins - global $plugin_controller_class, $plugin_controller; - $plugin_controller = new $plugin_controller_class(); - global $EVENT_HANDLER; - $EVENT_HANDLER = new Doku_Event_Handler(); - - // reload language - $local = $conf['lang']; - trigger_event('INIT_LANG_LOAD', $local, 'init_lang', true); - } - -} - -// Helper class to execute a fake request -class TestRequest { - - function execute() { - global $output_buffer; - $output_buffer = ''; - - // now execute dokuwiki and grep the output - header_remove(); - ob_start('ob_start_callback'); - include(DOKU_INC.'doku.php'); - ob_end_flush(); - - // it's done, return the page result - return new TestResponse( - $output_buffer, - headers_list() - ); - } -} - -// holds a copy of all produced outputs of a TestRequest -class TestResponse { - protected $content; - protected $headers; - protected $pq = null; - function __construct($content, $headers) { - $this->content = $content; - $this->headers = $headers; - } - - function getContent() { - return $this->content; - } - - function getHeaders() { - return $this->headers; - } - - /** - * Query the response for a JQuery compatible CSS selector - * - * @link https://code.google.com/p/phpquery/wiki/Selectors - * @param string selector - * @returns object a PHPQuery object - */ - function queryHTML($selector){ - if(is_null($pq)) $pq = phpQuery::newDocument($this->content); - return pq($selector); - } -} diff --git a/_testing/core/DokuWikiTest.php b/_testing/core/DokuWikiTest.php new file mode 100644 index 000000000..8ae261a52 --- /dev/null +++ b/_testing/core/DokuWikiTest.php @@ -0,0 +1,52 @@ +content = $content; + $this->headers = $headers; + } + + function getContent() { + return $this->content; + } + + function getHeaders() { + return $this->headers; + } + + /** + * Query the response for a JQuery compatible CSS selector + * + * @link https://code.google.com/p/phpquery/wiki/Selectors + * @param string selector + * @returns object a PHPQuery object + */ + function queryHTML($selector){ + if(is_null($pq)) $pq = phpQuery::newDocument($this->content); + return pq($selector); + } +} diff --git a/_testing/core/TestUtils.php b/_testing/core/TestUtils.php new file mode 100644 index 000000000..4fd56e85d --- /dev/null +++ b/_testing/core/TestUtils.php @@ -0,0 +1,52 @@ +read())) { + if ($entry == '.' || $entry == '..') { + continue; + } + TestUtils::rcopy($newdestdir, $source.'/'.$entry); + } + $dh->close(); + } + } + + /** + * helper for recursive rmdir()/unlink() + */ + static function rdelete($target) { + if (!is_dir($target)) { + unlink($target); + } else { + $dh = dir($target); + while (false !== ($entry = $dh->read())) { + if ($entry == '.' || $entry == '..') { + continue; + } + TestUtils::rdelete("$target/$entry"); + } + $dh->close(); + rmdir($target); + } + } + + // helper to append text to a file + static function fappend($file, $text) { + $fh = fopen($file, 'a'); + fwrite($fh, $text); + fclose($fh); + } + +} -- cgit v1.2.3