Skip to content

Commit

Permalink
Make attribute removal to actually work
Browse files Browse the repository at this point in the history
  • Loading branch information
theseer committed Mar 6, 2024
1 parent 9456358 commit d83fc48
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/viewmodel/ViewModelRenderer.php
Original file line number Diff line number Diff line change
Expand Up @@ -631,7 +631,7 @@ private function objectApply(DOMElement $context, object $model): void {
}

if ($result instanceof Remove || $result === false) {
$context->removeChild($attribute);
$context->removeAttributeNode($attribute);

continue;
}
Expand Down
24 changes: 24 additions & 0 deletions tests/viewmodel/ViewModelRendererTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -1325,4 +1325,28 @@ public function b(): string {
$this->assertEquals('b', $dom->documentElement->textContent);
}

public function testAttributeGetsRemovedWhenRemoveSignalIsGiven(): void {
$dom = new DOMDocument();
$dom->loadXML('<root property="root" attr="foo" />');

$renderer = new ViewModelRenderer();

$renderer->render(
$dom->documentElement,
new class {

public function root(): self {
return $this;
}
public function attr(): Signal {
return Signal::remove();
}
}
);

$this->assertFalse(
$dom->documentElement->hasAttribute('attr')
);

}
}

0 comments on commit d83fc48

Please sign in to comment.