FormTest::testDecorateButtons()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 9
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 4
c 1
b 0
f 0
nc 1
nop 0
dl 0
loc 9
rs 10
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\Form\Container\CheckboxGroup;
9
use AbterPhp\Framework\Form\Container\FormGroup;
10
use AbterPhp\Framework\Form\Element\IElement;
11
use AbterPhp\Framework\Form\Element\Input;
12
use AbterPhp\Framework\Form\Element\Select;
13
use AbterPhp\Framework\Form\Element\Textarea;
14
use AbterPhp\Framework\Form\Label\Label;
15
use AbterPhp\Framework\Html\Component;
16
use PHPUnit\Framework\TestCase;
17
use AbterPhp\Framework\Html\Component\Button;
18
19
class FormTest extends TestCase
20
{
21
    /** @var Form - System Under Test */
22
    protected $sut;
23
24
    public function setUp(): void
25
    {
26
        $this->sut = (new Form())->init();
27
28
        parent::setUp();
29
    }
30
31
    public function testDecorateWithEmptyComponents()
32
    {
33
        $this->sut->decorate([]);
34
35
        $this->assertTrue(true, 'No error was found.');
36
    }
37
38
    public function testDecorateNonMatchingComponents()
39
    {
40
        $this->sut->decorate([new Component()]);
41
42
        $this->assertTrue(true, 'No error was found.');
43
    }
44
45
    public function testDecorateWithDoubleInit()
46
    {
47
        $this->sut->init();
48
49
        $this->sut->decorate([new Component()]);
50
51
        $this->testDecorateNonMatchingComponents();
52
    }
53
54
    public function testDecorateLabels()
55
    {
56
        /** @var Label[] $nodes */
57
        $nodes = [new Label('a', 'A'), new Label('b', 'B')];
58
59
        $this->sut->decorate($nodes);
60
61
        $this->assertStringContainsString(Form::DEFAULT_LABEL_CLASS, $nodes[0]->getAttribute(Html5::ATTR_CLASS));
0 ignored issues
show
Bug introduced by
It seems like $nodes[0]->getAttribute(...tant\Html5::ATTR_CLASS) can also be of type null; however, parameter $haystack of PHPUnit\Framework\Assert...tStringContainsString() does only seem to accept string, maybe add an additional type check? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

61
        $this->assertStringContainsString(Form::DEFAULT_LABEL_CLASS, /** @scrutinizer ignore-type */ $nodes[0]->getAttribute(Html5::ATTR_CLASS));
Loading history...
62
        $this->assertStringContainsString(Form::DEFAULT_LABEL_CLASS, $nodes[1]->getAttribute(Html5::ATTR_CLASS));
63
    }
64
65
    public function testDecorateInputs()
66
    {
67
        /** @var IElement[] $nodes */
68
        $nodes = [new Input('a', 'A'), new Textarea('b', 'B'), new Select('c', 'C')];
69
70
        $this->sut->decorate($nodes);
71
72
        $this->assertStringContainsString(Form::DEFAULT_INPUT_CLASS, $nodes[0]->getAttribute(Html5::ATTR_CLASS));
0 ignored issues
show
Bug introduced by
It seems like $nodes[0]->getAttribute(...tant\Html5::ATTR_CLASS) can also be of type null; however, parameter $haystack of PHPUnit\Framework\Assert...tStringContainsString() does only seem to accept string, maybe add an additional type check? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

72
        $this->assertStringContainsString(Form::DEFAULT_INPUT_CLASS, /** @scrutinizer ignore-type */ $nodes[0]->getAttribute(Html5::ATTR_CLASS));
Loading history...
73
        $this->assertStringContainsString(Form::DEFAULT_INPUT_CLASS, $nodes[1]->getAttribute(Html5::ATTR_CLASS));
74
        $this->assertStringContainsString(Form::DEFAULT_INPUT_CLASS, $nodes[2]->getAttribute(Html5::ATTR_CLASS));
75
    }
76
77
    public function testDecorateFormGroups()
78
    {
79
        $input = new Input('a', 'A');
80
        $label = new Label('a', 'A');
81
82
        /** @var Textarea[] $nodes */
83
        $nodes = [new FormGroup($input, $label), new FormGroup($input, $label)];
84
85
        $this->sut->decorate($nodes);
86
87
        $this->assertStringContainsString(Form::DEFAULT_FORM_GROUP_CLASS, $nodes[0]->getAttribute(Html5::ATTR_CLASS));
0 ignored issues
show
Bug introduced by
It seems like $nodes[0]->getAttribute(...tant\Html5::ATTR_CLASS) can also be of type null; however, parameter $haystack of PHPUnit\Framework\Assert...tStringContainsString() does only seem to accept string, maybe add an additional type check? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

87
        $this->assertStringContainsString(Form::DEFAULT_FORM_GROUP_CLASS, /** @scrutinizer ignore-type */ $nodes[0]->getAttribute(Html5::ATTR_CLASS));
Loading history...
88
        $this->assertStringContainsString(Form::DEFAULT_FORM_GROUP_CLASS, $nodes[1]->getAttribute(Html5::ATTR_CLASS));
89
    }
90
91
    public function testDecorateButtons()
92
    {
93
        /** @var Button[] $nodes */
94
        $nodes = [new Button('a', [Button::INTENT_FORM]), new Button('b', [Button::INTENT_FORM])];
95
96
        $this->sut->decorate($nodes);
97
98
        $this->assertStringContainsString(Form::DEFAULT_BUTTON_CLASS, $nodes[0]->getAttribute(Html5::ATTR_CLASS));
0 ignored issues
show
Bug introduced by
It seems like $nodes[0]->getAttribute(...tant\Html5::ATTR_CLASS) can also be of type null; however, parameter $haystack of PHPUnit\Framework\Assert...tStringContainsString() does only seem to accept string, maybe add an additional type check? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

98
        $this->assertStringContainsString(Form::DEFAULT_BUTTON_CLASS, /** @scrutinizer ignore-type */ $nodes[0]->getAttribute(Html5::ATTR_CLASS));
Loading history...
99
        $this->assertStringContainsString(Form::DEFAULT_BUTTON_CLASS, $nodes[1]->getAttribute(Html5::ATTR_CLASS));
100
    }
101
102
    public function testDecorateCheckboxGroups()
103
    {
104
        $input = new Input('a', 'A');
105
        $label = new Label('a', 'A');
106
107
        /** @var CheckboxGroup[] $nodes */
108
        $nodes = [new CheckboxGroup($input, $label), new CheckboxGroup($input, $label)];
109
110
        $this->sut->decorate($nodes);
111
112
        $this->assertStringContainsString(Form::CHECKBOX_GROUP_CLASS, $nodes[0]->getAttribute(Html5::ATTR_CLASS));
0 ignored issues
show
Bug introduced by
It seems like $nodes[0]->getAttribute(...tant\Html5::ATTR_CLASS) can also be of type null; however, parameter $haystack of PHPUnit\Framework\Assert...tStringContainsString() does only seem to accept string, maybe add an additional type check? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

112
        $this->assertStringContainsString(Form::CHECKBOX_GROUP_CLASS, /** @scrutinizer ignore-type */ $nodes[0]->getAttribute(Html5::ATTR_CLASS));
Loading history...
113
        $this->assertStringContainsString(Form::CHECKBOX_GROUP_CLASS, $nodes[1]->getAttribute(Html5::ATTR_CLASS));
114
    }
115
}
116