diff --git a/includes/validation/class-amp-validation-error-taxonomy.php b/includes/validation/class-amp-validation-error-taxonomy.php index f4fa98adfcf..96820da5669 100644 --- a/includes/validation/class-amp-validation-error-taxonomy.php +++ b/includes/validation/class-amp-validation-error-taxonomy.php @@ -2923,10 +2923,19 @@ public static function handle_validation_error_update( $redirect_to, $action, $t } } + if ( $updated_count ) { + delete_transient( AMP_Validated_URL_Post_Type::NEW_VALIDATION_ERROR_URLS_COUNT_TRANSIENT ); + } + if ( false !== $has_pre_term_description_filter ) { add_filter( 'pre_term_description', 'wp_filter_kses', $has_pre_term_description_filter ); } + // Bail if `$redirect_to` is passed as null. + if ( null === $redirect_to ) { + return $redirect_to; + } + $term_ids_count = count( $term_ids ); if ( 'edit.php' === $pagenow && 1 === $updated_count ) { // Redirect to error index screen if deleting an validation error with no associated validated URLs. @@ -2947,10 +2956,6 @@ public static function handle_validation_error_update( $redirect_to, $action, $t ); } - if ( $updated_count ) { - delete_transient( AMP_Validated_URL_Post_Type::NEW_VALIDATION_ERROR_URLS_COUNT_TRANSIENT ); - } - return $redirect_to; } diff --git a/phpunit.xml.dist b/phpunit.xml.dist index 8785ea3f5a2..4314b39002e 100644 --- a/phpunit.xml.dist +++ b/phpunit.xml.dist @@ -2,10 +2,10 @@ bootstrap="tests/php/bootstrap.php" backupGlobals="false" colors="true" - convertDeprecationsToExceptions="false" - convertErrorsToExceptions="false" - convertNoticesToExceptions="false" - convertWarningsToExceptions="false" + convertDeprecationsToExceptions="true" + convertErrorsToExceptions="true" + convertNoticesToExceptions="true" + convertWarningsToExceptions="true" defaultTestSuite="default" > diff --git a/src/Admin/OnboardingWizardSubmenu.php b/src/Admin/OnboardingWizardSubmenu.php index dbe3a29adc4..57f9051da04 100644 --- a/src/Admin/OnboardingWizardSubmenu.php +++ b/src/Admin/OnboardingWizardSubmenu.php @@ -40,7 +40,7 @@ public static function get_registration_action() { */ public function register() { add_submenu_page( - '', + 'options.php', __( 'AMP Onboarding Wizard', 'amp' ), __( 'AMP Onboarding Wizard', 'amp' ), 'manage_options', diff --git a/tests/e2e/config/bootstrap.js b/tests/e2e/config/bootstrap.js index fb67ed2fe7a..eb21611aa90 100644 --- a/tests/e2e/config/bootstrap.js +++ b/tests/e2e/config/bootstrap.js @@ -298,8 +298,8 @@ beforeAll(async () => { await cleanUpSettings(); // Keep navigation timeout high since CI resources can be slow. - await page.setDefaultNavigationTimeout(30000); - await page.setDefaultTimeout(30000); + await page.setDefaultNavigationTimeout(60000); + await page.setDefaultTimeout(60000); }); // eslint-disable-next-line jest/require-top-level-describe diff --git a/tests/php/src/Admin/OnboardingWizardSubmenuTest.php b/tests/php/src/Admin/OnboardingWizardSubmenuTest.php index bb6706d1781..3396c39c968 100644 --- a/tests/php/src/Admin/OnboardingWizardSubmenuTest.php +++ b/tests/php/src/Admin/OnboardingWizardSubmenuTest.php @@ -61,6 +61,6 @@ public function test_register() { $this->instance->register(); - $this->assertEquals( end( $submenu[''] )[2], 'amp-onboarding-wizard' ); + $this->assertEquals( end( $submenu['options.php'] )[2], 'amp-onboarding-wizard' ); } } diff --git a/tests/php/src/Admin/OptionsMenuTest.php b/tests/php/src/Admin/OptionsMenuTest.php index b10973bd1c8..cb34e593db3 100644 --- a/tests/php/src/Admin/OptionsMenuTest.php +++ b/tests/php/src/Admin/OptionsMenuTest.php @@ -290,6 +290,13 @@ public function test_render_screen_for_admin_user() { ) ); + // Set current screen to be the options menu. + set_current_screen( $this->instance->screen_handle() ); + + // Set title to be used in the screen. + global $title; + $title = 'Test Title'; + ob_start(); $this->instance->render_screen(); $this->assertStringContainsString( '
', ob_get_clean() ); diff --git a/tests/php/validation/test-class-amp-validation-error-taxonomy.php b/tests/php/validation/test-class-amp-validation-error-taxonomy.php index 9e337c65d55..f658bb7a3dd 100644 --- a/tests/php/validation/test-class-amp-validation-error-taxonomy.php +++ b/tests/php/validation/test-class-amp-validation-error-taxonomy.php @@ -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. @@ -20,6 +21,7 @@ class Test_AMP_Validation_Error_Taxonomy extends TestCase { use HandleValidation; + use MockAdminUser; /** * The tested class. @@ -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&_actioned=amp_validation_error_accept&_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&_actioned=amp_validation_error_reject&_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&_actioned=delete&_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 ) ); }