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