Skip to content

Commit

Permalink
Fixed some bugs in the Loader and added tests
Browse files Browse the repository at this point in the history
  • Loading branch information
splitbrain committed May 25, 2018
1 parent c73b800 commit 91109d5
Show file tree
Hide file tree
Showing 5 changed files with 105 additions and 9 deletions.
77 changes: 77 additions & 0 deletions lib/plugins/config/_test/LoaderTest.php
@@ -0,0 +1,77 @@
<?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____schnibble', $lang);
$this->assertEquals(
'Turns on the schnibble before the frobble is used',
$lang['plugin____testing____schnibble']
);
}
}
18 changes: 9 additions & 9 deletions lib/plugins/config/core/Loader.php
Expand Up @@ -42,21 +42,21 @@ public function loadMeta() {

// plugins
foreach($this->plugins as $plugin) {
array_merge(
$meta = array_merge(
$meta,
$this->loadExtensionMeta(
DOKU_PLUGIN . $plugin . '/conf/settings.php',
DOKU_PLUGIN . $plugin . '/conf/metadata.php',
'plugin',
$plugin
)
);
}

// current template
array_merge(
$meta = array_merge(
$meta,
$this->loadExtensionMeta(
tpl_incdir() . '/conf/settings.php',
tpl_incdir() . '/conf/metadata.php',
'tpl',
$this->template
)
Expand All @@ -79,7 +79,7 @@ public function loadDefaults() {

// plugins
foreach($this->plugins as $plugin) {
array_merge(
$conf = array_merge(
$conf,
$this->loadExtensionConf(
DOKU_PLUGIN . $plugin . '/conf/default.php',
Expand All @@ -90,7 +90,7 @@ public function loadDefaults() {
}

// current template
array_merge(
$conf = array_merge(
$conf,
$this->loadExtensionConf(
tpl_incdir() . '/conf/default.php',
Expand All @@ -114,7 +114,7 @@ public function loadLangs() {

// plugins
foreach($this->plugins as $plugin) {
array_merge(
$lang = array_merge(
$lang,
$this->loadExtensionLang(
DOKU_PLUGIN . $plugin . '/',
Expand All @@ -125,9 +125,9 @@ public function loadLangs() {
}

// current template
array_merge(
$lang = array_merge(
$lang,
$this->loadExtensionConf(
$this->loadExtensionLang(
tpl_incdir() . '/',
'tpl',
$this->template
Expand Down
7 changes: 7 additions & 0 deletions lib/plugins/testing/conf/default.php
@@ -0,0 +1,7 @@
<?php
/**
* Default options
*
* They don't do anything and are just there for testing config reading
*/
$conf['schnibble'] = 0;
7 changes: 7 additions & 0 deletions lib/plugins/testing/conf/metadata.php
@@ -0,0 +1,7 @@
<?php
/**
* Option Metadata
*
* They don't do anything and are just there for testing config reading
*/
$meta['schnibble'] = array('onoff');
5 changes: 5 additions & 0 deletions lib/plugins/testing/lang/en/settings.php
@@ -0,0 +1,5 @@
<?php
/**
* Default options texts
*/
$lang['schnibble'] = 'Turns on the schnibble before the frobble is used';

0 comments on commit 91109d5

Please sign in to comment.