1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
declare(strict_types=1); |
4
|
|
|
|
5
|
|
|
namespace AbterPhp\PropellerAdmin\Decorator; |
6
|
|
|
|
7
|
|
|
use AbterPhp\Framework\Constant\Html5; |
8
|
|
|
use AbterPhp\Framework\Html\Component; |
9
|
|
|
use PHPUnit\Framework\TestCase; |
10
|
|
|
|
11
|
|
|
class GeneralTest extends TestCase |
12
|
|
|
{ |
13
|
|
|
/** @var General - System Under Test */ |
14
|
|
|
protected $sut; |
15
|
|
|
|
16
|
|
|
public function setUp(): void |
17
|
|
|
{ |
18
|
|
|
$this->sut = (new General())->init(); |
19
|
|
|
|
20
|
|
|
parent::setUp(); |
21
|
|
|
} |
22
|
|
|
|
23
|
|
|
public function testDecorateWithEmptyComponents() |
24
|
|
|
{ |
25
|
|
|
$this->sut->decorate([]); |
26
|
|
|
|
27
|
|
|
$this->assertTrue(true, 'No error was found.'); |
28
|
|
|
} |
29
|
|
|
|
30
|
|
|
public function testDecorateNonMatchingComponents() |
31
|
|
|
{ |
32
|
|
|
$this->sut->decorate([new Component()]); |
33
|
|
|
|
34
|
|
|
$this->assertTrue(true, 'No error was found.'); |
35
|
|
|
} |
36
|
|
|
|
37
|
|
|
public function testDecorateHiddenComponents() |
38
|
|
|
{ |
39
|
|
|
$component1 = new Component('a', [Component::INTENT_HIDDEN]); |
40
|
|
|
$component2 = new Component('b', []); |
41
|
|
|
$component3 = new Component('c', [Component::INTENT_HIDDEN]); |
42
|
|
|
|
43
|
|
|
$this->sut->decorate([$component1, $component2, $component3]); |
44
|
|
|
|
45
|
|
|
$this->assertTrue($component1->hasAttribute(Html5::ATTR_CLASS)); |
46
|
|
|
$this->assertStringContainsString(Component::CLASS_HIDDEN, $component1->getAttribute(Html5::ATTR_CLASS)); |
|
|
|
|
47
|
|
|
$this->assertFalse($component2->hasAttribute(Html5::ATTR_CLASS)); |
48
|
|
|
$this->assertTrue($component3->hasAttribute(Html5::ATTR_CLASS)); |
49
|
|
|
$this->assertStringContainsString(Component::CLASS_HIDDEN, $component3->getAttribute(Html5::ATTR_CLASS)); |
50
|
|
|
} |
51
|
|
|
|
52
|
|
|
public function testDecorateButtons() |
53
|
|
|
{ |
54
|
|
|
$component1 = new Component\Button('a'); |
55
|
|
|
$component2 = new Component('b'); |
56
|
|
|
$component3 = new Component\Button('c'); |
57
|
|
|
|
58
|
|
|
$this->sut->decorate([$component1, $component2, $component3]); |
59
|
|
|
|
60
|
|
|
$this->assertTrue($component1->hasAttribute(Html5::ATTR_CLASS)); |
61
|
|
|
$this->assertStringContainsString(General::BUTTON_CLASS, $component1->getAttribute(Html5::ATTR_CLASS)); |
|
|
|
|
62
|
|
|
$this->assertFalse($component2->hasAttribute(Html5::ATTR_CLASS)); |
63
|
|
|
$this->assertTrue($component3->hasAttribute(Html5::ATTR_CLASS)); |
64
|
|
|
$this->assertStringContainsString(General::BUTTON_CLASS, $component3->getAttribute(Html5::ATTR_CLASS)); |
65
|
|
|
} |
66
|
|
|
|
67
|
|
|
public function testDecorateButtonsWithDoubleInit() |
68
|
|
|
{ |
69
|
|
|
$this->sut->init(); |
70
|
|
|
|
71
|
|
|
$this->testDecorateButtons(); |
72
|
|
|
} |
73
|
|
|
} |
74
|
|
|
|