xref: /dokuwiki/lib/plugins/config/_test/Setting/SettingTest.php (revision 6dd8fd818073602607c15bd93e7894b560abef71)
198a151baSAndreas Gohr<?php
298a151baSAndreas Gohr
398a151baSAndreas Gohrnamespace dokuwiki\plugin\config\test\Setting;
498a151baSAndreas Gohr
598a151baSAndreas Gohruse dokuwiki\plugin\config\core\Setting\Setting;
698a151baSAndreas Gohr
798a151baSAndreas Gohr/**
898a151baSAndreas Gohr * @group plugin_config
998a151baSAndreas Gohr * @group admin_plugins
1098a151baSAndreas Gohr * @group plugins
1198a151baSAndreas Gohr * @group bundled_plugins
1298a151baSAndreas Gohr */
1398a151baSAndreas Gohrclass SettingTest extends AbstractSettingTest {
1498a151baSAndreas Gohr
1598a151baSAndreas Gohr    /**
16*6dd8fd81SAndreas Gohr     * Dataprovider for testOut()
1798a151baSAndreas Gohr     *
1898a151baSAndreas Gohr     * @return array
1998a151baSAndreas Gohr     */
2098a151baSAndreas Gohr    public function dataOut() {
2198a151baSAndreas Gohr        return [
2298a151baSAndreas Gohr            ['bar', "\$conf['test'] = 'bar';\n"],
2398a151baSAndreas Gohr            ["foo'bar", "\$conf['test'] = 'foo\\'bar';\n"],
2498a151baSAndreas Gohr        ];
2598a151baSAndreas Gohr    }
2698a151baSAndreas Gohr
2798a151baSAndreas Gohr    /**
2898a151baSAndreas Gohr     * Check the output
2998a151baSAndreas Gohr     *
3098a151baSAndreas Gohr     * @param mixed $in The value to initialize the setting with
3198a151baSAndreas Gohr     * @param string $out The expected output (for conf[test])
3298a151baSAndreas Gohr     * @dataProvider dataOut
3398a151baSAndreas Gohr     */
3498a151baSAndreas Gohr    public function testOut($in, $out) {
3598a151baSAndreas Gohr        /** @var Setting $setting */
36c73b800aSAndreas Gohr        $setting = new $this->class('test');
3798a151baSAndreas Gohr        $setting->initialize('ignore', $in);
3898a151baSAndreas Gohr
3998a151baSAndreas Gohr        $this->assertEquals($out, $setting->out('conf'));
4098a151baSAndreas Gohr    }
41*6dd8fd81SAndreas Gohr
42*6dd8fd81SAndreas Gohr    /**
43*6dd8fd81SAndreas Gohr     * DataProvider for testShouldBeSaved()
44*6dd8fd81SAndreas Gohr     *
45*6dd8fd81SAndreas Gohr     * @return array
46*6dd8fd81SAndreas Gohr     */
47*6dd8fd81SAndreas Gohr    public function dataShouldBeSaved() {
48*6dd8fd81SAndreas Gohr        return [
49*6dd8fd81SAndreas Gohr            ['default', null, false],
50*6dd8fd81SAndreas Gohr            ['default', 'default', false],
51*6dd8fd81SAndreas Gohr            ['default', 'new', true],
52*6dd8fd81SAndreas Gohr        ];
53*6dd8fd81SAndreas Gohr    }
54*6dd8fd81SAndreas Gohr
55*6dd8fd81SAndreas Gohr    /**
56*6dd8fd81SAndreas Gohr     * Check if shouldBeSaved works as expected
57*6dd8fd81SAndreas Gohr     *
58*6dd8fd81SAndreas Gohr     * @dataProvider dataShouldBeSaved
59*6dd8fd81SAndreas Gohr     * @param mixed $default The default value
60*6dd8fd81SAndreas Gohr     * @param mixed $local The current local value
61*6dd8fd81SAndreas Gohr     * @param bool $expect The expected outcome
62*6dd8fd81SAndreas Gohr     */
63*6dd8fd81SAndreas Gohr    public function testShouldBeSaved($default, $local, $expect) {
64*6dd8fd81SAndreas Gohr        /** @var Setting $setting */
65*6dd8fd81SAndreas Gohr        $setting = new $this->class('test');
66*6dd8fd81SAndreas Gohr        $setting->initialize($default, $local, null);
67*6dd8fd81SAndreas Gohr        $this->assertSame($expect, $setting->shouldBeSaved());
68*6dd8fd81SAndreas Gohr    }
69*6dd8fd81SAndreas Gohr
7098a151baSAndreas Gohr}
71