diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 98e8699..9811cdd 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -46,7 +46,7 @@ jobs: run: tar -xvf /tmp/github-actions/build.tar ./ - name: PHP Unit tests - uses: php-actions/phpunit@v3 + uses: php-actions/phpunit@v4 env: XDEBUG_MODE: cover with: diff --git a/src/HTMLAttributeBinder.php b/src/HTMLAttributeBinder.php index 5d93b37..64849a9 100644 --- a/src/HTMLAttributeBinder.php +++ b/src/HTMLAttributeBinder.php @@ -63,7 +63,7 @@ public function bind( // skip this attribute. $trimmedAttrValue = ltrim($attrValue, ":!?"); $trimmedAttrValue = strtok($trimmedAttrValue, " "); - if($key !== $trimmedAttrValue) { + if($key !== $trimmedAttrValue && $trimmedAttrValue !== "@") { continue; } if($attrValue !== $trimmedAttrValue) { @@ -126,7 +126,12 @@ public function expandAttributes(Element $element):void { } if($attrValue[0] === "@") { - $otherAttrName = substr($attrValue, 1); + if($attrValue === "@") { + $otherAttrName = "name"; + } + else { + $otherAttrName = substr($attrValue, 1); + } $element->setAttribute( $attrName, $element->getAttribute($otherAttrName) diff --git a/test/phpunit/HTMLAttributeBinderTest.php b/test/phpunit/HTMLAttributeBinderTest.php index 501a7cd..76ea7fa 100644 --- a/test/phpunit/HTMLAttributeBinderTest.php +++ b/test/phpunit/HTMLAttributeBinderTest.php @@ -146,4 +146,16 @@ public function testBind_multipleAttributes():void { self::assertSame("value1", $outputElement->dataset->get("attr1")); self::assertSame("value2", $outputElement->dataset->get("attr2")); } + + public function testExpandAttributes_atCharacter():void { + $document = new HTMLDocument(HTMLPageContent::HTML_BASIC_FORM_WITH_AT_BINDER); + $sut = new HTMLAttributeBinder(); + $fromInput = $document->querySelector("input[name=from]"); + $toInput = $document->querySelector("input[name=to]"); + $sut->bind("from", "London", $fromInput); + $sut->bind("to", "Derby", $toInput); + + self::assertSame("London", $fromInput->value); + self::assertSame("Derby", $toInput->value); + } } diff --git a/test/phpunit/TestHelper/HTMLPageContent.php b/test/phpunit/TestHelper/HTMLPageContent.php index 1b800e4..c9601b0 100644 --- a/test/phpunit/TestHelper/HTMLPageContent.php +++ b/test/phpunit/TestHelper/HTMLPageContent.php @@ -771,6 +771,16 @@ class HTMLPageContent { HTML; + const HTML_BASIC_FORM_WITH_AT_BINDER = << + +
+ + +
+HTML; + + const HTML_SALES = <<

Sales