1f8369d7dSTobias Sarnowski<?php 2f8369d7dSTobias Sarnowski/** 3f8369d7dSTobias Sarnowski * Helper class to provide basic functionality for tests 4f8369d7dSTobias Sarnowski */ 5f8369d7dSTobias Sarnowskiabstract class DokuWikiTest extends PHPUnit_Framework_TestCase { 6f8369d7dSTobias Sarnowski 7f8369d7dSTobias Sarnowski /** 8f8369d7dSTobias Sarnowski * tests can override this 9f8369d7dSTobias Sarnowski * 10f8369d7dSTobias Sarnowski * @var array plugins to enable for test class 11f8369d7dSTobias Sarnowski */ 12f8369d7dSTobias Sarnowski protected $pluginsEnabled = array(); 13f8369d7dSTobias Sarnowski 14f8369d7dSTobias Sarnowski /** 15f8369d7dSTobias Sarnowski * tests can override this 16f8369d7dSTobias Sarnowski * 17f8369d7dSTobias Sarnowski * @var array plugins to disable for test class 18f8369d7dSTobias Sarnowski */ 19f8369d7dSTobias Sarnowski protected $pluginsDisabled = array(); 20f8369d7dSTobias Sarnowski 21f8369d7dSTobias Sarnowski /** 220644090aSAndreas Gohr * Setup the data directory 230644090aSAndreas Gohr * 240644090aSAndreas Gohr * This is ran before each test class 250644090aSAndreas Gohr */ 260644090aSAndreas Gohr public static function setUpBeforeClass() { 270644090aSAndreas Gohr // just to be safe not to delete something undefined later 280644090aSAndreas Gohr if(!defined('TMP_DIR')) die('no temporary directory'); 290644090aSAndreas Gohr if(!defined('DOKU_TMP_DATA')) die('no temporary data directory'); 300644090aSAndreas Gohr 310644090aSAndreas Gohr // remove any leftovers from the last run 320644090aSAndreas Gohr if(is_dir(DOKU_TMP_DATA)){ 334f708321SMichael Hamann // clear indexer data and cache 344f708321SMichael Hamann idx_get_indexer()->clear(); 350644090aSAndreas Gohr TestUtils::rdelete(DOKU_TMP_DATA); 360644090aSAndreas Gohr } 370644090aSAndreas Gohr 380644090aSAndreas Gohr // populate default dirs 390644090aSAndreas Gohr TestUtils::rcopy(TMP_DIR, dirname(__FILE__).'/../data/'); 400644090aSAndreas Gohr } 410644090aSAndreas Gohr 420644090aSAndreas Gohr /** 43f8369d7dSTobias Sarnowski * Reset the DokuWiki environment before each test run. Makes sure loaded config, 44f8369d7dSTobias Sarnowski * language and plugins are correct. 45f8369d7dSTobias Sarnowski * 46f8369d7dSTobias Sarnowski * @throws Exception if plugin actions fail 47f8369d7dSTobias Sarnowski * @return void 48f8369d7dSTobias Sarnowski */ 49f8369d7dSTobias Sarnowski public function setUp() { 500644090aSAndreas Gohr 51f8369d7dSTobias Sarnowski // reload config 52f8369d7dSTobias Sarnowski global $conf, $config_cascade; 53f8369d7dSTobias Sarnowski $conf = array(); 54f8369d7dSTobias Sarnowski foreach (array('default','local','protected') as $config_group) { 55f8369d7dSTobias Sarnowski if (empty($config_cascade['main'][$config_group])) continue; 56f8369d7dSTobias Sarnowski foreach ($config_cascade['main'][$config_group] as $config_file) { 57*79e79377SAndreas Gohr if (file_exists($config_file)) { 58f8369d7dSTobias Sarnowski include($config_file); 59f8369d7dSTobias Sarnowski } 60f8369d7dSTobias Sarnowski } 61f8369d7dSTobias Sarnowski } 62f8369d7dSTobias Sarnowski 63f8369d7dSTobias Sarnowski // reload license config 64f8369d7dSTobias Sarnowski global $license; 65f8369d7dSTobias Sarnowski $license = array(); 66f8369d7dSTobias Sarnowski 67f8369d7dSTobias Sarnowski // load the license file(s) 68f8369d7dSTobias Sarnowski foreach (array('default','local') as $config_group) { 69f8369d7dSTobias Sarnowski if (empty($config_cascade['license'][$config_group])) continue; 70f8369d7dSTobias Sarnowski foreach ($config_cascade['license'][$config_group] as $config_file) { 71*79e79377SAndreas Gohr if(file_exists($config_file)){ 72f8369d7dSTobias Sarnowski include($config_file); 73f8369d7dSTobias Sarnowski } 74f8369d7dSTobias Sarnowski } 75f8369d7dSTobias Sarnowski } 76f8369d7dSTobias Sarnowski 77f8369d7dSTobias Sarnowski // make real paths and check them 78f8369d7dSTobias Sarnowski init_paths(); 79f8369d7dSTobias Sarnowski init_files(); 80f8369d7dSTobias Sarnowski 81f8369d7dSTobias Sarnowski // reset loaded plugins 82f8369d7dSTobias Sarnowski global $plugin_controller_class, $plugin_controller; 83e3ab6fc5SMichael Hamann /** @var Doku_Plugin_Controller $plugin_controller */ 84f8369d7dSTobias Sarnowski $plugin_controller = new $plugin_controller_class(); 85f8369d7dSTobias Sarnowski 86f8369d7dSTobias Sarnowski // disable all non-default plugins 87f8369d7dSTobias Sarnowski global $default_plugins; 88f8369d7dSTobias Sarnowski foreach ($plugin_controller->getList() as $plugin) { 89f8369d7dSTobias Sarnowski if (!in_array($plugin, $default_plugins)) { 90f8369d7dSTobias Sarnowski if (!$plugin_controller->disable($plugin)) { 91f8369d7dSTobias Sarnowski throw new Exception('Could not disable plugin "'.$plugin.'"!'); 92f8369d7dSTobias Sarnowski } 93f8369d7dSTobias Sarnowski } 94f8369d7dSTobias Sarnowski } 95f8369d7dSTobias Sarnowski 96f8369d7dSTobias Sarnowski // disable and enable configured plugins 97f8369d7dSTobias Sarnowski foreach ($this->pluginsDisabled as $plugin) { 98f8369d7dSTobias Sarnowski if (!$plugin_controller->disable($plugin)) { 99f8369d7dSTobias Sarnowski throw new Exception('Could not disable plugin "'.$plugin.'"!'); 100f8369d7dSTobias Sarnowski } 101f8369d7dSTobias Sarnowski } 102f8369d7dSTobias Sarnowski foreach ($this->pluginsEnabled as $plugin) { 103f8369d7dSTobias Sarnowski /* enable() returns false but works... 104f8369d7dSTobias Sarnowski if (!$plugin_controller->enable($plugin)) { 105f8369d7dSTobias Sarnowski throw new Exception('Could not enable plugin "'.$plugin.'"!'); 106f8369d7dSTobias Sarnowski } 107f8369d7dSTobias Sarnowski */ 108f8369d7dSTobias Sarnowski $plugin_controller->enable($plugin); 109f8369d7dSTobias Sarnowski } 110f8369d7dSTobias Sarnowski 111f8369d7dSTobias Sarnowski // reset event handler 112f8369d7dSTobias Sarnowski global $EVENT_HANDLER; 113f8369d7dSTobias Sarnowski $EVENT_HANDLER = new Doku_Event_Handler(); 114f8369d7dSTobias Sarnowski 115f8369d7dSTobias Sarnowski // reload language 116f8369d7dSTobias Sarnowski $local = $conf['lang']; 117f8369d7dSTobias Sarnowski trigger_event('INIT_LANG_LOAD', $local, 'init_lang', true); 118c01cdb70SChristopher Smith 119c01cdb70SChristopher Smith global $INPUT; 120c01cdb70SChristopher Smith $INPUT = new Input(); 121f8369d7dSTobias Sarnowski } 122f8369d7dSTobias Sarnowski} 123