From 32e27694dad76c43db70f02e00ae09cb08667a22 Mon Sep 17 00:00:00 2001 From: Greg Bowler Date: Thu, 30 Nov 2023 14:27:46 +0000 Subject: [PATCH] test: test all camel case conversion fixes #448 --- test/phpunit/DOMStringMapTest.php | 40 ++++++++++++++++++++++++++++++- 1 file changed, 39 insertions(+), 1 deletion(-) diff --git a/test/phpunit/DOMStringMapTest.php b/test/phpunit/DOMStringMapTest.php index e7efa4e4..def33f85 100644 --- a/test/phpunit/DOMStringMapTest.php +++ b/test/phpunit/DOMStringMapTest.php @@ -19,7 +19,7 @@ public function testGetterSetter():void { self::assertSame($keyValuePairs["example"], $sut->example); } - public function testGetterCamelCaseConversion():void { + public function testGetter_fromCamelCase():void { $keyValuePairs = [ "this-is-camel-case" => uniqid("example-"), ]; @@ -34,6 +34,44 @@ public function testGetterCamelCaseConversion():void { self::assertSame($keyValuePairs["this-is-camel-case"], $sut->thisIsCamelCase); } + public function testGetter_fromHyphenated():void { + $keyValuePairs = [ + "this-is-camel-case" => uniqid("example-"), + ]; + $getter = function() use (&$keyValuePairs) { + return $keyValuePairs; + }; + $setter = function(array $kvp) use (&$keyValuePairs) { + $keyValuePairs = $kvp; + }; + $sut = new DOMStringMap($getter, $setter); + + self::assertSame($keyValuePairs["this-is-camel-case"], $sut->get("this-is-camel-case")); + self::assertSame($keyValuePairs["this-is-camel-case"], $sut->get("thisIsCamelCase")); + self::assertArrayNotHasKey("thisIsCamelCase", $keyValuePairs); + } + + public function testSetter_fromHyphenated():void { + $keyValuePairs = [ + "this-is-camel-case" => uniqid("example-"), + ]; + $getter = function() use (&$keyValuePairs) { + return $keyValuePairs; + }; + $setter = function(array $kvp) use (&$keyValuePairs) { + $keyValuePairs = $kvp; + }; + $sut = new DOMStringMap($getter, $setter); + + $sut->set("this-is-camel-case", "update1"); + $sut->set("thisIsCamelCase", "update2"); + $sut->set("other-key", "other-update"); + + self::assertCount(2, $keyValuePairs); + self::assertSame("update2", $sut->thisIsCamelCase); + self::assertSame("other-update", $sut->otherKey); + } + public function testSetterCamelCaseConversion():void { $keyValuePairs = []; $getter = function() use (&$keyValuePairs) {