|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
declare(strict_types=1); |
|
4
|
|
|
|
|
5
|
|
|
namespace AbterPhp\Framework\Form\Extra; |
|
6
|
|
|
|
|
7
|
|
|
use AbterPhp\Framework\Constant\Html5; |
|
8
|
|
|
use AbterPhp\Framework\Html\Attribute; |
|
9
|
|
|
use AbterPhp\Framework\Html\Helper\AttributesHelper; |
|
10
|
|
|
use AbterPhp\Framework\TestDouble\Html\Component\StubAttributeFactory; |
|
11
|
|
|
use AbterPhp\Framework\TestDouble\I18n\MockTranslatorFactory; |
|
12
|
|
|
use PHPUnit\Framework\TestCase; |
|
13
|
|
|
|
|
14
|
|
|
class HelpTest extends TestCase |
|
15
|
|
|
{ |
|
16
|
|
|
/** |
|
17
|
|
|
* @return array |
|
18
|
|
|
*/ |
|
19
|
|
|
public function renderProvider(): array |
|
20
|
|
|
{ |
|
21
|
|
|
$defaultAttr = StubAttributeFactory::createAttributes(); |
|
22
|
|
|
$additionalAttr = AttributesHelper::fromArray([Html5::ATTR_CLASS => [Help::CLASS_HELP_BLOCK]]); |
|
23
|
|
|
$attributes = AttributesHelper::merge($defaultAttr, $additionalAttr); |
|
24
|
|
|
$str = AttributesHelper::toString($attributes); |
|
25
|
|
|
|
|
26
|
|
|
return [ |
|
27
|
|
|
'simple' => ['ABC', null, null, null, '<div class="help-block">ABC</div>'], |
|
28
|
|
|
'attributes' => ['ABC', $attributes, [], null, "<div$str>ABC</div>"], |
|
29
|
|
|
'missing translations' => ['ABC', null, [], null, '<div class="help-block">ABC</div>'], |
|
30
|
|
|
'found translations' => ['ABC', null, ['ABC' => 'CBA'], null, '<div class="help-block">CBA</div>'], |
|
31
|
|
|
]; |
|
32
|
|
|
} |
|
33
|
|
|
|
|
34
|
|
|
/** |
|
35
|
|
|
* @dataProvider renderProvider |
|
36
|
|
|
* |
|
37
|
|
|
* @param string $content |
|
38
|
|
|
* @param array<string,Attribute>|null $attributes |
|
39
|
|
|
* @param string[]|null $translations |
|
40
|
|
|
* @param string|null $tag |
|
41
|
|
|
* @param string $expectedResult |
|
42
|
|
|
*/ |
|
43
|
|
|
public function testRender( |
|
44
|
|
|
string $content, |
|
45
|
|
|
?array $attributes, |
|
46
|
|
|
?array $translations, |
|
47
|
|
|
?string $tag, |
|
48
|
|
|
string $expectedResult |
|
49
|
|
|
): void { |
|
50
|
|
|
$sut = $this->createHelp($content, $attributes, $translations, $tag); |
|
51
|
|
|
|
|
52
|
|
|
$actualResult = (string)$sut; |
|
53
|
|
|
$repeatedResult = (string)$sut; |
|
54
|
|
|
|
|
55
|
|
|
$this->assertSame($actualResult, $repeatedResult); |
|
56
|
|
|
$this->assertSame($expectedResult, $actualResult); |
|
57
|
|
|
} |
|
58
|
|
|
|
|
59
|
|
|
/** |
|
60
|
|
|
* @param string $content |
|
61
|
|
|
* @param array<string,Attribute>|null $attributes |
|
62
|
|
|
* @param string[]|null $translations |
|
63
|
|
|
* @param string|null $tag |
|
64
|
|
|
* |
|
65
|
|
|
* @return Help |
|
66
|
|
|
*/ |
|
67
|
|
|
private function createHelp( |
|
68
|
|
|
string $content, |
|
69
|
|
|
?array $attributes, |
|
70
|
|
|
?array $translations, |
|
71
|
|
|
?string $tag |
|
72
|
|
|
): Help { |
|
73
|
|
|
$translatorMock = MockTranslatorFactory::createSimpleTranslator($this, $translations); |
|
74
|
|
|
|
|
75
|
|
|
$help = new Help($content, [], $attributes, $tag); |
|
76
|
|
|
|
|
77
|
|
|
$help->setTranslator($translatorMock); |
|
78
|
|
|
|
|
79
|
|
|
return $help; |
|
80
|
|
|
} |
|
81
|
|
|
} |
|
82
|
|
|
|