Completed
Push — master ( 2b7ec8...e65692 )
by Alex
09:34
created

SelectUnitTest::getSettings()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 16
Code Lines 13

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 13
nc 1
nop 0
dl 0
loc 16
rs 9.8333
c 0
b 0
f 0
1
<?php
2
namespace Mezon\Gui\Field\Tests;
3
4
class SelectUnitTest extends \PHPUnit\Framework\TestCase
5
{
6
7
    /**
8
     * Field settings
9
     *
10
     * @return array select field settings
11
     */
12
    protected function getSettings(): array
13
    {
14
        return [
15
            'name' => 'name',
16
            'required' => 1,
17
            'disabled' => 1,
18
            'name-prefix' => 'prefix',
19
            'batch' => 1,
20
            'toggler' => 'toggler-name',
21
            'toggle-value' => 3,
22
            'items' => [
23
                '1' => '111',
24
                '2' => '222'
25
            ],
26
            'type' => 'integer',
27
            'class' => 'cls'
28
        ];
29
    }
30
31
    /**
32
     * Testing constructor
33
     */
34
    public function testConstructor()
35
    {
36
        // setupp
37
        $field = new \Mezon\Gui\Field\Select($this->getSettings(), '');
38
39
        // test bodyy
40
        $content = $field->html();
41
42
        // assertionss
43
        $this->assertStringContainsString('<select ', $content);
44
        $this->assertStringContainsString('name="prefix-name[{_creation_form_items_counter}]"', $content);
45
        $this->assertStringContainsString('required="required"', $content);
46
        $this->assertStringContainsString('disabled', $content);
47
        $this->assertStringContainsString('toggler="toggler-name"', $content);
48
        $this->assertStringContainsString('toggle-value="3"', $content);
49
        $this->assertStringContainsString('class="cls"', $content);
50
    }
51
52
    /**
53
     * Testing constructor with type wich is defaulted to integer
54
     */
55
    public function testConstructorWithDefaultedType()
56
    {
57
        // setup
58
        $settings = $this->getSettings();
59
        unset($settings['type']);
60
        $field = new \Mezon\Gui\Field\Select($settings, '');
61
62
        // test body and assertions
63
        $this->assertEquals('integer', $field->getType());
64
    }
65
}
66