Skip to content

Commit

Permalink
reset config directory for every test
Browse files Browse the repository at this point in the history
Our test suite did not reset the config directory for each test class as
it does for the data directory. In addition it copied all files from the
main config directory over. Both may create an unpredictable state for
tests.

This streamlines the initialization.
  • Loading branch information
splitbrain committed May 18, 2018
1 parent 7a371ad commit 1c0be3e
Show file tree
Hide file tree
Showing 2 changed files with 55 additions and 18 deletions.
12 changes: 3 additions & 9 deletions _test/bootstrap.php
Expand Up @@ -88,15 +88,9 @@
echo ">>>> Preserving temporary directory: ".TMP_DIR."\n";
}

// populate default dirs
TestUtils::rcopy(TMP_DIR, DOKU_INC.'/conf');
TestUtils::rcopy(TMP_DIR, dirname(__FILE__).'/conf');
mkdir(DOKU_TMP_DATA);
foreach(array(
'attic', 'cache', 'index', 'locks', 'media',
'media_attic', 'media_meta', 'meta', 'pages', 'tmp') as $dir){
mkdir(DOKU_TMP_DATA.'/'.$dir);
}
// populate default dirs for initial setup
DokuWikiTest::setupDataDir();
DokuWikiTest::setupConfDir();

// disable all non-default plugins by default
$dh = dir(DOKU_INC.'lib/plugins/');
Expand Down
61 changes: 52 additions & 9 deletions _test/core/DokuWikiTest.php
Expand Up @@ -50,15 +50,8 @@ public static function setUpBeforeClass() {
if(!defined('TMP_DIR')) die('no temporary directory');
if(!defined('DOKU_TMP_DATA')) die('no temporary data directory');

// remove any leftovers from the last run
if(is_dir(DOKU_TMP_DATA)){
// clear indexer data and cache
idx_get_indexer()->clear();
TestUtils::rdelete(DOKU_TMP_DATA);
}

// populate default dirs
TestUtils::rcopy(TMP_DIR, dirname(__FILE__).'/../data/');
self::setupDataDir();
self::setupConfDir();
}

/**
Expand Down Expand Up @@ -150,6 +143,56 @@ public function setUp() {
$INPUT = new Input();
}

/**
* Reinitialize the data directory for this class run
*/
public static function setupDataDir() {
// remove any leftovers from the last run
if(is_dir(DOKU_TMP_DATA)) {
// clear indexer data and cache
idx_get_indexer()->clear();
TestUtils::rdelete(DOKU_TMP_DATA);
}

// populate default dirs
TestUtils::rcopy(TMP_DIR, __DIR__ . '/../data/');
}

/**
* Reinitialize the conf directory for this class run
*/
public static function setupConfDir() {
$defaults = [
'acronyms.conf',
'dokuwiki.php',
'entities.conf',
'interwiki.conf',
'license.php',
'manifest.json',
'mediameta.php',
'mime.conf',
'plugins.php',
'plugins.required.php',
'scheme.conf',
'smileys.conf',
'wordblock.conf'
];

// clear any leftovers
if(is_dir(DOKU_CONF)) {
TestUtils::rdelete(DOKU_CONF);
}
mkdir(DOKU_CONF);

// copy defaults
foreach($defaults as $file) {
copy(DOKU_INC . '/conf/' . $file, DOKU_CONF . $file);
}

// copy test files
TestUtils::rcopy(TMP_DIR, __DIR__ . '/../conf');
}

/**
* Waits until a new second has passed
*
Expand Down

0 comments on commit 1c0be3e

Please sign in to comment.