|
11 | 11 | use AmpProject\AmpWP\Services; |
12 | 12 | use AmpProject\AmpWP\Tests\Helpers\HandleValidation; |
13 | 13 | use AmpProject\AmpWP\Tests\TestCase; |
| 14 | +use AmpProject\AmpWP\Tests\Helpers\MockAdminUser; |
14 | 15 |
|
15 | 16 | /** |
16 | 17 | * Tests for AMP_Validation_Error_Taxonomy class. |
|
20 | 21 | class Test_AMP_Validation_Error_Taxonomy extends TestCase { |
21 | 22 |
|
22 | 23 | use HandleValidation; |
| 24 | + use MockAdminUser; |
23 | 25 |
|
24 | 26 | /** |
25 | 27 | * The tested class. |
@@ -1429,27 +1431,41 @@ static function ( $redirect_url ) use ( &$redirected_url ) { |
1429 | 1431 | AMP_Validation_Error_Taxonomy::handle_single_url_page_bulk_and_inline_actions( $incorrect_post_type ); |
1430 | 1432 | $this->assertEquals( get_term( $error_term->term_id )->term_group, $initial_accepted_status ); |
1431 | 1433 |
|
| 1434 | + // Setup admin user which have edit_posts capability. |
| 1435 | + $this->mock_admin_user(); |
| 1436 | + |
| 1437 | + // Build the expected URL for the redirect. |
| 1438 | + $admin_post_url = admin_url( 'post.php' ); |
| 1439 | + $redirect_query_args = [ |
| 1440 | + 'post' => $correct_post_type, |
| 1441 | + 'action' => 'edit', |
| 1442 | + 'amp_actioned' => AMP_Validation_Error_Taxonomy::VALIDATION_ERROR_ACCEPT_ACTION, |
| 1443 | + 'amp_actioned_count' => 1, |
| 1444 | + ]; |
| 1445 | + |
1432 | 1446 | /* |
1433 | 1447 | * Although the post type is correct, this should not update the post accepted status to be 'accepted'. |
1434 | 1448 | * There should be a warning because wp_safe_redirect() should be called at the end of the tested method. |
1435 | 1449 | */ |
1436 | 1450 | AMP_Validation_Error_Taxonomy::handle_single_url_page_bulk_and_inline_actions( $correct_post_type ); |
1437 | 1451 |
|
1438 | | - $this->assertSame( '?action=edit&_actioned=amp_validation_error_accept&_actioned_count=1', $redirected_url ); |
| 1452 | + $this->assertSame( add_query_arg( $redirect_query_args, $admin_post_url ), $redirected_url ); |
1439 | 1453 | $this->assertEquals( get_term( $error_term->term_id )->term_group, AMP_Validation_Error_Taxonomy::VALIDATION_ERROR_NEW_ACCEPTED_STATUS ); |
1440 | 1454 |
|
1441 | 1455 | // When the action is to 'reject' the error, this should not update the status of the error to 'rejected'. |
1442 | | - $_REQUEST['action'] = AMP_Validation_Error_Taxonomy::VALIDATION_ERROR_REJECT_ACTION; |
| 1456 | + $_REQUEST['action'] = AMP_Validation_Error_Taxonomy::VALIDATION_ERROR_REJECT_ACTION; |
| 1457 | + $redirect_query_args['amp_actioned'] = AMP_Validation_Error_Taxonomy::VALIDATION_ERROR_REJECT_ACTION; |
1443 | 1458 | AMP_Validation_Error_Taxonomy::handle_single_url_page_bulk_and_inline_actions( $correct_post_type ); |
1444 | 1459 |
|
1445 | | - $this->assertSame( '?action=edit&_actioned=amp_validation_error_reject&_actioned_count=1', $redirected_url ); |
| 1460 | + $this->assertSame( add_query_arg( $redirect_query_args, $admin_post_url ), $redirected_url ); |
1446 | 1461 | $this->assertEquals( get_term( $error_term->term_id )->term_group, AMP_Validation_Error_Taxonomy::VALIDATION_ERROR_NEW_ACCEPTED_STATUS ); |
1447 | 1462 |
|
1448 | 1463 | // When the action is to 'delete' the error, this should delete the error. |
1449 | | - $_REQUEST['action'] = 'delete'; |
| 1464 | + $_REQUEST['action'] = 'delete'; |
| 1465 | + $redirect_query_args['amp_actioned'] = 'delete'; |
1450 | 1466 | AMP_Validation_Error_Taxonomy::handle_single_url_page_bulk_and_inline_actions( $correct_post_type ); |
1451 | 1467 |
|
1452 | | - $this->assertSame( '?action=edit&_actioned=delete&_actioned_count=1', $redirected_url ); |
| 1468 | + $this->assertSame( add_query_arg( $redirect_query_args, $admin_post_url ), $redirected_url ); |
1453 | 1469 | $this->assertEquals( null, get_term( $error_term->term_id ) ); |
1454 | 1470 | } |
1455 | 1471 |
|
|
0 commit comments