Skip to content

Commit

Permalink
Merge pull request #2382 from splitbrain/psr2-config
Browse files Browse the repository at this point in the history
PSR-2 refactoring for config plugin
  • Loading branch information
splitbrain committed Jun 15, 2018
2 parents 8eb28c6 + f8dcd5b commit c68e269
Show file tree
Hide file tree
Showing 52 changed files with 2,747 additions and 2,112 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
7 changes: 5 additions & 2 deletions _test/phpunit.xml
Expand Up @@ -10,12 +10,15 @@
<testsuites>
<testsuite name="DokuWiki Tests">
<directory suffix=".test.php">tests/</directory>
<directory suffix="Test.php">tests/</directory>
</testsuite>
<testsuite name="Plugin Tests">
<directory suffix=".test.php">../lib/plugins/*/_test</directory>
<directory suffix=".test.php">../lib/plugins/*/_test/</directory>
<directory suffix="Test.php">../lib/plugins/*/_test/</directory>
</testsuite>
<testsuite name="Template Tests">
<directory suffix=".test.php">../lib/tpl/*/_test</directory>
<directory suffix=".test.php">../lib/tpl/*/_test/</directory>
<directory suffix="Test.php">../lib/tpl/*/_test/</directory>
</testsuite>
</testsuites>

Expand Down
43 changes: 39 additions & 4 deletions inc/deprecated.php
Expand Up @@ -11,7 +11,7 @@
class RemoteAccessDeniedException extends \dokuwiki\Remote\AccessDeniedException {
/** @inheritdoc */
public function __construct($message = "", $code = 0, Throwable $previous = null) {
dbg_deprecated('dokuwiki\Remote\AccessDeniedException');
dbg_deprecated(\dokuwiki\Remote\AccessDeniedException::class);
parent::__construct($message, $code, $previous);
}

Expand All @@ -24,13 +24,12 @@ public function __construct($message = "", $code = 0, Throwable $previous = null
class RemoteException extends \dokuwiki\Remote\RemoteException {
/** @inheritdoc */
public function __construct($message = "", $code = 0, Throwable $previous = null) {
dbg_deprecated('dokuwiki\\Remote\\RemoteException');
dbg_deprecated(\dokuwiki\Remote\RemoteException::class);
parent::__construct($message, $code, $previous);
}

}


/**
* Escapes regex characters other than (, ) and /
*
Expand All @@ -39,6 +38,42 @@ public function __construct($message = "", $code = 0, Throwable $previous = null
* @deprecated 2018-05-04
*/
function Doku_Lexer_Escape($str) {
dbg_deprecated('dokuwiki\\Parsing\\Lexer\\Lexer::escape');
dbg_deprecated('\\dokuwiki\\Parsing\\Lexer\\Lexer::escape()');
return \dokuwiki\Parsing\Lexer\Lexer::escape($str);
}

/**
* @inheritdoc
* @deprecated 2018-06-01
*/
class setting extends \dokuwiki\plugin\config\core\Setting\Setting {
/** @inheritdoc */
public function __construct($key, array $params = null) {
dbg_deprecated(\dokuwiki\plugin\config\core\Setting\Setting::class);
parent::__construct($key, $params);
}
}

/**
* @inheritdoc
* @deprecated 2018-06-01
*/
class setting_authtype extends \dokuwiki\plugin\config\core\Setting\SettingAuthtype {
/** @inheritdoc */
public function __construct($key, array $params = null) {
dbg_deprecated(\dokuwiki\plugin\config\core\Setting\SettingAuthtype::class);
parent::__construct($key, $params);
}
}

/**
* @inheritdoc
* @deprecated 2018-06-01
*/
class setting_string extends \dokuwiki\plugin\config\core\Setting\SettingString {
/** @inheritdoc */
public function __construct($key, array $params = null) {
dbg_deprecated(\dokuwiki\plugin\config\core\Setting\SettingString::class);
parent::__construct($key, $params);
}
}
@@ -1,31 +1,20 @@
<?php

namespace dokuwiki\plugin\config\test;

use dokuwiki\plugin\config\core\ConfigParser;

/**
* @group plugin_config
* @group admin_plugins
* @group plugins
* @group bundled_plugins
*/

class plugin_config_configuration_test extends DokuWikiTest {

private $config = '';
private $meta = '';

/**
* Load config files
*/
function __construct() {
parent::__construct();

$this->config = dirname(__FILE__).'/data/config.php';
$this->meta = dirname(__FILE__).'/data/metadata.php';
require_once(dirname(__FILE__).'/../settings/config.class.php');
}
class ConfigParserTest extends \DokuWikiTest {

function test_readconfig() {
$confmgr = new configuration($this->meta);

$conf = $this->callInaccessibleMethod($confmgr, '_read_config', [$this->config]);
$parser = new ConfigParser();
$conf = $parser->parse(__DIR__ . '/data/config.php');

// var_dump($conf);

Expand All @@ -42,9 +31,8 @@ function test_readconfig() {
}

function test_readconfig_onoff() {
$confmgr = new configuration($this->meta);

$conf = $this->callInaccessibleMethod($confmgr, '_read_config', [$this->config]);
$parser = new ConfigParser();
$conf = $parser->parse(__DIR__ . '/data/config.php');

// var_dump($conf);

Expand Down
79 changes: 79 additions & 0 deletions lib/plugins/config/_test/LoaderTest.php
@@ -0,0 +1,79 @@
<?php

namespace dokuwiki\plugin\config\test;

use dokuwiki\plugin\config\core\ConfigParser;
use dokuwiki\plugin\config\core\Loader;

/**
* @group plugin_config
* @group admin_plugins
* @group plugins
* @group bundled_plugins
*/
class LoaderTest extends \DokuWikiTest {

protected $pluginsEnabled = ['testing'];

/**
* Ensure loading the config meta data works
*/
public function testMetaData() {
$loader = new Loader(new ConfigParser());

$meta = $loader->loadMeta();
$this->assertTrue(is_array($meta));

// there should be some defaults
$this->assertArrayHasKey('savedir', $meta);
$this->assertEquals(['savedir', '_caution' => 'danger'], $meta['savedir']);
$this->assertArrayHasKey('proxy____port', $meta);
$this->assertEquals(['numericopt'], $meta['proxy____port']);

// there should be plugin info
$this->assertArrayHasKey('plugin____testing____plugin_settings_name', $meta);
$this->assertEquals(['fieldset'], $meta['plugin____testing____plugin_settings_name']);
$this->assertArrayHasKey('plugin____testing____schnibble', $meta);
$this->assertEquals(['onoff'], $meta['plugin____testing____schnibble']);
}

/**
* Ensure loading the defaults work
*/
public function testDefaults() {
$loader = new Loader(new ConfigParser());

$conf = $loader->loadDefaults();
$this->assertTrue(is_array($conf));

// basic defaults
$this->assertArrayHasKey('title', $conf);
$this->assertEquals('DokuWiki', $conf['title']);

// plugin defaults
$this->assertArrayHasKey('plugin____testing____schnibble', $conf);
$this->assertEquals(0, $conf['plugin____testing____schnibble']);
}

/**
* Ensure language loading works
*/
public function testLangs() {
$loader = new Loader(new ConfigParser());

$lang = $loader->loadLangs();
$this->assertTrue(is_array($lang));

// basics are not included in the returned array!
$this->assertArrayNotHasKey('title', $lang);

// plugin strings
$this->assertArrayHasKey('plugin____testing____plugin_settings_name', $lang);
$this->assertEquals('Testing', $lang['plugin____testing____plugin_settings_name']);
$this->assertArrayHasKey('plugin____testing____schnibble', $lang);
$this->assertEquals(
'Turns on the schnibble before the frobble is used',
$lang['plugin____testing____schnibble']
);
}
}

0 comments on commit c68e269

Please sign in to comment.