xref: /dokuwiki/lib/plugins/config/_test/LoaderTest.php (revision 2e618646c962d15a7d5aa56e81f287d0cdc79bb6)
191109d52SAndreas Gohr<?php
291109d52SAndreas Gohr
391109d52SAndreas Gohrnamespace dokuwiki\plugin\config\test;
491109d52SAndreas Gohr
591109d52SAndreas Gohruse dokuwiki\plugin\config\core\ConfigParser;
691109d52SAndreas Gohruse dokuwiki\plugin\config\core\Loader;
791109d52SAndreas Gohr
891109d52SAndreas Gohr/**
991109d52SAndreas Gohr * @group plugin_config
1091109d52SAndreas Gohr * @group admin_plugins
1191109d52SAndreas Gohr * @group plugins
1291109d52SAndreas Gohr * @group bundled_plugins
1391109d52SAndreas Gohr */
1491109d52SAndreas Gohrclass LoaderTest extends \DokuWikiTest {
1591109d52SAndreas Gohr
1691109d52SAndreas Gohr    protected $pluginsEnabled = ['testing'];
1791109d52SAndreas Gohr
1891109d52SAndreas Gohr    /**
1991109d52SAndreas Gohr     * Ensure loading the config meta data works
2091109d52SAndreas Gohr     */
2191109d52SAndreas Gohr    public function testMetaData() {
2291109d52SAndreas Gohr        $loader = new Loader(new ConfigParser());
2391109d52SAndreas Gohr
2491109d52SAndreas Gohr        $meta = $loader->loadMeta();
2591109d52SAndreas Gohr        $this->assertTrue(is_array($meta));
2691109d52SAndreas Gohr
2791109d52SAndreas Gohr        // there should be some defaults
2891109d52SAndreas Gohr        $this->assertArrayHasKey('savedir', $meta);
2991109d52SAndreas Gohr        $this->assertEquals(['savedir', '_caution' => 'danger'], $meta['savedir']);
3091109d52SAndreas Gohr        $this->assertArrayHasKey('proxy____port', $meta);
3191109d52SAndreas Gohr        $this->assertEquals(['numericopt'], $meta['proxy____port']);
3291109d52SAndreas Gohr
3391109d52SAndreas Gohr        // there should be plugin info
3491109d52SAndreas Gohr        $this->assertArrayHasKey('plugin____testing____plugin_settings_name', $meta);
3591109d52SAndreas Gohr        $this->assertEquals(['fieldset'], $meta['plugin____testing____plugin_settings_name']);
3691109d52SAndreas Gohr        $this->assertArrayHasKey('plugin____testing____schnibble', $meta);
3791109d52SAndreas Gohr        $this->assertEquals(['onoff'], $meta['plugin____testing____schnibble']);
3891109d52SAndreas Gohr    }
3991109d52SAndreas Gohr
4091109d52SAndreas Gohr    /**
4191109d52SAndreas Gohr     * Ensure loading the defaults work
4291109d52SAndreas Gohr     */
4391109d52SAndreas Gohr    public function testDefaults() {
4491109d52SAndreas Gohr        $loader = new Loader(new ConfigParser());
4591109d52SAndreas Gohr
4691109d52SAndreas Gohr        $conf = $loader->loadDefaults();
4791109d52SAndreas Gohr        $this->assertTrue(is_array($conf));
4891109d52SAndreas Gohr
4991109d52SAndreas Gohr        // basic defaults
5091109d52SAndreas Gohr        $this->assertArrayHasKey('title', $conf);
5191109d52SAndreas Gohr        $this->assertEquals('DokuWiki', $conf['title']);
5291109d52SAndreas Gohr
5391109d52SAndreas Gohr        // plugin defaults
5491109d52SAndreas Gohr        $this->assertArrayHasKey('plugin____testing____schnibble', $conf);
5591109d52SAndreas Gohr        $this->assertEquals(0, $conf['plugin____testing____schnibble']);
56*2e618646SGerrit Uitslag        $this->assertEquals('Default value', $conf['plugin____testing____second']);
5791109d52SAndreas Gohr    }
5891109d52SAndreas Gohr
5991109d52SAndreas Gohr    /**
6091109d52SAndreas Gohr     * Ensure language loading works
6191109d52SAndreas Gohr     */
6291109d52SAndreas Gohr    public function testLangs() {
6391109d52SAndreas Gohr        $loader = new Loader(new ConfigParser());
6491109d52SAndreas Gohr
6591109d52SAndreas Gohr        $lang = $loader->loadLangs();
6691109d52SAndreas Gohr        $this->assertTrue(is_array($lang));
6791109d52SAndreas Gohr
6891109d52SAndreas Gohr        // basics are not included in the returned array!
6991109d52SAndreas Gohr        $this->assertArrayNotHasKey('title', $lang);
7091109d52SAndreas Gohr
7191109d52SAndreas Gohr        // plugin strings
72d6fc72e1SAndreas Gohr        $this->assertArrayHasKey('plugin____testing____plugin_settings_name', $lang);
73d6fc72e1SAndreas Gohr        $this->assertEquals('Testing', $lang['plugin____testing____plugin_settings_name']);
7491109d52SAndreas Gohr        $this->assertArrayHasKey('plugin____testing____schnibble', $lang);
7591109d52SAndreas Gohr        $this->assertEquals(
7691109d52SAndreas Gohr            'Turns on the schnibble before the frobble is used',
7791109d52SAndreas Gohr            $lang['plugin____testing____schnibble']
7891109d52SAndreas Gohr        );
7991109d52SAndreas Gohr    }
8091109d52SAndreas Gohr}
81