|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
declare(strict_types=1); |
|
4
|
|
|
|
|
5
|
|
|
namespace AbterPhp\Framework\Grid\Cell; |
|
6
|
|
|
|
|
7
|
|
|
use AbterPhp\Framework\Html\Attribute; |
|
8
|
|
|
use AbterPhp\Framework\Html\Helper\Attributes; |
|
9
|
|
|
use AbterPhp\Framework\Html\INode; |
|
10
|
|
|
use AbterPhp\Framework\TestDouble\Html\Component\StubAttributeFactory; |
|
11
|
|
|
use AbterPhp\Framework\TestDouble\I18n\MockTranslatorFactory; |
|
12
|
|
|
use PHPUnit\Framework\TestCase; |
|
13
|
|
|
|
|
14
|
|
|
class CellTest extends TestCase |
|
15
|
|
|
{ |
|
16
|
|
|
protected const CONTENT = 'foo'; |
|
17
|
|
|
protected const GROUP = 'bar'; |
|
18
|
|
|
|
|
19
|
|
|
/** |
|
20
|
|
|
* @return array[] |
|
21
|
|
|
*/ |
|
22
|
|
|
public function renderProvider(): array |
|
23
|
|
|
{ |
|
24
|
|
|
$attribs = StubAttributeFactory::createAttributes(); |
|
25
|
|
|
$str = Attributes::toString($attribs); |
|
26
|
|
|
|
|
27
|
|
|
return [ |
|
28
|
|
|
'simple' => ['ABC', 'a', null, null, null, "<td>ABC</td>"], |
|
29
|
|
|
'with attributes' => ['ABC', 'a', $attribs, null, null, "<td$str>ABC</td>"], |
|
30
|
|
|
'missing translations' => ['ABC', 'a', null, [], null, "<td>ABC</td>"], |
|
31
|
|
|
'custom tag' => ['ABC', 'a', null, null, 'mytd', "<mytd>ABC</mytd>"], |
|
32
|
|
|
'with translations' => ['ABC', 'a', null, ['ABC' => 'CBA'], null, "<td>CBA</td>"], |
|
33
|
|
|
]; |
|
34
|
|
|
} |
|
35
|
|
|
|
|
36
|
|
|
/** |
|
37
|
|
|
* @dataProvider renderProvider |
|
38
|
|
|
* |
|
39
|
|
|
* @param INode[]|INode|string|null $content |
|
40
|
|
|
* @param string $group |
|
41
|
|
|
* @param array|null $attributes |
|
42
|
|
|
* @param array|null $translations |
|
43
|
|
|
* @param string|null $tag |
|
44
|
|
|
* @param string $expectedResult |
|
45
|
|
|
*/ |
|
46
|
|
|
public function testRender( |
|
47
|
|
|
$content, |
|
48
|
|
|
string $group, |
|
49
|
|
|
?array $attributes, |
|
50
|
|
|
?array $translations, |
|
51
|
|
|
?string $tag, |
|
52
|
|
|
string $expectedResult |
|
53
|
|
|
): void { |
|
54
|
|
|
$sut = $this->createCell($content, $group, $attributes, $translations, $tag); |
|
55
|
|
|
|
|
56
|
|
|
$actualResult1 = (string)$sut; |
|
57
|
|
|
$actualResult2 = (string)$sut; |
|
58
|
|
|
|
|
59
|
|
|
$this->assertSame($expectedResult, $actualResult1); |
|
60
|
|
|
$this->assertSame($expectedResult, $actualResult2); |
|
61
|
|
|
} |
|
62
|
|
|
|
|
63
|
|
|
public function testGetGroup() |
|
64
|
|
|
{ |
|
65
|
|
|
$expectedResult = 'foo'; |
|
66
|
|
|
|
|
67
|
|
|
$sut = $this->createCell(null, $expectedResult); |
|
68
|
|
|
|
|
69
|
|
|
$group = $sut->getGroup(); |
|
70
|
|
|
|
|
71
|
|
|
$this->assertSame($expectedResult, $group); |
|
72
|
|
|
} |
|
73
|
|
|
|
|
74
|
|
|
/** |
|
75
|
|
|
* @param INode[]|INode|string|null $content |
|
76
|
|
|
* @param string|null $group |
|
77
|
|
|
* @param array<string,Attribute>|null $attributes |
|
78
|
|
|
* @param array|null $translations |
|
79
|
|
|
* @param string|null $tag |
|
80
|
|
|
* |
|
81
|
|
|
* @return Cell |
|
82
|
|
|
*/ |
|
83
|
|
|
protected function createCell( |
|
84
|
|
|
$content = null, |
|
85
|
|
|
string $group = null, |
|
86
|
|
|
?array $attributes = null, |
|
87
|
|
|
?array $translations = null, |
|
88
|
|
|
?string $tag = null |
|
89
|
|
|
): Cell { |
|
90
|
|
|
$group ??= static::GROUP; |
|
91
|
|
|
|
|
92
|
|
|
$cell = new Cell($content, $group, [], $attributes, $tag); |
|
93
|
|
|
|
|
94
|
|
|
$cell->setTranslator(MockTranslatorFactory::createSimpleTranslator($this, $translations)); |
|
95
|
|
|
|
|
96
|
|
|
return $cell; |
|
97
|
|
|
} |
|
98
|
|
|
} |
|
99
|
|
|
|