|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
declare(strict_types=1); |
|
4
|
|
|
|
|
5
|
|
|
namespace AbterPhp\Framework\Form\Container; |
|
6
|
|
|
|
|
7
|
|
|
use AbterPhp\Framework\Form\Element\Input; |
|
8
|
|
|
use AbterPhp\Framework\Form\Extra\Help; |
|
9
|
|
|
use AbterPhp\Framework\Form\Label\Label; |
|
10
|
|
|
use AbterPhp\Framework\Html\Attribute; |
|
11
|
|
|
use AbterPhp\Framework\Html\Tag; |
|
12
|
|
|
use AbterPhp\Framework\TestDouble\I18n\MockTranslatorFactory; |
|
13
|
|
|
use PHPUnit\Framework\MockObject\MockObject; |
|
14
|
|
|
use PHPUnit\Framework\TestCase; |
|
15
|
|
|
|
|
16
|
|
|
class CheckboxGroupTest extends TestCase |
|
17
|
|
|
{ |
|
18
|
|
|
/** |
|
19
|
|
|
* @return array[] |
|
20
|
|
|
*/ |
|
21
|
|
|
public function renderProvider(): array |
|
22
|
|
|
{ |
|
23
|
|
|
return [ |
|
24
|
|
|
'simple' => ['<foo>', '<bar>', '<baz>', null, null, null, '<div><bar></div>'], |
|
25
|
|
|
]; |
|
26
|
|
|
} |
|
27
|
|
|
|
|
28
|
|
|
/** |
|
29
|
|
|
* @dataProvider renderProvider |
|
30
|
|
|
* |
|
31
|
|
|
* @param string $inputOutput |
|
32
|
|
|
* @param string $labelOutput |
|
33
|
|
|
* @param string $helpOutput |
|
34
|
|
|
* @param array<string,Attribute>|null $attributes |
|
35
|
|
|
* @param string[]|null $translations |
|
36
|
|
|
* @param string|null $tag |
|
37
|
|
|
* @param string $expectedResult |
|
38
|
|
|
*/ |
|
39
|
|
|
public function testRenderWillMoveHelpIntoLabel( |
|
40
|
|
|
string $inputOutput, |
|
41
|
|
|
string $labelOutput, |
|
42
|
|
|
string $helpOutput, |
|
43
|
|
|
?array $attributes, |
|
44
|
|
|
?array $translations, |
|
45
|
|
|
?string $tag, |
|
46
|
|
|
string $expectedResult |
|
47
|
|
|
): void { |
|
48
|
|
|
$sut = $this->createCheckboxGroup($inputOutput, $labelOutput, $helpOutput, $attributes, $translations, $tag); |
|
49
|
|
|
|
|
50
|
|
|
$actualResult = (string)$sut; |
|
51
|
|
|
$repeatedResult = (string)$sut; |
|
52
|
|
|
|
|
53
|
|
|
$this->assertSame($actualResult, $repeatedResult); |
|
54
|
|
|
$this->assertSame($expectedResult, $actualResult); |
|
55
|
|
|
} |
|
56
|
|
|
|
|
57
|
|
|
/** |
|
58
|
|
|
* @param string $inputOutput |
|
59
|
|
|
* @param string $labelOutput |
|
60
|
|
|
* @param string $helpOutput |
|
61
|
|
|
* @param array<string,Attribute>|null $attributes |
|
62
|
|
|
* @param string[]|null $translations |
|
63
|
|
|
* @param string|null $tag |
|
64
|
|
|
* |
|
65
|
|
|
* @return CheckboxGroup |
|
66
|
|
|
*/ |
|
67
|
|
|
protected function createCheckboxGroup( |
|
68
|
|
|
string $inputOutput, |
|
69
|
|
|
string $labelOutput, |
|
70
|
|
|
string $helpOutput, |
|
71
|
|
|
?array $attributes, |
|
72
|
|
|
?array $translations, |
|
73
|
|
|
?string $tag |
|
74
|
|
|
): CheckboxGroup { |
|
75
|
|
|
/** @var Input|MockObject $inputMock */ |
|
76
|
|
|
$inputMock = $this->createMock(Input::class); |
|
77
|
|
|
|
|
78
|
|
|
/** @var Label|MockObject $labelMock */ |
|
79
|
|
|
$labelMock = $this->createMock(Label::class); |
|
80
|
|
|
|
|
81
|
|
|
/** @var Help|MockObject $helpMock */ |
|
82
|
|
|
$helpMock = $this->createMock(Help::class); |
|
83
|
|
|
|
|
84
|
|
|
$inputMock->expects($this->any())->method('__toString')->willReturn($inputOutput); |
|
85
|
|
|
$labelMock->expects($this->any())->method('__toString')->willReturn($labelOutput); |
|
86
|
|
|
$helpMock->expects($this->any())->method('__toString')->willReturn($helpOutput); |
|
87
|
|
|
|
|
88
|
|
|
$translatorMock = MockTranslatorFactory::createSimpleTranslator($this, $translations); |
|
89
|
|
|
|
|
90
|
|
|
$checkboxGroup = new CheckboxGroup($inputMock, $labelMock, $helpMock, [], $attributes, $tag); |
|
91
|
|
|
|
|
92
|
|
|
$checkboxGroup->setTranslator($translatorMock); |
|
93
|
|
|
|
|
94
|
|
|
return $checkboxGroup; |
|
95
|
|
|
} |
|
96
|
|
|
|
|
97
|
|
|
public function testGetCheckboxSpan(): void |
|
98
|
|
|
{ |
|
99
|
|
|
/** @var Input|MockObject $input */ |
|
100
|
|
|
$input = $this->createMock(Input::class); |
|
101
|
|
|
|
|
102
|
|
|
/** @var Label|MockObject $label */ |
|
103
|
|
|
$label = $this->createMock(Label::class); |
|
104
|
|
|
|
|
105
|
|
|
$sut = new CheckboxGroup($input, $label); |
|
106
|
|
|
|
|
107
|
|
|
$actualResult = $sut->getCheckboxSpan(); |
|
108
|
|
|
|
|
109
|
|
|
$this->assertInstanceOf(Tag::class, $actualResult); |
|
110
|
|
|
} |
|
111
|
|
|
} |
|
112
|
|
|
|