diff --git a/assets/css/src/amp-default.css b/assets/css/src/amp-default.css index 28dc272106a..2e75bb62f03 100644 --- a/assets/css/src/amp-default.css +++ b/assets/css/src/amp-default.css @@ -81,3 +81,11 @@ amp-carousel .amp-wp-gallery-caption { margin-bottom: 1.5em; max-width: 100%; } + +/* + * Ensure the button used to expand AMP components is placed in the bottom left hand corner of the component, + * where it's most likely to be seen. + */ +button[overflow] { + bottom: 0; +} diff --git a/includes/embeds/class-amp-base-embed-handler.php b/includes/embeds/class-amp-base-embed-handler.php index 409daac9b2f..48e3c6ec610 100644 --- a/includes/embeds/class-amp-base-embed-handler.php +++ b/includes/embeds/class-amp-base-embed-handler.php @@ -7,6 +7,8 @@ * @package AMP */ +use AmpProject\Tag; + /** * Class AMP_Base_Embed_Handler * @@ -151,4 +153,51 @@ protected function unwrap_p_element( DOMElement $node ) { $parent_node->parentNode->replaceChild( $node, $parent_node ); } } + + /** + * Removes the node's nearest `#', '', $content ); + $dom = AMP_DOM_Utils::get_dom_from_content( $content ); + $embed->sanitize_raw_embeds( $dom ); + $content = AMP_DOM_Utils::get_content_from_dom( $dom ); + $this->assertEqualMarkup( $expected, $content ); + } + + /** + * Data for test_get_scripts(). + * + * @return array Data. + */ + public function get_scripts_data() { + return [ + 'not_converted' => [ + '
Hello World.
', + [], + ], + 'converted' => [ + 'https://ifpaintingscouldtext.tumblr.com/post/92003045635/grant-wood-american-gothic-1930' . PHP_EOL, + [ 'amp-iframe' => true ], + ], + ]; + } + + /** + * Test AMP_Tag_And_Attribute_Sanitizer::get_scripts(). + * + * @dataProvider get_scripts_data + * + * @param string $source Source content. + * @param array $expected Expected scripts. + */ + public function test_get_scripts( $source, $expected ) { + $embed = new AMP_Tumblr_Embed_Handler(); + + $filtered_content = apply_filters( 'the_content', $source ); + $dom = AMP_DOM_Utils::get_dom_from_content( $filtered_content ); + $embed->sanitize_raw_embeds( $dom ); + + $whitelist_sanitizer = new AMP_Tag_And_Attribute_Sanitizer( $dom ); + $whitelist_sanitizer->sanitize(); + + $scripts = array_merge( + $embed->get_scripts(), + $whitelist_sanitizer->get_scripts() + ); + + $this->assertEquals( $expected, $scripts ); + } +} diff --git a/tests/php/test-class-amp-core-theme-sanitizer.php b/tests/php/test-class-amp-core-theme-sanitizer.php index e68857edd74..39b090cb4b3 100644 --- a/tests/php/test-class-amp-core-theme-sanitizer.php +++ b/tests/php/test-class-amp-core-theme-sanitizer.php @@ -504,6 +504,7 @@ public function test_amend_twentytwentyone_styles() { $after = implode( '', wp_styles()->registered[ $style_handle ]->extra['after'] ); $this->assertNotEmpty( $after ); $this->assertStringContains( '@media only screen and (max-width: 481px)', $after ); + $this->assertStringContains( 'button[overflow]:hover', $after ); $this->assertStringEndsWith( '/*first*/', $after ); }