Skip to content
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

191 test helper php 81 improvements #192

Merged
merged 23 commits into from
Aug 24, 2023

Conversation

vraja-pro
Copy link
Contributor

@vraja-pro vraja-pro commented Jul 25, 2023

Summary

This PR can be summarized in the following changelog entry:

  • Removes filter_input and filter_var for PHP 8.1.

Relevant technical choices:

Go to Tools->Yoast Test and check the following:

Domain dropdown

  • Go to Domain dropdown card and change to local.
  • Refresh and check option is saved.
  • Restore to live and check it is saved.

Downgrade Yoast SEO

  • Go to Downgrade Yoast SEO and add a previous version and save.
  • Refresh and check version is saved.

Inline script

  • Go to Inline script card and check the checkbox.
  • Add to the Script box console.log('test'); and save.
  • Refresh and check it is saved.
  • Clear Script box and disable the Inline script and save.
  • Refresh and check it is saved.

Plugin toggler

  • Go to Plugin toggler card and enable.
  • Follow the test instructions here.

Schema

  • Go to Schema card and select different option for Influence the Breadcrumb Graph piece.
  • Select different option for Influence the WebPage Graph piece and save.
  • Refresh and check it is saved.

XML Sitemaps

  • Go to XML Sitemaps and check the checkbox.
  • Refresh and check it is saved.

Milestone

  • I've attached the next release's milestone to this pull request.

Test instructions

Test instructions for the acceptance test before the PR gets merged

This PR can be acceptance tested by following these steps:

Test instructions for QA when the code is in the RC

  • QA should use the same steps as above.

QA can test this PR by following these steps:

Fixes #191

@vraja-pro vraja-pro added this to the 1.19 milestone Jul 25, 2023
@enricobattocchi enricobattocchi modified the milestones: 1.19, 1.18 Aug 4, 2023
@enricobattocchi enricobattocchi changed the base branch from develop to release/1.18 August 4, 2023 12:24
@enricobattocchi enricobattocchi force-pushed the 191-test-helper-php-81-improvements branch 2 times, most recently from 0fb73ac to 4310295 Compare August 4, 2023 12:27
Copy link
Member

@igorschoester igorschoester left a comment

Choose a reason for hiding this comment

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

CR 🏗️

.gitignore Outdated
Comment on lines 20 to 21

.vscode/
Copy link
Member

Choose a reason for hiding this comment

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

I think this can live in the upper section next to say .idea (from PHPStorm) just fine?

src/domain-dropdown.php Outdated Show resolved Hide resolved
@@ -58,7 +58,8 @@ public function handle_submit() {
return;
}

$target_version = \filter_var( \wp_unslash( $_POST['target_version'] ) );
$target_version = ( isset( $_POST['target_version'] ) ) ? \sanitize_text_field( \wp_unslash( $_POST['target_version'] ) ) : null;
Copy link
Member

Choose a reason for hiding this comment

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

I think you want to add a is_string check here too. I'm not sure unslash and sanitize text field like operating on non-strings.

Also, the null fallback does not seem compatible with the downgrade method! What did you want to achieve?

Comment on lines 181 to 184
// phpcs:ignore WordPress.Security.NonceVerification.Recommended -- The nonce is verified above.
$group = ( isset( $_GET['group'] ) ) ? \sanitize_text_field( \wp_unslash( $_GET['group'] ) ) : null;
// phpcs:ignore WordPress.Security.NonceVerification.Recommended -- The nonce is verified above.
$plugin = ( isset( $_GET['plugin'] ) ) ? \sanitize_text_field( \wp_unslash( $_GET['plugin'] ) ) : null;
Copy link
Member

Choose a reason for hiding this comment

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

Same as above, about the is_string. As well as using null as fallback, that does not seem compatible with the methods they are passed too.

@@ -422,7 +424,7 @@ private function deactivate_plugin_group( $group ) {
*/
private function verify_nonce() {
// Get the nonce value.
$ajax_nonce = \filter_input( \INPUT_GET, 'ajax_nonce' );
$ajax_nonce = isset( $_GET['ajax_nonce'] ) ? sanitize_text_field( wp_unslash( $_GET['ajax_nonce'] ) ) : null;
Copy link
Member

Choose a reason for hiding this comment

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

In this case I think we can just check isset and then pass it to the nonce.
wp_verify_nonce does a (string) and hash_equals, which I think takes care of the need to is_string and sanitize_text_field and possibly the wp_unslash.
But as said in another PR, I'm not entirely sure on this 😅

src/schema.php Outdated
$is_needed_breadcrumb = $this->validate_submit( \filter_input( \INPUT_POST, 'is_needed_breadcrumb' ) );
$is_needed_webpage = $this->validate_submit( \filter_input( \INPUT_POST, 'is_needed_webpage' ) );
if ( isset( $_POST['is_needed_breadcrumb'] ) ) {
$is_needed_breadcrumb = \sanitize_text_field( \wp_unslash( $_POST['is_needed_breadcrumb'] ) );
Copy link
Member

Choose a reason for hiding this comment

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

validate_submit method is strict comparing only. Seems like we do not need sanitize_text_field here.

src/schema.php Outdated
$this->option->set( 'is_needed_breadcrumb', $is_needed_breadcrumb );
$this->option->set( 'is_needed_webpage', $is_needed_webpage );
if ( isset( $_POST['is_needed_webpage'] ) ) {
$is_needed_webpage = \sanitize_text_field( \wp_unslash( $_POST['is_needed_webpage'] ) );
Copy link
Member

Choose a reason for hiding this comment

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

Same as above: validate_submit method is strict comparing only. Seems like we do not need sanitize_text_field here.

src/xml-sitemaps.php Outdated Show resolved Hide resolved
@vraja-pro vraja-pro changed the base branch from release/1.18 to develop August 23, 2023 08:56
@vraja-pro vraja-pro changed the base branch from develop to main August 23, 2023 08:56
@vraja-pro vraja-pro changed the base branch from main to release/1.18 August 23, 2023 08:56
@vraja-pro vraja-pro force-pushed the 191-test-helper-php-81-improvements branch from a9d93f7 to d707698 Compare August 23, 2023 10:26
Copy link
Member

@igorschoester igorschoester left a comment

Choose a reason for hiding this comment

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

CR 🏗️

src/plugin-toggler.php Outdated Show resolved Hide resolved
src/plugin-toggler.php Outdated Show resolved Hide resolved
src/inline-script.php Outdated Show resolved Hide resolved
src/inline-script.php Outdated Show resolved Hide resolved
Copy link
Member

@igorschoester igorschoester left a comment

Choose a reason for hiding this comment

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

CR & AC ✅

About the test instructions:

  • Saving refreshes the page already
  • The plugin toggler functionality doesn't seem to work anymore, but that is unrelated to this PR. I'm pretty sure it is obsolete since we made it so that both plugins are active at the same time. It used to be that Premium totally included Free. I added a draft issue on our tech debt board.

@igorschoester igorschoester merged commit 644fd77 into release/1.18 Aug 24, 2023
7 checks passed
@igorschoester igorschoester deleted the 191-test-helper-php-81-improvements branch August 24, 2023 07:00
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Test Helper: PHP 8.1 improvements
3 participants