GridTest::testDecoratePaginations()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 19
Code Lines 12

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 12
c 1
b 0
f 0
nc 1
nop 0
dl 0
loc 19
rs 9.8666
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\Element\Input;
9
use AbterPhp\Framework\Form\Label\Label;
10
use AbterPhp\Framework\Grid\Filter\ExactFilter;
11
use AbterPhp\Framework\Grid\Filter\Filter;
12
use AbterPhp\Framework\Grid\Filter\IFilter;
13
use AbterPhp\Framework\Grid\Filter\LikeFilter;
14
use AbterPhp\Framework\Grid\Pagination\IPagination;
15
use AbterPhp\Framework\Grid\Pagination\Pagination;
16
use AbterPhp\Framework\Html\Component;
17
use AbterPhp\Framework\Html\IComponent;
18
use PHPUnit\Framework\TestCase;
19
20
class GridTest extends TestCase
21
{
22
    /** @var Grid - System Under Test */
23
    protected $sut;
24
25
    public function setUp(): void
26
    {
27
        $this->sut = (new Grid())->init();
28
29
        parent::setUp();
30
    }
31
32
    public function testDecorateWithEmptyComponents()
33
    {
34
        $this->sut->decorate([]);
35
36
        $this->assertTrue(true, 'No error was found.');
37
    }
38
39
    public function testDecorateNonMatchingComponents()
40
    {
41
        $this->sut->decorate([new Component()]);
42
43
        $this->assertTrue(true, 'No error was found.');
44
    }
45
46
    public function testDecorateWithDoubleInit()
47
    {
48
        $this->sut->init();
49
50
        $this->sut->decorate([new Component()]);
51
52
        $this->testDecorateNonMatchingComponents();
53
    }
54
55
    public function testDecorateFilters()
56
    {
57
        /** @var IFilter[] $nodes */
58
        $nodes = [new ExactFilter(), new LikeFilter()];
59
60
        $this->sut->decorate($nodes);
61
62
        $this->assertStringContainsString(Grid::FILTER_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

62
        $this->assertStringContainsString(Grid::FILTER_INPUT_CLASS, /** @scrutinizer ignore-type */ $nodes[0]->getAttribute(Html5::ATTR_CLASS));
Loading history...
63
        $this->assertStringContainsString(Grid::FILTER_INPUT_CLASS, $nodes[1]->getAttribute(Html5::ATTR_CLASS));
64
    }
65
66
    public function testDecoratePaginations()
67
    {
68
        $stubPagination1 = $this->getMockBuilder(Pagination::class)
0 ignored issues
show
Deprecated Code introduced by
The function PHPUnit\Framework\MockOb...ckBuilder::setMethods() has been deprecated: https://github.com/sebastianbergmann/phpunit/pull/3687 ( Ignorable by Annotation )

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

68
        $stubPagination1 = /** @scrutinizer ignore-deprecated */ $this->getMockBuilder(Pagination::class)

This function has been deprecated. The supplier of the function has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the function will be removed and what other function to use instead.

Loading history...
69
            ->disableOriginalConstructor()
70
            ->setMethods(['setTemplate'])
71
            ->getMock();
72
73
        $stubPagination2 = $this->getMockBuilder(Pagination::class)
0 ignored issues
show
Deprecated Code introduced by
The function PHPUnit\Framework\MockOb...ckBuilder::setMethods() has been deprecated: https://github.com/sebastianbergmann/phpunit/pull/3687 ( Ignorable by Annotation )

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

73
        $stubPagination2 = /** @scrutinizer ignore-deprecated */ $this->getMockBuilder(Pagination::class)

This function has been deprecated. The supplier of the function has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the function will be removed and what other function to use instead.

Loading history...
74
            ->disableOriginalConstructor()
75
            ->setMethods(['setTemplate'])
76
            ->getMock();
77
78
        $stubPagination1->expects($this->atLeastOnce())->method('setTemplate')->with(Grid::PAGINATION_TEMPLATE);
79
        $stubPagination2->expects($this->atLeastOnce())->method('setTemplate')->with(Grid::PAGINATION_TEMPLATE);
80
81
        /** @var IPagination[] $nodes */
82
        $nodes = [$stubPagination1, $stubPagination2];
83
84
        $this->sut->decorate($nodes);
85
    }
86
87
    public function testDecorateHelpBlocks()
88
    {
89
        $input     = new Input('a', 'A', '', [Filter::INTENT_HELP_BLOCK]);
90
        $label     = new Label('a', 'A', [Filter::INTENT_HELP_BLOCK]);
91
        $component = new Component('c', [Filter::INTENT_HELP_BLOCK]);
92
93
        /** @var IComponent[] $nodes */
94
        $nodes = [$input, $label, $component];
95
96
        $this->sut->decorate($nodes);
97
98
        $this->assertStringContainsString(Grid::HELP_BLOCK_CLASS, $input->getAttribute(Html5::ATTR_CLASS));
0 ignored issues
show
Bug introduced by
It seems like $input->getAttribute(Abt...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(Grid::HELP_BLOCK_CLASS, /** @scrutinizer ignore-type */ $input->getAttribute(Html5::ATTR_CLASS));
Loading history...
99
        $this->assertStringContainsString(Grid::HELP_BLOCK_CLASS, $label->getAttribute(Html5::ATTR_CLASS));
100
        $this->assertStringContainsString(Grid::HELP_BLOCK_CLASS, $component->getAttribute(Html5::ATTR_CLASS));
101
    }
102
}
103