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