Skip to content

Commit

Permalink
Add last missing tests for 100 MSI
Browse files Browse the repository at this point in the history
  • Loading branch information
theseer committed Jul 28, 2023
1 parent c60c324 commit 4f0593e
Showing 1 changed file with 48 additions and 6 deletions.
54 changes: 48 additions & 6 deletions tests/viewmodel/ViewModelRendererTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -1193,36 +1193,78 @@ public function __get($key): string {
}

public function testIterableWalksTheTree(): void {
$markup = '<r><a property="start" x="def"><b property="child" /></a></r>';
$markup = '<r><a property="start" x="def"><b property="child" /><b property="child" /><c property="c" /></a></r>';
$document = Document::fromString($markup);

$document->applyViewModel(new class {
public function start(): array {
return [
new class {
public function child(): string {
return 'text #1';
public function child(): array {
return ['text #1'];
}
public function x(): string {
return 'y';
}

public function c(): string {
return 'text-c';
}
},
new class {
public function child(): string {
return 'text #2';
public function child(): array {
return ['text #2'];
}
public function x(): string {
return 'y';
}
public function c(): string {
return 'text-c';
}
}
];
}
});

$exp = new DOMDocument();
$expMarkup = '<r><a property="start" x="y" ><b property="child">text #1</b></a><a x="y" property="start"><b property="child">text #2</b></a></r>';
$expMarkup = '<r><a property="start" x="y" ><b property="child">text #1</b><c property="c">text-c</c></a><a x="y" property="start"><b property="child">text #2</b><c property="c">text-c</c></a></r>';
$exp->loadXML($expMarkup);

$this->assertResultMatches($exp->documentElement, $document->asDomDocument()->documentElement);
}

public function testConditionalApplyWalksSkippingUnlinkedNodes(): void {
$dom = new DOMDocument();
$dom->loadXML('<r property="r" typeof="a"><a property="a" /><a property="a" /><b property="b" /></r>');

$exp = new DOMDocument();
$exp->loadXML('<r property="r" typeof="a"><a property="a">text</a><b property="b">b-text</b></r>');

$renderer = new ViewModelRenderer();
$renderer->render(
$dom->documentElement,
new class {

public function r() {
return new class {
public function typeOf(): string {
return 'a';
}
public function a(): array {
return [
'text'
];
}

public function b(): string {
return 'b-text';
}
};
}
}
);

$this->assertResultMatches($exp->documentElement, $dom->documentElement);

}
}

0 comments on commit 4f0593e

Please sign in to comment.