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