1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
|
<?php
namespace dokuwiki\plugin\config\test\Setting;
use dokuwiki\plugin\config\core\Setting\Setting;
class AbstractSettingTest extends \DokuWikiTest {
/** @var string the class to test */
protected $class;
/**
* Sets up the proper class to test based on the test's class name
* @throws \Exception
*/
public function setUp() {
parent::setUp();
$class = get_class($this);
$class = substr($class, strrpos($class, '\\') + 1, -4);
$class = 'dokuwiki\\plugin\\config\\core\\Setting\\' . $class;
$this->class = $class;
}
public function testInitialBasics() {
/** @var Setting $setting */
$setting = new $this->class('test');
$this->assertEquals('test', $setting->getKey());
$this->assertSame(false, $setting->isProtected());
$this->assertSame(true, $setting->isDefault());
$this->assertSame(false, $setting->hasError());
$this->assertSame(false, $setting->shouldBeSaved());
}
public function testShouldHaveDefault() {
/** @var Setting $setting */
$setting = new $this->class('test');
$this->assertSame(true, $setting->shouldHaveDefault());
}
public function testPrettyKey() {
/** @var Setting $setting */
$setting = new $this->class('test');
$this->assertEquals('test', $setting->getPrettyKey(false));
$setting = new $this->class('test____foo');
$this->assertEquals('test»foo', $setting->getPrettyKey(false));
$setting = new $this->class('test');
$this->assertEquals(
'<a href="http://www.dokuwiki.org/config:test">test</a>',
$setting->getPrettyKey(true)
);
$setting = new $this->class('test____foo');
$this->assertEquals('test»foo', $setting->getPrettyKey(true));
$setting = new $this->class('start');
$this->assertEquals(
'<a href="http://www.dokuwiki.org/config:startpage">start</a>',
$setting->getPrettyKey(true)
);
}
public function testType() {
/** @var Setting $setting */
$setting = new $this->class('test');
$this->assertEquals('dokuwiki', $setting->getType());
$setting = new $this->class('test_foo');
$this->assertEquals('dokuwiki', $setting->getType());
$setting = new $this->class('plugin____test');
$this->assertEquals('plugin', $setting->getType());
$setting = new $this->class('tpl____test');
$this->assertEquals('template', $setting->getType());
}
public function testCaution() {
/** @var Setting $setting */
$setting = new $this->class('test');
$this->assertEquals(false, $setting->caution());
$setting = new $this->class('test', ['_caution' => 'warning']);
$this->assertEquals('warning', $setting->caution());
$setting = new $this->class('test', ['_caution' => 'danger']);
$this->assertEquals('danger', $setting->caution());
$setting = new $this->class('test', ['_caution' => 'security']);
$this->assertEquals('security', $setting->caution());
$setting = new $this->class('test', ['_caution' => 'flargh']);
$this->expectException(\RuntimeException::class);
$setting->caution();
}
}
|