Skip to content
Permalink
Browse files

Merge pull request #2382 from splitbrain/psr2-config

PSR-2 refactoring for config plugin
  • Loading branch information...
splitbrain committed Jun 15, 2018
2 parents 8eb28c6 + f8dcd5b commit c68e26990b12edc475a3156a8f7c4663a3abc078
Showing with 2,747 additions and 2,112 deletions.
  1. +3 −9 _test/bootstrap.php
  2. +52 −9 _test/core/DokuWikiTest.php
  3. +5 −2 _test/phpunit.xml
  4. +39 −4 inc/deprecated.php
  5. +10 −22 lib/plugins/config/_test/{configuration.test.php → ConfigParserTest.php}
  6. +79 −0 lib/plugins/config/_test/LoaderTest.php
  7. +99 −0 lib/plugins/config/_test/Setting/AbstractSettingTest.php
  8. +20 −0 lib/plugins/config/_test/Setting/SettingArrayTest.php
  9. +24 −0 lib/plugins/config/_test/Setting/SettingNumericTest.php
  10. +23 −0 lib/plugins/config/_test/Setting/SettingNumericoptTest.php
  11. +72 −0 lib/plugins/config/_test/Setting/SettingOnoffTest.php
  12. +13 −0 lib/plugins/config/_test/Setting/SettingStringTest.php
  13. +70 −0 lib/plugins/config/_test/Setting/SettingTest.php
  14. +63 −0 lib/plugins/config/_test/WriterTest.php
  15. +147 −281 lib/plugins/config/admin.php
  16. +90 −0 lib/plugins/config/core/ConfigParser.php
  17. +219 −0 lib/plugins/config/core/Configuration.php
  18. +267 −0 lib/plugins/config/core/Loader.php
  19. +294 −0 lib/plugins/config/core/Setting/Setting.php
  20. +105 −0 lib/plugins/config/core/Setting/SettingArray.php
  21. +60 −0 lib/plugins/config/core/Setting/SettingAuthtype.php
  22. +21 −0 lib/plugins/config/core/Setting/SettingCompression.php
  23. +33 −0 lib/plugins/config/core/Setting/SettingDirchoice.php
  24. +23 −0 lib/plugins/config/core/Setting/SettingDisableactions.php
  25. +58 −0 lib/plugins/config/core/Setting/SettingEmail.php
  26. +17 −0 lib/plugins/config/core/Setting/SettingFieldset.php
  27. +10 −0 lib/plugins/config/core/Setting/SettingHidden.php
  28. +28 −0 lib/plugins/config/core/Setting/SettingImConvert.php
  29. +23 −0 lib/plugins/config/core/Setting/SettingLicense.php
  30. +163 −0 lib/plugins/config/core/Setting/SettingMulticheckbox.php
  31. +71 −0 lib/plugins/config/core/Setting/SettingMultichoice.php
  32. +12 −0 lib/plugins/config/core/Setting/SettingNoClass.php
  33. +13 −0 lib/plugins/config/core/Setting/SettingNoDefault.php
  34. +11 −0 lib/plugins/config/core/Setting/SettingNoKnownClass.php
  35. +42 −0 lib/plugins/config/core/Setting/SettingNumeric.php
  36. +25 −0 lib/plugins/config/core/Setting/SettingNumericopt.php
  37. +57 −0 lib/plugins/config/core/Setting/SettingOnoff.php
  38. +39 −0 lib/plugins/config/core/Setting/SettingPassword.php
  39. +34 −0 lib/plugins/config/core/Setting/SettingRegex.php
  40. +56 −0 lib/plugins/config/core/Setting/SettingRenderer.php
  41. +26 −0 lib/plugins/config/core/Setting/SettingSavedir.php
  42. +18 −0 lib/plugins/config/core/Setting/SettingSepchar.php
  43. +32 −0 lib/plugins/config/core/Setting/SettingString.php
  44. +40 −0 lib/plugins/config/core/Setting/SettingUndefined.php
  45. +116 −0 lib/plugins/config/core/Writer.php
  46. +1 −0 lib/plugins/config/lang/en/lang.php
  47. +0 −1,454 lib/plugins/config/settings/config.class.php
  48. +5 −22 lib/plugins/config/settings/config.metadata.php
  49. +0 −309 lib/plugins/config/settings/extra.class.php
  50. +7 −0 lib/plugins/testing/conf/default.php
  51. +7 −0 lib/plugins/testing/conf/metadata.php
  52. +5 −0 lib/plugins/testing/lang/en/settings.php
@@ -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/');
@@ -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();
}
/**
@@ -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
*
@@ -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>

@@ -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);
}
@@ -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 /
*
@@ -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);
@@ -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);
@@ -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']
);
}
}
Oops, something went wrong.

0 comments on commit c68e269

Please sign in to comment.
You can’t perform that action at this time.
You signed in with another tab or window. Reload to refresh your session. You signed out in another tab or window. Reload to refresh your session.