diff --git a/bin/amphtml-update.py b/bin/amphtml-update.py index 87f8aaad937..7278f958004 100755 --- a/bin/amphtml-update.py +++ b/bin/amphtml-update.py @@ -354,6 +354,13 @@ def ParseRules(repo_directory, out_dir): '!DOCTYPE', ] + manual_versioning = { + 'amp-stream-gallery': ['0.1'], + 'amp-wordpress-embed': ['1.0'], + } + + bento_spec_names = {} + for (field_desc, field_val) in rules.ListFields(): if 'tags' == field_desc.name: for tag_spec in field_val: @@ -380,6 +387,32 @@ def ParseRules(repo_directory, out_dir): else: tag_list = allowed_tags[tag_name] + if 'SCRIPT' == tag_spec.tag_name: + gotten_tag_spec = GetTagSpec(tag_spec, attr_lists) + if gotten_tag_spec is not None: + if 'extension_spec' in gotten_tag_spec['tag_spec'] and 'bento_supported_version' in gotten_tag_spec['tag_spec']['extension_spec']: + if '' != tag_spec.spec_name: + # In case some other extension requires bento extension, we need to know the spec name of the bento extension. + bento_spec_names[ gotten_tag_spec['tag_spec']['extension_spec']['name'] ] = tag_spec.spec_name + + # Remove bento spec version from the list of versions. + version = gotten_tag_spec['tag_spec']['extension_spec']['version'] + bento_version = gotten_tag_spec['tag_spec']['extension_spec']['bento_supported_version'] + + for _version in bento_version: + if _version in version: + version.remove( _version ) + + gotten_tag_spec['tag_spec']['extension_spec'].pop('bento_supported_version', None) + gotten_tag_spec['tag_spec']['extension_spec']['version'] = version + + if len( version ) == 0 and gotten_tag_spec['tag_spec']['extension_spec']['name'] in manual_versioning.keys(): + gotten_tag_spec['tag_spec']['extension_spec']['version'] = manual_versioning[ gotten_tag_spec['tag_spec']['extension_spec']['name'] ] + + tag_list.append(gotten_tag_spec) + allowed_tags[tag_name] = tag_list + continue + gotten_tag_spec = GetTagSpec(tag_spec, attr_lists) if gotten_tag_spec is not None: tag_list.append(gotten_tag_spec) @@ -399,6 +432,18 @@ def ParseRules(repo_directory, out_dir): descendant_lists[_list.name].append( val.lower() ) + # Remove any tags that requires bento_spec_names.keys() + for tag_name, tag_list in allowed_tags.items(): + for tag in tag_list: + if 'requires_extension' not in tag['tag_spec'] or 'requires_condition' not in tag['tag_spec']: + continue + requires_condition = tag['tag_spec']['requires_condition'][0] + requires_extension = tag['tag_spec']['requires_extension'][0] + if requires_extension not in bento_spec_names: + continue + if bento_spec_names[requires_extension] == requires_condition: + tag_list.remove( tag ) + # Separate extension scripts from non-extension scripts and gather the versions extension_scripts = collections.defaultdict(list) extension_specs_by_satisfies = dict() @@ -407,8 +452,8 @@ def ParseRules(repo_directory, out_dir): if 'extension_spec' in script_tag['tag_spec']: extension = script_tag['tag_spec']['extension_spec']['name'] extension_scripts[extension].append(script_tag) - if 'satisfies' in script_tag['tag_spec']: - satisfies = script_tag['tag_spec']['satisfies'] + if 'satisfies_condition' in script_tag['tag_spec']: + satisfies = script_tag['tag_spec']['satisfies_condition'] else: satisfies = extension if satisfies in extension_specs_by_satisfies: @@ -440,7 +485,8 @@ def ParseRules(repo_directory, out_dir): # Amend the allowed_tags to supply the required versions for each component. for tag_name, tags in allowed_tags.items(): for tag in tags: - tag['tag_spec'].pop('satisfies', None) # We don't need it anymore. + tag['tag_spec'].pop('satisfies_condition', None) # We don't need it anymore. + tag['tag_spec'].pop('requires_condition', None) # We don't need it anymore. requires = tag['tag_spec'].pop('requires', []) if 'requires_extension' not in tag['tag_spec']: @@ -468,11 +514,10 @@ def ParseRules(repo_directory, out_dir): tag['tag_spec']['requires_extension'] = requires_extension_versions extensions = json.load( open( os.path.join( repo_directory, 'build-system/compile/bundles.config.extensions.json' ) ) ) - bento_extensions = json.load( open( os.path.join( repo_directory, 'build-system/compile/bundles.config.bento.json' ) ) ) latest_versions = json.load( open( latest_extensions_file_path ) ) extensions_versions = dict() - for extension in extensions + bento_extensions: + for extension in extensions: if '-impl' in extension['name'] or '-polyfill' in extension['name']: continue @@ -686,6 +731,11 @@ def GetTagRules(tag_spec): for requires_extension in tag_spec.requires_extension: requires_extension_list.add(requires_extension) + requires_condition_list = set() + if hasattr(tag_spec, 'requires_condition') and len( tag_spec.requires_condition ) != 0: + for requires_condition in tag_spec.requires_condition: + requires_condition_list.add(requires_condition) + if hasattr(tag_spec, 'requires') and len( tag_spec.requires ) != 0: tag_rules['requires'] = [ requires for requires in tag_spec.requires ] @@ -699,6 +749,9 @@ def GetTagRules(tag_spec): if len( requires_extension_list ) > 0: tag_rules['requires_extension'] = list( requires_extension_list ) + if len( requires_condition_list ) > 0: + tag_rules['requires_condition'] = list( requires_condition_list ) + if hasattr(tag_spec, 'reference_points') and len( tag_spec.reference_points ) != 0: tag_reference_points = {} for reference_point_spec in tag_spec.reference_points: @@ -785,10 +838,10 @@ def GetTagRules(tag_spec): if tag_spec.HasField('spec_name'): tag_rules['spec_name'] = UnicodeEscape(tag_spec.spec_name) - if hasattr(tag_spec, 'satisfies') and len( tag_spec.satisfies ) > 0: - if len( tag_spec.satisfies ) > 1: + if hasattr(tag_spec, 'satisfies_condition') and len( tag_spec.satisfies_condition ) > 0: + if len( tag_spec.satisfies_condition ) > 1: raise Exception('More than expected was satisfied') - tag_rules['satisfies'] = tag_spec.satisfies[0] + tag_rules['satisfies_condition'] = tag_spec.satisfies_condition[0] if tag_spec.HasField('spec_url'): tag_rules['spec_url'] = UnicodeEscape(tag_spec.spec_url) diff --git a/bin/latest-extension-versions.json b/bin/latest-extension-versions.json index 991e2b07a28..ca9c50c7fc9 100644 --- a/bin/latest-extension-versions.json +++ b/bin/latest-extension-versions.json @@ -98,7 +98,6 @@ "amp-powr-player" : "0.1", "amp-reach-player" : "0.1", "amp-recaptcha-input" : "0.1", - "amp-redbull-player" : "0.1", "amp-reddit" : "0.1", "amp-render" : "1.0", "amp-riddle-quiz" : "0.1", @@ -107,6 +106,7 @@ "amp-sidebar" : "0.1", "amp-skimlinks" : "0.1", "amp-slides" : "0.1", + "amp-slikeplayer" : "0.1", "amp-smartlinks" : "0.1", "amp-social-share" : "0.1", "amp-soundcloud" : "0.1", diff --git a/includes/amp-helper-functions.php b/includes/amp-helper-functions.php index a1e6b5635d1..5d8424eb9c2 100644 --- a/includes/amp-helper-functions.php +++ b/includes/amp-helper-functions.php @@ -913,32 +913,6 @@ function amp_add_generator_metadata() { printf( '', esc_attr( $content ) ); } -/** - * Determine whether the use of Bento components is enabled. - * - * When Bento is enabled, newer experimental versions of AMP components are used which incorporate the next generation - * of the component framework. - * - * @since 2.2 - * @link https://blog.amp.dev/2021/01/28/bento/ - * - * @return bool Whether Bento components are enabled. - */ -function amp_is_bento_enabled() { - /** - * Filters whether the use of Bento components is enabled. - * - * When Bento is enabled, newer experimental versions of AMP components are used which incorporate the next generation - * of the component framework. - * - * @since 2.2 - * @link https://blog.amp.dev/2021/01/28/bento/ - * - * @param bool $enabled Enabled. - */ - return apply_filters( 'amp_bento_enabled', false ); -} - /** * Register default scripts for AMP components. * @@ -990,15 +964,10 @@ function amp_register_default_scripts( $wp_scripts ) { $extension_specs['amp-carousel']['latest'] = '0.2'; } - $bento_enabled = amp_is_bento_enabled(); foreach ( $extension_specs as $extension_name => $extension_spec ) { - if ( $bento_enabled && ! empty( $extension_spec['bento'] ) ) { - $version = $extension_spec['bento']['version']; - } else { - $version = $extension_spec['latest']; - } + $version = $extension_spec['latest']; - // Skip registering the amp-gfycat extension. + // Skip registering the amp-gfycat extension, as gfycat have been sunset. // @TODO: Remove this once the amp-gfycat extension is removed from spec. if ( 'amp-gfycat' === $extension_name ) { continue; @@ -1013,7 +982,7 @@ function amp_register_default_scripts( $wp_scripts ) { $wp_scripts->add( $extension_name, $src, - [ 'amp-runtime' ], // @todo Eventually this will not be present for Bento. + [ 'amp-runtime' ], null ); } @@ -1043,28 +1012,6 @@ function amp_register_default_styles( WP_Styles $styles ) { AMP__VERSION ); $styles->add_data( 'amp-icons', 'rtl', 'replace' ); - - // These are registered exclusively for non-AMP pages that manually enqueue them. They aren't needed on - // AMP pages due to the runtime style being present and because the styles are inlined in the scripts already. - if ( amp_is_bento_enabled() ) { - foreach ( AMP_Allowed_Tags_Generated::get_extension_specs() as $extension_name => $extension_spec ) { - if ( empty( $extension_spec['bento']['has_css'] ) ) { - continue; - } - - $src = sprintf( - 'https://cdn.ampproject.org/v0/%s-%s.css', - $extension_name, - $extension_spec['bento']['version'] - ); - $styles->add( - $extension_name, - $src, - [], - null - ); - } - } } /** @@ -1560,8 +1507,6 @@ function amp_get_content_sanitizers( $post = null ) { 'comments_live_list' => ! empty( $theme_support_args['comments_live_list'] ), ], - AMP_Bento_Sanitizer::class => [], - // The AMP_PWA_Script_Sanitizer run before AMP_Script_Sanitizer, to prevent the script tags // from getting removed in PWA plugin offline/500 templates. AMP_PWA_Script_Sanitizer::class => [], @@ -1606,7 +1551,6 @@ function amp_get_content_sanitizers( $post = null ) { AMP_Accessibility_Sanitizer::class => [], // Note: This validating sanitizer must come at the end to clean up any remaining issues the other sanitizers didn't catch. AMP_Tag_And_Attribute_Sanitizer::class => [ - 'prefer_bento' => amp_is_bento_enabled(), 'allow_localhost_http_protocol' => $is_dev_mode, ], ]; @@ -1743,7 +1687,6 @@ function amp_get_content_sanitizers( $post = null ) { $expected_final_sanitizer_order = [ AMP_Auto_Lightbox_Disable_Sanitizer::class, AMP_Core_Theme_Sanitizer::class, // Must come before script sanitizer since onclick attributes are removed. - AMP_Bento_Sanitizer::class, // Bento scripts may be preserved here. AMP_PWA_Script_Sanitizer::class, // Must come before script sanitizer since PWA offline page scripts are removed. AMP_GTag_Script_Sanitizer::class, // Must come before script sanitizer since gtag.js is removed. AMP_Script_Sanitizer::class, // Must come before sanitizers for images, videos, audios, comments, forms, and styles. diff --git a/includes/class-amp-theme-support.php b/includes/class-amp-theme-support.php index 00b5e46a04a..df74d38088b 100644 --- a/includes/class-amp-theme-support.php +++ b/includes/class-amp-theme-support.php @@ -1559,47 +1559,6 @@ public static function ensure_required_markup( Document $dom, $script_handles = } } - // Make sure that Bento versions are used when required, either by explicitly requesting Bento or when the document is non-valid AMP. - $is_using_bento = ( - array_key_exists( AMP_Tag_And_Attribute_Sanitizer::class, $sanitizers ) - && - $sanitizers[ AMP_Tag_And_Attribute_Sanitizer::class ]->get_arg( 'prefer_bento' ) - ); - if ( $is_using_bento ) { - $bento_extension_count = 0; - - // Override all required scripts with the available Bento versions. - foreach ( $amp_scripts as $extension_name => $script_element ) { - if ( ! empty( $extension_specs[ $extension_name ]['bento']['version'] ) ) { - $script_element->setAttribute( - Attribute::SRC, - sprintf( - 'https://cdn.ampproject.org/v0/%s-%s.js', - $extension_name, - $extension_specs[ $extension_name ]['bento']['version'] - ) - ); - $bento_extension_count++; - } - } - - // Enable Bento experiment per . - // @todo Remove this once Bento no longer requires an experiment to opt-in. - if ( $bento_extension_count > 0 ) { - $bento_experiment_script = $dom->createElement( Tag::SCRIPT ); - $bento_experiment_script->appendChild( - $dom->createTextNode( '(self.AMP = self.AMP || []).push(function (AMP) { AMP.toggleExperiment("bento", true); });' ) - ); - - ValidationExemption::mark_node_as_px_verified( $bento_experiment_script ); - if ( DevMode::isActiveForDocument( $dom ) ) { - $bento_experiment_script->setAttributeNode( $dom->createAttribute( Attribute::DATA_AMPDEVMODE ) ); - } - - $dom->head->appendChild( $bento_experiment_script ); - } - } - /* * "3. If your page includes render-delaying extensions (e.g., amp-experiment, amp-dynamic-css-classes, amp-story), * preload those extensions as they're required by the AMP runtime for rendering the page." diff --git a/includes/deprecated.php b/includes/deprecated.php index ef47a7393c2..7daaf7e1aca 100644 --- a/includes/deprecated.php +++ b/includes/deprecated.php @@ -351,3 +351,35 @@ function amp_post_template_add_analytics_script( $data ) { } return $data; } + +/** + * Determine whether the use of Bento components is enabled. + * + * When Bento is enabled, newer experimental versions of AMP components are used which incorporate the next generation + * of the component framework. + * + * @since 2.2 + * @link https://blog.amp.dev/2021/01/28/bento/ + * + * @deprecated 2.4.3 Bento support has been removed. + * @codeCoverageIgnore + * @return bool Whether Bento components are enabled. + */ +function amp_is_bento_enabled() { + _deprecated_function( __FUNCTION__, 'AMP 2.4.3' ); + + /** + * Filters whether the use of Bento components is enabled. + * + * When Bento is enabled, newer experimental versions of AMP components are used which incorporate the next generation + * of the component framework. + * + * @since 2.2 + * @link https://blog.amp.dev/2021/01/28/bento/ + * + * @deprecated 2.4.3 Bento support has been removed. + * + * @param bool $enabled Enabled. + */ + return apply_filters_deprecated( 'amp_bento_enabled', [ false ], 'AMP 2.4.3', 'Remove beno support', 'Bento support has been removed.' ); +} diff --git a/includes/sanitizers/class-amp-allowed-tags-generated.php b/includes/sanitizers/class-amp-allowed-tags-generated.php index aaf60cbbb8c..751e83022d1 100644 --- a/includes/sanitizers/class-amp-allowed-tags-generated.php +++ b/includes/sanitizers/class-amp-allowed-tags-generated.php @@ -49,6 +49,7 @@ class AMP_Allowed_Tags_Generated { 'li', 'mark', 'nav', + 'noscript', 'ol', 'option', 'p', @@ -3173,42 +3174,11 @@ class AMP_Allowed_Tags_Generated { 4, ), ), - 'bento' => false, 'requires_extension' => array( 'amp-facebook-comments', ), ), ), - array( - 'attr_spec_list' => array( - 'data-href' => array( - 'mandatory' => true, - ), - 'media' => array(), - 'noloading' => array( - 'value' => array( - '', - ), - ), - ), - 'tag_spec' => array( - 'amp_layout' => array( - 'supported_layouts' => array( - 6, - 2, - 3, - 7, - 1, - 4, - ), - ), - 'bento' => true, - 'requires_extension' => array( - 'amp-facebook', - ), - 'spec_name' => 'amp-facebook-comments 1.0', - ), - ), ), 'amp-facebook-like' => array( array( @@ -3241,49 +3211,11 @@ class AMP_Allowed_Tags_Generated { 4, ), ), - 'bento' => false, 'requires_extension' => array( 'amp-facebook-like', ), ), ), - array( - 'attr_spec_list' => array( - 'data-href' => array( - 'mandatory' => true, - 'value_url' => array( - 'allow_relative' => false, - 'protocol' => array( - 'http', - 'https', - ), - ), - ), - 'media' => array(), - 'noloading' => array( - 'value' => array( - '', - ), - ), - ), - 'tag_spec' => array( - 'amp_layout' => array( - 'supported_layouts' => array( - 6, - 2, - 3, - 7, - 1, - 4, - ), - ), - 'bento' => true, - 'requires_extension' => array( - 'amp-facebook', - ), - 'spec_name' => 'amp-facebook-like 1.0', - ), - ), ), 'amp-facebook-page' => array( array( @@ -3316,49 +3248,11 @@ class AMP_Allowed_Tags_Generated { 4, ), ), - 'bento' => false, 'requires_extension' => array( 'amp-facebook-page', ), ), ), - array( - 'attr_spec_list' => array( - 'data-href' => array( - 'mandatory' => true, - 'value_url' => array( - 'allow_relative' => false, - 'protocol' => array( - 'http', - 'https', - ), - ), - ), - 'media' => array(), - 'noloading' => array( - 'value' => array( - '', - ), - ), - ), - 'tag_spec' => array( - 'amp_layout' => array( - 'supported_layouts' => array( - 6, - 2, - 3, - 7, - 1, - 4, - ), - ), - 'bento' => true, - 'requires_extension' => array( - 'amp-facebook', - ), - 'spec_name' => 'amp-facebook-page 1.0', - ), - ), ), 'amp-fit-text' => array( array( @@ -5485,37 +5379,6 @@ class AMP_Allowed_Tags_Generated { ), ), ), - 'amp-redbull-player' => array( - array( - 'attr_spec_list' => array( - 'data-param-videoid' => array( - 'mandatory' => true, - ), - 'media' => array(), - 'noloading' => array( - 'value' => array( - '', - ), - ), - ), - 'tag_spec' => array( - 'amp_layout' => array( - 'supported_layouts' => array( - 2, - 3, - 4, - 6, - 7, - 8, - 9, - ), - ), - 'requires_extension' => array( - 'amp-redbull-player', - ), - ), - ), - ), 'amp-reddit' => array( array( 'attr_spec_list' => array( @@ -5858,6 +5721,33 @@ class AMP_Allowed_Tags_Generated { ), ), ), + 'amp-slikeplayer' => array( + array( + 'attr_spec_list' => array( + 'data-apikey' => array( + 'mandatory' => true, + ), + 'data-videoid' => array( + 'mandatory' => true, + ), + ), + 'tag_spec' => array( + 'amp_layout' => array( + 'supported_layouts' => array( + 5, + 6, + 2, + 3, + 4, + ), + ), + 'requires_extension' => array( + 'amp-slikeplayer', + ), + 'spec_url' => 'https://developers.slike.in/html5/', + ), + ), + ), 'amp-smartlinks' => array( array( 'attr_spec_list' => array( @@ -11729,6 +11619,13 @@ class AMP_Allowed_Tags_Generated { 'async', ), ), + 'fetchpriority' => array( + 'value_casei' => array( + 'high', + 'low', + 'auto', + ), + ), 'height' => array(), 'hspace' => array(), 'importance' => array( @@ -11811,6 +11708,13 @@ class AMP_Allowed_Tags_Generated { 'async', ), ), + 'fetchpriority' => array( + 'value_casei' => array( + 'high', + 'low', + 'auto', + ), + ), 'height' => array(), 'hspace' => array(), 'importance' => array( @@ -11890,6 +11794,13 @@ class AMP_Allowed_Tags_Generated { 'async', ), ), + 'fetchpriority' => array( + 'value_casei' => array( + 'high', + 'low', + 'auto', + ), + ), 'height' => array(), 'hspace' => array(), 'importance' => array( @@ -12075,6 +11986,13 @@ class AMP_Allowed_Tags_Generated { 'async', ), ), + 'fetchpriority' => array( + 'value_casei' => array( + 'high', + 'low', + 'auto', + ), + ), 'height' => array(), 'hspace' => array(), 'importance' => array( @@ -12157,6 +12075,13 @@ class AMP_Allowed_Tags_Generated { 'async', ), ), + 'fetchpriority' => array( + 'value_casei' => array( + 'high', + 'low', + 'auto', + ), + ), 'height' => array(), 'hspace' => array(), 'importance' => array( @@ -12236,6 +12161,13 @@ class AMP_Allowed_Tags_Generated { 'async', ), ), + 'fetchpriority' => array( + 'value_casei' => array( + 'high', + 'low', + 'auto', + ), + ), 'height' => array(), 'hspace' => array(), 'importance' => array( @@ -12318,6 +12250,13 @@ class AMP_Allowed_Tags_Generated { 'sync', ), ), + 'fetchpriority' => array( + 'value_casei' => array( + 'high', + 'low', + 'auto', + ), + ), 'height' => array(), 'hspace' => array(), 'importance' => array( @@ -13455,6 +13394,13 @@ class AMP_Allowed_Tags_Generated { ), 'color' => array(), 'crossorigin' => array(), + 'fetchpriority' => array( + 'value_casei' => array( + 'high', + 'low', + 'auto', + ), + ), 'href' => array(), 'hreflang' => array(), 'media' => array(), @@ -13483,6 +13429,13 @@ class AMP_Allowed_Tags_Generated { ), 'color' => array(), 'crossorigin' => array(), + 'fetchpriority' => array( + 'value_casei' => array( + 'high', + 'low', + 'auto', + ), + ), 'href' => array( 'disallowed_value_regex' => '__amp_source_origin', 'mandatory' => true, @@ -13523,6 +13476,13 @@ class AMP_Allowed_Tags_Generated { ), 'color' => array(), 'crossorigin' => array(), + 'fetchpriority' => array( + 'value_casei' => array( + 'high', + 'low', + 'auto', + ), + ), 'href' => array( 'disallowed_value_regex' => '__amp_source_origin', 'mandatory' => true, @@ -13593,6 +13553,13 @@ class AMP_Allowed_Tags_Generated { ), 'color' => array(), 'crossorigin' => array(), + 'fetchpriority' => array( + 'value_casei' => array( + 'high', + 'low', + 'auto', + ), + ), 'href' => array(), 'hreflang' => array(), 'imagesizes' => array(), @@ -13664,6 +13631,13 @@ class AMP_Allowed_Tags_Generated { ), 'color' => array(), 'crossorigin' => array(), + 'fetchpriority' => array( + 'value_casei' => array( + 'high', + 'low', + 'auto', + ), + ), 'href' => array( 'mandatory' => true, ), @@ -13694,6 +13668,13 @@ class AMP_Allowed_Tags_Generated { ), 'color' => array(), 'crossorigin' => array(), + 'fetchpriority' => array( + 'value_casei' => array( + 'high', + 'low', + 'auto', + ), + ), 'href' => array( 'mandatory' => true, ), @@ -13720,6 +13701,13 @@ class AMP_Allowed_Tags_Generated { ), 'color' => array(), 'crossorigin' => array(), + 'fetchpriority' => array( + 'value_casei' => array( + 'high', + 'low', + 'auto', + ), + ), 'href' => array( 'mandatory' => true, ), @@ -16349,16 +16337,11 @@ class AMP_Allowed_Tags_Generated { ), 'tag_spec' => array( 'extension_spec' => array( - 'bento' => array( - 'has_css' => true, - 'version' => '1.0', - ), 'latest' => '0.1', 'name' => 'amp-accordion', 'requires_usage' => true, 'version' => array( '0.1', - '1.0', ), ), ), @@ -16664,16 +16647,11 @@ class AMP_Allowed_Tags_Generated { ), 'tag_spec' => array( 'extension_spec' => array( - 'bento' => array( - 'has_css' => false, - 'version' => '1.0', - ), 'latest' => '0.1', 'name' => 'amp-audio', 'requires_usage' => true, 'version' => array( '0.1', - '1.0', ), ), ), @@ -16762,16 +16740,11 @@ class AMP_Allowed_Tags_Generated { ), 'tag_spec' => array( 'extension_spec' => array( - 'bento' => array( - 'has_css' => true, - 'version' => '1.0', - ), 'latest' => '0.1', 'name' => 'amp-base-carousel', 'requires_usage' => true, 'version' => array( '0.1', - '1.0', ), ), ), @@ -16922,16 +16895,11 @@ class AMP_Allowed_Tags_Generated { ), 'tag_spec' => array( 'extension_spec' => array( - 'bento' => array( - 'has_css' => true, - 'version' => '1.0', - ), 'latest' => '0.1', 'name' => 'amp-brightcove', 'requires_usage' => true, 'version' => array( '0.1', - '1.0', ), ), ), @@ -17145,16 +17113,11 @@ class AMP_Allowed_Tags_Generated { ), 'tag_spec' => array( 'extension_spec' => array( - 'bento' => array( - 'has_css' => true, - 'version' => '1.0', - ), 'latest' => '0.1', 'name' => 'amp-dailymotion', 'requires_usage' => true, 'version' => array( '0.1', - '1.0', ), ), ), @@ -17181,16 +17144,11 @@ class AMP_Allowed_Tags_Generated { ), 'tag_spec' => array( 'extension_spec' => array( - 'bento' => array( - 'has_css' => true, - 'version' => '1.0', - ), 'latest' => '0.1', 'name' => 'amp-date-countdown', 'requires_usage' => true, 'version' => array( '0.1', - '1.0', ), ), ), @@ -17217,16 +17175,11 @@ class AMP_Allowed_Tags_Generated { ), 'tag_spec' => array( 'extension_spec' => array( - 'bento' => array( - 'has_css' => true, - 'version' => '1.0', - ), 'latest' => '0.1', 'name' => 'amp-date-display', 'requires_usage' => true, 'version' => array( '0.1', - '1.0', ), ), ), @@ -17346,16 +17299,11 @@ class AMP_Allowed_Tags_Generated { ), 'tag_spec' => array( 'extension_spec' => array( - 'bento' => array( - 'has_css' => true, - 'version' => '1.0', - ), 'latest' => '0.1', 'name' => 'amp-embedly-card', 'requires_usage' => true, 'version' => array( '0.1', - '1.0', ), ), ), @@ -17414,16 +17362,11 @@ class AMP_Allowed_Tags_Generated { ), 'tag_spec' => array( 'extension_spec' => array( - 'bento' => array( - 'has_css' => true, - 'version' => '1.0', - ), 'latest' => '0.1', 'name' => 'amp-facebook', 'requires_usage' => true, 'version' => array( '0.1', - '1.0', ), ), ), @@ -17543,16 +17486,11 @@ class AMP_Allowed_Tags_Generated { ), 'tag_spec' => array( 'extension_spec' => array( - 'bento' => array( - 'has_css' => true, - 'version' => '1.0', - ), 'latest' => '0.1', 'name' => 'amp-fit-text', 'requires_usage' => true, 'version' => array( '0.1', - '1.0', ), ), ), @@ -17889,16 +17827,11 @@ class AMP_Allowed_Tags_Generated { ), 'tag_spec' => array( 'extension_spec' => array( - 'bento' => array( - 'has_css' => true, - 'version' => '1.0', - ), 'latest' => '0.1', 'name' => 'amp-iframe', 'requires_usage' => true, 'version' => array( '0.1', - '1.0', ), ), ), @@ -18080,16 +18013,11 @@ class AMP_Allowed_Tags_Generated { ), 'tag_spec' => array( 'extension_spec' => array( - 'bento' => array( - 'has_css' => true, - 'version' => '1.0', - ), 'latest' => '0.1', 'name' => 'amp-inline-gallery', 'requires_usage' => true, 'version' => array( '0.1', - '1.0', ), ), ), @@ -18147,16 +18075,11 @@ class AMP_Allowed_Tags_Generated { ), 'tag_spec' => array( 'extension_spec' => array( - 'bento' => array( - 'has_css' => true, - 'version' => '1.0', - ), 'latest' => '0.1', 'name' => 'amp-instagram', 'requires_usage' => true, 'version' => array( '0.1', - '1.0', ), ), ), @@ -18307,16 +18230,11 @@ class AMP_Allowed_Tags_Generated { ), 'tag_spec' => array( 'extension_spec' => array( - 'bento' => array( - 'has_css' => true, - 'version' => '1.0', - ), 'latest' => '0.1', 'name' => 'amp-lightbox', 'requires_usage' => true, 'version' => array( '0.1', - '1.0', ), ), ), @@ -18343,16 +18261,11 @@ class AMP_Allowed_Tags_Generated { ), 'tag_spec' => array( 'extension_spec' => array( - 'bento' => array( - 'has_css' => true, - 'version' => '1.0', - ), 'latest' => '0.1', 'name' => 'amp-lightbox-gallery', 'requires_usage' => false, 'version' => array( '0.1', - '1.0', ), ), ), @@ -18474,16 +18387,11 @@ class AMP_Allowed_Tags_Generated { ), 'tag_spec' => array( 'extension_spec' => array( - 'bento' => array( - 'has_css' => true, - 'version' => '1.0', - ), 'latest' => '0.1', 'name' => 'amp-mathml', 'requires_usage' => true, 'version' => array( '0.1', - '1.0', ), ), ), @@ -19102,7 +19010,7 @@ class AMP_Allowed_Tags_Generated { 'tag_spec' => array( 'extension_spec' => array( 'latest' => '0.1', - 'name' => 'amp-redbull-player', + 'name' => 'amp-reddit', 'requires_usage' => true, 'version' => array( '0.1', @@ -19132,11 +19040,11 @@ class AMP_Allowed_Tags_Generated { ), 'tag_spec' => array( 'extension_spec' => array( - 'latest' => '0.1', - 'name' => 'amp-reddit', + 'latest' => '1.0', + 'name' => 'amp-render', 'requires_usage' => true, 'version' => array( - '0.1', + '1.0', ), ), ), @@ -19163,11 +19071,11 @@ class AMP_Allowed_Tags_Generated { ), 'tag_spec' => array( 'extension_spec' => array( - 'latest' => '1.0', - 'name' => 'amp-render', + 'latest' => '0.1', + 'name' => 'amp-riddle-quiz', 'requires_usage' => true, 'version' => array( - '1.0', + '0.1', ), ), ), @@ -19195,7 +19103,7 @@ class AMP_Allowed_Tags_Generated { 'tag_spec' => array( 'extension_spec' => array( 'latest' => '0.1', - 'name' => 'amp-riddle-quiz', + 'name' => 'amp-script', 'requires_usage' => true, 'version' => array( '0.1', @@ -19226,7 +19134,7 @@ class AMP_Allowed_Tags_Generated { 'tag_spec' => array( 'extension_spec' => array( 'latest' => '0.1', - 'name' => 'amp-script', + 'name' => 'amp-selector', 'requires_usage' => true, 'version' => array( '0.1', @@ -19256,16 +19164,11 @@ class AMP_Allowed_Tags_Generated { ), 'tag_spec' => array( 'extension_spec' => array( - 'bento' => array( - 'has_css' => true, - 'version' => '1.0', - ), 'latest' => '0.1', - 'name' => 'amp-selector', + 'name' => 'amp-sidebar', 'requires_usage' => true, 'version' => array( '0.1', - '1.0', ), ), ), @@ -19292,16 +19195,11 @@ class AMP_Allowed_Tags_Generated { ), 'tag_spec' => array( 'extension_spec' => array( - 'bento' => array( - 'has_css' => true, - 'version' => '1.0', - ), 'latest' => '0.1', - 'name' => 'amp-sidebar', + 'name' => 'amp-skimlinks', 'requires_usage' => true, 'version' => array( '0.1', - '1.0', ), ), ), @@ -19329,7 +19227,7 @@ class AMP_Allowed_Tags_Generated { 'tag_spec' => array( 'extension_spec' => array( 'latest' => '0.1', - 'name' => 'amp-skimlinks', + 'name' => 'amp-slikeplayer', 'requires_usage' => true, 'version' => array( '0.1', @@ -19390,16 +19288,11 @@ class AMP_Allowed_Tags_Generated { ), 'tag_spec' => array( 'extension_spec' => array( - 'bento' => array( - 'has_css' => true, - 'version' => '1.0', - ), 'latest' => '0.1', 'name' => 'amp-social-share', 'requires_usage' => true, 'version' => array( '0.1', - '1.0', ), ), ), @@ -19426,16 +19319,11 @@ class AMP_Allowed_Tags_Generated { ), 'tag_spec' => array( 'extension_spec' => array( - 'bento' => array( - 'has_css' => true, - 'version' => '1.0', - ), 'latest' => '0.1', 'name' => 'amp-soundcloud', 'requires_usage' => true, 'version' => array( '0.1', - '1.0', ), ), ), @@ -19565,6 +19453,37 @@ class AMP_Allowed_Tags_Generated { ), ), ), + array( + 'attr_spec_list' => array( + 'async' => array( + 'mandatory' => true, + 'value' => array( + '', + ), + ), + 'crossorigin' => array( + 'value' => array( + 'anonymous', + ), + ), + 'nonce' => array(), + 'type' => array( + 'value_casei' => array( + 'text/javascript', + ), + ), + ), + 'tag_spec' => array( + 'extension_spec' => array( + 'latest' => '0.1', + 'name' => 'amp-story-audio-sticker', + 'requires_usage' => true, + 'version' => array( + '0.1', + ), + ), + ), + ), array( 'attr_spec_list' => array( 'async' => array( @@ -19836,15 +19755,11 @@ class AMP_Allowed_Tags_Generated { ), 'tag_spec' => array( 'extension_spec' => array( - 'bento' => array( - 'has_css' => true, - 'version' => '1.0', - ), 'latest' => '0.1', 'name' => 'amp-stream-gallery', 'requires_usage' => true, 'version' => array( - '1.0', + '0.1', ), ), ), @@ -19967,16 +19882,11 @@ class AMP_Allowed_Tags_Generated { ), 'tag_spec' => array( 'extension_spec' => array( - 'bento' => array( - 'has_css' => true, - 'version' => '1.0', - ), 'latest' => '0.1', 'name' => 'amp-timeago', 'requires_usage' => true, 'version' => array( '0.1', - '1.0', ), ), ), @@ -20034,16 +19944,11 @@ class AMP_Allowed_Tags_Generated { ), 'tag_spec' => array( 'extension_spec' => array( - 'bento' => array( - 'has_css' => true, - 'version' => '1.0', - ), 'latest' => '0.1', 'name' => 'amp-twitter', 'requires_usage' => true, 'version' => array( '0.1', - '1.0', ), ), ), @@ -20101,16 +20006,11 @@ class AMP_Allowed_Tags_Generated { ), 'tag_spec' => array( 'extension_spec' => array( - 'bento' => array( - 'has_css' => true, - 'version' => '1.0', - ), 'latest' => '0.1', 'name' => 'amp-video', 'requires_usage' => true, 'version' => array( '0.1', - '1.0', ), ), ), @@ -20168,16 +20068,11 @@ class AMP_Allowed_Tags_Generated { ), 'tag_spec' => array( 'extension_spec' => array( - 'bento' => array( - 'has_css' => true, - 'version' => '1.0', - ), 'latest' => '0.1', 'name' => 'amp-video-iframe', 'requires_usage' => true, 'version' => array( '0.1', - '1.0', ), ), ), @@ -20204,10 +20099,6 @@ class AMP_Allowed_Tags_Generated { ), 'tag_spec' => array( 'extension_spec' => array( - 'bento' => array( - 'has_css' => true, - 'version' => '1.0', - ), 'latest' => '0.1', 'name' => 'amp-vimeo', 'requires_usage' => true, @@ -20395,10 +20286,6 @@ class AMP_Allowed_Tags_Generated { ), 'tag_spec' => array( 'extension_spec' => array( - 'bento' => array( - 'has_css' => true, - 'version' => '1.0', - ), 'latest' => '1.0', 'name' => 'amp-wordpress-embed', 'requires_usage' => true, @@ -20462,16 +20349,11 @@ class AMP_Allowed_Tags_Generated { ), 'tag_spec' => array( 'extension_spec' => array( - 'bento' => array( - 'has_css' => true, - 'version' => '1.0', - ), 'latest' => '0.1', 'name' => 'amp-youtube', 'requires_usage' => true, 'version' => array( '0.1', - '1.0', ), ), ), diff --git a/includes/sanitizers/class-amp-bento-sanitizer.php b/includes/sanitizers/class-amp-bento-sanitizer.php index b1fec7a2810..02cb0791a26 100644 --- a/includes/sanitizers/class-amp-bento-sanitizer.php +++ b/includes/sanitizers/class-amp-bento-sanitizer.php @@ -17,6 +17,7 @@ * AMP versions. Remove Bento stylesheets and scripts if they aren't needed. * * @since 2.2 + * @deprecated 2.4.3 Bento support have been removed from amphtml. * @internal */ class AMP_Bento_Sanitizer extends AMP_Base_Sanitizer { @@ -24,26 +25,6 @@ class AMP_Bento_Sanitizer extends AMP_Base_Sanitizer { /** @var string */ const XPATH_BENTO_ELEMENTS_QUERY = './/*[ starts-with( name(), "bento-" ) ]'; - /** - * Tag and attribute sanitizer. - * - * @var AMP_Base_Sanitizer|null - */ - protected $tag_and_attribute_sanitizer; - - /** - * Init. - * - * @param AMP_Base_Sanitizer[] $sanitizers Sanitizers. - */ - public function init( $sanitizers ) { - parent::init( $sanitizers ); - - if ( array_key_exists( AMP_Tag_And_Attribute_Sanitizer::class, $sanitizers ) ) { - $this->tag_and_attribute_sanitizer = $sanitizers[ AMP_Tag_And_Attribute_Sanitizer::class ]; - } - } - /** * Get mapping of HTML selectors to the AMP component selectors which they may be converted into. * @@ -193,16 +174,6 @@ public function sanitize() { ValidationExemption::mark_node_as_px_verified( $bento_runtime_script ); } } - - // If bento-prefixed components were discovered, then ensure that the tag-and-attribute sanitizer will prefer - // Bento components when validating and that it will use the Bento versions of component scripts, and ultimately - // AMP_Theme_Support::ensure_required_markup() will add the Bento experiment opt-in which is still required at - // the moment. - if ( count( $bento_elements_discovered ) > 0 && $this->tag_and_attribute_sanitizer ) { - $this->tag_and_attribute_sanitizer->update_args( - [ 'prefer_bento' => true ] - ); - } } /** diff --git a/includes/sanitizers/class-amp-script-sanitizer.php b/includes/sanitizers/class-amp-script-sanitizer.php index b153129930f..24fe1f39c83 100644 --- a/includes/sanitizers/class-amp-script-sanitizer.php +++ b/includes/sanitizers/class-amp-script-sanitizer.php @@ -141,8 +141,8 @@ public function sanitize() { $sanitizer_arg_updates[ AMP_Img_Sanitizer::class ]['native_img_used'] = true; } - // When custom scripts are on the page, use Bento AMP components whenever possible and turn off some CSS - // processing is unnecessary for a valid AMP page and which can break custom scripts. + // When custom scripts are on the page, turn off some CSS processing because it is + // unnecessary for a valid AMP page and which can break custom scripts. if ( $this->px_verified_kept_node_count > 0 || $this->kept_script_count > 0 ) { $sanitizer_arg_updates[ AMP_Style_Sanitizer::class ]['transform_important_qualifiers'] = false; $sanitizer_arg_updates[ AMP_Style_Sanitizer::class ]['allow_excessive_css'] = true; diff --git a/includes/sanitizers/class-amp-tag-and-attribute-sanitizer.php b/includes/sanitizers/class-amp-tag-and-attribute-sanitizer.php index aac823f191a..eaddcb92e4e 100644 --- a/includes/sanitizers/class-amp-tag-and-attribute-sanitizer.php +++ b/includes/sanitizers/class-amp-tag-and-attribute-sanitizer.php @@ -191,7 +191,6 @@ public function __construct( $dom, $args = [] ) { 'amp_allowed_tags' => AMP_Allowed_Tags_Generated::get_allowed_tags(), 'amp_globally_allowed_attributes' => AMP_Allowed_Tags_Generated::get_allowed_attributes(), 'amp_layout_allowed_attributes' => AMP_Allowed_Tags_Generated::get_layout_attributes(), - 'prefer_bento' => false, 'allow_localhost_http_protocol' => false, ]; @@ -444,18 +443,8 @@ private function process_node( DOMElement $node ) { $validation_errors = []; $rule_spec_list = $this->allowed_tags[ $node->nodeName ]; foreach ( $rule_spec_list as $id => $rule_spec ) { - // When there are multiple versions of a rule spec, with one specifically for Bento and another for - // non-Bento make sure that only the preferred version is considered. Otherwise, the wrong requires_extension - // constraint may be applied. - if ( - isset( $rule_spec['tag_spec']['bento'] ) - && - $this->args['prefer_bento'] !== $rule_spec['tag_spec']['bento'] - ) { - continue; - } - $validity = $this->validate_tag_spec_for_node( $node, $rule_spec[ AMP_Rule_Spec::TAG_SPEC ] ); + if ( true === $validity ) { $rule_spec_list_to_validate[ $id ] = $this->get_rule_spec_list_to_validate( $node, $rule_spec ); } else { diff --git a/src/ValidationExemption.php b/src/ValidationExemption.php index 00480a35f24..5064112d91c 100644 --- a/src/ValidationExemption.php +++ b/src/ValidationExemption.php @@ -35,7 +35,7 @@ final class ValidationExemption { * HTML attribute to indicate an tag/element has been verified for PX. * * The difference here with `data-amp-unvalidated-tag` is that the PX-verified means that the tag will work - * properly Bento components and CSS tree shaking. + * properly with CSS tree shaking. * * @var string */ diff --git a/tests/php/src/PluginSuppressionTest.php b/tests/php/src/PluginSuppressionTest.php index 1fc54566e3f..916205cd07c 100644 --- a/tests/php/src/PluginSuppressionTest.php +++ b/tests/php/src/PluginSuppressionTest.php @@ -583,6 +583,10 @@ private function assert_plugin_suppressed_state( $suppressed, $plugin_slugs ) { $this->assertStringContainsString( 'Bad filter!', $content ); } + // Avoid running deprecated `the_block_template_skip_link()` while printing styles. + // @see . + remove_action( 'wp_footer', 'the_block_template_skip_link' ); + // Check action. ob_start(); wp_footer(); diff --git a/tests/php/test-amp-bento-sanitizer.php b/tests/php/test-amp-bento-sanitizer.php deleted file mode 100644 index 4b8d36ee9f4..00000000000 --- a/tests/php/test-amp-bento-sanitizer.php +++ /dev/null @@ -1,581 +0,0 @@ - [ - 'source' => ' - - - - - - - -

The following should have a green outline.

- - - - - -
-

Section 1

-
Content in section 1.
-
-
-

Section 2

-
Content in section 2.
-
- -
-

Section 3

-
Content in section 3.
-
-
- - - - - - ', - 'expected' => ' - - - - - - -

The following should have a green outline.

- - -
-

Section 1

-
Content in section 1.
-
-
-

Section 2

-
Content in section 2.
-
- -
-

Section 3

-
Content in section 3.
-
-
- - - - - ', - 'sanitizer_args' => [], - 'expected_error_codes' => [], - 'expect_prefer_bento' => true, - ], - - 'non-amp-bento-component' => [ - 'source' => ' - - - - - - - - - - - -

News flash!!!

-
- - - - - ', - 'expected' => ' - - - - - - - - - - - - -

News flash!!!

-
- - - ', - 'sanitizer_args' => [], - 'expected_error_codes' => [], - 'expect_prefer_bento' => true, - ], - - 'both-amp-and-bento-components' => [ - 'source' => ' - - - - - - - - - - - - - - - - - - - - - Saturday 11 April 2017 00.37 - - - - - - - - - -
- -
- -

News flash!!!

-
- - - ', - 'expected' => ' - - - - - - - - - - - - Saturday 11 April 2017 00.37 - - - - - - - - - -
- -
- - -

News flash!!!

-
- - - ', - 'sanitizer_args' => [], - 'expected_error_codes' => [], - 'expect_prefer_bento' => true, - ], - - 'bento-components-hidden-initially' => [ - 'source' => ' - - - - - - - - - - - - - - - - - - Lightboxed content - - - - - - ', - 'expected' => ' - - - - - - - - - - - - - Lightboxed content - - - - - - ', - 'sanitizer_args' => [], - 'expected_error_codes' => [], - 'expect_prefer_bento' => true, - ], - - 'no-bento-components' => [ - 'source' => ' - - - - - - - - - - - - - - - - - Hello World!! - - - ', - 'expected' => ' - - - - - - - Hello World!! - - - ', - 'sanitizer_args' => [], - 'expected_error_codes' => [ AMP_Tag_And_Attribute_Sanitizer::DISALLOWED_TAG ], - 'expect_prefer_bento' => false, - ], - - 'bento-mathml' => [ - 'source' => ' - - - - - - - - - -

The Quadratic Formula

- - -

Inline formula

-

- This is an example of a formula, - - placed inline in the middle of a block of text. -

- - - ', - 'expected' => ' - - - - - - -

The Quadratic Formula

- - -

Inline formula

-

- This is an example of a formula, - - placed inline in the middle of a block of text. -

- - - ', - 'sanitizer_args' => [], - 'expected_error_codes' => [], - 'expect_prefer_bento' => true, - ], - - 'bento-no-layout-available' => [ - 'source' => ' - - - - - - - - - - - - - - -
-
-
-
- - - ', - // Note: It's somewhat unexpected that the styles are still in the document since the element was removed. - // But this is because the tree shaking happened before the tag-and-attribute sanitizer ran, so at the - // time of tree shaking the bento-base-carousel element was still in the document. - 'expected' => ' - - - - - - - - ', - 'sanitizer_args' => [], - 'expected_error_codes' => [ - AMP_Tag_And_Attribute_Sanitizer::MISSING_LAYOUT_ATTRIBUTES, - ], - 'expect_prefer_bento' => true, - ], - ]; - } - - /** - * Test that noscript elements get replaced with their children. - * - * @dataProvider get_sanitizer_data - * @param string $source Source. - * @param string $expected Expected. - * @param array $sanitizer_args Sanitizer args. - * @param array $expected_error_codes Expected error codes. - * @param bool $expect_prefer_bento Whether expecting prefer_bento to be set. - * @covers ::init() - * @covers ::sanitize() - * @covers ::has_light_shadow_dom() - * @covers ::get_selector_conversion_mapping() - * @covers ::adapt_layout_styles() - * @covers ::get_bento_component_name_from_url() - * @covers \AMP_Base_Sanitizer::set_layout() - */ - public function test_sanitize( $source, $expected = null, $sanitizer_args = [], $expected_error_codes = [], $expect_prefer_bento = false ) { - if ( null === $expected ) { - $expected = $source; - } - $dom = Document::fromHtml( $source, Options::DEFAULTS ); - - $validation_error_callback_arg = isset( $sanitizer_args['validation_error_callback'] ) ? $sanitizer_args['validation_error_callback'] : null; - - $actual_error_codes = []; - - $sanitizer_args['validation_error_callback'] = static function ( $error ) use ( &$actual_error_codes, $validation_error_callback_arg ) { - $actual_error_codes[] = $error['code']; - - if ( $validation_error_callback_arg ) { - return $validation_error_callback_arg(); - } else { - return true; - } - }; - - $sanitizer_args['use_document_element'] = true; - - $bento_sanitizer = new AMP_Bento_Sanitizer( - $dom, - $sanitizer_args - ); - - $tag_and_attribute_sanitizer = new AMP_Tag_And_Attribute_Sanitizer( - $dom, - array_merge( - $sanitizer_args, - [ - 'prefer_bento' => false, // Overridden by AMP_Base_Sanitizer. - ] - ) - ); - - $sanitizers = [ - AMP_Bento_Sanitizer::class => $bento_sanitizer, - AMP_Script_Sanitizer::class => new AMP_Script_Sanitizer( - $dom, - $sanitizer_args - ), - AMP_Style_Sanitizer::class => new AMP_Style_Sanitizer( - $dom, - $sanitizer_args - ), - AMP_Tag_And_Attribute_Sanitizer::class => $tag_and_attribute_sanitizer, - ]; - - foreach ( $sanitizers as $sanitizer ) { - $sanitizer->init( $sanitizers ); - } - - $this->assertFalse( $tag_and_attribute_sanitizer->get_arg( 'prefer_bento' ) ); - - foreach ( $sanitizers as $sanitizer ) { - $sanitizer->sanitize(); - } - - $content = $dom->saveHTML( $dom->documentElement ); - $this->assertSimilarMarkup( $expected, $content ); - - $this->assertSame( $expected_error_codes, $actual_error_codes ); - $this->assertSame( $expect_prefer_bento, $tag_and_attribute_sanitizer->get_arg( 'prefer_bento' ) ); - } -} diff --git a/tests/php/test-amp-helper-functions.php b/tests/php/test-amp-helper-functions.php index 51720c8033f..a2bc5c9dd1e 100644 --- a/tests/php/test-amp-helper-functions.php +++ b/tests/php/test-amp-helper-functions.php @@ -1490,7 +1490,6 @@ public function test_amp_register_default_scripts_and_styles() { global $wp_scripts, $wp_styles; $wp_scripts = null; $wp_styles = null; - add_filter( 'amp_bento_enabled', '__return_false' ); $registered_script_srcs = []; foreach ( wp_scripts()->registered as $handle => $dependency ) { @@ -1502,7 +1501,25 @@ public function test_amp_register_default_scripts_and_styles() { ksort( $registered_script_srcs ); // This allows us to ensure that we catch any version changes in scripts. - $expected_scripts = [ + $expected_scripts = $this->get_expected_registered_scripts(); + + ksort( $expected_scripts ); + ksort( $registered_script_srcs ); + // phpcs:ignore WordPress.PHP.DevelopmentFunctions.error_log_var_export + $this->assertEquals( $expected_scripts, $registered_script_srcs, "Actual fixture:\n" . var_export( $registered_script_srcs, true ) ); + + $this->assertTrue( wp_style_is( 'amp-default', 'registered' ) ); + $this->assertTrue( wp_style_is( 'amp-icons', 'registered' ) ); + $this->assertFalse( wp_style_is( 'amp-base-carousel', 'registered' ) ); + } + + /** + * Get expected registered scripts. + * + * @return array + */ + private function get_expected_registered_scripts() { + return [ 'amp-3d-gltf' => 'v0/amp-3d-gltf-0.1.js', 'amp-3q-player' => 'v0/amp-3q-player-0.1.js', 'amp-access' => 'v0/amp-access-0.1.js', @@ -1595,7 +1612,6 @@ public function test_amp_register_default_scripts_and_styles() { 'amp-powr-player' => 'v0/amp-powr-player-0.1.js', 'amp-reach-player' => 'v0/amp-reach-player-0.1.js', 'amp-recaptcha-input' => 'v0/amp-recaptcha-input-0.1.js', - 'amp-redbull-player' => 'v0/amp-redbull-player-0.1.js', 'amp-reddit' => 'v0/amp-reddit-0.1.js', 'amp-render' => 'v0/amp-render-1.0.js', 'amp-riddle-quiz' => 'v0/amp-riddle-quiz-0.1.js', @@ -1640,235 +1656,9 @@ public function test_amp_register_default_scripts_and_styles() { 'amp-wordpress-embed' => 'v0/amp-wordpress-embed-1.0.js', 'amp-yotpo' => 'v0/amp-yotpo-0.1.js', 'amp-youtube' => 'v0/amp-youtube-0.1.js', + 'amp-slikeplayer' => 'v0/amp-slikeplayer-0.1.js', + 'amp-story-audio-sticker' => 'v0/amp-story-audio-sticker-0.1.js', ]; - - ksort( $expected_scripts ); - ksort( $registered_script_srcs ); - // phpcs:ignore WordPress.PHP.DevelopmentFunctions.error_log_var_export - $this->assertEquals( $expected_scripts, $registered_script_srcs, "Actual fixture:\n" . var_export( $registered_script_srcs, true ) ); - - $this->assertTrue( wp_style_is( 'amp-default', 'registered' ) ); - $this->assertTrue( wp_style_is( 'amp-icons', 'registered' ) ); - $this->assertFalse( wp_style_is( 'amp-base-carousel', 'registered' ) ); - } - - /** - * @covers ::amp_register_default_scripts() - * @covers ::amp_register_default_styles() - */ - public function test_amp_register_default_scripts_and_styles_with_bento() { - global $wp_scripts, $wp_styles; - $wp_scripts = null; - $wp_styles = null; - add_filter( 'amp_bento_enabled', '__return_true' ); - - $registered_script_srcs = []; - foreach ( wp_scripts()->registered as $handle => $dependency ) { - if ( 'amp-' === substr( $handle, 0, 4 ) ) { - $this->assertStringStartsWith( 'https://cdn.ampproject.org/', $dependency->src ); - $registered_script_srcs[ $handle ] = str_replace( 'https://cdn.ampproject.org/', '', $dependency->src ); - } - } - ksort( $registered_script_srcs ); - - // This allows us to ensure that we catch any version changes in scripts. - $expected_scripts = [ - 'amp-3d-gltf' => 'v0/amp-3d-gltf-0.1.js', - 'amp-3q-player' => 'v0/amp-3q-player-0.1.js', - 'amp-access' => 'v0/amp-access-0.1.js', - 'amp-access-fewcents' => 'v0/amp-access-fewcents-0.1.js', - 'amp-access-laterpay' => 'v0/amp-access-laterpay-0.2.js', - 'amp-access-poool' => 'v0/amp-access-poool-0.1.js', - 'amp-access-scroll' => 'v0/amp-access-scroll-0.1.js', - 'amp-accordion' => 'v0/amp-accordion-1.0.js', - 'amp-action-macro' => 'v0/amp-action-macro-0.1.js', - 'amp-ad' => 'v0/amp-ad-0.1.js', - 'amp-ad-custom' => 'v0/amp-ad-custom-0.1.js', - 'amp-addthis' => 'v0/amp-addthis-0.1.js', - 'amp-analytics' => 'v0/amp-analytics-0.1.js', - 'amp-anim' => 'v0/amp-anim-0.1.js', - 'amp-animation' => 'v0/amp-animation-0.1.js', - 'amp-apester-media' => 'v0/amp-apester-media-0.1.js', - 'amp-app-banner' => 'v0/amp-app-banner-0.1.js', - 'amp-audio' => 'v0/amp-audio-1.0.js', - 'amp-auto-ads' => 'v0/amp-auto-ads-0.1.js', - 'amp-autocomplete' => 'v0/amp-autocomplete-0.1.js', - 'amp-base-carousel' => 'v0/amp-base-carousel-1.0.js', - 'amp-beopinion' => 'v0/amp-beopinion-0.1.js', - 'amp-bind' => 'v0/amp-bind-0.1.js', - 'amp-bodymovin-animation' => 'v0/amp-bodymovin-animation-0.1.js', - 'amp-brid-player' => 'v0/amp-brid-player-0.1.js', - 'amp-brightcove' => 'v0/amp-brightcove-1.0.js', - 'amp-byside-content' => 'v0/amp-byside-content-0.1.js', - 'amp-cache-url' => 'v0/amp-cache-url-0.1.js', - 'amp-call-tracking' => 'v0/amp-call-tracking-0.1.js', - 'amp-carousel' => 'v0/amp-carousel-0.2.js', - 'amp-connatix-player' => 'v0/amp-connatix-player-0.1.js', - 'amp-consent' => 'v0/amp-consent-0.1.js', - 'amp-dailymotion' => 'v0/amp-dailymotion-1.0.js', - 'amp-date-countdown' => 'v0/amp-date-countdown-1.0.js', - 'amp-date-display' => 'v0/amp-date-display-1.0.js', - 'amp-date-picker' => 'v0/amp-date-picker-0.1.js', - 'amp-delight-player' => 'v0/amp-delight-player-0.1.js', - 'amp-dynamic-css-classes' => 'v0/amp-dynamic-css-classes-0.1.js', - 'amp-embedly-card' => 'v0/amp-embedly-card-1.0.js', - 'amp-experiment' => 'v0/amp-experiment-0.1.js', - 'amp-facebook' => 'v0/amp-facebook-1.0.js', - 'amp-facebook-comments' => 'v0/amp-facebook-comments-0.1.js', - 'amp-facebook-like' => 'v0/amp-facebook-like-0.1.js', - 'amp-facebook-page' => 'v0/amp-facebook-page-0.1.js', - 'amp-fit-text' => 'v0/amp-fit-text-1.0.js', - 'amp-font' => 'v0/amp-font-0.1.js', - 'amp-form' => 'v0/amp-form-0.1.js', - 'amp-fx-collection' => 'v0/amp-fx-collection-0.1.js', - 'amp-fx-flying-carpet' => 'v0/amp-fx-flying-carpet-0.1.js', - 'amp-geo' => 'v0/amp-geo-0.1.js', - 'amp-gist' => 'v0/amp-gist-0.1.js', - 'amp-google-document-embed' => 'v0/amp-google-document-embed-0.1.js', - 'amp-google-read-aloud-player' => 'v0/amp-google-read-aloud-player-0.1.js', - 'amp-hulu' => 'v0/amp-hulu-0.1.js', - 'amp-iframe' => 'v0/amp-iframe-1.0.js', - 'amp-iframely' => 'v0/amp-iframely-0.1.js', - 'amp-ima-video' => 'v0/amp-ima-video-0.1.js', - 'amp-image-lightbox' => 'v0/amp-image-lightbox-0.1.js', - 'amp-image-slider' => 'v0/amp-image-slider-0.1.js', - 'amp-imgur' => 'v0/amp-imgur-0.1.js', - 'amp-inline-gallery' => 'v0/amp-inline-gallery-1.0.js', - 'amp-inputmask' => 'v0/amp-inputmask-0.1.js', - 'amp-instagram' => 'v0/amp-instagram-1.0.js', - 'amp-install-serviceworker' => 'v0/amp-install-serviceworker-0.1.js', - 'amp-izlesene' => 'v0/amp-izlesene-0.1.js', - 'amp-jwplayer' => 'v0/amp-jwplayer-0.1.js', - 'amp-kaltura-player' => 'v0/amp-kaltura-player-0.1.js', - 'amp-lightbox' => 'v0/amp-lightbox-1.0.js', - 'amp-lightbox-gallery' => 'v0/amp-lightbox-gallery-1.0.js', - 'amp-link-rewriter' => 'v0/amp-link-rewriter-0.1.js', - 'amp-list' => 'v0/amp-list-0.1.js', - 'amp-live-list' => 'v0/amp-live-list-0.1.js', - 'amp-mathml' => 'v0/amp-mathml-1.0.js', - 'amp-mega-menu' => 'v0/amp-mega-menu-0.1.js', - 'amp-megaphone' => 'v0/amp-megaphone-0.1.js', - 'amp-minute-media-player' => 'v0/amp-minute-media-player-0.1.js', - 'amp-mowplayer' => 'v0/amp-mowplayer-0.1.js', - 'amp-mustache' => 'v0/amp-mustache-0.2.js', - 'amp-nested-menu' => 'v0/amp-nested-menu-0.1.js', - 'amp-next-page' => 'v0/amp-next-page-1.0.js', - 'amp-nexxtv-player' => 'v0/amp-nexxtv-player-0.1.js', - 'amp-o2-player' => 'v0/amp-o2-player-0.1.js', - 'amp-onetap-google' => 'v0/amp-onetap-google-0.1.js', - 'amp-ooyala-player' => 'v0/amp-ooyala-player-0.1.js', - 'amp-orientation-observer' => 'v0/amp-orientation-observer-0.1.js', - 'amp-pan-zoom' => 'v0/amp-pan-zoom-0.1.js', - 'amp-pinterest' => 'v0/amp-pinterest-0.1.js', - 'amp-playbuzz' => 'v0/amp-playbuzz-0.1.js', - 'amp-position-observer' => 'v0/amp-position-observer-0.1.js', - 'amp-powr-player' => 'v0/amp-powr-player-0.1.js', - 'amp-reach-player' => 'v0/amp-reach-player-0.1.js', - 'amp-recaptcha-input' => 'v0/amp-recaptcha-input-0.1.js', - 'amp-redbull-player' => 'v0/amp-redbull-player-0.1.js', - 'amp-reddit' => 'v0/amp-reddit-0.1.js', - 'amp-render' => 'v0/amp-render-1.0.js', - 'amp-riddle-quiz' => 'v0/amp-riddle-quiz-0.1.js', - 'amp-runtime' => 'v0.js', - 'amp-script' => 'v0/amp-script-0.1.js', - 'amp-selector' => 'v0/amp-selector-1.0.js', - 'amp-shadow' => 'shadow-v0.js', - 'amp-sidebar' => 'v0/amp-sidebar-1.0.js', - 'amp-skimlinks' => 'v0/amp-skimlinks-0.1.js', - 'amp-smartlinks' => 'v0/amp-smartlinks-0.1.js', - 'amp-social-share' => 'v0/amp-social-share-1.0.js', - 'amp-soundcloud' => 'v0/amp-soundcloud-1.0.js', - 'amp-springboard-player' => 'v0/amp-springboard-player-0.1.js', - 'amp-sticky-ad' => 'v0/amp-sticky-ad-1.0.js', - 'amp-story' => 'v0/amp-story-1.0.js', - 'amp-story-360' => 'v0/amp-story-360-0.1.js', - 'amp-story-auto-ads' => 'v0/amp-story-auto-ads-0.1.js', - 'amp-story-auto-analytics' => 'v0/amp-story-auto-analytics-0.1.js', - 'amp-story-captions' => 'v0/amp-story-captions-0.1.js', - 'amp-story-interactive' => 'v0/amp-story-interactive-0.1.js', - 'amp-story-panning-media' => 'v0/amp-story-panning-media-0.1.js', - 'amp-story-player' => 'v0/amp-story-player-0.1.js', - 'amp-story-shopping' => 'v0/amp-story-shopping-0.1.js', - 'amp-story-subscriptions' => 'v0/amp-story-subscriptions-0.1.js', - 'amp-stream-gallery' => 'v0/amp-stream-gallery-1.0.js', - 'amp-subscriptions' => 'v0/amp-subscriptions-0.1.js', - 'amp-subscriptions-google' => 'v0/amp-subscriptions-google-0.1.js', - 'amp-tiktok' => 'v0/amp-tiktok-0.1.js', - 'amp-timeago' => 'v0/amp-timeago-1.0.js', - 'amp-truncate-text' => 'v0/amp-truncate-text-0.1.js', - 'amp-twitter' => 'v0/amp-twitter-1.0.js', - 'amp-user-notification' => 'v0/amp-user-notification-0.1.js', - 'amp-video' => 'v0/amp-video-1.0.js', - 'amp-video-docking' => 'v0/amp-video-docking-0.1.js', - 'amp-video-iframe' => 'v0/amp-video-iframe-1.0.js', - 'amp-vimeo' => 'v0/amp-vimeo-1.0.js', - 'amp-vine' => 'v0/amp-vine-0.1.js', - 'amp-viqeo-player' => 'v0/amp-viqeo-player-0.1.js', - 'amp-vk' => 'v0/amp-vk-0.1.js', - 'amp-web-push' => 'v0/amp-web-push-0.1.js', - 'amp-wistia-player' => 'v0/amp-wistia-player-0.1.js', - 'amp-wordpress-embed' => 'v0/amp-wordpress-embed-1.0.js', - 'amp-yotpo' => 'v0/amp-yotpo-0.1.js', - 'amp-youtube' => 'v0/amp-youtube-1.0.js', - ]; - - ksort( $expected_scripts ); - ksort( $registered_script_srcs ); - // phpcs:ignore WordPress.PHP.DevelopmentFunctions.error_log_var_export - $this->assertEquals( $expected_scripts, $registered_script_srcs, "Actual fixture:\n" . var_export( $registered_script_srcs, true ) ); - - $bundled_styles = [ 'amp-default', 'amp-icons' ]; - foreach ( $bundled_styles as $bundled_style ) { - $this->assertTrue( wp_style_is( $bundled_style, 'registered' ) ); - } - $registered_style_srcs = []; - foreach ( wp_styles()->registered as $handle => $dependency ) { - if ( in_array( $handle, $bundled_styles, true ) ) { - continue; - } - - if ( 'amp-' === substr( $handle, 0, 4 ) ) { - $this->assertStringStartsWith( 'https://cdn.ampproject.org/', $dependency->src ); - $registered_style_srcs[ $handle ] = str_replace( 'https://cdn.ampproject.org/', '', $dependency->src ); - } - } - ksort( $registered_style_srcs ); - - // This allows us to ensure that we catch any version changes in styles. - $expected_styles = [ - 'amp-accordion' => 'v0/amp-accordion-1.0.css', - 'amp-base-carousel' => 'v0/amp-base-carousel-1.0.css', - 'amp-brightcove' => 'v0/amp-brightcove-1.0.css', - 'amp-dailymotion' => 'v0/amp-dailymotion-1.0.css', - 'amp-date-countdown' => 'v0/amp-date-countdown-1.0.css', - 'amp-date-display' => 'v0/amp-date-display-1.0.css', - 'amp-embedly-card' => 'v0/amp-embedly-card-1.0.css', - 'amp-facebook' => 'v0/amp-facebook-1.0.css', - 'amp-fit-text' => 'v0/amp-fit-text-1.0.css', - 'amp-iframe' => 'v0/amp-iframe-1.0.css', - 'amp-inline-gallery' => 'v0/amp-inline-gallery-1.0.css', - 'amp-instagram' => 'v0/amp-instagram-1.0.css', - 'amp-lightbox' => 'v0/amp-lightbox-1.0.css', - 'amp-lightbox-gallery' => 'v0/amp-lightbox-gallery-1.0.css', - 'amp-mathml' => 'v0/amp-mathml-1.0.css', - 'amp-selector' => 'v0/amp-selector-1.0.css', - 'amp-sidebar' => 'v0/amp-sidebar-1.0.css', - 'amp-social-share' => 'v0/amp-social-share-1.0.css', - 'amp-soundcloud' => 'v0/amp-soundcloud-1.0.css', - 'amp-stream-gallery' => 'v0/amp-stream-gallery-1.0.css', - 'amp-timeago' => 'v0/amp-timeago-1.0.css', - 'amp-twitter' => 'v0/amp-twitter-1.0.css', - 'amp-video' => 'v0/amp-video-1.0.css', - 'amp-video-iframe' => 'v0/amp-video-iframe-1.0.css', - 'amp-vimeo' => 'v0/amp-vimeo-1.0.css', - 'amp-wordpress-embed' => 'v0/amp-wordpress-embed-1.0.css', - 'amp-youtube' => 'v0/amp-youtube-1.0.css', - ]; - - ksort( $expected_styles ); - ksort( $registered_style_srcs ); - // phpcs:ignore WordPress.PHP.DevelopmentFunctions.error_log_var_export - $this->assertEquals( $expected_styles, $registered_style_srcs, "Actual fixture:\n" . var_export( $registered_style_srcs, true ) ); } /** diff --git a/tests/php/test-amp-script-sanitizer.php b/tests/php/test-amp-script-sanitizer.php index 070e7ac2c01..72a6c3689fc 100644 --- a/tests/php/test-amp-script-sanitizer.php +++ b/tests/php/test-amp-script-sanitizer.php @@ -501,7 +501,6 @@ static function( $preempt, $request, $url ) { $dom, [ 'use_document_element' => true, - 'prefer_bento' => false, // Overridden by AMP_Script_Sanitizer when there is a kept script. ] ), ]; @@ -633,15 +632,10 @@ function ( Element $element ) { $this->assertStringContainsString( 'body:after{', $css_text ); } - // Verify that prefer_bento got set. + // Get registered scripts. $scripts = $sanitizers[ AMP_Tag_And_Attribute_Sanitizer::class ]->get_scripts(); - if ( 3 === $level ) { - $this->assertArrayHasKey( Extension::FACEBOOK_PAGE, $scripts ); - $this->assertArrayNotHasKey( Extension::FACEBOOK, $scripts ); - } else { - $this->assertArrayHasKey( Extension::FACEBOOK_PAGE, $scripts ); - $this->assertArrayNotHasKey( Extension::FACEBOOK, $scripts ); - } + $this->assertArrayHasKey( Extension::FACEBOOK_PAGE, $scripts ); + $this->assertArrayNotHasKey( Extension::FACEBOOK, $scripts ); } /** @return array */ diff --git a/tests/php/test-amp-style-sanitizer.php b/tests/php/test-amp-style-sanitizer.php index 537149fd4d9..7145218c473 100644 --- a/tests/php/test-amp-style-sanitizer.php +++ b/tests/php/test-amp-style-sanitizer.php @@ -1637,20 +1637,6 @@ public function get_attribute_selector_data() { '.stateful' => false, ], ], - 'bento_accordion_with_id' => [ - ' - -
-

Section 1

-
Content in section 1.
-
-
- ', - [ - '#my-accordion' => true, - 'amp-accordion#my-accordion' => true, - ], - ], 'amp_replacement_elements_with_id' => [ ' diff --git a/tests/php/test-class-amp-theme-support.php b/tests/php/test-class-amp-theme-support.php index b150436a8d0..05d6bbcef6f 100644 --- a/tests/php/test-class-amp-theme-support.php +++ b/tests/php/test-class-amp-theme-support.php @@ -1846,54 +1846,6 @@ public function test_prepare_response_in_forced_dev_mode() { $this->assertStringNotContainsString( 'set_template_mode( AMP_Theme_Support::STANDARD_MODE_SLUG ); - - add_filter( 'amp_bento_enabled', '__return_true' ); - wp(); - - $html = AMP_Theme_Support::prepare_response( $this->get_original_html() ); - $this->assertStringContainsString( '', $html ); - $this->assertStringContainsString( 'amp-facebook-1.0', $html ); // As opposed to amp-facebook-page-0.1, since Bento is enabled. - } - - /** - * Test prepare_response when Bento is enabled and in dev mode. - * - * @covers AMP_Theme_Support::prepare_response() - */ - public function test_prepare_response_in_bento_with_dev_mode() { - $this->set_template_mode( AMP_Theme_Support::STANDARD_MODE_SLUG ); - - add_filter( 'amp_dev_mode_enabled', '__return_true' ); - add_filter( 'amp_bento_enabled', '__return_true' ); - wp(); - - $html = AMP_Theme_Support::prepare_response( $this->get_original_html() ); - $this->assertStringContainsString( '', $html ); - $this->assertStringContainsString( 'amp-facebook-1.0', $html ); // As opposed to amp-facebook-page-0.1, since Bento is enabled. - } - - /** - * Test prepare_response when Bento is not enabled. - * - * @covers AMP_Theme_Support::prepare_response() - */ - public function test_prepare_response_without_bento() { - $this->set_template_mode( AMP_Theme_Support::STANDARD_MODE_SLUG ); - - wp(); - - $html = AMP_Theme_Support::prepare_response( $this->get_original_html() ); - $this->assertStringNotContainsString( 'AMP.toggleExperiment("bento", true);', $html ); - $this->assertStringContainsString( 'amp-facebook-page-0.1', $html ); // As opposed to amp-facebook-page-1.0, since Bento is not enabled. - } - /** @return array */ public function get_data_to_test_prepare_response_standard_mode_non_amp() { return [ diff --git a/tests/php/test-tag-and-attribute-sanitizer.php b/tests/php/test-tag-and-attribute-sanitizer.php index 4a077f2d9a3..202777cb7f5 100644 --- a/tests/php/test-tag-and-attribute-sanitizer.php +++ b/tests/php/test-tag-and-attribute-sanitizer.php @@ -194,14 +194,6 @@ public function get_body_data() { [ 'amp-facebook-comments' ], ], - 'amp-facebook-comments_bento' => [ - '', - null, // No change. - [ 'amp-facebook' ], - [], - [ 'prefer_bento' => true ], - ], - 'amp-facebook-comments_missing_required_attribute' => [ '', '', @@ -220,28 +212,12 @@ public function get_body_data() { [ 'amp-facebook-like' ], ], - 'amp-facebook-like_bento' => [ - '', - null, // No change. - [ 'amp-facebook' ], - [], - [ 'prefer_bento' => true ], - ], - 'amp-facebook-page' => [ '', null, // No change. [ 'amp-facebook-page' ], ], - 'amp-facebook-page_bento' => [ - '', - null, // No change. - [ 'amp-facebook' ], - [], - [ 'prefer_bento' => true ], - ], - 'amp-facebook-like_missing_required_attribute' => [ '', '', @@ -2994,20 +2970,6 @@ class="slide" [ 'amp-sidebar', 'amp-list', 'amp-mustache' ], ], - 'amp-redbull-player' => [ - ' - - ', - null, - [ 'amp-redbull-player' ], - ], - 'mustache_templates_with_variable_attrs' => [ '