From fe33e95b31fab270113ef3a2e82c6763ea561306 Mon Sep 17 00:00:00 2001 From: Weston Ruter Date: Thu, 13 Sep 2018 16:52:48 -0700 Subject: [PATCH 01/25] Rename force-sanitization to auto-accept-sanitization --- .../options/class-amp-options-manager.php | 24 +++++++-------- includes/options/class-amp-options-menu.php | 10 +++---- .../class-amp-invalid-url-post-type.php | 12 ++++---- .../class-amp-validation-error-taxonomy.php | 2 +- .../class-amp-validation-manager.php | 10 +++---- tests/test-amp-helper-functions.php | 2 +- tests/test-class-amp-options-manager.php | 18 +++++------ .../test-class-amp-invalid-url-post-type.php | 8 ++--- ...st-class-amp-validation-error-taxonomy.php | 4 +-- .../test-class-amp-validation-manager.php | 30 +++++++++---------- 10 files changed, 60 insertions(+), 60 deletions(-) diff --git a/includes/options/class-amp-options-manager.php b/includes/options/class-amp-options-manager.php index afaff853f52..8ddbcf55aec 100644 --- a/includes/options/class-amp-options-manager.php +++ b/includes/options/class-amp-options-manager.php @@ -23,15 +23,15 @@ class AMP_Options_Manager { * @var array */ protected static $defaults = array( - 'theme_support' => 'disabled', - 'supported_post_types' => array( 'post' ), - 'analytics' => array(), - 'force_sanitization' => true, - 'accept_tree_shaking' => true, - 'disable_admin_bar' => false, - 'all_templates_supported' => true, - 'supported_templates' => array( 'is_singular' ), - 'enable_response_caching' => true, + 'theme_support' => 'disabled', + 'supported_post_types' => array( 'post' ), + 'analytics' => array(), + 'auto_accept_sanitization' => true, + 'accept_tree_shaking' => true, + 'disable_admin_bar' => false, + 'all_templates_supported' => true, + 'supported_templates' => array( 'is_singular' ), + 'enable_response_caching' => true, ); /** @@ -121,9 +121,9 @@ public static function validate_options( $new_options ) { $options['theme_support'] = $new_options['theme_support']; } - $options['force_sanitization'] = ! empty( $new_options['force_sanitization'] ); - $options['accept_tree_shaking'] = ! empty( $new_options['accept_tree_shaking'] ); - $options['disable_admin_bar'] = ! empty( $new_options['disable_admin_bar'] ); + $options['auto_accept_sanitization'] = ! empty( $new_options['auto_accept_sanitization'] ); + $options['accept_tree_shaking'] = ! empty( $new_options['accept_tree_shaking'] ); + $options['disable_admin_bar'] = ! empty( $new_options['disable_admin_bar'] ); // Validate post type support. $options['supported_post_types'] = array(); diff --git a/includes/options/class-amp-options-menu.php b/includes/options/class-amp-options-menu.php index c62091526bb..16e21006ded 100644 --- a/includes/options/class-amp-options-menu.php +++ b/includes/options/class-amp-options-menu.php @@ -257,15 +257,15 @@ public function render_validation_handling() {

- +

-

@@ -302,7 +302,7 @@ public function render_validation_handling() { }; var updateTreeShakingHiddenClass = function() { - var checkbox = $( '#force_sanitization' ); + var checkbox = $( '#auto_accept_sanitization' ); $( '.amp-tree-shaking' ).toggleClass( 'hidden', checkbox.prop( 'checked' ) && 'native' !== getThemeSupportMode() ); }; @@ -315,7 +315,7 @@ public function render_validation_handling() { }; $( 'input[type=radio][name="amp-options[theme_support]"]' ).change( updateHiddenClasses ); - $( '#force_sanitization' ).change( updateTreeShakingHiddenClass ); + $( '#auto_accept_sanitization' ).change( updateTreeShakingHiddenClass ); updateHiddenClasses(); })( jQuery ); diff --git a/includes/validation/class-amp-invalid-url-post-type.php b/includes/validation/class-amp-invalid-url-post-type.php index 43e68e0a576..22bd82c978e 100644 --- a/includes/validation/class-amp-invalid-url-post-type.php +++ b/includes/validation/class-amp-invalid-url-post-type.php @@ -482,7 +482,7 @@ public static function get_validated_environment() { 'theme' => get_stylesheet(), 'plugins' => get_option( 'active_plugins', array() ), 'options' => array( - 'accept_tree_shaking' => ( AMP_Options_Manager::get_option( 'accept_tree_shaking' ) || AMP_Options_Manager::get_option( 'force_sanitization' ) ), + 'accept_tree_shaking' => ( AMP_Options_Manager::get_option( 'accept_tree_shaking' ) || AMP_Options_Manager::get_option( 'auto_accept_sanitization' ) ), ), ); } @@ -838,7 +838,7 @@ public static function print_admin_notice() { } else { $template_mode = 'classic'; } - $auto_sanitization = AMP_Options_Manager::get_option( 'force_sanitization' ); + $auto_sanitization = AMP_Options_Manager::get_option( 'auto_accept_sanitization' ); if ( 'native' === $template_mode ) { $message = __( 'The site is using native AMP mode, the validation errors found are already automatically handled.', 'amp' ); @@ -1117,7 +1117,7 @@ public static function add_meta_boxes() { * @return void */ public static function print_status_meta_box( $post ) { - $is_sanitization_forcibly_accepted_by_filter = AMP_Validation_Error_Taxonomy::is_validation_error_sanitized( array( + $is_sanitization_auto_accepted_by_filter = AMP_Validation_Error_Taxonomy::is_validation_error_sanitized( array( 'code' => 'does_not_exist', ) ); @@ -1140,7 +1140,7 @@ public static function print_status_meta_box( $post ) {
- +
@@ -1260,7 +1260,7 @@ public static function print_validation_errors_meta_box( $post ) { return AMP_Validation_Error_Taxonomy::VALIDATION_ERROR_ACCEPTED_STATUS !== $validation_error['term_status']; } ) ); - $is_sanitization_forcibly_accepted_by_filter = AMP_Validation_Error_Taxonomy::is_validation_error_sanitized( array( + $is_sanitization_auto_accepted_by_filter = AMP_Validation_Error_Taxonomy::is_validation_error_sanitized( array( 'code' => 'does_not_exist', ) ); @@ -1276,7 +1276,7 @@ public static function print_validation_errors_meta_box( $post ) { - +

diff --git a/includes/validation/class-amp-validation-error-taxonomy.php b/includes/validation/class-amp-validation-error-taxonomy.php index b97c4f4e8ee..e004876427b 100644 --- a/includes/validation/class-amp-validation-error-taxonomy.php +++ b/includes/validation/class-amp-validation-error-taxonomy.php @@ -319,7 +319,7 @@ public static function get_validation_error_sanitization( $error ) { $is_forced = ( amp_is_canonical() || - AMP_Options_Manager::get_option( 'force_sanitization' ) + AMP_Options_Manager::get_option( 'auto_accept_sanitization' ) ); if ( $is_forced ) { $forced = 'with_option'; diff --git a/includes/validation/class-amp-validation-manager.php b/includes/validation/class-amp-validation-manager.php index a07feb5cb8d..811c468bcab 100644 --- a/includes/validation/class-amp-validation-manager.php +++ b/includes/validation/class-amp-validation-manager.php @@ -187,7 +187,7 @@ public static function init( $args = array() ) { add_action( 'admin_bar_menu', array( __CLASS__, 'add_admin_bar_menu_items' ), 100 ); // Add filter to auto-accept tree shaking validation error. - if ( AMP_Options_Manager::get_option( 'accept_tree_shaking' ) || AMP_Options_Manager::get_option( 'force_sanitization' ) ) { + if ( AMP_Options_Manager::get_option( 'accept_tree_shaking' ) || AMP_Options_Manager::get_option( 'auto_accept_sanitization' ) ) { add_filter( 'amp_validation_error_sanitized', array( __CLASS__, 'filter_tree_shaking_validation_error_as_accepted' ), 10, 2 ); } @@ -216,8 +216,8 @@ public static function is_theme_support_forced() { * * @return bool Whether sanitization is forcibly accepted. */ - public static function is_sanitization_forcibly_accepted() { - return amp_is_canonical() || AMP_Options_Manager::get_option( 'force_sanitization' ); + public static function is_sanitization_auto_accepted() { + return amp_is_canonical() || AMP_Options_Manager::get_option( 'auto_accept_sanitization' ); } /** @@ -317,7 +317,7 @@ public static function add_admin_bar_menu_items( $wp_admin_bar ) { if ( is_amp_endpoint() ) { $icon = '✅'; // WHITE HEAVY CHECK MARK. This will get overridden in AMP_Validation_Manager::finalize_validation() if there are unaccepted errors. - } elseif ( $error_count > 0 && ! self::is_sanitization_forcibly_accepted() ) { + } elseif ( $error_count > 0 && ! self::is_sanitization_auto_accepted() ) { $icon = '❌'; // CROSS MARK. } else { $icon = '🔗'; // LINK SYMBOL. @@ -357,7 +357,7 @@ public static function add_admin_bar_menu_items( $wp_admin_bar ) { $first_item_is_validate = ( amp_is_canonical() || - ( ! is_amp_endpoint() && $error_count > 0 && ! self::is_sanitization_forcibly_accepted() ) + ( ! is_amp_endpoint() && $error_count > 0 && ! self::is_sanitization_auto_accepted() ) ); if ( $first_item_is_validate ) { $title = __( 'Validate AMP', 'amp' ); diff --git a/tests/test-amp-helper-functions.php b/tests/test-amp-helper-functions.php index 85228f10842..e9bfe27f096 100644 --- a/tests/test-amp-helper-functions.php +++ b/tests/test-amp-helper-functions.php @@ -269,7 +269,7 @@ public function get_amphtml_urls() { */ public function test_amp_add_amphtml_link( $canonical_url, $amphtml_url ) { $test = $this; // For PHP 5.3. - AMP_Options_Manager::update_option( 'force_sanitization', false ); + AMP_Options_Manager::update_option( 'auto_accept_sanitization', false ); $get_amp_html_link = function() { ob_start(); diff --git a/tests/test-class-amp-options-manager.php b/tests/test-class-amp-options-manager.php index 2d243aa2bd8..7480b671fa6 100644 --- a/tests/test-class-amp-options-manager.php +++ b/tests/test-class-amp-options-manager.php @@ -93,15 +93,15 @@ public function test_get_and_set_options() { delete_option( AMP_Options_Manager::OPTION_NAME ); $this->assertEquals( array( - 'theme_support' => 'disabled', - 'supported_post_types' => array( 'post' ), - 'analytics' => array(), - 'force_sanitization' => true, - 'accept_tree_shaking' => true, - 'disable_admin_bar' => false, - 'all_templates_supported' => true, - 'supported_templates' => array( 'is_singular' ), - 'enable_response_caching' => true, + 'theme_support' => 'disabled', + 'supported_post_types' => array( 'post' ), + 'analytics' => array(), + 'auto_accept_sanitization' => true, + 'accept_tree_shaking' => true, + 'disable_admin_bar' => false, + 'all_templates_supported' => true, + 'supported_templates' => array( 'is_singular' ), + 'enable_response_caching' => true, ), AMP_Options_Manager::get_options() ); diff --git a/tests/validation/test-class-amp-invalid-url-post-type.php b/tests/validation/test-class-amp-invalid-url-post-type.php index f8b861a7815..df553ee4619 100644 --- a/tests/validation/test-class-amp-invalid-url-post-type.php +++ b/tests/validation/test-class-amp-invalid-url-post-type.php @@ -169,7 +169,7 @@ public function test_add_admin_menu_new_invalid_url_count() { * @covers \AMP_Invalid_URL_Post_Type::store_validation_errors() */ public function test_get_invalid_url_validation_errors() { - AMP_Options_Manager::update_option( 'force_sanitization', false ); + AMP_Options_Manager::update_option( 'auto_accept_sanitization', false ); add_theme_support( 'amp', array( 'paired' => true ) ); AMP_Validation_Manager::init(); $post = $this->factory()->post->create(); @@ -433,7 +433,7 @@ public function test_get_validated_environment() { switch_theme( 'twentysixteen' ); update_option( 'active_plugins', array( 'foo/foo.php', 'bar.php' ) ); AMP_Options_Manager::update_option( 'accept_tree_shaking', true ); - AMP_Options_Manager::update_option( 'force_sanitization', false ); + AMP_Options_Manager::update_option( 'auto_accept_sanitization', false ); $old_env = AMP_Invalid_URL_Post_Type::get_validated_environment(); $this->assertArrayHasKey( 'theme', $old_env ); $this->assertArrayHasKey( 'plugins', $old_env ); @@ -624,7 +624,7 @@ public function test_filter_bulk_actions() { * @covers \AMP_Invalid_URL_Post_Type::handle_bulk_action() */ public function test_handle_bulk_action() { - AMP_Options_Manager::update_option( 'force_sanitization', false ); + AMP_Options_Manager::update_option( 'auto_accept_sanitization', false ); add_theme_support( 'amp', array( 'paired' => true ) ); AMP_Validation_Manager::init(); @@ -750,7 +750,7 @@ public function test_print_admin_notice() { * @covers \AMP_Invalid_URL_Post_Type::handle_validate_request() */ public function test_handle_validate_request() { - AMP_Options_Manager::update_option( 'force_sanitization', false ); + AMP_Options_Manager::update_option( 'auto_accept_sanitization', false ); add_theme_support( 'amp', array( 'paired' => true ) ); wp_set_current_user( $this->factory()->user->create( array( 'role' => 'administrator' ) ) ); AMP_Validation_Manager::init(); diff --git a/tests/validation/test-class-amp-validation-error-taxonomy.php b/tests/validation/test-class-amp-validation-error-taxonomy.php index c7e6774efc9..a65a8ab6a76 100644 --- a/tests/validation/test-class-amp-validation-error-taxonomy.php +++ b/tests/validation/test-class-amp-validation-error-taxonomy.php @@ -135,7 +135,7 @@ public function test_prepare_validation_error_taxonomy_term() { * @covers \AMP_Validation_Error_Taxonomy::is_validation_error_sanitized() */ public function test_is_validation_error_sanitized() { - AMP_Options_Manager::update_option( 'force_sanitization', false ); + AMP_Options_Manager::update_option( 'auto_accept_sanitization', false ); $this->assertFalse( AMP_Validation_Error_Taxonomy::is_validation_error_sanitized( $this->get_mock_error() ) ); // Trigger Native AMP, which makes all errors accepted. @@ -149,7 +149,7 @@ public function test_is_validation_error_sanitized() { * @covers \AMP_Validation_Error_Taxonomy::get_validation_error_sanitization() */ public function test_get_validation_error_sanitization() { - AMP_Options_Manager::update_option( 'force_sanitization', false ); + AMP_Options_Manager::update_option( 'auto_accept_sanitization', false ); $this->assertEquals( array( 'forced' => false, diff --git a/tests/validation/test-class-amp-validation-manager.php b/tests/validation/test-class-amp-validation-manager.php index b978eb43707..1b0a84740c8 100644 --- a/tests/validation/test-class-amp-validation-manager.php +++ b/tests/validation/test-class-amp-validation-manager.php @@ -135,7 +135,7 @@ public function test_init() { // Make sure should_locate_sources arg is recognized, as is disabling of tree-shaking. remove_all_filters( 'amp_validation_error_sanitized' ); - AMP_Options_Manager::update_option( 'force_sanitization', false ); + AMP_Options_Manager::update_option( 'auto_accept_sanitization', false ); AMP_Options_Manager::update_option( 'accept_tree_shaking', false ); AMP_Validation_Manager::init( array( 'should_locate_sources' => true, @@ -157,28 +157,28 @@ public function test_filter_tree_shaking_validation_error_as_accepted() { /** * Test add_validation_hooks. * - * @covers AMP_Validation_Manager::is_sanitization_forcibly_accepted() + * @covers AMP_Validation_Manager::is_sanitization_auto_accepted() */ - public function test_is_sanitization_forcibly_accepted() { + public function test_is_sanitization_auto_accepted() { remove_theme_support( 'amp' ); - AMP_Options_Manager::update_option( 'force_sanitization', false ); - $this->assertFalse( AMP_Validation_Manager::is_sanitization_forcibly_accepted() ); + AMP_Options_Manager::update_option( 'auto_accept_sanitization', false ); + $this->assertFalse( AMP_Validation_Manager::is_sanitization_auto_accepted() ); remove_theme_support( 'amp' ); - AMP_Options_Manager::update_option( 'force_sanitization', true ); - $this->assertTrue( AMP_Validation_Manager::is_sanitization_forcibly_accepted() ); + AMP_Options_Manager::update_option( 'auto_accept_sanitization', true ); + $this->assertTrue( AMP_Validation_Manager::is_sanitization_auto_accepted() ); add_theme_support( 'amp' ); - AMP_Options_Manager::update_option( 'force_sanitization', false ); - $this->assertTrue( AMP_Validation_Manager::is_sanitization_forcibly_accepted() ); + AMP_Options_Manager::update_option( 'auto_accept_sanitization', false ); + $this->assertTrue( AMP_Validation_Manager::is_sanitization_auto_accepted() ); add_theme_support( 'amp', array( 'paired' => true ) ); - AMP_Options_Manager::update_option( 'force_sanitization', false ); - $this->assertFalse( AMP_Validation_Manager::is_sanitization_forcibly_accepted() ); + AMP_Options_Manager::update_option( 'auto_accept_sanitization', false ); + $this->assertFalse( AMP_Validation_Manager::is_sanitization_auto_accepted() ); add_theme_support( 'amp', array( 'paired' => true ) ); - AMP_Options_Manager::update_option( 'force_sanitization', true ); - $this->assertTrue( AMP_Validation_Manager::is_sanitization_forcibly_accepted() ); + AMP_Options_Manager::update_option( 'auto_accept_sanitization', true ); + $this->assertTrue( AMP_Validation_Manager::is_sanitization_auto_accepted() ); } /** @@ -187,7 +187,7 @@ public function test_is_sanitization_forcibly_accepted() { * @covers AMP_Validation_Manager::add_admin_bar_menu_items() */ public function test_add_admin_bar_menu_items() { - AMP_Options_Manager::update_option( 'force_sanitization', false ); + AMP_Options_Manager::update_option( 'auto_accept_sanitization', false ); // No admin bar item when user lacks capability. $this->go_to( home_url( '/' ) ); @@ -379,7 +379,7 @@ protected function assert_rest_api_field_present( $post_types ) { * @covers AMP_Validation_Manager::validate_url() */ public function test_get_amp_validity_rest_field() { - AMP_Options_Manager::update_option( 'force_sanitization', false ); + AMP_Options_Manager::update_option( 'auto_accept_sanitization', false ); AMP_Invalid_URL_Post_Type::register(); AMP_Validation_Error_Taxonomy::register(); From aed7380f405595105f88c9ff177c83258dfdba6b Mon Sep 17 00:00:00 2001 From: Weston Ruter Date: Thu, 13 Sep 2018 22:31:19 -0700 Subject: [PATCH 02/25] Split new status into new-accepted and new-rejected --- includes/class-amp-cli.php | 2 +- .../class-amp-invalid-url-post-type.php | 39 ++++++---- .../class-amp-validation-error-taxonomy.php | 78 ++++++++++++------- .../class-amp-validation-manager.php | 14 ++-- .../test-class-amp-invalid-url-post-type.php | 20 ++--- ...st-class-amp-validation-error-taxonomy.php | 16 ++-- .../test-class-amp-validation-manager.php | 8 +- 7 files changed, 104 insertions(+), 73 deletions(-) diff --git a/includes/class-amp-cli.php b/includes/class-amp-cli.php index b062b2a66cf..18698d47d95 100644 --- a/includes/class-amp-cli.php +++ b/includes/class-amp-cli.php @@ -586,7 +586,7 @@ public static function validate_and_store_url( $url, $type ) { $validation_errors, function( $error ) { $validation_status = AMP_Validation_Error_Taxonomy::get_validation_error_sanitization( $error ); - return AMP_Validation_Error_Taxonomy::VALIDATION_ERROR_ACCEPTED_STATUS !== $validation_status['term_status']; + return AMP_Validation_Error_Taxonomy::VALIDATION_ERROR_ACK_ACCEPTED_STATUS !== $validation_status['term_status']; } ) ); diff --git a/includes/validation/class-amp-invalid-url-post-type.php b/includes/validation/class-amp-invalid-url-post-type.php index 22bd82c978e..1715e8f0db7 100644 --- a/includes/validation/class-amp-invalid-url-post-type.php +++ b/includes/validation/class-amp-invalid-url-post-type.php @@ -180,7 +180,7 @@ public static function add_admin_menu_new_invalid_url_count() { $query = new WP_Query( array( 'post_type' => self::POST_TYPE_SLUG, - AMP_Validation_Error_Taxonomy::VALIDATION_ERROR_STATUS_QUERY_VAR => AMP_Validation_Error_Taxonomy::VALIDATION_ERROR_NEW_STATUS, + AMP_Validation_Error_Taxonomy::VALIDATION_ERROR_STATUS_QUERY_VAR => AMP_Validation_Error_Taxonomy::VALIDATION_ERROR_NEW_REJECTED_STATUS, 'update_post_meta_cache' => false, 'update_post_term_cache' => false, ) ); @@ -243,7 +243,7 @@ public static function get_invalid_url_validation_errors( $url, $args = array() } $sanitization = AMP_Validation_Error_Taxonomy::get_validation_error_sanitization( $stored_validation_error['data'] ); - if ( $args['ignore_accepted'] && AMP_Validation_Error_Taxonomy::VALIDATION_ERROR_ACCEPTED_STATUS === $sanitization['status'] ) { + if ( $args['ignore_accepted'] && AMP_Validation_Error_Taxonomy::VALIDATION_ERROR_ACK_ACCEPTED_STATUS === $sanitization['status'] ) { continue; } @@ -272,13 +272,13 @@ public static function display_invalid_url_validation_error_counts_summary( $pos $validation_errors = self::get_invalid_url_validation_errors( $post ); foreach ( $validation_errors as $error ) { switch ( $error['term']->term_group ) { - case AMP_Validation_Error_Taxonomy::VALIDATION_ERROR_NEW_STATUS: + case AMP_Validation_Error_Taxonomy::VALIDATION_ERROR_NEW_REJECTED_STATUS: $counts['new']++; break; - case AMP_Validation_Error_Taxonomy::VALIDATION_ERROR_ACCEPTED_STATUS: + case AMP_Validation_Error_Taxonomy::VALIDATION_ERROR_ACK_ACCEPTED_STATUS: $counts['accepted']++; break; - case AMP_Validation_Error_Taxonomy::VALIDATION_ERROR_REJECTED_STATUS: + case AMP_Validation_Error_Taxonomy::VALIDATION_ERROR_ACK_REJECTED_STATUS: $counts['rejected']++; break; } @@ -394,6 +394,10 @@ public static function store_validation_errors( $validation_errors, $url, $args // Not using WP_Term_Query since more likely individual terms are cached and wp_insert_term() will itself look at this cache anyway. $term = get_term_by( 'slug', $term_slug, AMP_Validation_Error_Taxonomy::TAXONOMY_SLUG ); if ( ! ( $term instanceof WP_Term ) ) { + /* + * The default term_group is 0 so that is AMP_Validation_Error_Taxonomy::VALIDATION_ERROR_NEW_REJECTED_STATUS. + * If sanitization auto-acceptance is enabled, then the term_group will be updated below. + */ $r = wp_insert_term( $term_slug, AMP_Validation_Error_Taxonomy::TAXONOMY_SLUG, wp_slash( $term_data ) ); if ( is_wp_error( $r ) ) { continue; @@ -407,10 +411,15 @@ public static function store_validation_errors( $validation_errors, $url, $args */ $sanitization = AMP_Validation_Error_Taxonomy::get_validation_error_sanitization( $data ); if ( 'with_filter' === $sanitization['forced'] ) { + $term_data['term_group'] = $sanitization['status']; wp_update_term( $term_id, AMP_Validation_Error_Taxonomy::TAXONOMY_SLUG, array( 'term_group' => $sanitization['status'], ) ); - $term_data['term_group'] = $sanitization['status']; + } elseif ( AMP_Validation_Manager::is_sanitization_auto_accepted() ) { + $term_data['term_group'] = AMP_Validation_Error_Taxonomy::VALIDATION_ERROR_NEW_ACCEPTED_STATUS; + wp_update_term( $term_id, AMP_Validation_Error_Taxonomy::TAXONOMY_SLUG, array( + 'term_group' => $term_data['term_group'], + ) ); } $term = get_term( $term_id ); @@ -1257,7 +1266,7 @@ public static function print_validation_errors_meta_box( $post ) { $url = self::get_url_from_post( $post ); $has_unaccepted_errors = 0 !== count( array_filter( $validation_errors, function( $validation_error ) { - return AMP_Validation_Error_Taxonomy::VALIDATION_ERROR_ACCEPTED_STATUS !== $validation_error['term_status']; + return AMP_Validation_Error_Taxonomy::VALIDATION_ERROR_ACK_ACCEPTED_STATUS !== $validation_error['term_status']; } ) ); $is_sanitization_auto_accepted_by_filter = AMP_Validation_Error_Taxonomy::is_validation_error_sanitized( array( @@ -1346,28 +1355,28 @@ public static function print_validation_errors_meta_box( $post ) { $select_name = sprintf( '%s[%s]', AMP_Validation_Manager::VALIDATION_ERROR_TERM_STATUS_QUERY_VAR, $term->slug ); ?>

  • -
    term_group ) ? 'open' : ''; ?>> +
    term_group ) ? 'open' : ''; ?>> description, true ) ); - if ( self::VALIDATION_ERROR_REJECTED_STATUS !== $sanitization['term_status'] ) { + if ( self::VALIDATION_ERROR_ACK_REJECTED_STATUS !== $sanitization['term_status'] ) { $actions[ self::VALIDATION_ERROR_REJECT_ACTION ] = sprintf( '%s', wp_nonce_url( @@ -1249,7 +1271,7 @@ public static function filter_tag_row_actions( $actions, WP_Term $tag ) { esc_html__( 'Reject', 'amp' ) ); } - if ( self::VALIDATION_ERROR_ACCEPTED_STATUS !== $sanitization['term_status'] ) { + if ( self::VALIDATION_ERROR_ACK_ACCEPTED_STATUS !== $sanitization['term_status'] ) { $actions[ self::VALIDATION_ERROR_ACCEPT_ACTION ] = sprintf( '%s', wp_nonce_url( @@ -1270,7 +1292,7 @@ public static function filter_tag_row_actions( $actions, WP_Term $tag ) { public static function add_admin_menu_validation_error_item() { $menu_item_label = esc_html__( 'Error Index', 'amp' ); $new_error_count = self::get_validation_error_count( array( - 'group' => self::VALIDATION_ERROR_NEW_STATUS, + 'group' => self::VALIDATION_ERROR_NEW_REJECTED_STATUS, ) ); if ( $new_error_count ) { $menu_item_label .= ' ' . esc_html( number_format_i18n( $new_error_count ) ) . ''; @@ -1355,14 +1377,14 @@ public static function filter_manage_custom_columns( $content, $column_name, $te break; case 'status': $sanitization = self::get_validation_error_sanitization( $validation_error ); - if ( self::VALIDATION_ERROR_ACCEPTED_STATUS === $sanitization['term_status'] ) { + if ( self::VALIDATION_ERROR_ACK_ACCEPTED_STATUS === $sanitization['term_status'] ) { if ( $sanitization['forced'] && $sanitization['term_status'] !== $sanitization['status'] ) { $class = 'sanitized'; } else { $class = 'accepted'; } $text = __( 'Accepted', 'amp' ); - } elseif ( self::VALIDATION_ERROR_REJECTED_STATUS === $sanitization['term_status'] ) { + } elseif ( self::VALIDATION_ERROR_ACK_REJECTED_STATUS === $sanitization['term_status'] ) { if ( $sanitization['forced'] && $sanitization['term_status'] !== $sanitization['status'] ) { $class = 'sanitized'; } else { @@ -1511,9 +1533,9 @@ public static function handle_inline_edit_request() { public static function handle_validation_error_update( $redirect_to, $action, $term_ids ) { $term_group = null; if ( self::VALIDATION_ERROR_ACCEPT_ACTION === $action ) { - $term_group = self::VALIDATION_ERROR_ACCEPTED_STATUS; + $term_group = self::VALIDATION_ERROR_ACK_ACCEPTED_STATUS; } elseif ( self::VALIDATION_ERROR_REJECT_ACTION === $action ) { - $term_group = self::VALIDATION_ERROR_REJECTED_STATUS; + $term_group = self::VALIDATION_ERROR_ACK_REJECTED_STATUS; } if ( $term_group ) { diff --git a/includes/validation/class-amp-validation-manager.php b/includes/validation/class-amp-validation-manager.php index 811c468bcab..296fa9e2fb1 100644 --- a/includes/validation/class-amp-validation-manager.php +++ b/includes/validation/class-amp-validation-manager.php @@ -304,7 +304,7 @@ public static function add_admin_bar_menu_items( $wp_admin_bar ) { if ( $amp_invalid_url_post ) { $error_count = 0; foreach ( AMP_Invalid_URL_Post_Type::get_invalid_url_validation_errors( $amp_invalid_url_post ) as $error ) { - if ( AMP_Validation_Error_Taxonomy::VALIDATION_ERROR_ACCEPTED_STATUS !== $error['term_status'] ) { + if ( AMP_Validation_Error_Taxonomy::VALIDATION_ERROR_ACK_ACCEPTED_STATUS !== $error['term_status'] ) { $error_count++; } } @@ -662,7 +662,7 @@ public static function get_amp_validity_rest_field( $post_data, $field_name, $re $field['review_link'] = get_edit_post_link( $validation_status_post->ID, 'raw' ); foreach ( AMP_Invalid_URL_Post_Type::get_invalid_url_validation_errors( $validation_status_post ) as $result ) { $field['results'][] = array( - 'sanitized' => AMP_Validation_Error_Taxonomy::VALIDATION_ERROR_ACCEPTED_STATUS === $result['status'], + 'sanitized' => AMP_Validation_Error_Taxonomy::VALIDATION_ERROR_ACK_ACCEPTED_STATUS === $result['status'], 'error' => $result['data'], 'status' => $result['status'], 'term_status' => $result['term_status'], @@ -739,7 +739,7 @@ public static function add_validation_error( array $error, array $data = array() $error = apply_filters( 'amp_validation_error', $error, compact( 'node' ) ); $sanitization = AMP_Validation_Error_Taxonomy::get_validation_error_sanitization( $error ); - $sanitized = AMP_Validation_Error_Taxonomy::VALIDATION_ERROR_ACCEPTED_STATUS === $sanitization['status']; + $sanitized = AMP_Validation_Error_Taxonomy::VALIDATION_ERROR_ACK_ACCEPTED_STATUS === $sanitization['status']; // Ignore validation errors which are forcibly sanitized by filter or in special case if it is a tree shaking error and this is accepted by options. if ( $sanitized && 'with_filter' === $sanitization['forced'] ) { @@ -796,9 +796,9 @@ public static function print_edit_form_validation_status( $post ) { $has_actually_unaccepted_error = false; $validation_errors = array(); foreach ( AMP_Invalid_URL_Post_Type::get_invalid_url_validation_errors( $invalid_url_post ) as $error ) { - if ( AMP_Validation_Error_Taxonomy::VALIDATION_ERROR_ACCEPTED_STATUS !== $error['term_status'] ) { + if ( AMP_Validation_Error_Taxonomy::VALIDATION_ERROR_ACK_ACCEPTED_STATUS !== $error['term_status'] ) { $validation_errors[] = $error['data']; - if ( AMP_Validation_Error_Taxonomy::VALIDATION_ERROR_ACCEPTED_STATUS !== $error['status'] ) { + if ( AMP_Validation_Error_Taxonomy::VALIDATION_ERROR_ACK_ACCEPTED_STATUS !== $error['status'] ) { $has_actually_unaccepted_error = true; } } @@ -1535,9 +1535,9 @@ public static function finalize_validation( DOMDocument $dom, $args = array() ) $validation_status = AMP_Validation_Error_Taxonomy::get_validation_error_sanitization( $validation_result['error'] ); $is_unaccepted = 'with_preview' === $validation_status['forced'] ? - AMP_Validation_Error_Taxonomy::VALIDATION_ERROR_ACCEPTED_STATUS !== $validation_status['status'] + AMP_Validation_Error_Taxonomy::VALIDATION_ERROR_ACK_ACCEPTED_STATUS !== $validation_status['status'] : - AMP_Validation_Error_Taxonomy::VALIDATION_ERROR_ACCEPTED_STATUS !== $validation_status['term_status']; + AMP_Validation_Error_Taxonomy::VALIDATION_ERROR_ACK_ACCEPTED_STATUS !== $validation_status['term_status']; if ( $is_unaccepted ) { $error_count++; } diff --git a/tests/validation/test-class-amp-invalid-url-post-type.php b/tests/validation/test-class-amp-invalid-url-post-type.php index df553ee4619..0ff6992a7d1 100644 --- a/tests/validation/test-class-amp-invalid-url-post-type.php +++ b/tests/validation/test-class-amp-invalid-url-post-type.php @@ -199,22 +199,22 @@ public function test_get_invalid_url_validation_errors() { $error = array_shift( $errors ); $this->assertEquals( 'accepted', $error['data']['code'] ); - $this->assertEquals( AMP_Validation_Error_Taxonomy::VALIDATION_ERROR_ACCEPTED_STATUS, $error['term_status'] ); + $this->assertEquals( AMP_Validation_Error_Taxonomy::VALIDATION_ERROR_ACK_ACCEPTED_STATUS, $error['term_status'] ); $error = array_shift( $errors ); $this->assertEquals( 'rejected', $error['data']['code'] ); - $this->assertEquals( AMP_Validation_Error_Taxonomy::VALIDATION_ERROR_REJECTED_STATUS, $error['term_status'] ); + $this->assertEquals( AMP_Validation_Error_Taxonomy::VALIDATION_ERROR_ACK_REJECTED_STATUS, $error['term_status'] ); $error = array_shift( $errors ); $this->assertEquals( 'new', $error['data']['code'] ); - $this->assertEquals( AMP_Validation_Error_Taxonomy::VALIDATION_ERROR_NEW_STATUS, $error['term_status'] ); + $this->assertEquals( AMP_Validation_Error_Taxonomy::VALIDATION_ERROR_NEW_REJECTED_STATUS, $error['term_status'] ); $errors = AMP_Invalid_URL_Post_Type::get_invalid_url_validation_errors( get_permalink( $post ), array( 'ignore_accepted' => true ) ); $this->assertCount( 2, $errors ); $error = array_shift( $errors ); $this->assertEquals( 'rejected', $error['data']['code'] ); - $this->assertEquals( AMP_Validation_Error_Taxonomy::VALIDATION_ERROR_REJECTED_STATUS, $error['term_status'] ); + $this->assertEquals( AMP_Validation_Error_Taxonomy::VALIDATION_ERROR_ACK_REJECTED_STATUS, $error['term_status'] ); $error = array_shift( $errors ); $this->assertEquals( 'new', $error['data']['code'] ); - $this->assertEquals( AMP_Validation_Error_Taxonomy::VALIDATION_ERROR_NEW_STATUS, $error['term_status'] ); + $this->assertEquals( AMP_Validation_Error_Taxonomy::VALIDATION_ERROR_NEW_REJECTED_STATUS, $error['term_status'] ); ob_start(); AMP_Invalid_URL_Post_Type::display_invalid_url_validation_error_counts_summary( $invalid_url_post_id ); @@ -397,9 +397,9 @@ function( $stored_error ) { ); $error_groups = array( - AMP_Validation_Error_Taxonomy::VALIDATION_ERROR_ACCEPTED_STATUS, - AMP_Validation_Error_Taxonomy::VALIDATION_ERROR_REJECTED_STATUS, - AMP_Validation_Error_Taxonomy::VALIDATION_ERROR_NEW_STATUS, + AMP_Validation_Error_Taxonomy::VALIDATION_ERROR_ACK_ACCEPTED_STATUS, + AMP_Validation_Error_Taxonomy::VALIDATION_ERROR_ACK_REJECTED_STATUS, + AMP_Validation_Error_Taxonomy::VALIDATION_ERROR_NEW_ACCEPTED_STATUS, ); foreach ( $errors as $i => $error ) { @@ -975,7 +975,7 @@ public function test_handle_validation_error_status_update() { $errors = AMP_Invalid_URL_Post_Type::get_invalid_url_validation_errors( $invalid_url_post_id ); $_POST[ AMP_Validation_Manager::VALIDATION_ERROR_TERM_STATUS_QUERY_VAR ] = array( - $errors[0]['term']->slug => AMP_Validation_Error_Taxonomy::VALIDATION_ERROR_ACCEPTED_STATUS, + $errors[0]['term']->slug => AMP_Validation_Error_Taxonomy::VALIDATION_ERROR_ACK_ACCEPTED_STATUS, ); add_filter( 'wp_redirect', function( $url, $status ) { @@ -1172,7 +1172,7 @@ public function test_render_post_filters() { $validation_error_term = $this->factory()->term->create( array( 'taxonomy' => AMP_Validation_Error_Taxonomy::TAXONOMY_SLUG, 'description' => wp_json_encode( $this->get_mock_errors() ), - 'term_group' => AMP_Validation_Error_Taxonomy::VALIDATION_ERROR_NEW_STATUS, + 'term_group' => AMP_Validation_Error_Taxonomy::VALIDATION_ERROR_NEW_REJECTED_STATUS, ) ); // Associate the validation error term with a URL. diff --git a/tests/validation/test-class-amp-validation-error-taxonomy.php b/tests/validation/test-class-amp-validation-error-taxonomy.php index a65a8ab6a76..94d91fd23b1 100644 --- a/tests/validation/test-class-amp-validation-error-taxonomy.php +++ b/tests/validation/test-class-amp-validation-error-taxonomy.php @@ -164,7 +164,7 @@ public function test_get_validation_error_sanitization() { $this->assertEquals( array( 'forced' => 'with_option', - 'status' => 1, + 'status' => AMP_Validation_Error_Taxonomy::VALIDATION_ERROR_ACK_ACCEPTED_STATUS, 'term_status' => 0, ), AMP_Validation_Error_Taxonomy::get_validation_error_sanitization( $this->get_mock_error() ) @@ -174,7 +174,7 @@ public function test_get_validation_error_sanitization() { $this->assertEquals( array( 'forced' => 'with_filter', - 'status' => 1, + 'status' => AMP_Validation_Error_Taxonomy::VALIDATION_ERROR_ACK_ACCEPTED_STATUS, 'term_status' => 0, ), AMP_Validation_Error_Taxonomy::get_validation_error_sanitization( $this->get_mock_error() ) @@ -415,7 +415,7 @@ public function test_add_group_terms_clauses_filter() { $this->assertFalse( has_filter( $tested_filter ) ); // The entire conditional should be true, and this should add the filter. - $_GET[ AMP_Validation_Error_Taxonomy::VALIDATION_ERROR_STATUS_QUERY_VAR ] = 1; + $_GET[ AMP_Validation_Error_Taxonomy::VALIDATION_ERROR_STATUS_QUERY_VAR ] = AMP_Validation_Error_Taxonomy::VALIDATION_ERROR_NEW_ACCEPTED_STATUS; AMP_Validation_Error_Taxonomy::add_group_terms_clauses_filter(); $this->assertTrue( has_filter( $tested_filter ) ); } @@ -458,7 +458,7 @@ public function test_add_term_filter_query_var() { $this->assertEquals( $expected_url, AMP_Validation_Error_Taxonomy::add_term_filter_query_var( $initial_url, $correct_taxonomy ) ); // The $_POST has a value for the accepted status, so this method should pass that to the redirect URL as a query var. - $status_query_var_value = AMP_Validation_Error_Taxonomy::VALIDATION_ERROR_ACCEPTED_STATUS; + $status_query_var_value = AMP_Validation_Error_Taxonomy::VALIDATION_ERROR_ACK_ACCEPTED_STATUS; $_POST[ AMP_Validation_Error_Taxonomy::VALIDATION_ERROR_STATUS_QUERY_VAR ] = $status_query_var_value; $_POST[ AMP_Validation_Error_Taxonomy::VALIDATION_ERROR_TYPE_QUERY_VAR ] = null; $expected_url = add_query_arg( @@ -520,7 +520,7 @@ public function test_render_taxonomy_filters() { $this->factory()->term->create( array( 'taxonomy' => AMP_Validation_Error_Taxonomy::TAXONOMY_SLUG, 'description' => wp_json_encode( $this->get_mock_error() ), - 'term_group' => AMP_Validation_Error_Taxonomy::VALIDATION_ERROR_NEW_STATUS, + 'term_group' => AMP_Validation_Error_Taxonomy::VALIDATION_ERROR_NEW_REJECTED_STATUS, ) ); // When passing the wrong $taxonomy_name to the method, it should not output anything. @@ -532,7 +532,7 @@ public function test_render_taxonomy_filters() { $this->factory()->term->create( array( 'taxonomy' => AMP_Validation_Error_Taxonomy::TAXONOMY_SLUG, 'description' => wp_json_encode( $this->get_mock_error() ), - 'term_group' => AMP_Validation_Error_Taxonomy::VALIDATION_ERROR_NEW_STATUS, + 'term_group' => AMP_Validation_Error_Taxonomy::VALIDATION_ERROR_NEW_REJECTED_STATUS, ) ); ob_start(); AMP_Validation_Error_Taxonomy::render_taxonomy_filters( AMP_Validation_Error_Taxonomy::TAXONOMY_SLUG ); @@ -586,7 +586,7 @@ public function test_render_error_status_filter() { $validation_error_term = $this->factory()->term->create( array( 'taxonomy' => AMP_Validation_Error_Taxonomy::TAXONOMY_SLUG, 'description' => wp_json_encode( $this->get_mock_error() ), - 'term_group' => AMP_Validation_Error_Taxonomy::VALIDATION_ERROR_NEW_STATUS, + 'term_group' => AMP_Validation_Error_Taxonomy::VALIDATION_ERROR_NEW_REJECTED_STATUS, ) ); // Associate the validation error term with a URL so that it appears in a query. @@ -637,7 +637,7 @@ public function test_render_error_type_filter() { $this->factory()->term->create( array( 'taxonomy' => AMP_Validation_Error_Taxonomy::TAXONOMY_SLUG, 'description' => wp_json_encode( $this->get_mock_error() ), - 'term_group' => AMP_Validation_Error_Taxonomy::VALIDATION_ERROR_NEW_STATUS, + 'term_group' => AMP_Validation_Error_Taxonomy::VALIDATION_ERROR_NEW_REJECTED_STATUS, ) ); } diff --git a/tests/validation/test-class-amp-validation-manager.php b/tests/validation/test-class-amp-validation-manager.php index 1b0a84740c8..5356edf2444 100644 --- a/tests/validation/test-class-amp-validation-manager.php +++ b/tests/validation/test-class-amp-validation-manager.php @@ -260,8 +260,8 @@ public function test_add_validation_error_sourcing() { $validation_error_term_2 = AMP_Validation_Error_Taxonomy::prepare_validation_error_taxonomy_term( array( 'test' => 2 ) ); $_REQUEST[ AMP_Validation_Manager::VALIDATE_QUERY_VAR ] = AMP_Validation_Manager::get_amp_validate_nonce(); $_REQUEST[ AMP_Validation_Manager::VALIDATION_ERROR_TERM_STATUS_QUERY_VAR ] = array( - $validation_error_term_1['slug'] => AMP_Validation_Error_Taxonomy::VALIDATION_ERROR_ACCEPTED_STATUS, - $validation_error_term_2['slug'] => AMP_Validation_Error_Taxonomy::VALIDATION_ERROR_REJECTED_STATUS, + $validation_error_term_1['slug'] => AMP_Validation_Error_Taxonomy::VALIDATION_ERROR_ACK_ACCEPTED_STATUS, + $validation_error_term_2['slug'] => AMP_Validation_Error_Taxonomy::VALIDATION_ERROR_ACK_REJECTED_STATUS, ); AMP_Validation_Manager::add_validation_error_sourcing(); $this->assertCount( 2, AMP_Validation_Manager::$validation_error_status_overrides ); @@ -425,8 +425,8 @@ function ( $error ) { return array( 'sanitized' => false, 'error' => $error, - 'status' => AMP_Validation_Error_Taxonomy::VALIDATION_ERROR_NEW_STATUS, - 'term_status' => AMP_Validation_Error_Taxonomy::VALIDATION_ERROR_NEW_STATUS, + 'status' => AMP_Validation_Error_Taxonomy::VALIDATION_ERROR_NEW_REJECTED_STATUS, + 'term_status' => AMP_Validation_Error_Taxonomy::VALIDATION_ERROR_NEW_REJECTED_STATUS, 'forced' => false, ); }, From 8f6a26ec97951b62d780db1bc2dea9f0b41d77b9 Mon Sep 17 00:00:00 2001 From: Weston Ruter Date: Fri, 14 Sep 2018 11:14:39 -0700 Subject: [PATCH 03/25] Update options related to auto-sanitization --- includes/options/class-amp-options-menu.php | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/includes/options/class-amp-options-menu.php b/includes/options/class-amp-options-menu.php index 16e21006ded..c2f09376b87 100644 --- a/includes/options/class-amp-options-menu.php +++ b/includes/options/class-amp-options-menu.php @@ -259,18 +259,19 @@ public function render_validation_handling() {
  • -
    -

    +
    +

    -
    +

    +

    @@ -308,9 +309,9 @@ public function render_validation_handling() { var updateHiddenClasses = function() { var themeSupportMode = getThemeSupportMode(); - $( '.amp-force-sanitize' ).toggleClass( 'hidden', 'native' === themeSupportMode ); + $( '.amp-auto-accept-sanitize' ).toggleClass( 'hidden', 'native' === themeSupportMode ); $( '.amp-validation-field' ).toggleClass( 'hidden', 'disabled' === themeSupportMode ); - $( '.amp-force-sanitize-canonical' ).toggleClass( 'hidden', 'native' !== themeSupportMode ); + $( '.amp-auto-accept-sanitize-canonical' ).toggleClass( 'hidden', 'native' !== themeSupportMode ); updateTreeShakingHiddenClass(); }; From 58d03c987526fc8f1082b54052e412097e6dabce Mon Sep 17 00:00:00 2001 From: Weston Ruter Date: Fri, 14 Sep 2018 17:50:39 -0700 Subject: [PATCH 04/25] Update term list table styling for validation errors * Add unapproved comment styling for new validation rows. * Show new accepted/rejected. * Let reject link be red and accept link be green. --- assets/css/amp-validation-error-taxonomy.css | 20 ++++++++++++++++ .../src/amp-validation-error-detail-toggle.js | 19 +++++++++++++++ .../class-amp-validation-error-taxonomy.php | 23 ++++++++----------- ...st-class-amp-validation-error-taxonomy.php | 2 +- 4 files changed, 49 insertions(+), 15 deletions(-) diff --git a/assets/css/amp-validation-error-taxonomy.css b/assets/css/amp-validation-error-taxonomy.css index 91192865397..d945b6d4564 100644 --- a/assets/css/amp-validation-error-taxonomy.css +++ b/assets/css/amp-validation-error-taxonomy.css @@ -136,3 +136,23 @@ details[open] .details-attributes__summary::after { background-image: url( '../images/baseline-error-blue.svg' ); } +body.taxonomy-amp_validation_error .wp-list-table .new th, +body.taxonomy-amp_validation_error .wp-list-table .new td { + background-color: #fef7f1; +} + +body.taxonomy-amp_validation_error .wp-list-table .new th.check-column { + border-left: 4px solid #d54e21; +} + +body.taxonomy-amp_validation_error .wp-list-table .new th.check-column input { + margin-left: 4px; +} + +.row-actions .amp_validation_error_accept > a { + color: #006505; +} + +.row-actions .amp_validation_error_reject > a { + color: #a00; +} diff --git a/assets/src/amp-validation-error-detail-toggle.js b/assets/src/amp-validation-error-detail-toggle.js index 85275c20b06..243d217c84f 100644 --- a/assets/src/amp-validation-error-detail-toggle.js +++ b/assets/src/amp-validation-error-detail-toggle.js @@ -54,7 +54,26 @@ function addToggleListener() { } ); } +/** + * Adds classes to the rows for the amp_validation_error term list table. + * + * This is needed because \WP_Terms_List_Table::single_row() does not allow for additional + * attributes to be added to the element. + */ +function addTermListTableRowClasses() { + const rows = [ ...document.querySelectorAll( '#the-list > tr' ) ]; + rows.forEach( ( row ) => { + const statusText = row.querySelector( '.column-status > .status-text' ); + if ( statusText ) { + row.classList.toggle( 'new', statusText.classList.contains( 'new' ) ); + row.classList.toggle( 'accepted', statusText.classList.contains( 'accepted' ) ); + row.classList.toggle( 'rejected', statusText.classList.contains( 'rejected' ) ); + } + } ); +} + domReady( () => { addToggleButtons(); addToggleListener(); + addTermListTableRowClasses(); } ); diff --git a/includes/validation/class-amp-validation-error-taxonomy.php b/includes/validation/class-amp-validation-error-taxonomy.php index 66636fa8155..5b15d113395 100644 --- a/includes/validation/class-amp-validation-error-taxonomy.php +++ b/includes/validation/class-amp-validation-error-taxonomy.php @@ -1378,22 +1378,17 @@ public static function filter_manage_custom_columns( $content, $column_name, $te case 'status': $sanitization = self::get_validation_error_sanitization( $validation_error ); if ( self::VALIDATION_ERROR_ACK_ACCEPTED_STATUS === $sanitization['term_status'] ) { - if ( $sanitization['forced'] && $sanitization['term_status'] !== $sanitization['status'] ) { - $class = 'sanitized'; - } else { - $class = 'accepted'; - } - $text = __( 'Accepted', 'amp' ); + $class = 'ack accepted'; + $text = __( 'Accepted', 'amp' ); } elseif ( self::VALIDATION_ERROR_ACK_REJECTED_STATUS === $sanitization['term_status'] ) { - if ( $sanitization['forced'] && $sanitization['term_status'] !== $sanitization['status'] ) { - $class = 'sanitized'; - } else { - $class = 'rejected'; - } - $text = __( 'Rejected', 'amp' ); + $class = 'ack rejected'; + $text = __( 'Rejected', 'amp' ); + } elseif ( self::VALIDATION_ERROR_NEW_REJECTED_STATUS === $sanitization['term_status'] ) { + $class = 'new rejected'; + $text = __( 'New Rejected', 'amp' ); } else { - $class = 'new'; - $text = __( 'New', 'amp' ); + $class = 'new accepted'; + $text = __( 'New Accepted', 'amp' ); } $content .= sprintf( '%s', esc_attr( $class ), esc_html( $text ) ); break; diff --git a/tests/validation/test-class-amp-validation-error-taxonomy.php b/tests/validation/test-class-amp-validation-error-taxonomy.php index 94d91fd23b1..2f071564cd0 100644 --- a/tests/validation/test-class-amp-validation-error-taxonomy.php +++ b/tests/validation/test-class-amp-validation-error-taxonomy.php @@ -852,7 +852,7 @@ public function test_filter_manage_custom_columns() { // Test the 'status' block in the switch. $filtered_content = AMP_Validation_Error_Taxonomy::filter_manage_custom_columns( $initial_content, 'status', $term_id ); - $this->assertEquals( $initial_content . 'New', $filtered_content ); + $this->assertEquals( $initial_content . 'New Rejected', $filtered_content ); // Test the 'created_date_gmt' block in the switch. $date = current_time( 'mysql', true ); From de7b04bc7befb999f1cd7d0345cc256ea6fc9c04 Mon Sep 17 00:00:00 2001 From: Weston Ruter Date: Fri, 14 Sep 2018 22:01:40 -0700 Subject: [PATCH 05/25] Eliminate forced sanitization with special with_option case; incorporate VALIDATION_ERROR_NEW_ACCEPTED_STATUS --- .../class-amp-validation-error-taxonomy.php | 25 ++-- .../class-amp-validation-manager.php | 8 +- tests/test-class-amp-base-sanitizer.php | 11 +- ...st-class-amp-validation-error-taxonomy.php | 136 ++++++++++++++---- 4 files changed, 129 insertions(+), 51 deletions(-) diff --git a/includes/validation/class-amp-validation-error-taxonomy.php b/includes/validation/class-amp-validation-error-taxonomy.php index 5b15d113395..0cd0d1616e5 100644 --- a/includes/validation/class-amp-validation-error-taxonomy.php +++ b/includes/validation/class-amp-validation-error-taxonomy.php @@ -298,7 +298,11 @@ public static function prepare_validation_error_taxonomy_term( $error ) { */ public static function is_validation_error_sanitized( $error ) { $sanitization = self::get_validation_error_sanitization( $error ); - return self::VALIDATION_ERROR_ACK_ACCEPTED_STATUS === $sanitization['status']; + return ( + self::VALIDATION_ERROR_ACK_ACCEPTED_STATUS === $sanitization['status'] + || + self::VALIDATION_ERROR_NEW_ACCEPTED_STATUS === $sanitization['status'] + ); } /** @@ -326,7 +330,7 @@ public static function get_validation_error_sanitization( $error ) { if ( ! empty( $term ) && in_array( $term->term_group, $statuses, true ) ) { $term_status = $term->term_group; } else { - $term_status = self::VALIDATION_ERROR_NEW_REJECTED_STATUS; + $term_status = AMP_Validation_Manager::is_sanitization_auto_accepted() ? self::VALIDATION_ERROR_NEW_ACCEPTED_STATUS : self::VALIDATION_ERROR_NEW_REJECTED_STATUS; } $forced = false; @@ -338,16 +342,6 @@ public static function get_validation_error_sanitization( $error ) { $forced = 'with_preview'; } - $is_forced = ( - amp_is_canonical() - || - AMP_Options_Manager::get_option( 'auto_accept_sanitization' ) - ); - if ( $is_forced ) { - $forced = 'with_option'; - $status = self::VALIDATION_ERROR_ACK_ACCEPTED_STATUS; - } - /** * Filters whether the validation error should be sanitized. * @@ -1259,26 +1253,25 @@ public static function filter_tag_row_actions( $actions, WP_Term $tag ) { esc_html__( 'Details', 'amp' ) ); + // @todo We should consider reversing the order. $sanitization = self::get_validation_error_sanitization( json_decode( $term->description, true ) ); if ( self::VALIDATION_ERROR_ACK_REJECTED_STATUS !== $sanitization['term_status'] ) { $actions[ self::VALIDATION_ERROR_REJECT_ACTION ] = sprintf( - '%s', + '%s', wp_nonce_url( add_query_arg( array_merge( array( 'action' => self::VALIDATION_ERROR_REJECT_ACTION ), compact( 'term_id' ) ) ), self::VALIDATION_ERROR_REJECT_ACTION ), - esc_attr__( 'Rejecting an error acknowledges that it should block a URL from being served as AMP.', 'amp' ), esc_html__( 'Reject', 'amp' ) ); } if ( self::VALIDATION_ERROR_ACK_ACCEPTED_STATUS !== $sanitization['term_status'] ) { $actions[ self::VALIDATION_ERROR_ACCEPT_ACTION ] = sprintf( - '%s', + '%s', wp_nonce_url( add_query_arg( array_merge( array( 'action' => self::VALIDATION_ERROR_ACCEPT_ACTION ), compact( 'term_id' ) ) ), self::VALIDATION_ERROR_ACCEPT_ACTION ), - esc_attr__( 'Accepting an error means it will get sanitized and not block a URL from being served as AMP.', 'amp' ), esc_html__( 'Accept', 'amp' ) ); } diff --git a/includes/validation/class-amp-validation-manager.php b/includes/validation/class-amp-validation-manager.php index 296fa9e2fb1..c3b486a2001 100644 --- a/includes/validation/class-amp-validation-manager.php +++ b/includes/validation/class-amp-validation-manager.php @@ -738,13 +738,7 @@ public static function add_validation_error( array $error, array $data = array() */ $error = apply_filters( 'amp_validation_error', $error, compact( 'node' ) ); - $sanitization = AMP_Validation_Error_Taxonomy::get_validation_error_sanitization( $error ); - $sanitized = AMP_Validation_Error_Taxonomy::VALIDATION_ERROR_ACK_ACCEPTED_STATUS === $sanitization['status']; - - // Ignore validation errors which are forcibly sanitized by filter or in special case if it is a tree shaking error and this is accepted by options. - if ( $sanitized && 'with_filter' === $sanitization['forced'] ) { - return true; - } + $sanitized = AMP_Validation_Error_Taxonomy::is_validation_error_sanitized( $error ); // Add sources back into the $error for referencing later. @todo It may be cleaner to store sources separately to avoid having to re-remove later during storage. $error = array_merge( $error, compact( 'sources' ) ); diff --git a/tests/test-class-amp-base-sanitizer.php b/tests/test-class-amp-base-sanitizer.php index a56d16fdf7a..2cb31c7cfed 100644 --- a/tests/test-class-amp-base-sanitizer.php +++ b/tests/test-class-amp-base-sanitizer.php @@ -224,7 +224,7 @@ public function test_remove_invalid_child() { 'type' => AMP_Validation_Error_Taxonomy::JS_ERROR_TYPE, ); - // Test forcibly sanitized with filter, resulting in no validation error being surfaced. + // Test forcibly sanitized with filter. add_filter( 'amp_validation_error_sanitized', '__return_true' ); $this->assertEquals( $child, $parent->firstChild ); $sanitizer = new AMP_Iframe_Sanitizer( @@ -234,7 +234,14 @@ public function test_remove_invalid_child() { ); $sanitizer->remove_invalid_child( $child, array( 'foo' => 'bar' ) ); $this->assertEquals( null, $parent->firstChild ); - $this->assertCount( 0, AMP_Validation_Manager::$validation_results ); + $this->assertCount( 1, AMP_Validation_Manager::$validation_results ); + $this->assertEquals( + array( + 'error' => $expected_error, + 'sanitized' => true, + ), + AMP_Validation_Manager::$validation_results[0] + ); remove_filter( 'amp_validation_error_sanitized', '__return_true' ); // Test unsanitized. diff --git a/tests/validation/test-class-amp-validation-error-taxonomy.php b/tests/validation/test-class-amp-validation-error-taxonomy.php index 2f071564cd0..5ed7eebefb0 100644 --- a/tests/validation/test-class-amp-validation-error-taxonomy.php +++ b/tests/validation/test-class-amp-validation-error-taxonomy.php @@ -34,6 +34,7 @@ public function tearDown() { remove_filter( 'amp_validation_error_sanitized', '__return_true' ); remove_all_filters( 'amp_validation_error_sanitized' ); remove_all_filters( 'terms_clauses' ); + AMP_Validation_Manager::$validation_error_status_overrides = array(); parent::tearDown(); } @@ -130,54 +131,137 @@ public function test_prepare_validation_error_taxonomy_term() { } /** - * Test is_validation_error_sanitized. + * Test is_validation_error_sanitized and get_validation_error_sanitization. * * @covers \AMP_Validation_Error_Taxonomy::is_validation_error_sanitized() + * @covers \AMP_Validation_Error_Taxonomy::get_validation_error_sanitization() */ - public function test_is_validation_error_sanitized() { - AMP_Options_Manager::update_option( 'auto_accept_sanitization', false ); - $this->assertFalse( AMP_Validation_Error_Taxonomy::is_validation_error_sanitized( $this->get_mock_error() ) ); + public function test_is_validation_error_sanitized_and_get_validation_error_sanitization() { - // Trigger Native AMP, which makes all errors accepted. - add_theme_support( 'amp' ); - $this->assertTrue( AMP_Validation_Error_Taxonomy::is_validation_error_sanitized( $this->get_mock_error() ) ); - } + // New accepted. + AMP_Options_Manager::update_option( 'auto_accept_sanitization', true ); + $error_foo = array_merge( + $this->get_mock_error(), + array( 'foo' => 1 ) + ); + AMP_Invalid_URL_Post_Type::store_validation_errors( + array( $error_foo ), + home_url( '/foo' ) + ); + $this->assertTrue( AMP_Validation_Error_Taxonomy::is_validation_error_sanitized( $error_foo ) ); + $this->assertEquals( + array( + 'forced' => false, + 'status' => AMP_Validation_Error_Taxonomy::VALIDATION_ERROR_NEW_ACCEPTED_STATUS, + 'term_status' => AMP_Validation_Error_Taxonomy::VALIDATION_ERROR_NEW_ACCEPTED_STATUS, + ), + AMP_Validation_Error_Taxonomy::get_validation_error_sanitization( $error_foo ) + ); - /** - * Test get_validation_error_sanitization. - * - * @covers \AMP_Validation_Error_Taxonomy::get_validation_error_sanitization() - */ - public function test_get_validation_error_sanitization() { + // New rejected. AMP_Options_Manager::update_option( 'auto_accept_sanitization', false ); + $error_bar = array_merge( + $this->get_mock_error(), + array( 'bar' => 1 ) + ); + AMP_Invalid_URL_Post_Type::store_validation_errors( + array( $error_bar ), + home_url( '/bar' ) + ); + $this->assertFalse( AMP_Validation_Error_Taxonomy::is_validation_error_sanitized( $error_bar ) ); $this->assertEquals( array( 'forced' => false, - 'status' => 0, - 'term_status' => 0, + 'status' => AMP_Validation_Error_Taxonomy::VALIDATION_ERROR_NEW_REJECTED_STATUS, + 'term_status' => AMP_Validation_Error_Taxonomy::VALIDATION_ERROR_NEW_REJECTED_STATUS, ), - AMP_Validation_Error_Taxonomy::get_validation_error_sanitization( $this->get_mock_error() ) + AMP_Validation_Error_Taxonomy::get_validation_error_sanitization( $error_bar ) ); - // Trigger Native AMP, which should result in 'forced' => 'with_option'. - add_theme_support( 'amp' ); + // New accepted, since canonical. + add_theme_support( 'amp', array( + 'paired' => false, + ) ); + $this->assertTrue( amp_is_canonical() ); + $this->assertTrue( AMP_Validation_Manager::is_sanitization_auto_accepted() ); + $error_baz = array_merge( + $this->get_mock_error(), + array( 'baz' => 1 ) + ); + AMP_Invalid_URL_Post_Type::store_validation_errors( + array( $error_baz ), + home_url( '/baz' ) + ); + $this->assertTrue( AMP_Validation_Error_Taxonomy::is_validation_error_sanitized( $error_baz ) ); $this->assertEquals( array( - 'forced' => 'with_option', + 'forced' => false, + 'status' => AMP_Validation_Error_Taxonomy::VALIDATION_ERROR_NEW_ACCEPTED_STATUS, + 'term_status' => AMP_Validation_Error_Taxonomy::VALIDATION_ERROR_NEW_ACCEPTED_STATUS, + ), + AMP_Validation_Error_Taxonomy::get_validation_error_sanitization( $error_baz ) + ); + + // New accepted => Ack rejected. + $this->assertTrue( AMP_Validation_Error_Taxonomy::is_validation_error_sanitized( $error_foo ) ); + $term_data = AMP_Validation_Error_Taxonomy::prepare_validation_error_taxonomy_term( $error_foo ); + $term = get_term_by( 'slug', $term_data['slug'], AMP_Validation_Error_Taxonomy::TAXONOMY_SLUG ); + wp_update_term( $term->term_id, AMP_Validation_Error_Taxonomy::TAXONOMY_SLUG, array( + 'term_group' => AMP_Validation_Error_Taxonomy::VALIDATION_ERROR_ACK_REJECTED_STATUS, + ) ); + $this->assertFalse( AMP_Validation_Error_Taxonomy::is_validation_error_sanitized( $error_foo ) ); + $this->assertEquals( + array( + 'forced' => false, + 'status' => AMP_Validation_Error_Taxonomy::VALIDATION_ERROR_ACK_REJECTED_STATUS, + 'term_status' => AMP_Validation_Error_Taxonomy::VALIDATION_ERROR_ACK_REJECTED_STATUS, + ), + AMP_Validation_Error_Taxonomy::get_validation_error_sanitization( $error_foo ) + ); + + // New rejected => Ack accepted. + $this->assertFalse( AMP_Validation_Error_Taxonomy::is_validation_error_sanitized( $error_bar ) ); + $term_data = AMP_Validation_Error_Taxonomy::prepare_validation_error_taxonomy_term( $error_bar ); + $term = get_term_by( 'slug', $term_data['slug'], AMP_Validation_Error_Taxonomy::TAXONOMY_SLUG ); + wp_update_term( $term->term_id, AMP_Validation_Error_Taxonomy::TAXONOMY_SLUG, array( + 'term_group' => AMP_Validation_Error_Taxonomy::VALIDATION_ERROR_ACK_ACCEPTED_STATUS, + ) ); + $this->assertTrue( AMP_Validation_Error_Taxonomy::is_validation_error_sanitized( $error_bar ) ); + $this->assertEquals( + array( + 'forced' => false, 'status' => AMP_Validation_Error_Taxonomy::VALIDATION_ERROR_ACK_ACCEPTED_STATUS, - 'term_status' => 0, + 'term_status' => AMP_Validation_Error_Taxonomy::VALIDATION_ERROR_ACK_ACCEPTED_STATUS, ), - AMP_Validation_Error_Taxonomy::get_validation_error_sanitization( $this->get_mock_error() ) + AMP_Validation_Error_Taxonomy::get_validation_error_sanitization( $error_bar ) ); + // Ack rejected => Ack accepted (forcibly by filter). The next time the URL will be re-checked, this validation error will be omitted. + $this->assertFalse( AMP_Validation_Error_Taxonomy::is_validation_error_sanitized( $error_foo ) ); add_filter( 'amp_validation_error_sanitized', '__return_true' ); + $this->assertTrue( AMP_Validation_Error_Taxonomy::is_validation_error_sanitized( $error_foo ) ); $this->assertEquals( array( 'forced' => 'with_filter', 'status' => AMP_Validation_Error_Taxonomy::VALIDATION_ERROR_ACK_ACCEPTED_STATUS, - 'term_status' => 0, + 'term_status' => AMP_Validation_Error_Taxonomy::VALIDATION_ERROR_ACK_REJECTED_STATUS, + ), + AMP_Validation_Error_Taxonomy::get_validation_error_sanitization( $error_foo ) + ); + remove_filter( 'amp_validation_error_sanitized', '__return_true' ); + + // Ack accepted => Ack rejected (forcibly by preview). + $this->assertTrue( AMP_Validation_Error_Taxonomy::is_validation_error_sanitized( $error_bar ) ); + $term_data = AMP_Validation_Error_Taxonomy::prepare_validation_error_taxonomy_term( $error_bar ); + AMP_Validation_Manager::$validation_error_status_overrides[ $term_data['slug'] ] = AMP_Validation_Error_Taxonomy::VALIDATION_ERROR_ACK_REJECTED_STATUS; + $this->assertFalse( AMP_Validation_Error_Taxonomy::is_validation_error_sanitized( $error_bar ) ); + $this->assertEquals( + array( + 'forced' => 'with_preview', + 'status' => AMP_Validation_Error_Taxonomy::VALIDATION_ERROR_ACK_REJECTED_STATUS, + 'term_status' => AMP_Validation_Error_Taxonomy::VALIDATION_ERROR_ACK_ACCEPTED_STATUS, ), - AMP_Validation_Error_Taxonomy::get_validation_error_sanitization( $this->get_mock_error() ) + AMP_Validation_Error_Taxonomy::get_validation_error_sanitization( $error_bar ) ); } @@ -786,8 +870,7 @@ public function test_filter_tag_row_actions() { $accept_action = $filtered_actions[ AMP_Validation_Error_Taxonomy::VALIDATION_ERROR_ACCEPT_ACTION ]; $reject_action = $filtered_actions[ AMP_Validation_Error_Taxonomy::VALIDATION_ERROR_REJECT_ACTION ]; $this->assertContains( strval( $term_this_taxonomy->term_id ), $accept_action ); - $this->assertContains( 'Accepting an error means it will get sanitized and not block a URL from being served as AMP.', $accept_action ); - $this->assertContains( 'Rejecting an error acknowledges that it should block a URL from being served as AMP.', $reject_action ); + $this->assertContains( strval( $term_this_taxonomy->term_id ), $reject_action ); } @@ -832,6 +915,7 @@ public function test_get_reader_friendly_error_type_text() { * @covers \AMP_Validation_Error_Taxonomy::filter_manage_custom_columns() */ public function test_filter_manage_custom_columns() { + AMP_Options_Manager::update_option( 'auto_accept_sanitization', false ); AMP_Validation_Error_Taxonomy::register(); $validation_error = $this->get_mock_error(); $initial_content = 'example initial content'; From a3d442d508ea9dd67bb5c1400df4f925e865ba10 Mon Sep 17 00:00:00 2001 From: Weston Ruter Date: Sat, 15 Sep 2018 21:13:19 -0700 Subject: [PATCH 06/25] Add support for querying multiple term statuses at a time; use for New --- .../class-amp-invalid-url-post-type.php | 25 +++- .../class-amp-validation-error-taxonomy.php | 120 +++++++++++------- .../test-class-amp-invalid-url-post-type.php | 46 +++++-- ...st-class-amp-validation-error-taxonomy.php | 3 +- 4 files changed, 131 insertions(+), 63 deletions(-) diff --git a/includes/validation/class-amp-invalid-url-post-type.php b/includes/validation/class-amp-invalid-url-post-type.php index 1715e8f0db7..a1a33f7b5bc 100644 --- a/includes/validation/class-amp-invalid-url-post-type.php +++ b/includes/validation/class-amp-invalid-url-post-type.php @@ -180,7 +180,10 @@ public static function add_admin_menu_new_invalid_url_count() { $query = new WP_Query( array( 'post_type' => self::POST_TYPE_SLUG, - AMP_Validation_Error_Taxonomy::VALIDATION_ERROR_STATUS_QUERY_VAR => AMP_Validation_Error_Taxonomy::VALIDATION_ERROR_NEW_REJECTED_STATUS, + AMP_Validation_Error_Taxonomy::VALIDATION_ERROR_STATUS_QUERY_VAR => array( + AMP_Validation_Error_Taxonomy::VALIDATION_ERROR_NEW_REJECTED_STATUS, + AMP_Validation_Error_Taxonomy::VALIDATION_ERROR_NEW_ACCEPTED_STATUS, + ), 'update_post_meta_cache' => false, 'update_post_term_cache' => false, ) ); @@ -273,6 +276,7 @@ public static function display_invalid_url_validation_error_counts_summary( $pos foreach ( $validation_errors as $error ) { switch ( $error['term']->term_group ) { case AMP_Validation_Error_Taxonomy::VALIDATION_ERROR_NEW_REJECTED_STATUS: + case AMP_Validation_Error_Taxonomy::VALIDATION_ERROR_NEW_ACCEPTED_STATUS: $counts['new']++; break; case AMP_Validation_Error_Taxonomy::VALIDATION_ERROR_ACK_ACCEPTED_STATUS: @@ -1353,15 +1357,20 @@ public static function print_validation_errors_meta_box( $post ) { $collapsed_details = array(); $term = $error['term']; $select_name = sprintf( '%s[%s]', AMP_Validation_Manager::VALIDATION_ERROR_TERM_STATUS_QUERY_VAR, $term->slug ); + $is_new_error = ( + AMP_Validation_Error_Taxonomy::VALIDATION_ERROR_NEW_REJECTED_STATUS === $error['term']->term_group + || + AMP_Validation_Error_Taxonomy::VALIDATION_ERROR_NEW_ACCEPTED_STATUS === $error['term']->term_group + ); ?>
  • -
    term_group ) ? 'open' : ''; ?>> +
    > self::VALIDATION_ERROR_NEW_REJECTED_STATUS, + 'group' => array( self::VALIDATION_ERROR_NEW_REJECTED_STATUS, self::VALIDATION_ERROR_NEW_ACCEPTED_STATUS ), ) ); if ( $new_error_count ) { $menu_item_label .= ' ' . esc_html( number_format_i18n( $new_error_count ) ) . ''; diff --git a/tests/validation/test-class-amp-invalid-url-post-type.php b/tests/validation/test-class-amp-invalid-url-post-type.php index 0ff6992a7d1..cd0f1717458 100644 --- a/tests/validation/test-class-amp-invalid-url-post-type.php +++ b/tests/validation/test-class-amp-invalid-url-post-type.php @@ -1166,27 +1166,41 @@ public function test_filter_the_title_in_post_list_table() { */ public function test_render_post_filters() { set_current_screen( 'edit.php' ); - $number_of_errors = 20; - for ( $i = 0; $i < $number_of_errors; $i++ ) { + AMP_Invalid_URL_Post_Type::register(); + AMP_Validation_Error_Taxonomy::register(); + + $number_of_new_errors = 20; + $number_of_rejected = 15; + $number_of_accepted = 5; + + for ( $i = 0; $i < 40; $i++ ) { $invalid_url_post = $this->factory()->post->create( array( 'post_type' => AMP_Invalid_URL_Post_Type::POST_TYPE_SLUG ) ); $validation_error_term = $this->factory()->term->create( array( 'taxonomy' => AMP_Validation_Error_Taxonomy::TAXONOMY_SLUG, - 'description' => wp_json_encode( $this->get_mock_errors() ), - 'term_group' => AMP_Validation_Error_Taxonomy::VALIDATION_ERROR_NEW_REJECTED_STATUS, + 'description' => wp_json_encode( array( 'code' => 'test' ), compact( 'i' ) ), + ) ); + if ( $i < 9 ) { + $status = AMP_Validation_Error_Taxonomy::VALIDATION_ERROR_NEW_REJECTED_STATUS; + } elseif ( $i < 20 ) { + $status = AMP_Validation_Error_Taxonomy::VALIDATION_ERROR_NEW_ACCEPTED_STATUS; + } elseif ( $i < 35 ) { + $status = AMP_Validation_Error_Taxonomy::VALIDATION_ERROR_ACK_REJECTED_STATUS; + } else { + $status = AMP_Validation_Error_Taxonomy::VALIDATION_ERROR_ACK_ACCEPTED_STATUS; + } + wp_update_term( $validation_error_term, AMP_Validation_Error_Taxonomy::TAXONOMY_SLUG, array( + 'term_group' => $status, ) ); // Associate the validation error term with a URL. wp_set_post_terms( $invalid_url_post, - $validation_error_term, + array( $validation_error_term ), AMP_Validation_Error_Taxonomy::TAXONOMY_SLUG ); + } - $new_error_count = sprintf( - 'With New Errors (%d)', - $number_of_errors - ); $correct_post_type = AMP_Invalid_URL_Post_Type::POST_TYPE_SLUG; $wrong_post_type = 'page'; $correct_which_second_argument = 'top'; @@ -1205,7 +1219,19 @@ public function test_render_post_filters() { // This is now on the invalid URL post type edit.php screen, so it should output a