diff options
author | Andreas Gohr <andi@splitbrain.org> | 2022-06-24 14:18:08 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-06-24 14:18:08 +0200 |
commit | 71ff00b0973df55f7beca9b1e04be75b5ed549ab (patch) | |
tree | 9b39307703885e66df98fa63087afdc9207ad3a2 | |
parent | 164ef04c61c5c3d1eb16217610a1de8104921b50 (diff) | |
parent | 5d2c5d7e32d5b0d835d896a62533da6991c51291 (diff) | |
download | dokuwiki-71ff00b0973df55f7beca9b1e04be75b5ed549ab.tar.gz dokuwiki-71ff00b0973df55f7beca9b1e04be75b5ed549ab.zip |
Merge pull request #3349 from cziehr/master
Fix loading order of extra defaults settings in the Configuration Manager
-rw-r--r-- | _test/conf/local.php | 2 | ||||
-rw-r--r-- | _test/tests/conf/CascadeExtraDefaultsTest.php | 56 | ||||
-rw-r--r-- | _test/tests/conf/CascadeNormalTest.php | 37 | ||||
-rw-r--r-- | _test/tests/conf/CascadeProtectedTest.php | 46 | ||||
-rw-r--r-- | lib/plugins/config/_test/LoaderExtraDefaultsTest.php | 76 | ||||
-rw-r--r-- | lib/plugins/config/_test/LoaderTest.php | 1 | ||||
-rw-r--r-- | lib/plugins/config/core/Loader.php | 18 | ||||
-rw-r--r-- | lib/plugins/testing/conf/default.php | 2 | ||||
-rw-r--r-- | lib/plugins/testing/conf/metadata.php | 1 |
9 files changed, 233 insertions, 6 deletions
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..772bc9a58 --- /dev/null +++ b/_test/tests/conf/CascadeExtraDefaultsTest.php @@ -0,0 +1,56 @@ +<?php + +class CascadeExtraDefaultsTest extends DokuWikiTest +{ + + protected $oldSetting = []; + + public function setUp(): void + { + global $config_cascade; + + $this->pluginsEnabled = [ + 'testing' + ]; + + $out = "<?php\n/*\n * protected settings, cannot modified in the Config manager\n" . + " * Some test data */\n"; + $out .= "\$conf['title'] = 'New default Title';\n"; + $out .= "\$conf['tagline'] = 'New default Tagline';\n"; + $out .= "\$conf['plugin']['testing']['schnibble'] = 1;\n"; + $out .= "\$conf['plugin']['testing']['second'] = 'New default setting';\n"; + + $file = DOKU_CONF . 'otherdefaults.php'; + file_put_contents($file, $out); + + //store original settings + $this->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..c916ef659 --- /dev/null +++ b/_test/tests/conf/CascadeNormalTest.php @@ -0,0 +1,37 @@ +<?php + +class CascadeNormalTest extends DokuWikiTest +{ + + public function setUp(): void + { + $this->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..ff5241967 --- /dev/null +++ b/_test/tests/conf/CascadeProtectedTest.php @@ -0,0 +1,46 @@ +<?php + +class CascadeProtectedTest extends DokuWikiTest +{ + + public function setUp(): void + { + global $config_cascade; + + $this->pluginsEnabled = [ + 'testing' + ]; + + $out = "<?php\n/*\n * protected settings, cannot modified in the Config manager\n" . + " * Some test data */\n"; + $out .= "\$conf['title'] = 'Protected Title';\n"; + $out .= "\$conf['tagline'] = 'Protected Tagline';\n"; + $out .= "\$conf['plugin']['testing']['schnibble'] = 1;\n"; + $out .= "\$conf['plugin']['testing']['second'] = 'Protected setting';\n"; + + file_put_contents(end($config_cascade['main']['protected']), $out); + + parent::setUp(); + } + + public function testDefaults() + { + global $conf; + + $this->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/config/_test/LoaderExtraDefaultsTest.php b/lib/plugins/config/_test/LoaderExtraDefaultsTest.php new file mode 100644 index 000000000..a358bd3a8 --- /dev/null +++ b/lib/plugins/config/_test/LoaderExtraDefaultsTest.php @@ -0,0 +1,76 @@ +<?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 LoaderExtraDefaultsTest extends \DokuWikiTest +{ + + protected $pluginsEnabled = ['testing']; + + protected $oldSetting = []; + + public function setUp(): void + { + global $config_cascade; + + $out = "<?php\n/*\n * protected settings, cannot modified in the Config manager\n" . + " * Some test data */\n"; + $out .= "\$conf['title'] = 'New default Title';\n"; + $out .= "\$conf['tagline'] = 'New default Tagline';\n"; + $out .= "\$conf['plugin']['testing']['schnibble'] = 1;\n"; + $out .= "\$conf['plugin']['testing']['second'] = 'New default setting';\n"; + + $file = DOKU_CONF . 'otherdefaults.php'; + file_put_contents($file, $out); + + //store original settings + $this->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']); } /** diff --git a/lib/plugins/config/core/Loader.php b/lib/plugins/config/core/Loader.php index 90ad0f50e..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() { - // load main files - global $config_cascade; - $conf = $this->loadConfigs($config_cascade['main']['default']); + public function loadDefaults() + { + + // initialize array + $conf = array(); // plugins - foreach($this->plugins as $plugin) { + foreach ($this->plugins as $plugin) { $conf = array_merge( $conf, $this->loadExtensionConf( @@ -104,7 +105,12 @@ class Loader { ) ); - return $conf; + // load main files + global $config_cascade; + return array_merge( + $conf, + $this->loadConfigs($config_cascade['main']['default']) + ); } /** 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'); |