diff --git a/includes/sanitizers/class-amp-base-sanitizer.php b/includes/sanitizers/class-amp-base-sanitizer.php index a94852fbdd6..aa958caa344 100644 --- a/includes/sanitizers/class-amp-base-sanitizer.php +++ b/includes/sanitizers/class-amp-base-sanitizer.php @@ -218,42 +218,6 @@ public function set_layout( $attributes ) { return $attributes; } - /** - * This is our workaround to enforce max sizing with layout=responsive. - * - * We want elements to not grow beyond their width and shrink to fill the screen on viewports smaller than their width. - * - * See https://github.com/ampproject/amphtml/issues/1280#issuecomment-171533526 - * See https://github.com/Automattic/amp-wp/issues/101 - * - * @param string[] $attributes { - * Attributes. - * - * @type int $height - * @type int $width - * @type string $sizes - * @type string $class - * @type string $layout - * } - * @return string[] - */ - public function enforce_sizes_attribute( $attributes ) { - if ( ! isset( $attributes['width'], $attributes['height'] ) ) { - return $attributes; - } - - $max_width = $attributes['width']; - if ( isset( $this->args['content_max_width'] ) && $max_width >= $this->args['content_max_width'] ) { - $max_width = $this->args['content_max_width']; - } - - $attributes['sizes'] = sprintf( '(min-width: %1$dpx) %1$dpx, 100vw', absint( $max_width ) ); - - $this->add_or_append_attribute( $attributes, 'class', 'amp-wp-enforced-sizes' ); - - return $attributes; - } - /** * Adds or appends key and value to list of attributes * diff --git a/includes/sanitizers/class-amp-img-sanitizer.php b/includes/sanitizers/class-amp-img-sanitizer.php index 8007aaa7152..22242a2fa0a 100644 --- a/includes/sanitizers/class-amp-img-sanitizer.php +++ b/includes/sanitizers/class-amp-img-sanitizer.php @@ -192,7 +192,7 @@ private function adjust_and_replace_nodes_in_array_map( $node_lists ) { private function adjust_and_replace_node( $node ) { $old_attributes = AMP_DOM_Utils::get_node_attributes_as_assoc_array( $node ); $new_attributes = $this->filter_attributes( $old_attributes ); - $new_attributes = $this->enforce_sizes_attribute( $new_attributes ); + $this->add_or_append_attribute( $new_attributes, 'class', 'amp-wp-enforced-sizes' ); if ( $this->is_gif_url( $new_attributes['src'] ) ) { $this->did_convert_elements = true; diff --git a/tests/test-amp-img-sanitizer.php b/tests/test-amp-img-sanitizer.php index 2c437b7deff..557b9faa675 100644 --- a/tests/test-amp-img-sanitizer.php +++ b/tests/test-amp-img-sanitizer.php @@ -29,47 +29,47 @@ public function get_data() { 'image_with_self_closing_tag' => array( 'Placeholder!', - '', + '', ), 'image_with_no_end_tag' => array( 'Placeholder!', - '', + '', ), 'image_with_end_tag' => array( 'Placeholder!', - '', + '', ), 'image_with_on_attribute' => array( '', - '', + '', ), 'image_with_blacklisted_attribute' => array( '', - '', + '', ), 'image_with_no_dimensions_is_forced_dimensions' => array( '', - '', + '', ), 'image_with_sizes_attribute_is_overridden' => array( - '', - '', + '', + '', ), 'gif_image_conversion' => array( 'Placeholder!', - '', + '', ), 'gif_image_url_with_querystring' => array( 'Placeholder!', - '', + '', ), 'multiple_same_image' => array( @@ -78,7 +78,7 @@ public function get_data() { ', - '', + '', ), 'multiple_different_images' => array( @@ -86,7 +86,7 @@ public function get_data() { ', - '', + '', ), ); } diff --git a/tests/test-class-amp-base-sanitizer.php b/tests/test-class-amp-base-sanitizer.php index 87575059e86..2f26ff6c64a 100644 --- a/tests/test-class-amp-base-sanitizer.php +++ b/tests/test-class-amp-base-sanitizer.php @@ -1,112 +1,5 @@ array( - array( - 'sizes' => 'blah', - ), - array( - 'sizes' => 'blah', - ), - ), - - 'empty' => array( - array(), - array(), - ), - - 'no_width' => array( - array( - 'height' => 100, - ), - array( - 'height' => 100, - ), - ), - - 'no_height' => array( - array( - 'width' => 200, - ), - array( - 'width' => 200, - ), - ), - - 'enforce_sizes_no_class' => array( - array( - 'width' => 200, - 'height' => 100, - ), - array( - 'width' => 200, - 'height' => 100, - 'sizes' => '(min-width: 200px) 200px, 100vw', - 'class' => 'amp-wp-enforced-sizes', - ), - ), - - 'enforce_sizes_has_class' => array( - array( - 'width' => 200, - 'height' => 100, - 'class' => 'my-class', - ), - array( - 'width' => 200, - 'height' => 100, - 'sizes' => '(min-width: 200px) 200px, 100vw', - 'class' => 'my-class amp-wp-enforced-sizes', - ), - ), - - 'enforce_sizes_with_bigger_content_max_width' => array( - array( - 'width' => 250, - 'height' => 100, - ), - array( - 'width' => 250, - 'height' => 100, - 'sizes' => '(min-width: 250px) 250px, 100vw', - 'class' => 'amp-wp-enforced-sizes', - ), - array( - 'content_max_width' => 500, - ), - ), - - 'enforce_sizes_with_smaller_content_max_width' => array( - array( - 'width' => 800, - 'height' => 350, - ), - array( - 'width' => 800, - 'height' => 350, - 'sizes' => '(min-width: 675px) 675px, 100vw', - 'class' => 'amp-wp-enforced-sizes', - ), - array( - 'content_max_width' => 675, - ), - ), - ); - } - - /** - * @dataProvider get_data - */ - public function test_enforce_sizes_attribute( $source_attributes, $expected_attributes, $args = array() ) { - $sanitizer = new AMP_Test_Stub_Sanitizer( new DOMDocument, $args ); - $returned_attributes = $sanitizer->enforce_sizes_attribute( $source_attributes ); - - $this->assertEquals( $expected_attributes, $returned_attributes ); - } -} - class AMP_Base_Sanitizer__Enforce_Fixed_Height__Test extends WP_UnitTestCase { public function get_data() { return array(