diff --git a/amp.php b/amp.php index 9273e5c9284..064f006bafc 100644 --- a/amp.php +++ b/amp.php @@ -95,7 +95,7 @@ function amp_after_setup_theme() { add_action( 'wp_loaded', 'amp_add_options_menu' ); add_action( 'parse_query', 'amp_correct_query_when_is_front_page' ); AMP_Post_Type_Support::add_post_type_support(); - AMP_Mutation_Utils::init(); + AMP_Validation_Utils::init(); } add_action( 'after_setup_theme', 'amp_after_setup_theme', 5 ); diff --git a/includes/class-amp-autoloader.php b/includes/class-amp-autoloader.php index 4169f3e7b62..7bf991c8d54 100644 --- a/includes/class-amp-autoloader.php +++ b/includes/class-amp-autoloader.php @@ -83,7 +83,7 @@ class AMP_Autoloader { 'AMP_DOM_Utils' => 'includes/utils/class-amp-dom-utils', 'AMP_HTML_Utils' => 'includes/utils/class-amp-html-utils', 'AMP_Image_Dimension_Extractor' => 'includes/utils/class-amp-image-dimension-extractor', - 'AMP_Mutation_Utils' => 'includes/utils/class-amp-mutation-utils', + 'AMP_Validation_Utils' => 'includes/utils/class-amp-validation-utils', 'AMP_String_Utils' => 'includes/utils/class-amp-string-utils', 'AMP_WP_Utils' => 'includes/utils/class-amp-wp-utils', 'AMP_Widget_Archives' => 'includes/widgets/class-amp-widget-archives', diff --git a/includes/class-amp-theme-support.php b/includes/class-amp-theme-support.php index 800aed397e9..45b00f36a14 100644 --- a/includes/class-amp-theme-support.php +++ b/includes/class-amp-theme-support.php @@ -753,7 +753,7 @@ public static function start_output_buffering() { */ public static function finish_output_buffering() { $output = self::prepare_response( ob_get_clean() ); - AMP_Mutation_Utils::add_header(); + AMP_Validation_Utils::add_header(); echo $output; // WPCS: xss ok. } @@ -787,8 +787,8 @@ public static function prepare_response( $response ) { 'content_max_width' => ! empty( $content_width ) ? $content_width : AMP_Post_Template::CONTENT_MAX_WIDTH, // Back-compat. 'use_document_element' => true, ); - if ( AMP_Mutation_Utils::is_authorized() ) { - $args['mutation_callback'] = 'AMP_Mutation_Utils::track_removed'; + if ( AMP_Validation_Utils::is_authorized() ) { + $args['mutation_callback'] = 'AMP_Validation_Utils::track_removed'; } // First ensure the mandatory amp attribute is present on the html element, as otherwise it will be stripped entirely. diff --git a/includes/utils/class-amp-mutation-utils.php b/includes/utils/class-amp-validation-utils.php similarity index 98% rename from includes/utils/class-amp-mutation-utils.php rename to includes/utils/class-amp-validation-utils.php index cd6e658ae7f..28784ae04db 100644 --- a/includes/utils/class-amp-mutation-utils.php +++ b/includes/utils/class-amp-validation-utils.php @@ -1,16 +1,16 @@ ! empty( $content_width ) ? $content_width : AMP_Post_Template::CONTENT_MAX_WIDTH, ); if ( self::is_authorized() ) { - $args['mutation_callback'] = 'AMP_Mutation_Utils::track_removed'; + $args['mutation_callback'] = 'AMP_Validation_Utils::track_removed'; } AMP_Content_Sanitizer::sanitize( $markup, amp_get_content_sanitizers(), $args ); } diff --git a/tests/test-class-amp-base-sanitizer.php b/tests/test-class-amp-base-sanitizer.php index 4a4cee8a816..d527dd0457c 100644 --- a/tests/test-class-amp-base-sanitizer.php +++ b/tests/test-class-amp-base-sanitizer.php @@ -260,11 +260,11 @@ public function test_remove_child() { $this->assertEquals( $child, $parent->firstChild ); $sanitizer = new AMP_Iframe_Sanitizer( $dom_document, array( - 'mutation_callback' => 'AMP_Mutation_Utils::track_removed', + 'mutation_callback' => 'AMP_Validation_Utils::track_removed', ) ); $sanitizer->remove_child( $child ); $this->assertEquals( null, $parent->firstChild ); - $this->assertEquals( 1, AMP_Mutation_Utils::$removed_nodes[ $child_tag_name ] ); + $this->assertEquals( 1, AMP_Validation_Utils::$removed_nodes[ $child_tag_name ] ); $parent->appendChild( $child ); $this->assertEquals( $child, $parent->firstChild ); @@ -273,7 +273,7 @@ public function test_remove_child() { $this->assertEquals( null, $parent->firstChild ); $this->assertEquals( null, $child->parentNode ); // @codingStandardsIgnoreEnd - AMP_Mutation_Utils::$removed_nodes = null; + AMP_Validation_Utils::$removed_nodes = null; } /** @@ -282,7 +282,7 @@ public function test_remove_child() { * @see AMP_Base_Sanitizer::remove_child() */ public function test_remove_attribute() { - AMP_Mutation_Utils::reset_removed(); + AMP_Validation_Utils::reset_removed(); $video_name = 'amp-video'; $attribute = 'onload'; $dom_document = new DOMDocument( '1.0', 'utf-8' ); @@ -292,7 +292,7 @@ public function test_remove_attribute() { // To ignore WordPress.NamingConventions.ValidVariableName.NotSnakeCaseMemberVar. // @codingStandardsIgnoreStart $args = array( - 'mutation_callback' => 'AMP_Mutation_Utils::track_removed', + 'mutation_callback' => 'AMP_Validation_Utils::track_removed', ); $expected_removed = array( $attribute => 1, @@ -300,9 +300,9 @@ public function test_remove_attribute() { $sanitizer = new AMP_Video_Sanitizer( $dom_document, $args ); $sanitizer->remove_attribute( $video, $attribute ); $this->assertEquals( null, $video->getAttribute( $attribute ) ); - $this->assertEquals( $expected_removed, AMP_Mutation_Utils::$removed_attributes ); + $this->assertEquals( $expected_removed, AMP_Validation_Utils::$removed_attributes ); // @codingStandardsIgnoreEnd - AMP_Mutation_Utils::reset_removed(); + AMP_Validation_Utils::reset_removed(); } } diff --git a/tests/test-class-amp-mutation-utils.php b/tests/test-class-amp-validation-utils.php similarity index 52% rename from tests/test-class-amp-mutation-utils.php rename to tests/test-class-amp-validation-utils.php index 72e721c65e6..1ad8e814ad6 100644 --- a/tests/test-class-amp-mutation-utils.php +++ b/tests/test-class-amp-validation-utils.php @@ -1,16 +1,16 @@ node = $dom_document->createElement( self::TAG_NAME ); - AMP_Mutation_Utils::reset_removed(); + AMP_Validation_Utils::reset_removed(); } /** * Test init. * - * @see AMP_Mutation_Utils::init() + * @see AMP_Validation_Utils::init() */ public function test_init() { - $this->assertEquals( 10, has_action( 'rest_api_init', 'AMP_Mutation_Utils::amp_rest_validation' ) ); - $this->assertEquals( 10, has_action( 'save_post', 'AMP_Mutation_Utils::validate_content' ) ); - $this->assertEquals( 10, has_action( 'edit_form_top', 'AMP_Mutation_Utils::display_error' ) ); + $this->assertEquals( 10, has_action( 'rest_api_init', 'AMP_Validation_Utils::amp_rest_validation' ) ); + $this->assertEquals( 10, has_action( 'save_post', 'AMP_Validation_Utils::validate_content' ) ); + $this->assertEquals( 10, has_action( 'edit_form_top', 'AMP_Validation_Utils::display_error' ) ); } /** * Test track_removed. * - * @see AMP_Mutation_Utils::track_removed() + * @see AMP_Validation_Utils::track_removed() */ public function test_track_removed() { $attr_name = 'invalid-attr'; @@ -90,18 +90,18 @@ public function test_track_removed() { $expected_removed_nodes = array( 'img' => 1, ); - $this->assertEmpty( AMP_Mutation_Utils::$removed_attributes ); - $this->assertEmpty( AMP_Mutation_Utils::$removed_nodes ); - AMP_Mutation_Utils::track_removed( $this->node, AMP_Mutation_Utils::ATTRIBUTE_REMOVED, $attr_name ); - $this->assertEquals( $expected_removed_attrs, AMP_Mutation_Utils::$removed_attributes ); - AMP_Mutation_Utils::track_removed( $this->node, AMP_Mutation_Utils::NODE_REMOVED ); - $this->assertEquals( $expected_removed_nodes, AMP_Mutation_Utils::$removed_nodes ); + $this->assertEmpty( AMP_Validation_Utils::$removed_attributes ); + $this->assertEmpty( AMP_Validation_Utils::$removed_nodes ); + AMP_Validation_Utils::track_removed( $this->node, AMP_Validation_Utils::ATTRIBUTE_REMOVED, $attr_name ); + $this->assertEquals( $expected_removed_attrs, AMP_Validation_Utils::$removed_attributes ); + AMP_Validation_Utils::track_removed( $this->node, AMP_Validation_Utils::NODE_REMOVED ); + $this->assertEquals( $expected_removed_nodes, AMP_Validation_Utils::$removed_nodes ); } /** * Test increment_count. * - * @see AMP_Mutation_Utils::increment_count() + * @see AMP_Validation_Utils::increment_count() */ public function test_increment_count() { $attribute = 'script'; @@ -111,65 +111,65 @@ public function test_increment_count() { $expected = array( $attribute => 2, ); - $this->assertEquals( $one_attribute, AMP_Mutation_Utils::increment_count( array(), $attribute ) ); - $this->assertEquals( $expected, AMP_Mutation_Utils::increment_count( $one_attribute, $attribute ) ); + $this->assertEquals( $one_attribute, AMP_Validation_Utils::increment_count( array(), $attribute ) ); + $this->assertEquals( $expected, AMP_Validation_Utils::increment_count( $one_attribute, $attribute ) ); } /** * Test was_node_removed. * - * @see AMP_Mutation_Utils::was_node_removed() + * @see AMP_Validation_Utils::was_node_removed() */ public function test_was_node_removed() { $attr_name = 'invalid-attr'; - $this->assertFalse( AMP_Mutation_Utils::was_node_removed() ); - AMP_Mutation_Utils::track_removed( $this->node, AMP_Mutation_Utils::NODE_REMOVED ); - $this->assertTrue( AMP_Mutation_Utils::was_node_removed() ); + $this->assertFalse( AMP_Validation_Utils::was_node_removed() ); + AMP_Validation_Utils::track_removed( $this->node, AMP_Validation_Utils::NODE_REMOVED ); + $this->assertTrue( AMP_Validation_Utils::was_node_removed() ); } /** * Test process_markup. * - * @see AMP_Mutation_Utils::process_markup() + * @see AMP_Validation_Utils::process_markup() */ public function test_process_markup() { $this->set_authorized(); - AMP_Mutation_Utils::process_markup( $this->valid_amp_img ); - $this->assertEquals( null, AMP_Mutation_Utils::$removed_nodes ); - $this->assertEquals( null, AMP_Mutation_Utils::$removed_attributes ); + AMP_Validation_Utils::process_markup( $this->valid_amp_img ); + $this->assertEquals( null, AMP_Validation_Utils::$removed_nodes ); + $this->assertEquals( null, AMP_Validation_Utils::$removed_attributes ); - AMP_Mutation_Utils::reset_removed(); + AMP_Validation_Utils::reset_removed(); $video = '