1<?php
2
3namespace dokuwiki\plugin\config\test\Setting;
4
5use dokuwiki\plugin\config\core\Setting\Setting;
6
7/**
8 * @group plugin_config
9 * @group admin_plugins
10 * @group plugins
11 * @group bundled_plugins
12 */
13class SettingTest extends AbstractSettingTest {
14
15    /**
16     * Dataprovider for testOut()
17     *
18     * @return array
19     */
20    public function dataOut() {
21        return [
22            ['bar', "\$conf['test'] = 'bar';\n"],
23            ["foo'bar", "\$conf['test'] = 'foo\\'bar';\n"],
24        ];
25    }
26
27    /**
28     * Check the output
29     *
30     * @param mixed $in The value to initialize the setting with
31     * @param string $out The expected output (for conf[test])
32     * @dataProvider dataOut
33     */
34    public function testOut($in, $out) {
35        /** @var Setting $setting */
36        $setting = new $this->class('test');
37        $setting->initialize('ignore', $in);
38
39        $this->assertEquals($out, $setting->out('conf'));
40    }
41
42    /**
43     * DataProvider for testShouldBeSaved()
44     *
45     * @return array
46     */
47    public function dataShouldBeSaved() {
48        return [
49            ['default', null, false],
50            ['default', 'default', false],
51            ['default', 'new', true],
52        ];
53    }
54
55    /**
56     * Check if shouldBeSaved works as expected
57     *
58     * @dataProvider dataShouldBeSaved
59     * @param mixed $default The default value
60     * @param mixed $local The current local value
61     * @param bool $expect The expected outcome
62     */
63    public function testShouldBeSaved($default, $local, $expect) {
64        /** @var Setting $setting */
65        $setting = new $this->class('test');
66        $setting->initialize($default, $local, null);
67        $this->assertSame($expect, $setting->shouldBeSaved());
68    }
69
70}
71