diff --git a/CHANGELOG.md b/CHANGELOG.md index 753dc13..43c3c4f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -30,20 +30,22 @@ - Bug #42: Fix messages in `assert()` methods and code style (@terabytesoftw) - Bug #43: Update `ui-awesome/html-helper` to version `^0.7` and `ui-awesome/html-mixin` to version `^0.4` in `composer.json` and apply necessary changes to `src` and `tests` directories (@terabytesoftw) - Bug #44: Update last modified from `ui-awesome/html-attribute` in related classes (@terabytesoftw) -- Bug #45: Better naming for `CanBeUnchecked` to `HasUnchecked` and update PHPDoc `BaseChoice` classes (@terabytesoftw) +- Bug #45: Better naming for `CanBeUnchecked` to `HasUnchecked` and update phpdoc `BaseChoice` classes (@terabytesoftw) - Enh #46: Add `InputFile` class for HTML `` element with attributes and rendering capabilities (@terabytesoftw) - Bug #47: Update PHPDoc in `tests` and add new tests for `on*` attribute (@terabytesoftw) - Enh #48: Add `InputEmail` class for HTML `` element with attributes and rendering capabilities (@terabytesoftw) -- Enh #49: Add `InputDateTimeLocal` class for HTML `` element with attributes and rendering capabilities (@terabytesoftw) -- Bug #50: Standardize `tests` for clarity and consistency across all test cases (@terabytesoftw) -- Enh #51: Add `InputDate` class for HTML `` element with attributes and rendering capabilities (@terabytesoftw) -- Enh #52: Add `InputColor` class for HTML `` element with attributes and rendering capabilities (@terabytesoftw) -- Enh #53: Add `TextArea` class for HTML ` + HTML, + TextArea::tag() + ->addAriaAttribute('describedby', 'value') + ->render(), + "Failed asserting that an explicit 'aria-describedby' string value is preserved.", + ); + } + + public function testRenderWithAddAriaDescribedByTrueBooleanValue(): void + { + self::assertSame( + << + + HTML, + TextArea::tag() + ->addAriaAttribute('describedby', true) + ->id('textarea') + ->render(), + "Failed asserting that element renders correctly with 'aria-describedby' attribute set to " + . "'true'.", + ); + } + + public function testRenderWithAddAriaDescribedByTrueBooleanValueAndIdNull(): void + { + self::assertSame( + << + + HTML, + TextArea::tag() + ->addAriaAttribute('describedby', true) + ->id(null) + ->render(), + "Failed asserting that element renders correctly with 'aria-describedby' attribute set to 'true' and 'id'" + . " is 'null'.", + ); + } + + public function testRenderWithAddAriaDescribedByTrueBooleanValueString(): void + { + self::assertSame( + << + + HTML, + TextArea::tag() + ->addAriaAttribute('describedby', 'true') + ->id('textarea') + ->render(), + "Failed asserting that element renders correctly with 'aria-describedby' attribute set to 'true'.", + ); + } + public function testRenderWithAddDataAttribute(): void { self::assertSame( @@ -180,6 +241,52 @@ public function testRenderWithAriaAttributes(): void ); } + public function testRenderWithAriaAttributesAndAriaDescribedByTrueBooleanValue(): void + { + self::assertSame( + << + + HTML, + TextArea::tag() + ->ariaAttributes(['describedby' => true]) + ->id('textarea') + ->render(), + "Failed asserting that element renders correctly with 'aria-describedby' attribute set to 'true'.", + ); + } + + public function testRenderWithAriaAttributesAndAriaDescribedByTrueStringValue(): void + { + self::assertSame( + << + + HTML, + TextArea::tag() + ->ariaAttributes(['describedby' => 'true']) + ->id('textarea') + ->render(), + "Failed asserting that element renders correctly with 'aria-describedby' attribute set to 'true'.", + ); + } + + public function testRenderWithAriaDescribedByCustomSuffix(): void + { + self::assertSame( + << + + HTML, + TextArea::tag() + ->addAriaAttribute('describedby', true) + ->ariaDescribedBySuffix('value') + ->id('textarea') + ->render(), + "Failed asserting that 'ariaDescribedBySuffix()' correctly applies the custom suffix.", + ); + } + public function testRenderWithAttributes(): void { self::assertSame( @@ -194,6 +301,36 @@ public function testRenderWithAttributes(): void ); } + public function testRenderWithAttributesAndAriaDescribedByTrueBooleanValue(): void + { + self::assertSame( + << + + HTML, + TextArea::tag() + ->attributes(['aria-describedby' => true]) + ->id('textarea') + ->render(), + "Failed asserting that element renders correctly with 'aria-describedby' attribute set to 'true'.", + ); + } + + public function testRenderWithAttributesAndAriaDescribedByTrueStringValue(): void + { + self::assertSame( + << + + HTML, + TextArea::tag() + ->attributes(['aria-describedby' => 'true']) + ->id('textarea') + ->render(), + "Failed asserting that element renders correctly with 'aria-describedby' attribute set to 'true'.", + ); + } + public function testRenderWithAutocapitalize(): void { self::assertSame( @@ -990,6 +1127,11 @@ public function testReturnNewInstanceWhenSettingAttribute(): void { $textArea = TextArea::tag(); + self::assertNotSame( + $textArea, + $textArea->ariaDescribedBySuffix(''), + 'Should return a new instance when setting the attribute, ensuring immutability.', + ); self::assertNotSame( $textArea, $textArea->cols(1), diff --git a/tests/Provider/Form/CheckedProvider.php b/tests/Provider/Form/CheckedProvider.php index bee8dce..3bfeb44 100644 --- a/tests/Provider/Form/CheckedProvider.php +++ b/tests/Provider/Form/CheckedProvider.php @@ -36,7 +36,7 @@ public static function checked(): array [1, 2], 1, << + HTML, ], // array (unchecked) @@ -44,7 +44,7 @@ public static function checked(): array [1, 2], 3, << + HTML, ], // array type juggling (checked) @@ -52,14 +52,14 @@ public static function checked(): array ['1', '2'], 1, << + HTML, ], 'checked: [1, 2], value: "1"' => [ [1, 2], '1', << + HTML, ], // backed enum (checked) @@ -67,7 +67,7 @@ public static function checked(): array BackedString::VALUE, 'value', << + HTML, ], // backed enum (unchecked) @@ -75,7 +75,7 @@ public static function checked(): array BackedString::VALUE, 'other', << + HTML, ], // boolean `false` (never checked) @@ -83,35 +83,35 @@ public static function checked(): array false, 'active', << + HTML, ], 'checked: false, value: ""' => [ false, '', << + HTML, ], 'checked: false, value: 1' => [ false, 1, << + HTML, ], 'checked: false, value: false' => [ false, false, << + HTML, ], 'checked: false, value: null' => [ false, null, << + HTML, ], // boolean `true` (always checked) @@ -119,21 +119,21 @@ public static function checked(): array true, 'active', << + HTML, ], 'checked: true, value: 1' => [ true, 1, << + HTML, ], 'checked: true, value: null' => [ true, null, << + HTML, ], // float matching (checked) @@ -141,21 +141,21 @@ public static function checked(): array 1.1, 1.1, << + HTML, ], 'checked: 1.1, value: "1.1"' => [ 1.1, '1.1', << + HTML, ], 'checked: "1.1", value: 1.1' => [ '1.1', 1.1, << + HTML, ], // float mismatch (unchecked) @@ -163,7 +163,7 @@ public static function checked(): array 1.1, 1.2, << + HTML, ], // null (never checked) @@ -171,14 +171,14 @@ public static function checked(): array null, 1, << + HTML, ], 'checked: null, value: null' => [ null, null, << + HTML, ], // scalar matching (checked) @@ -186,35 +186,35 @@ public static function checked(): array 'active', 'active', << + HTML, ], 'checked: 0, value: 0' => [ 0, 0, << + HTML, ], 'checked: 1, value: 1' => [ 1, 1, << + HTML, ], 'checked: "1", value: true' => [ '1', true, << + HTML, ], 'checked: "1", value: "1"' => [ '1', '1', << + HTML, ], // scalar mismatch (unchecked) @@ -222,14 +222,14 @@ public static function checked(): array 'active', 'inactive', << + HTML, ], 'checked: 1, value: 0' => [ 1, 0, << + HTML, ], // type juggling (checked) @@ -237,14 +237,14 @@ public static function checked(): array 1, '1', << + HTML, ], 'checked: "1", value: 1' => [ '1', 1, << + HTML, ], // type juggling (unchecked) @@ -252,7 +252,7 @@ public static function checked(): array 1, '0', << + HTML, ], // stringable (checked) @@ -265,7 +265,7 @@ public function __toString(): string }, 'active', << + HTML, ], // stringable (unchecked) @@ -278,7 +278,7 @@ public function __toString(): string }, 'active', << + HTML, ], // unit enum (checked) @@ -286,7 +286,7 @@ public function __toString(): string Unit::value, 'value', << + HTML, ], // unit enum (unchecked) @@ -294,7 +294,7 @@ public function __toString(): string Unit::value, 'other', << + HTML, ], ];