1<?php 2/** 3 * Helper class to provide basic functionality for tests 4 */ 5abstract class DokuWikiTest extends PHPUnit_Framework_TestCase { 6 7 /** 8 * tests can override this 9 * 10 * @var array plugins to enable for test class 11 */ 12 protected $pluginsEnabled = array(); 13 14 /** 15 * tests can override this 16 * 17 * @var array plugins to disable for test class 18 */ 19 protected $pluginsDisabled = array(); 20 21 /** 22 * Reset the DokuWiki environment before each test run. Makes sure loaded config, 23 * language and plugins are correct. 24 * 25 * @throws Exception if plugin actions fail 26 * @return void 27 */ 28 public function setUp() { 29 // reload config 30 global $conf, $config_cascade; 31 $conf = array(); 32 foreach (array('default','local','protected') as $config_group) { 33 if (empty($config_cascade['main'][$config_group])) continue; 34 foreach ($config_cascade['main'][$config_group] as $config_file) { 35 if (@file_exists($config_file)) { 36 include($config_file); 37 } 38 } 39 } 40 41 // reload license config 42 global $license; 43 $license = array(); 44 45 // load the license file(s) 46 foreach (array('default','local') as $config_group) { 47 if (empty($config_cascade['license'][$config_group])) continue; 48 foreach ($config_cascade['license'][$config_group] as $config_file) { 49 if(@file_exists($config_file)){ 50 include($config_file); 51 } 52 } 53 } 54 55 // make real paths and check them 56 init_paths(); 57 init_files(); 58 59 // reset loaded plugins 60 global $plugin_controller_class, $plugin_controller; 61 $plugin_controller = new $plugin_controller_class(); 62 63 // disable all non-default plugins 64 global $default_plugins; 65 foreach ($plugin_controller->getList() as $plugin) { 66 if (!in_array($plugin, $default_plugins)) { 67 if (!$plugin_controller->disable($plugin)) { 68 throw new Exception('Could not disable plugin "'.$plugin.'"!'); 69 } 70 } 71 } 72 73 // disable and enable configured plugins 74 foreach ($this->pluginsDisabled as $plugin) { 75 if (!$plugin_controller->disable($plugin)) { 76 throw new Exception('Could not disable plugin "'.$plugin.'"!'); 77 } 78 } 79 foreach ($this->pluginsEnabled as $plugin) { 80 /* enable() returns false but works... 81 if (!$plugin_controller->enable($plugin)) { 82 throw new Exception('Could not enable plugin "'.$plugin.'"!'); 83 } 84 */ 85 $plugin_controller->enable($plugin); 86 } 87 88 // reset event handler 89 global $EVENT_HANDLER; 90 $EVENT_HANDLER = new Doku_Event_Handler(); 91 92 // reload language 93 $local = $conf['lang']; 94 trigger_event('INIT_LANG_LOAD', $local, 'init_lang', true); 95 } 96} 97