-
Notifications
You must be signed in to change notification settings - Fork 42
Fix dangling aria-labelledby in GDPR field's disabled notice #3485
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
276926a
0d719e9
90de42b
b40ae7d
50227d0
4ae6739
7beada3
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -8,6 +8,22 @@ | |
| #[\PHPUnit\Framework\Attributes\CoversClass( FrmFieldGdpr::class )] | ||
| class test_FrmFieldGdpr extends FrmUnitTest { | ||
|
|
||
| /** | ||
| * @var int | ||
| */ | ||
| private $original_enable_gdpr; | ||
|
|
||
| public function setUp(): void { | ||
| parent::setUp(); | ||
| // $frm_settings is a process-wide global, not reset between tests by the DB rollback. | ||
| $this->original_enable_gdpr = FrmAppHelper::get_settings()->enable_gdpr; | ||
| } | ||
|
|
||
| public function tearDown(): void { | ||
| FrmAppHelper::get_settings()->enable_gdpr = $this->original_enable_gdpr; | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
| parent::tearDown(); | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
| } | ||
|
|
||
| public function test_label_does_not_duplicate_for_attribute_when_wrapping_input() { | ||
| $frm_settings = FrmAppHelper::get_settings(); | ||
| $original_enable_gdpr = $frm_settings->enable_gdpr; | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
|
|
@@ -79,4 +95,62 @@ public function test_disabled_notice_label_has_no_dangling_for_attribute() { | |
| 'The disabled-notice label has no input to associate with, so it should not carry a for attribute' | ||
| ); | ||
| } | ||
|
|
||
| /** | ||
| * @covers FrmFieldType::include_front_field_input | ||
| */ | ||
| public function test_disabled_notice_has_no_dangling_aria_labelledby() { | ||
| $user_id = $this->factory->user->create( array( 'role' => 'administrator' ) ); | ||
| wp_set_current_user( $user_id ); | ||
| // FrmAppHelper::maybe_add_permissions() grants this via a separate WP_User | ||
| // instance, which doesn't reach the current_user_can() cache for this request. | ||
| wp_get_current_user()->add_cap( 'frm_edit_forms' ); | ||
| FrmAppHelper::get_settings()->enable_gdpr = false; | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
|
|
||
| $html = $this->render_gdpr_field( 543 ); | ||
|
|
||
| $this->assertStringNotContainsString( | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
| 'aria-labelledby', | ||
| $html, | ||
| 'The disabled-notice branch has no element carrying the referenced id, so aria-labelledby should not be printed.' | ||
| ); | ||
| $this->assertStringContainsString( 'GDPR field is disabled', $html ); | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
| } | ||
|
|
||
| /** | ||
| * @covers FrmFieldType::include_front_field_input | ||
| */ | ||
| public function test_enabled_field_still_has_aria_labelledby() { | ||
| FrmAppHelper::get_settings()->enable_gdpr = true; | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
|
|
||
| $html = $this->render_gdpr_field( 544 ); | ||
|
|
||
| $this->assertStringContainsString( 'aria-labelledby="frm-gdpr-accept-544"', $html ); | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
| $this->assertStringContainsString( 'id="frm-gdpr-accept-544"', $html ); | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
| } | ||
|
|
||
| /** | ||
| * @param int $field_id | ||
| * | ||
| * @return string | ||
| */ | ||
| private function render_gdpr_field( $field_id ) { | ||
| $field_type = new FrmFieldGdpr( | ||
| array( | ||
| 'id' => $field_id, | ||
| 'type' => 'gdpr', | ||
| 'gdpr_agreement_text' => 'I agree', | ||
| 'value' => '', | ||
| 'default_value' => '', | ||
| ) | ||
| ); | ||
|
|
||
| return $field_type->include_front_field_input( | ||
| array( | ||
| 'html_id' => 'field_gdpr_' . $field_id, | ||
| 'field_name' => 'item_meta[' . $field_id . ']', | ||
| ), | ||
| array() | ||
| ); | ||
| } | ||
| } | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The property you are trying to access is not defined and will cause unexpected behavior when used.