Skip to content

Commit 2a0d844

Browse files
committed
chore: completing partial tests
1 parent 39509c3 commit 2a0d844

6 files changed

Lines changed: 1577 additions & 155 deletions

File tree

clover.xml

Lines changed: 1343 additions & 153 deletions
Large diffs are not rendered by default.

phpunit.xml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,10 +22,10 @@
2222
<directory suffix=".php">./src/Mapping</directory>
2323
<directory suffix=".php">./src/Service</directory>
2424
<directory suffix=".php">./src/TemplateGenerator</directory>
25-
</include>
26-
<exclude>
2725
<directory suffix=".php">./src/Enum</directory>
2826
<directory suffix=".php">./src/Trait</directory>
27+
</include>
28+
<exclude>
2929
<directory suffix=".php">src/Command</directory>
3030
<directory suffix=".php">src/Resources</directory>
3131
<directory suffix=".php">src/Element</directory>

tests/Enum/EnumTest.php

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,20 +5,63 @@
55
test('enum functionality', function () {
66
$enums = [
77
\Html\Enum\AlignEnum::class,
8+
\Html\Enum\ARoleEnum::class,
9+
\Html\Enum\AriaAtomicEnum::class,
10+
\Html\Enum\AriaAutocompleteEnum::class,
11+
\Html\Enum\AriaBusyEnum::class,
12+
\Html\Enum\AriaCheckedEnum::class,
13+
\Html\Enum\AriaCurrentEnum::class,
14+
\Html\Enum\AriaDisabledEnum::class,
15+
\Html\Enum\AriaExpandedEnum::class,
16+
\Html\Enum\AriaHaspopupEnum::class,
17+
\Html\Enum\AriaHiddenEnum::class,
18+
\Html\Enum\AriaInvalidEnum::class,
19+
\Html\Enum\AriaLabelEnum::class,
20+
\Html\Enum\AriaLiveEnum::class,
21+
\Html\Enum\AriaModalEnum::class,
22+
\Html\Enum\AriaMultilineEnum::class,
23+
\Html\Enum\AriaMultiselectableEnum::class,
24+
\Html\Enum\AriaOrientationEnum::class,
25+
\Html\Enum\AriaPressedEnum::class,
26+
\Html\Enum\AriaReadonlyEnum::class,
27+
\Html\Enum\AriaRelevantEnum::class,
28+
\Html\Enum\AriaRequiredEnum::class,
29+
\Html\Enum\AriaSelectedEnum::class,
30+
\Html\Enum\AriaSortEnum::class,
831
\Html\Enum\AutoCapitalizeEnum::class,
932
\Html\Enum\AutocompleteEnum::class,
33+
\Html\Enum\AutocorrectEnum::class,
34+
\Html\Enum\ButtonTypeEnum::class,
35+
\Html\Enum\ClassEnum::class,
36+
\Html\Enum\ContentEditableEnum::class,
1037
\Html\Enum\CrossoriginEnum::class,
1138
\Html\Enum\DecodingEnum::class,
39+
\Html\Enum\DirectionEnum::class,
1240
\Html\Enum\EnctypeEnum::class,
41+
\Html\Enum\FormenctypeEnum::class,
42+
\Html\Enum\FormmethodEnum::class,
43+
\Html\Enum\FormtargetEnum::class,
44+
\Html\Enum\HrAlignEnum::class,
1345
\Html\Enum\HttpEquivEnum::class,
1446
\Html\Enum\InputModeEnum::class,
47+
\Html\Enum\InputTypeEnum::class,
1548
\Html\Enum\KindEnum::class,
49+
\Html\Enum\LinkRelEnum::class,
1650
\Html\Enum\MethodEnum::class,
51+
\Html\Enum\OlTypeEnum::class,
52+
\Html\Enum\PopoverEnum::class,
53+
\Html\Enum\PopovertargetactionEnum::class,
1754
\Html\Enum\PreloadEnum::class,
1855
\Html\Enum\ReferrerpolicyEnum::class,
1956
\Html\Enum\RelEnum::class,
57+
\Html\Enum\RoleEnum::class,
58+
\Html\Enum\ScriptTypeEnum::class,
2059
\Html\Enum\ShapeEnum::class,
60+
\Html\Enum\SpellCheckEnum::class,
61+
\Html\Enum\StyleTypeEnum::class,
2162
\Html\Enum\TargetEnum::class,
63+
\Html\Enum\TrAlignEnum::class,
64+
\Html\Enum\TranslateEnum::class,
2265
\Html\Enum\TypeButtonEnum::class,
2366
\Html\Enum\TypeInputEnum::class,
2467
\Html\Enum\TypeOlEnum::class,

tests/Service/ComponentBuilderTest.php

Lines changed: 137 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,4 +71,141 @@
7171

7272
expect(fn() => $this->builder->buildComponent($document, $data))
7373
->toThrow(InvalidArgumentException::class, "Element class for tag 'unknown-element' not found.");
74+
});
75+
76+
test('buildComponent builds DOM with nested children', function () {
77+
$document = HTMLDocumentDelegator::createEmpty();
78+
79+
$data = [
80+
'myComponent' => [
81+
'structure' => [
82+
'div' => [
83+
'class' => 'container',
84+
'children' => [
85+
[
86+
'p' => [
87+
'text' => 'Hello World',
88+
'class' => 'greeting'
89+
]
90+
],
91+
[
92+
'div' => [
93+
'class' => 'nested',
94+
'children' => [
95+
[
96+
'p' => [
97+
'text' => 'Nested content'
98+
]
99+
]
100+
]
101+
]
102+
]
103+
]
104+
]
105+
]
106+
]
107+
];
108+
109+
$this->builder->buildComponent($document, $data);
110+
111+
// For HTML documents, elements are appended to the documentElement (html)
112+
$htmlElement = $document->documentElement;
113+
expect($htmlElement)->not->toBeNull();
114+
expect(strtolower($htmlElement->tagName))->toBe('html');
115+
116+
// Our div should be a child of the html element
117+
$rootElement = $htmlElement->firstElementChild;
118+
expect($rootElement)->not->toBeNull();
119+
expect(strtolower($rootElement->tagName))->toBe('div');
120+
expect($rootElement->getAttribute('class'))->toBe('container');
121+
122+
// Check first child paragraph
123+
$firstChild = $rootElement->firstElementChild;
124+
expect($firstChild)->not->toBeNull();
125+
expect(strtolower($firstChild->tagName))->toBe('p');
126+
expect($firstChild->getAttribute('class'))->toBe('greeting');
127+
expect($firstChild->textContent)->toBe('Hello World');
128+
129+
// Check second child div
130+
$secondChild = $firstChild->nextElementSibling;
131+
expect($secondChild)->not->toBeNull();
132+
expect(strtolower($secondChild->tagName))->toBe('div');
133+
expect($secondChild->getAttribute('class'))->toBe('nested');
134+
135+
// Check nested paragraph inside second div
136+
$nestedParagraph = $secondChild->firstElementChild;
137+
expect($nestedParagraph)->not->toBeNull();
138+
expect(strtolower($nestedParagraph->tagName))->toBe('p');
139+
expect($nestedParagraph->textContent)->toBe('Nested content');
140+
});
141+
142+
test('buildComponent handles multiple siblings correctly', function () {
143+
$document = HTMLDocumentDelegator::createEmpty();
144+
145+
$data = [
146+
'myComponent' => [
147+
'structure' => [
148+
'div' => [
149+
'children' => [
150+
['p' => ['text' => 'First paragraph']],
151+
['p' => ['text' => 'Second paragraph']],
152+
['p' => ['text' => 'Third paragraph']]
153+
]
154+
]
155+
]
156+
]
157+
];
158+
159+
$this->builder->buildComponent($document, $data);
160+
161+
$htmlElement = $document->documentElement;
162+
$rootElement = $htmlElement->firstElementChild;
163+
expect($rootElement)->not->toBeNull();
164+
165+
// Count children
166+
$childCount = 0;
167+
$child = $rootElement->firstElementChild;
168+
while ($child !== null) {
169+
$childCount++;
170+
expect(strtolower($child->tagName))->toBe('p');
171+
$child = $child->nextElementSibling;
172+
}
173+
174+
expect($childCount)->toBe(3);
175+
});
176+
177+
test('buildComponent handles attributes on nested elements', function () {
178+
$document = HTMLDocumentDelegator::createEmpty();
179+
180+
$data = [
181+
'myComponent' => [
182+
'structure' => [
183+
'div' => [
184+
'id' => 'root',
185+
'children' => [
186+
[
187+
'p' => [
188+
'id' => 'para1',
189+
'class' => 'text-primary',
190+
'data-custom' => 'value',
191+
'text' => 'Content'
192+
]
193+
]
194+
]
195+
]
196+
]
197+
]
198+
];
199+
200+
$this->builder->buildComponent($document, $data);
201+
202+
$htmlElement = $document->documentElement;
203+
$rootElement = $htmlElement->firstElementChild;
204+
expect($rootElement->getAttribute('id'))->toBe('root');
205+
206+
$paragraph = $rootElement->firstElementChild;
207+
expect($paragraph->getAttribute('id'))->toBe('para1');
208+
expect($paragraph->getAttribute('class'))->toBe('text-primary');
209+
expect($paragraph->getAttribute('data-custom'))->toBe('value');
210+
expect($paragraph->textContent)->toBe('Content');
74211
});

tests/TemplateGenerator/HTMLGeneratorTest.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,11 @@
3838
->toBeTrue();
3939
});
4040

41+
test('is templated', function () {
42+
expect($this->generator->isTemplated())
43+
->toBeFalse();
44+
});
45+
4146
test('render element', function () {
4247
$document = HTMLDocumentDelegator::createEmpty();
4348
$element = Anchor::create($document);

tests/TemplateGenerator/TwigGeneratorTest.php

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -236,6 +236,53 @@
236236
expect($result)->toBeNull();
237237
});
238238

239+
test('render document method directly', function () {
240+
$reflection = new ReflectionClass($this->generator);
241+
$method = $reflection->getMethod('renderDocument');
242+
$method->setAccessible(true);
243+
244+
$document = HTMLDocumentDelegator::createEmpty();
245+
$body = Body::create($document);
246+
$document->appendChild($body);
247+
248+
$result = $method->invoke($this->generator, $document);
249+
250+
expect($result)->toBeString();
251+
expect($result)->toContain('<?xml version="1.0" encoding="UTF-8"?>');
252+
expect($result)->toContain('<!DOCTYPE html>');
253+
expect($result)->toContain('<html lang="en">');
254+
expect($result)->toContain('<body>');
255+
expect($result)->toContain('</body>');
256+
expect($result)->toContain('</html>');
257+
});
258+
259+
test('render head with metadata', function () {
260+
$reflection = new ReflectionClass($this->generator);
261+
262+
// Mock getDocumentMetadata to return data
263+
$metadataMethod = $reflection->getMethod('getDocumentMetadata');
264+
$metadataMethod->setAccessible(true);
265+
266+
// Create a document with a title
267+
$document = HTMLDocumentDelegator::createEmpty();
268+
$title = $document->createElement('title');
269+
$title->textContent = 'Test Document';
270+
$head = $document->createElement('head');
271+
$head->appendChild($title);
272+
$document->appendChild($head);
273+
274+
// Test getDocumentMetadata
275+
$metadata = $metadataMethod->invoke($this->generator, $document);
276+
expect($metadata)->toBeArray();
277+
278+
// Test renderHead - it will still return null since renderTwigTemplate returns null
279+
$headMethod = $reflection->getMethod('renderHead');
280+
$headMethod->setAccessible(true);
281+
282+
$result = $headMethod->invoke($this->generator, $document);
283+
expect($result)->toBeNull();
284+
});
285+
239286
test('camel to kebab', function () {
240287
$reflection = new ReflectionClass($this->generator);
241288
$method = $reflection->getMethod('camelToKebab');

0 commit comments

Comments
 (0)