From 03ae5b30f62757d2e7f3c22ed8aceffbbdbfeca9 Mon Sep 17 00:00:00 2001 From: Christoph Ziehr Date: Fri, 20 Nov 2020 17:29:49 +0100 Subject: [PATCH 1/5] Update Loader.php The config options are read in the order plugin-standard-values -> template-standard-values -> dokuwiki.php -> local.php -> local.protected.php into DokuWiki. But when entering the configuration manger, they options are displayed in the order dokuwiki.php -> plugin-standard-values -> template-standard-values -> local.php -> local.protected.php This patch fixes the issue, so that the right values are displayed if there are no configs set in local.php or local.protected.php See also https://forum.dokuwiki.org/d/18489-issues-with-modifying-confdokuwikiphp for further information. --- lib/plugins/config/core/Loader.php | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/lib/plugins/config/core/Loader.php b/lib/plugins/config/core/Loader.php index 90ad0f50e..29f9e8515 100644 --- a/lib/plugins/config/core/Loader.php +++ b/lib/plugins/config/core/Loader.php @@ -78,10 +78,6 @@ class Loader { * @return array */ public function loadDefaults() { - // load main files - global $config_cascade; - $conf = $this->loadConfigs($config_cascade['main']['default']); - // plugins foreach($this->plugins as $plugin) { $conf = array_merge( @@ -104,6 +100,10 @@ class Loader { ) ); + // load main files + global $config_cascade; + $conf = $this->loadConfigs($config_cascade['main']['default']); + return $conf; } From 95775ac735f4e08dd9c915316e4704b4f59af488 Mon Sep 17 00:00:00 2001 From: Christoph Ziehr Date: Sun, 22 Nov 2020 18:18:42 +0100 Subject: [PATCH 2/5] Update Loader.php The config options are read in the order plugin-standard-values -> template-standard-values -> dokuwiki.php -> local.php -> local.protected.php into DokuWiki. But when entering the configuration manger, they options are displayed in the order dokuwiki.php -> plugin-standard-values -> template-standard-values -> local.php -> local.protected.php This patch fixes the issue, so that the right values are displayed if there are no configs set in local.php or local.protected.php See also https://forum.dokuwiki.org/d/18489-issues-with-modifying-confdokuwikiphp for further information. This is a second version of this change, because on the first try, there was unnoticed php-error. --- lib/plugins/config/core/Loader.php | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/lib/plugins/config/core/Loader.php b/lib/plugins/config/core/Loader.php index 29f9e8515..a0cdaf160 100644 --- a/lib/plugins/config/core/Loader.php +++ b/lib/plugins/config/core/Loader.php @@ -78,6 +78,10 @@ class Loader { * @return array */ public function loadDefaults() { + + // initialize array + $conf = array(); + // plugins foreach($this->plugins as $plugin) { $conf = array_merge( @@ -99,10 +103,13 @@ class Loader { $this->template ) ); - - // load main files - global $config_cascade; - $conf = $this->loadConfigs($config_cascade['main']['default']); + + // load main files + global $config_cascade; + $conf = array_merge( + $conf, + $this->loadConfigs($config_cascade['main']['default']) + ); return $conf; } From 591ebe4523e0e3be14097d6d097eb5796628dcba Mon Sep 17 00:00:00 2001 From: Gerrit Uitslag Date: Wed, 5 Jan 2022 00:13:32 +0100 Subject: [PATCH 3/5] add unittests for loading of defaults, extra defaults, local and protected settings --- _test/conf/local.php | 2 + _test/tests/conf/CascadeExtraDefaultsTest.php | 55 +++++++++++++++++++ _test/tests/conf/CascadeNormalTest.php | 34 ++++++++++++ _test/tests/conf/CascadeProtectedTest.php | 43 +++++++++++++++ lib/plugins/testing/conf/default.php | 2 + lib/plugins/testing/conf/metadata.php | 1 + 6 files changed, 137 insertions(+) create mode 100644 _test/tests/conf/CascadeExtraDefaultsTest.php create mode 100644 _test/tests/conf/CascadeNormalTest.php create mode 100644 _test/tests/conf/CascadeProtectedTest.php diff --git a/_test/conf/local.php b/_test/conf/local.php index 6efb987fa..f06b20330 100644 --- a/_test/conf/local.php +++ b/_test/conf/local.php @@ -9,3 +9,5 @@ $conf['superuser'] = 'testuser'; //password: testpass $conf['dnslookups'] = 0; //speedup tests $conf['updatecheck'] = 0; //speedup tests + +$conf['plugin']['testing']['second'] = 'Local setting'; diff --git a/_test/tests/conf/CascadeExtraDefaultsTest.php b/_test/tests/conf/CascadeExtraDefaultsTest.php new file mode 100644 index 000000000..912876383 --- /dev/null +++ b/_test/tests/conf/CascadeExtraDefaultsTest.php @@ -0,0 +1,55 @@ +pluginsEnabled = [ + 'testing' + ]; + + $out = "oldSetting = $config_cascade['main']['default']; + //add second file with defaults, which override the defaults of DokuWiki + $config_cascade['main']['default'][] = $file; + + parent::setUp(); + } + + public function testNewDefaults() + { + global $conf; + + $this->assertEquals('New default Tagline', $conf['tagline'], 'new default value'); + $testing = plugin_load('action', 'testing'); + $this->assertEquals(1, $testing->getConf('schnibble'), 'new default value'); + + + $this->assertEquals('My Test Wiki', $conf['title'], 'local value still overrides default'); + $this->assertEquals('Local setting', $testing->getConf('second'), 'local value still overrides default'); + } + + public function tearDown() : void + { + global $config_cascade; + + $config_cascade['main']['default'] = $this->oldSetting; + unlink(DOKU_CONF . 'otherdefaults.php'); + + parent::tearDown(); + } +} diff --git a/_test/tests/conf/CascadeNormalTest.php b/_test/tests/conf/CascadeNormalTest.php new file mode 100644 index 000000000..c40ac41d2 --- /dev/null +++ b/_test/tests/conf/CascadeNormalTest.php @@ -0,0 +1,34 @@ +pluginsEnabled = [ + 'testing' + ]; + + parent::setUp(); + } + + public function testDefaults() + { + global $conf; + + $this->assertEquals('start', $conf['start'], 'default value'); + $this->assertEquals('', $conf['tagline'], 'default value'); + + $this->assertFalse(isset($conf['plugin']['testing']['schnibble']), 'not set before plugin call'); + + $testing = plugin_load('action', 'testing'); + $this->assertEquals(0, $testing->getConf('schnibble'), 'default value'); + } + + public function testLocal() { + global $conf; + + $this->assertEquals('My Test Wiki', $conf['title'], 'overriden in local.php (values from Config manager)'); + + $testing = plugin_load('action', 'testing'); + $this->assertEquals('Local setting', $testing->getConf('second'), 'overriden in local.php'); + } +} diff --git a/_test/tests/conf/CascadeProtectedTest.php b/_test/tests/conf/CascadeProtectedTest.php new file mode 100644 index 000000000..af3024cee --- /dev/null +++ b/_test/tests/conf/CascadeProtectedTest.php @@ -0,0 +1,43 @@ +pluginsEnabled = [ + 'testing' + ]; + + $out = "assertEquals('Protected Title', $conf['title'], 'protected local value, overrides local'); + $this->assertEquals('Protected Tagline', $conf['tagline'], 'protected local value, override default'); + + $testing = plugin_load('action', 'testing'); + $this->assertEquals(1, $testing->getConf('schnibble'), 'protected local value, '); + $this->assertEquals('Protected setting', $testing->getConf('second'), 'protected local value'); + } + + public function tearDown() : void + { + global $config_cascade; + + unlink(end($config_cascade['main']['protected'])); + + parent::tearDown(); + } +} diff --git a/lib/plugins/testing/conf/default.php b/lib/plugins/testing/conf/default.php index 392233dd8..28aef9b7e 100644 --- a/lib/plugins/testing/conf/default.php +++ b/lib/plugins/testing/conf/default.php @@ -5,3 +5,5 @@ * They don't do anything and are just there for testing config reading */ $conf['schnibble'] = 0; +$conf['second'] = 'Default value'; + diff --git a/lib/plugins/testing/conf/metadata.php b/lib/plugins/testing/conf/metadata.php index 377da63eb..3ea183cfa 100644 --- a/lib/plugins/testing/conf/metadata.php +++ b/lib/plugins/testing/conf/metadata.php @@ -5,3 +5,4 @@ * They don't do anything and are just there for testing config reading */ $meta['schnibble'] = array('onoff'); +$meta['second'] = array('string'); From 2e618646c962d15a7d5aa56e81f287d0cdc79bb6 Mon Sep 17 00:00:00 2001 From: Gerrit Uitslag Date: Wed, 5 Jan 2022 00:16:09 +0100 Subject: [PATCH 4/5] unittest for loading default and extra default settings in Config manager --- .../config/_test/LoaderExtraDefaultsTest.php | 73 +++++++++++++++++++ lib/plugins/config/_test/LoaderTest.php | 1 + 2 files changed, 74 insertions(+) create mode 100644 lib/plugins/config/_test/LoaderExtraDefaultsTest.php diff --git a/lib/plugins/config/_test/LoaderExtraDefaultsTest.php b/lib/plugins/config/_test/LoaderExtraDefaultsTest.php new file mode 100644 index 000000000..41032d766 --- /dev/null +++ b/lib/plugins/config/_test/LoaderExtraDefaultsTest.php @@ -0,0 +1,73 @@ +oldSetting = $config_cascade['main']['default']; + //add second file with defaults, which override the defaults of DokuWiki + $config_cascade['main']['default'][] = $file; + + parent::setUp(); + } + /** + * Ensure loading the defaults work, and that the extra default for plugins provided via an extra main default file + * override the plugin defaults as well + */ + public function testDefaultsOverwriting() { + $loader = new Loader(new ConfigParser()); + + $conf = $loader->loadDefaults(); + $this->assertTrue(is_array($conf)); + + // basic defaults + $this->assertArrayHasKey('title', $conf); + $this->assertEquals('New default Title', $conf['title']); + $this->assertEquals('New default Tagline', $conf['tagline']); + + // plugin defaults + $this->assertArrayHasKey('plugin____testing____schnibble', $conf); + $this->assertEquals(1, $conf['plugin____testing____schnibble']); + $this->assertEquals('New default setting', $conf['plugin____testing____second']); + + } + + public function tearDown() : void + { + global $config_cascade; + + $config_cascade['main']['default'] = $this->oldSetting; + unlink(DOKU_CONF . 'otherdefaults.php'); + + parent::tearDown(); + } + +} diff --git a/lib/plugins/config/_test/LoaderTest.php b/lib/plugins/config/_test/LoaderTest.php index 0c315842d..1a201fc29 100644 --- a/lib/plugins/config/_test/LoaderTest.php +++ b/lib/plugins/config/_test/LoaderTest.php @@ -53,6 +53,7 @@ class LoaderTest extends \DokuWikiTest { // plugin defaults $this->assertArrayHasKey('plugin____testing____schnibble', $conf); $this->assertEquals(0, $conf['plugin____testing____schnibble']); + $this->assertEquals('Default value', $conf['plugin____testing____second']); } /** From 5d2c5d7e32d5b0d835d896a62533da6991c51291 Mon Sep 17 00:00:00 2001 From: Gerrit Uitslag Date: Wed, 5 Jan 2022 00:31:01 +0100 Subject: [PATCH 5/5] reformat code --- _test/tests/conf/CascadeExtraDefaultsTest.php | 7 ++++--- _test/tests/conf/CascadeNormalTest.php | 9 +++++--- _test/tests/conf/CascadeProtectedTest.php | 11 ++++++---- .../config/_test/LoaderExtraDefaultsTest.php | 11 ++++++---- lib/plugins/config/core/Loader.php | 21 +++++++++---------- 5 files changed, 34 insertions(+), 25 deletions(-) diff --git a/_test/tests/conf/CascadeExtraDefaultsTest.php b/_test/tests/conf/CascadeExtraDefaultsTest.php index 912876383..772bc9a58 100644 --- a/_test/tests/conf/CascadeExtraDefaultsTest.php +++ b/_test/tests/conf/CascadeExtraDefaultsTest.php @@ -1,10 +1,11 @@ assertEquals('Local setting', $testing->getConf('second'), 'local value still overrides default'); } - public function tearDown() : void + public function tearDown(): void { global $config_cascade; diff --git a/_test/tests/conf/CascadeNormalTest.php b/_test/tests/conf/CascadeNormalTest.php index c40ac41d2..c916ef659 100644 --- a/_test/tests/conf/CascadeNormalTest.php +++ b/_test/tests/conf/CascadeNormalTest.php @@ -1,8 +1,10 @@ pluginsEnabled = [ 'testing' ]; @@ -23,7 +25,8 @@ class CascadeNormalTest extends DokuWikiTest { $this->assertEquals(0, $testing->getConf('schnibble'), 'default value'); } - public function testLocal() { + public function testLocal() + { global $conf; $this->assertEquals('My Test Wiki', $conf['title'], 'overriden in local.php (values from Config manager)'); diff --git a/_test/tests/conf/CascadeProtectedTest.php b/_test/tests/conf/CascadeProtectedTest.php index af3024cee..ff5241967 100644 --- a/_test/tests/conf/CascadeProtectedTest.php +++ b/_test/tests/conf/CascadeProtectedTest.php @@ -1,8 +1,10 @@ pluginsEnabled = [ @@ -21,7 +23,8 @@ class CascadeProtectedTest extends DokuWikiTest { parent::setUp(); } - public function testDefaults() { + public function testDefaults() + { global $conf; $this->assertEquals('Protected Title', $conf['title'], 'protected local value, overrides local'); @@ -32,7 +35,7 @@ class CascadeProtectedTest extends DokuWikiTest { $this->assertEquals('Protected setting', $testing->getConf('second'), 'protected local value'); } - public function tearDown() : void + public function tearDown(): void { global $config_cascade; diff --git a/lib/plugins/config/_test/LoaderExtraDefaultsTest.php b/lib/plugins/config/_test/LoaderExtraDefaultsTest.php index 41032d766..a358bd3a8 100644 --- a/lib/plugins/config/_test/LoaderExtraDefaultsTest.php +++ b/lib/plugins/config/_test/LoaderExtraDefaultsTest.php @@ -11,13 +11,14 @@ use dokuwiki\plugin\config\core\Loader; * @group plugins * @group bundled_plugins */ -class LoaderExtraDefaultsTest extends \DokuWikiTest { +class LoaderExtraDefaultsTest extends \DokuWikiTest +{ protected $pluginsEnabled = ['testing']; protected $oldSetting = []; - public function setUp() : void + public function setUp(): void { global $config_cascade; @@ -38,11 +39,13 @@ class LoaderExtraDefaultsTest extends \DokuWikiTest { parent::setUp(); } + /** * Ensure loading the defaults work, and that the extra default for plugins provided via an extra main default file * override the plugin defaults as well */ - public function testDefaultsOverwriting() { + public function testDefaultsOverwriting() + { $loader = new Loader(new ConfigParser()); $conf = $loader->loadDefaults(); @@ -60,7 +63,7 @@ class LoaderExtraDefaultsTest extends \DokuWikiTest { } - public function tearDown() : void + public function tearDown(): void { global $config_cascade; diff --git a/lib/plugins/config/core/Loader.php b/lib/plugins/config/core/Loader.php index a0cdaf160..e4d7b50af 100644 --- a/lib/plugins/config/core/Loader.php +++ b/lib/plugins/config/core/Loader.php @@ -77,13 +77,14 @@ class Loader { * * @return array */ - public function loadDefaults() { + public function loadDefaults() + { // initialize array $conf = array(); // plugins - foreach($this->plugins as $plugin) { + foreach ($this->plugins as $plugin) { $conf = array_merge( $conf, $this->loadExtensionConf( @@ -103,15 +104,13 @@ class Loader { $this->template ) ); - - // load main files - global $config_cascade; - $conf = array_merge( - $conf, - $this->loadConfigs($config_cascade['main']['default']) - ); - - return $conf; + + // load main files + global $config_cascade; + return array_merge( + $conf, + $this->loadConfigs($config_cascade['main']['default']) + ); } /**