1<?php
2
3namespace dokuwiki\plugin\config\test;
4
5use dokuwiki\plugin\config\core\ConfigParser;
6use dokuwiki\plugin\config\core\Loader;
7
8/**
9 * @group plugin_config
10 * @group admin_plugins
11 * @group plugins
12 * @group bundled_plugins
13 */
14class LoaderTest extends \DokuWikiTest {
15
16    protected $pluginsEnabled = ['testing'];
17
18    /**
19     * Ensure loading the config meta data works
20     */
21    public function testMetaData() {
22        $loader = new Loader(new ConfigParser());
23
24        $meta = $loader->loadMeta();
25        $this->assertTrue(is_array($meta));
26
27        // there should be some defaults
28        $this->assertArrayHasKey('savedir', $meta);
29        $this->assertEquals(['savedir', '_caution' => 'danger'], $meta['savedir']);
30        $this->assertArrayHasKey('proxy____port', $meta);
31        $this->assertEquals(['numericopt'], $meta['proxy____port']);
32
33        // there should be plugin info
34        $this->assertArrayHasKey('plugin____testing____plugin_settings_name', $meta);
35        $this->assertEquals(['fieldset'], $meta['plugin____testing____plugin_settings_name']);
36        $this->assertArrayHasKey('plugin____testing____schnibble', $meta);
37        $this->assertEquals(['onoff'], $meta['plugin____testing____schnibble']);
38    }
39
40    /**
41     * Ensure loading the defaults work
42     */
43    public function testDefaults() {
44        $loader = new Loader(new ConfigParser());
45
46        $conf = $loader->loadDefaults();
47        $this->assertTrue(is_array($conf));
48
49        // basic defaults
50        $this->assertArrayHasKey('title', $conf);
51        $this->assertEquals('DokuWiki', $conf['title']);
52
53        // plugin defaults
54        $this->assertArrayHasKey('plugin____testing____schnibble', $conf);
55        $this->assertEquals(0, $conf['plugin____testing____schnibble']);
56        $this->assertEquals('Default value', $conf['plugin____testing____second']);
57    }
58
59    /**
60     * Ensure language loading works
61     */
62    public function testLangs() {
63        $loader = new Loader(new ConfigParser());
64
65        $lang = $loader->loadLangs();
66        $this->assertTrue(is_array($lang));
67
68        // basics are not included in the returned array!
69        $this->assertArrayNotHasKey('title', $lang);
70
71        // plugin strings
72        $this->assertArrayHasKey('plugin____testing____plugin_settings_name', $lang);
73        $this->assertEquals('Testing', $lang['plugin____testing____plugin_settings_name']);
74        $this->assertArrayHasKey('plugin____testing____schnibble', $lang);
75        $this->assertEquals(
76            'Turns on the schnibble before the frobble is used',
77            $lang['plugin____testing____schnibble']
78        );
79    }
80}
81