Completed
Push — master ( 9e3236...5e24b3 )
by Alex
02:18
created

SimpleListBuilderUnitTest::setUp()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 2
c 0
b 0
f 0
nc 1
nop 0
dl 0
loc 5
rs 10
1
<?php
2
namespace Mezon\Gui\Tests;
3
4
use PHPUnit\Framework\TestCase;
5
use Mezon\Gui\ListBuilder\Simple as SimpleListBuilder;
6
use Mezon\Router\Router;
7
use Mezon\Transport\Request;
8
9
class SimpleListBuilderUnitTest extends TestCase
10
{
11
12
    /**
13
     * This method is called before each test.
14
     */
15
    protected function setUp(): void
16
    {
17
        $router = new Router();
18
19
        Request::registerRouter($router);
20
    }
21
22
    /**
23
     * Method returns list of fields
24
     *
25
     * @return array Fields algorithms object
26
     */
27
    protected function getFields(): array
28
    {
29
        return [
30
            'id',
31
            'domain_id',
32
            'title'
33
        ];
34
    }
35
36
    /**
37
     * Method runs string assertions
38
     *
39
     * @param array $asserts
40
     *            asserts
41
     * @param string $content
42
     *            content to assert
43
     */
44
    protected function runAssertions(array $asserts, string $content): void
45
    {
46
        foreach ($asserts as $assert) {
47
            $this->assertStringContainsString($assert, $content);
48
        }
49
    }
50
51
    /**
52
     * Testing constructor
53
     */
54
    public function testConstructorValid(): void
55
    {
56
        // setup and test body
57
        $listBuilder = new SimpleListBuilder($this->getFields(), new FakeAdapter());
58
59
        // assertions
60
        $this->assertIsArray($listBuilder->getFields(), 'Invalid fields list type');
61
    }
62
63
    /**
64
     * Method returns testing records
65
     *
66
     * @return array testing records
67
     */
68
    private function getRecords(): array
69
    {
70
        return [
71
            [
72
                'id' => 1,
73
            ],
74
            [
75
                'id' => 2,
76
            ]
77
        ];
78
    }
79
80
    /**
81
     * Data provider for the testSimpleListingForm
82
     *
83
     * @return array test data
84
     */
85
    public function simpleListingFormDataProvider(): array
86
    {
87
        return [
88
            // #0, no records
89
            [
90
                [],
91
                [
92
                    'class="no-items-title"'
93
                ]
94
            ],
95
            // #1, no records
96
            [
97
                $this->getRecords(),
98
                [
99
                    '>1<',
100
                    '>2<',
101
                ]
102
            ]
103
        ];
104
    }
105
106
    /**
107
     * Testing listing form
108
     *
109
     * @param array $records
110
     *            records to display
111
     * @param array $asserts
112
     *            asserts
113
     * @dataProvider simpleListingFormDataProvider
114
     */
115
    public function testSimpleListingForm(array $records, array $asserts): void
116
    {
117
        // setup
118
        $listBuilder = new SimpleListBuilder($this->getFields(), new FakeAdapter($records));
119
120
        // test body
121
        $content = $listBuilder->listingForm();
122
123
        // assertions
124
        $this->runAssertions($asserts, $content);
125
    }
126
}
127