1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
declare(strict_types=1); |
4
|
|
|
|
5
|
|
|
namespace AbterPhp\Framework\Form\Extra; |
6
|
|
|
|
7
|
|
|
use AbterPhp\Framework\Html\Attribute; |
8
|
|
|
use AbterPhp\Framework\TestDouble\I18n\MockTranslatorFactory; |
9
|
|
|
use PHPUnit\Framework\TestCase; |
10
|
|
|
|
11
|
|
|
class DefaultButtonsTest extends TestCase |
12
|
|
|
{ |
13
|
|
|
/** |
14
|
|
|
* @return array[] |
15
|
|
|
*/ |
16
|
|
|
public function renderProvider(): array |
17
|
|
|
{ |
18
|
|
|
$simpleExpected = [ |
19
|
|
|
"<div><button name=\"next\" type=\"submit\" value=\"\">framework:save</button>", |
20
|
|
|
"<button name=\"next\" type=\"submit\" value=\"back\">framework:saveAndBack</button>", |
21
|
|
|
"<button name=\"next\" type=\"submit\" value=\"edit\">framework:saveAndEdit</button>", |
22
|
|
|
"<button name=\"next\" type=\"submit\" value=\"create\">framework:saveAndCreate</button>", |
23
|
|
|
"<a href=\"/url\">framework:backToGrid</a></div>", |
24
|
|
|
]; |
25
|
|
|
|
26
|
|
|
return [ |
27
|
|
|
'simple' => ['/url', null, [], null, implode("\n", $simpleExpected)], |
28
|
|
|
]; |
29
|
|
|
} |
30
|
|
|
|
31
|
|
|
/** |
32
|
|
|
* @dataProvider renderProvider |
33
|
|
|
* |
34
|
|
|
* @param string $showUrl |
35
|
|
|
* @param array<string,Attribute>|null $attributes |
36
|
|
|
* @param string[] $translations |
37
|
|
|
* @param string|null $tag |
38
|
|
|
* @param string $expected |
39
|
|
|
*/ |
40
|
|
|
public function testRender( |
41
|
|
|
string $showUrl, |
42
|
|
|
?array $attributes, |
43
|
|
|
array $translations, |
44
|
|
|
?string $tag, |
45
|
|
|
string $expected |
46
|
|
|
): void { |
47
|
|
|
$sut = $this->createDefaultButtons($showUrl, $attributes, $translations, $tag); |
48
|
|
|
|
49
|
|
|
$actualResult = (string)$sut; |
50
|
|
|
$repeatedResult = (string)$sut; |
51
|
|
|
$this->assertSame($actualResult, $repeatedResult); |
52
|
|
|
|
53
|
|
|
$this->assertSame($expected, $actualResult); |
54
|
|
|
} |
55
|
|
|
|
56
|
|
|
/** |
57
|
|
|
* @param string $showUrl |
58
|
|
|
* @param array<string,Attribute>|null $attributes |
59
|
|
|
* @param string[] $translations |
60
|
|
|
* @param string|null $tag |
61
|
|
|
* |
62
|
|
|
* @return DefaultButtons |
63
|
|
|
*/ |
64
|
|
|
private function createDefaultButtons( |
65
|
|
|
string $showUrl, |
66
|
|
|
?array $attributes, |
67
|
|
|
array $translations, |
68
|
|
|
?string $tag |
69
|
|
|
): DefaultButtons { |
70
|
|
|
$translatorMock = MockTranslatorFactory::createSimpleTranslator($this, $translations); |
71
|
|
|
|
72
|
|
|
$defaultButtons = new DefaultButtons([], $attributes, $tag); |
73
|
|
|
|
74
|
|
|
$defaultButtons->setTranslator($translatorMock); |
75
|
|
|
$defaultButtons |
76
|
|
|
->addSave() |
77
|
|
|
->addSaveAndBack() |
78
|
|
|
->addSaveAndEdit() |
79
|
|
|
->addSaveAndCreate() |
80
|
|
|
->addBackToGrid($showUrl); |
81
|
|
|
|
82
|
|
|
return $defaultButtons; |
83
|
|
|
} |
84
|
|
|
} |
85
|
|
|
|