Skip to content

Commit 5d4ec6e

Browse files
committed
test(layout): update StructuredLayoutRendererTest
Signed-off-by: Vitor Mattos <1079143+vitormattos@users.noreply.github.com>
1 parent 85d6eaf commit 5d4ec6e

1 file changed

Lines changed: 112 additions & 0 deletions

File tree

tests/Unit/Layout/StructuredLayoutRendererTest.php

Lines changed: 112 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,20 @@
1616

1717
final class StructuredLayoutRendererTest extends TestCase
1818
{
19+
public function testLayoutUsesBreakNodesAsTwelvePointFlowSpacing(): void
20+
{
21+
$renderer = $this->createRenderer();
22+
23+
$result = $renderer->layout([
24+
new Node(tag: 'br', text: '', attributes: []),
25+
$this->textNode('After'),
26+
], 100.0, 100.0);
27+
28+
self::assertCount(1, $result->lines);
29+
self::assertSame('After', $result->lines[0]->text);
30+
self::assertSame(76.0, $result->lines[0]->y);
31+
}
32+
1933
public function testLayoutKeepsAbsoluteNodesOutOfFlowAndAccumulatesFlowHeights(): void
2034
{
2135
$renderer = $this->createRenderer();
@@ -115,6 +129,104 @@ public function testLayoutUsesAutoFlexHeightToPositionFollowingSiblings(): void
115129
self::assertSame(63.0, $result->lines[0]->y);
116130
}
117131

132+
public function testLayoutUsesAutoHeightForEmptyFlexContainersWithoutClipping(): void
133+
{
134+
$renderer = $this->createRenderer();
135+
136+
$result = $renderer->layout([
137+
new Node(
138+
tag: 'div',
139+
text: '',
140+
attributes: ['style' => 'display:flex;width:100;padding:2 0 3 0;background-color:#abcdef'],
141+
),
142+
], 120.0, 80.0);
143+
144+
self::assertCount(1, $result->decorations);
145+
self::assertSame(100.0, $result->decorations[0]->width);
146+
self::assertSame(5.0, $result->decorations[0]->height);
147+
self::assertSame(75.0, $result->decorations[0]->y);
148+
}
149+
150+
public function testLayoutUsesFixedHeightFallbackForEmptyFlexContainersInsideClipBoxes(): void
151+
{
152+
$renderer = $this->createRenderer();
153+
154+
$result = $renderer->layout([
155+
new Node(
156+
tag: 'div',
157+
text: '',
158+
attributes: ['style' => 'overflow:hidden;width:40;height:20'],
159+
children: [
160+
new Node(
161+
tag: 'div',
162+
text: '',
163+
attributes: [
164+
'style' => 'display:flex;width:40;height:2;padding:2 0 3 0;'
165+
. 'background-color:#abcdef',
166+
],
167+
),
168+
],
169+
),
170+
], 120.0, 80.0);
171+
172+
self::assertCount(1, $result->decorations);
173+
self::assertSame(40.0, $result->decorations[0]->width);
174+
self::assertSame(2.0, $result->decorations[0]->height);
175+
self::assertSame(78.0, $result->decorations[0]->y);
176+
}
177+
178+
public function testLayoutUsesPaddingHeightForEmptyFlexContainersInsideClipBoxesWithoutExplicitHeight(): void
179+
{
180+
$renderer = $this->createRenderer();
181+
182+
$result = $renderer->layout([
183+
new Node(
184+
tag: 'div',
185+
text: '',
186+
attributes: ['style' => 'overflow:hidden;width:40;height:20'],
187+
children: [
188+
new Node(
189+
tag: 'div',
190+
text: '',
191+
attributes: [
192+
'style' => 'display:flex;width:40;padding:2 0 3 0;background-color:#abcdef',
193+
],
194+
),
195+
],
196+
),
197+
], 120.0, 80.0);
198+
199+
self::assertCount(1, $result->decorations);
200+
self::assertSame(40.0, $result->decorations[0]->width);
201+
self::assertSame(5.0, $result->decorations[0]->height);
202+
self::assertSame(75.0, $result->decorations[0]->y);
203+
}
204+
205+
public function testLayoutSupportsAbsolutelyPositionedChildrenInsideFlexContainers(): void
206+
{
207+
$renderer = $this->createRenderer();
208+
209+
$result = $renderer->layout([
210+
new Node(
211+
tag: 'div',
212+
text: '',
213+
attributes: ['style' => 'display:flex;width:40;height:20'],
214+
children: [
215+
$this->imageNode('/absolute.png', 'position:absolute;left:5;top:2;width:10;height:10'),
216+
$this->imageNode('/flow.png', 'width:10;height:10'),
217+
],
218+
),
219+
], 40.0, 40.0);
220+
221+
self::assertCount(2, $result->images);
222+
self::assertSame('/absolute.png', $result->images[0]->source);
223+
self::assertSame(5.0, $result->images[0]->x);
224+
self::assertSame(28.0, $result->images[0]->y);
225+
self::assertSame('/flow.png', $result->images[1]->source);
226+
self::assertSame(0.0, $result->images[1]->x);
227+
self::assertSame(30.0, $result->images[1]->y);
228+
}
229+
118230
public function testLayoutAccumulatesParentTextAndChildHeightBeforeFollowingNodes(): void
119231
{
120232
$renderer = $this->createRenderer();

0 commit comments

Comments
 (0)