From ffa5afa135661d60591c4797674dbf2e59ce65c3 Mon Sep 17 00:00:00 2001 From: Wilmer Arambula Date: Mon, 23 Feb 2026 19:24:39 -0300 Subject: [PATCH 1/2] feat(form): Add `ariaDescribedBySuffix` property and update `getAttributes` method for improved accessibility support. --- CHANGELOG.md | 22 +-- src/Form/Button.php | 46 +++++ src/Form/Form.php | 46 +++++ src/Form/TextArea.php | 46 +++++ tests/Form/ButtonTest.php | 171 ++++++++++++++++++ tests/Form/FormTest.php | 137 +++++++++++++++ tests/Form/InputCheckboxTest.php | 189 +++++++++----------- tests/Form/InputColorTest.php | 203 +++++++++------------- tests/Form/InputDateTest.php | 209 +++++++++------------- tests/Form/InputDateTimeLocalTest.php | 215 ++++++++++------------- tests/Form/InputEmailTest.php | 221 ++++++++++-------------- tests/Form/InputFileTest.php | 197 +++++++++------------ tests/Form/InputHiddenTest.php | 169 +++++++----------- tests/Form/InputImageTest.php | 197 ++++++++------------- tests/Form/InputMonthTest.php | 197 ++++++++------------- tests/Form/InputNumberTest.php | 203 ++++++++-------------- tests/Form/InputPasswordTest.php | 203 ++++++++-------------- tests/Form/InputRadioTest.php | 174 +++++++------------ tests/Form/InputRangeTest.php | 194 ++++++++------------- tests/Form/InputResetTest.php | 165 +++++++----------- tests/Form/InputSearchTest.php | 216 +++++++++-------------- tests/Form/InputSubmitTest.php | 194 ++++++++------------- tests/Form/InputTelTest.php | 200 ++++++++------------- tests/Form/InputTextTest.php | 203 ++++++++-------------- tests/Form/InputTimeTest.php | 197 ++++++++------------- tests/Form/InputUrlTest.php | 203 ++++++++-------------- tests/Form/InputWeekTest.php | 200 ++++++++------------- tests/Form/TextAreaTest.php | 137 +++++++++++++++ tests/Provider/Form/CheckedProvider.php | 68 ++++---- 29 files changed, 2209 insertions(+), 2613 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 29c95c7..6c64def 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( 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, ], ]; From 63bcd5982d745e1ae6e8a99f5537543e98aa437e Mon Sep 17 00:00:00 2001 From: Wilmer Arambula Date: Fri, 27 Feb 2026 19:46:31 -0300 Subject: [PATCH 2/2] Apply fixed Coderabbitai review. --- tests/Form/ButtonTest.php | 11 +++++++++++ tests/Form/FormTest.php | 5 +++++ tests/Form/TextAreaTest.php | 5 +++++ 3 files changed, 21 insertions(+) diff --git a/tests/Form/ButtonTest.php b/tests/Form/ButtonTest.php index b873ec5..30acb99 100644 --- a/tests/Form/ButtonTest.php +++ b/tests/Form/ButtonTest.php @@ -1009,6 +1009,17 @@ public function testRenderWithValue(): void ); } + public function testReturnNewInstanceWhenSettingAttribute(): void + { + $button = Button::tag(); + + self::assertNotSame( + $button, + $button->ariaDescribedBySuffix(''), + 'Should return a new instance when setting the attribute, ensuring immutability.', + ); + } + public function testThrowInvalidArgumentExceptionWhenSettingDir(): void { $this->expectException(InvalidArgumentException::class); diff --git a/tests/Form/FormTest.php b/tests/Form/FormTest.php index 7ff1650..b975357 100644 --- a/tests/Form/FormTest.php +++ b/tests/Form/FormTest.php @@ -1097,6 +1097,11 @@ public function testReturnNewInstanceWhenSettingAttribute(): void $form->action(''), 'Should return a new instance when setting the attribute, ensuring immutability.', ); + self::assertNotSame( + $form, + $form->ariaDescribedBySuffix(''), + 'Should return a new instance when setting the attribute, ensuring immutability.', + ); self::assertNotSame( $form, $form->enctype(''), diff --git a/tests/Form/TextAreaTest.php b/tests/Form/TextAreaTest.php index afbdc28..fc22ea8 100644 --- a/tests/Form/TextAreaTest.php +++ b/tests/Form/TextAreaTest.php @@ -1127,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),