Skip to content

Commit

Permalink
test: add test from docs
Browse files Browse the repository at this point in the history
  • Loading branch information
g105b committed Nov 25, 2024
1 parent f13cae3 commit 37f6feb
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 0 deletions.
22 changes: 22 additions & 0 deletions test/phpunit/DocumentBinderTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -1261,6 +1261,28 @@ public function test_bindElementWithBindValue():void {
self::assertSame("There has been an error!", $errorDiv->textContent);
}

public function test_bindElementRemovesMultiple():void {
$document = new HTMLDocument(HTMLPageContent::HTML_ADMIN_PANEL);
$sut = new DocumentBinder($document);
$sut->setDependencies(...$this->documentBinderDependencies($document));
$sut->bindKeyValue("isAdmin", false);
$sut->cleanupDocument();

$panelDiv = $document->querySelector("div.panel");
self::assertCount(2, $panelDiv->children);
}

public function test_bindElementRemovesMultiple_doesNotRemoveWithTrue():void {
$document = new HTMLDocument(HTMLPageContent::HTML_ADMIN_PANEL);
$sut = new DocumentBinder($document);
$sut->setDependencies(...$this->documentBinderDependencies($document));
$sut->bindKeyValue("isAdmin", true);
$sut->cleanupDocument();

$panelDiv = $document->querySelector("div.panel");
self::assertCount(4, $panelDiv->children);
}

public function test_bindElementIsRemovedWhenNotBound():void {
$document = new HTMLDocument(HTMLPageContent::HTML_REMOVE_UNBOUND_BIND_VALUE);
$sut = new DocumentBinder($document);
Expand Down
10 changes: 10 additions & 0 deletions test/phpunit/TestHelper/HTMLPageContent.php
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,16 @@ class HTMLPageContent {
</div>
HTML;

const HTML_ADMIN_PANEL = <<<HTML
<div class="panel">
<p>You are logged in as <span data-bind:text="username">username</span></p>
<p data-element="isAdmin">You are an administrator</p>
<button name="do" value="save">Save record</button>
<button data-element="isAdmin" name="do" value="delete">Delete record</button>
</div>
HTML;


const HTML_DIFFERENT_BIND_PROPERTIES = <<<HTML
<!doctype html>
<img id="img1" class="main" src="/default.png" alt="Not bound"
Expand Down

0 comments on commit 37f6feb

Please sign in to comment.