Skip to content
2 changes: 1 addition & 1 deletion classes/views/frm-fields/front-end/gdpr/gdpr-field.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
</label>
</div>
<?php elseif ( current_user_can( 'frm_edit_forms' ) ) : ?>
<div class="frm_checkbox" role="group" aria-labelledby="<?php echo esc_attr( $label_id ); ?>">
<div class="frm_checkbox" role="group">
<label>
<?php
/* translators: %1$s: Link HTML, %2$s: End link */
Expand Down
74 changes: 74 additions & 0 deletions tests/phpunit/fields/test_FrmFieldGdpr.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Access to an undefined property FrmSettings::$enable_gdpr


The property you are trying to access is not defined and will cause unexpected behavior when used.

}

public function tearDown(): void {
FrmAppHelper::get_settings()->enable_gdpr = $this->original_enable_gdpr;

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Access to an undefined property FrmSettings::$enable_gdpr


This issue is raised when an attempt is made to access an undefined property.
This may not have been intended, and it is advisable to give the code another look to make sure the property is defined in the scope it is used in.

parent::tearDown();

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Call to an undefined static method FrmUnitTest::tearDown()


Invalid call to a static method. This would lead to a run time error.

}

public function test_label_does_not_duplicate_for_attribute_when_wrapping_input() {
$frm_settings = FrmAppHelper::get_settings();
$original_enable_gdpr = $frm_settings->enable_gdpr;

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Access to an undefined property FrmSettings::$enable_gdpr


The property you are trying to access is not defined and will cause unexpected behavior when used.

Expand Down Expand Up @@ -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;

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Access to an undefined property FrmSettings::$enable_gdpr


This issue is raised when an attempt is made to access an undefined property.
This may not have been intended, and it is advisable to give the code another look to make sure the property is defined in the scope it is used in.


$html = $this->render_gdpr_field( 543 );

$this->assertStringNotContainsString(

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Call to an undefined method test_FrmFieldGdpr::assertStringNotContainsString()


The method you are trying to call is not defined, which can result in a fatal error.

'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 );

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Call to an undefined method test_FrmFieldGdpr::assertStringContainsString()


The method you are trying to call is not defined, which can result in a fatal error.

}

/**
* @covers FrmFieldType::include_front_field_input
*/
public function test_enabled_field_still_has_aria_labelledby() {
FrmAppHelper::get_settings()->enable_gdpr = true;

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Access to an undefined property FrmSettings::$enable_gdpr


This issue is raised when an attempt is made to access an undefined property.
This may not have been intended, and it is advisable to give the code another look to make sure the property is defined in the scope it is used in.


$html = $this->render_gdpr_field( 544 );

$this->assertStringContainsString( 'aria-labelledby="frm-gdpr-accept-544"', $html );

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Call to an undefined method test_FrmFieldGdpr::assertStringContainsString()


The method you are trying to call is not defined, which can result in a fatal error.

$this->assertStringContainsString( 'id="frm-gdpr-accept-544"', $html );

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Call to an undefined method test_FrmFieldGdpr::assertStringContainsString()


The method you are trying to call is not defined, which can result in a fatal error.

}

/**
* @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()
);
}
}
Loading