diff options
author | Tobias Sarnowski <sarnowski@cosmocode.de> | 2012-04-18 12:08:28 +0200 |
---|---|---|
committer | Tobias Sarnowski <sarnowski@cosmocode.de> | 2012-04-18 12:08:28 +0200 |
commit | f8369d7d6e37248d6523fdac6e1d760fca4f1b52 (patch) | |
tree | 0848c213ffc191a23b55f07bd2ec55e777ea79ca /_test/core/DokuWikiTest.php | |
parent | d59108b91e9bf9fd56dc2e697cf31f9bbc7f9cd4 (diff) | |
download | rpg-f8369d7d6e37248d6523fdac6e1d760fca4f1b52.tar.gz rpg-f8369d7d6e37248d6523fdac6e1d760fca4f1b52.tar.bz2 |
moved _testing to _test
Diffstat (limited to '_test/core/DokuWikiTest.php')
-rw-r--r-- | _test/core/DokuWikiTest.php | 96 |
1 files changed, 96 insertions, 0 deletions
diff --git a/_test/core/DokuWikiTest.php b/_test/core/DokuWikiTest.php new file mode 100644 index 000000000..e47c06329 --- /dev/null +++ b/_test/core/DokuWikiTest.php @@ -0,0 +1,96 @@ +<?php +/** + * Helper class to provide basic functionality for tests + */ +abstract class DokuWikiTest extends PHPUnit_Framework_TestCase { + + /** + * tests can override this + * + * @var array plugins to enable for test class + */ + protected $pluginsEnabled = array(); + + /** + * tests can override this + * + * @var array plugins to disable for test class + */ + protected $pluginsDisabled = array(); + + /** + * Reset the DokuWiki environment before each test run. Makes sure loaded config, + * language and plugins are correct. + * + * @throws Exception if plugin actions fail + * @return void + */ + public 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(); + + // disable all non-default plugins + global $default_plugins; + foreach ($plugin_controller->getList() as $plugin) { + if (!in_array($plugin, $default_plugins)) { + if (!$plugin_controller->disable($plugin)) { + throw new Exception('Could not disable plugin "'.$plugin.'"!'); + } + } + } + + // disable and enable configured plugins + foreach ($this->pluginsDisabled as $plugin) { + if (!$plugin_controller->disable($plugin)) { + throw new Exception('Could not disable plugin "'.$plugin.'"!'); + } + } + foreach ($this->pluginsEnabled as $plugin) { + /* enable() returns false but works... + if (!$plugin_controller->enable($plugin)) { + throw new Exception('Could not enable plugin "'.$plugin.'"!'); + } + */ + $plugin_controller->enable($plugin); + } + + // reset event handler + global $EVENT_HANDLER; + $EVENT_HANDLER = new Doku_Event_Handler(); + + // reload language + $local = $conf['lang']; + trigger_event('INIT_LANG_LOAD', $local, 'init_lang', true); + } +} |