Skip to content
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 21 additions & 5 deletions tests/php/validation/test-class-amp-validation-error-taxonomy.php
Copy link
Member

Choose a reason for hiding this comment

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

Is this commit needed to work around the issue in tests which you're fixing in core?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Which commit? I am unable to see any diff with this comment.

Copy link
Member

Choose a reason for hiding this comment

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

Sorry, I meant 2c43d0d

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

It's different from that one. handle_single_url_page_bulk_and_inline_actions() uses get_edit_post_link() which requires edit_post capability in general. In test cases we were not setting up the user hence it was resulting into deprecation warnings.

Copy link
Member

Choose a reason for hiding this comment

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

What was the deprecation warning?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Those were the same as passing null to add_query_arg()

Deprecated: stripos(): Passing null to parameter #1 ($haystack) of type string is deprecated in /tmp/wordpress/src/wp-includes/functions.php on line 1157

Deprecated: str_contains(): Passing null to parameter #1 ($haystack) of type string is deprecated in /tmp/wordpress/src/wp-includes/functions.php on line 1164

Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
use AmpProject\AmpWP\Services;
use AmpProject\AmpWP\Tests\Helpers\HandleValidation;
use AmpProject\AmpWP\Tests\TestCase;
use AmpProject\AmpWP\Tests\Helpers\MockAdminUser;

/**
* Tests for AMP_Validation_Error_Taxonomy class.
Expand All @@ -20,6 +21,7 @@
class Test_AMP_Validation_Error_Taxonomy extends TestCase {

use HandleValidation;
use MockAdminUser;

/**
* The tested class.
Expand Down Expand Up @@ -1429,27 +1431,41 @@ static function ( $redirect_url ) use ( &$redirected_url ) {
AMP_Validation_Error_Taxonomy::handle_single_url_page_bulk_and_inline_actions( $incorrect_post_type );
$this->assertEquals( get_term( $error_term->term_id )->term_group, $initial_accepted_status );

// Setup admin user which have edit_posts capability.
$this->mock_admin_user();

// Build the expected URL for the redirect.
$admin_post_url = admin_url( 'post.php' );
$redirect_query_args = [
'post' => $correct_post_type,
'action' => 'edit',
'amp_actioned' => AMP_Validation_Error_Taxonomy::VALIDATION_ERROR_ACCEPT_ACTION,
'amp_actioned_count' => 1,
];

/*
* Although the post type is correct, this should not update the post accepted status to be 'accepted'.
* There should be a warning because wp_safe_redirect() should be called at the end of the tested method.
*/
AMP_Validation_Error_Taxonomy::handle_single_url_page_bulk_and_inline_actions( $correct_post_type );

$this->assertSame( '?action=edit&amp_actioned=amp_validation_error_accept&amp_actioned_count=1', $redirected_url );
$this->assertSame( add_query_arg( $redirect_query_args, $admin_post_url ), $redirected_url );
$this->assertEquals( get_term( $error_term->term_id )->term_group, AMP_Validation_Error_Taxonomy::VALIDATION_ERROR_NEW_ACCEPTED_STATUS );

// When the action is to 'reject' the error, this should not update the status of the error to 'rejected'.
$_REQUEST['action'] = AMP_Validation_Error_Taxonomy::VALIDATION_ERROR_REJECT_ACTION;
$_REQUEST['action'] = AMP_Validation_Error_Taxonomy::VALIDATION_ERROR_REJECT_ACTION;
$redirect_query_args['amp_actioned'] = AMP_Validation_Error_Taxonomy::VALIDATION_ERROR_REJECT_ACTION;
AMP_Validation_Error_Taxonomy::handle_single_url_page_bulk_and_inline_actions( $correct_post_type );

$this->assertSame( '?action=edit&amp_actioned=amp_validation_error_reject&amp_actioned_count=1', $redirected_url );
$this->assertSame( add_query_arg( $redirect_query_args, $admin_post_url ), $redirected_url );
$this->assertEquals( get_term( $error_term->term_id )->term_group, AMP_Validation_Error_Taxonomy::VALIDATION_ERROR_NEW_ACCEPTED_STATUS );

// When the action is to 'delete' the error, this should delete the error.
$_REQUEST['action'] = 'delete';
$_REQUEST['action'] = 'delete';
$redirect_query_args['amp_actioned'] = 'delete';
AMP_Validation_Error_Taxonomy::handle_single_url_page_bulk_and_inline_actions( $correct_post_type );

$this->assertSame( '?action=edit&amp_actioned=delete&amp_actioned_count=1', $redirected_url );
$this->assertSame( add_query_arg( $redirect_query_args, $admin_post_url ), $redirected_url );
$this->assertEquals( null, get_term( $error_term->term_id ) );
}

Expand Down