Skip to content

Commit 9f5d3fc

Browse files
authored
Merge branch 'develop' into fix/wrapped-embeds-in-p-tags
2 parents ca161e5 + 3396a0c commit 9f5d3fc

11 files changed

+123
-55
lines changed

.github/workflows/build-test-measure.yml

Lines changed: 40 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -156,6 +156,36 @@ jobs:
156156
repo-token: '${{ secrets.GITHUB_TOKEN }}'
157157
report-json: 'lint-js-report.json'
158158

159+
#-----------------------------------------------------------------------------------------------------------------------
160+
161+
normalize-composer:
162+
name: 'Normalize composer.json'
163+
needs: pre-run
164+
if: needs.pre-run.outputs.changed-php-count > 0 || needs.pre-run.outputs.changed-gha-workflow-count > 0
165+
runs-on: ubuntu-latest
166+
steps:
167+
- name: Checkout
168+
uses: actions/checkout@v3
169+
170+
- name: Setup PHP
171+
uses: shivammathur/setup-php@v2
172+
with:
173+
php-version: '8.1'
174+
coverage: none
175+
176+
- name: Get composer-normalize.phar
177+
run: |
178+
wget https://github.com/ergebnis/composer-normalize/releases/latest/download/composer-normalize.phar
179+
chmod +x composer-normalize.phar
180+
181+
- name: Validate composer.json
182+
run: composer --no-interaction validate --no-check-all
183+
184+
- name: Normalize composer.json
185+
run: |
186+
composer config --no-interaction --no-plugins allow-plugins.ergebnis/composer-normalize true
187+
./composer-normalize.phar --dry-run
188+
159189
#-----------------------------------------------------------------------------------------------------------------------
160190

161191
lint-php:
@@ -189,18 +219,9 @@ jobs:
189219
- name: Install Composer dependencies
190220
run: composer install --prefer-dist --optimize-autoloader --no-progress --no-interaction
191221

192-
- name: Validate composer.json
193-
run: composer --no-interaction validate --no-check-all
194-
195222
- name: Detect coding standard violations (PHPCS)
196223
run: vendor/bin/phpcs -q --report=checkstyle --runtime-set ignore_errors_on_exit 1 --runtime-set ignore_warnings_on_exit 1 | cs2pr --graceful-warnings
197224

198-
- name: Normalize composer.json
199-
run: |
200-
composer config --no-interaction --no-plugins allow-plugins.ergebnis/composer-normalize true
201-
composer require --no-interaction --dev ergebnis/composer-normalize --ignore-platform-reqs
202-
composer --no-interaction normalize --dry-run
203-
204225
#-----------------------------------------------------------------------------------------------------------------------
205226

206227
static-analysis-php:
@@ -362,12 +383,13 @@ jobs:
362383
mysql:
363384
image: mariadb:10
364385
env:
365-
MYSQL_ALLOW_EMPTY_PASSWORD: true
366-
MYSQL_ROOT_PASSWORD:
367-
MYSQL_DATABASE: wordpress_test
386+
MARIADB_ALLOW_EMPTY_ROOT_PASSWORD: true
387+
MARIADB_DATABASE: wordpress_test
388+
MARIADB_MYSQL_LOCALHOST_USER: 1
389+
MARIADB_MYSQL_LOCALHOST_GRANTS: USAGE
368390
ports:
369391
- 3306
370-
options: --health-cmd="mysqladmin ping" --health-interval=10s --health-timeout=5s --health-retries=3
392+
options: --health-cmd="healthcheck.sh --su-mysql --connect --innodb_initialized" --health-interval=10s --health-timeout=5s --health-retries=3
371393
continue-on-error: ${{ matrix.experimental == true }}
372394
strategy:
373395
fail-fast: false
@@ -606,12 +628,13 @@ jobs:
606628
mysql:
607629
image: mariadb:10
608630
env:
609-
MYSQL_ALLOW_EMPTY_PASSWORD: true
610-
MYSQL_ROOT_PASSWORD:
611-
MYSQL_DATABASE: wordpress_test
631+
MARIADB_ALLOW_EMPTY_ROOT_PASSWORD: true
632+
MARIADB_DATABASE: wordpress_test
633+
MARIADB_MYSQL_LOCALHOST_USER: 1
634+
MARIADB_MYSQL_LOCALHOST_GRANTS: USAGE
612635
ports:
613636
- 3306
614-
options: --health-cmd="mysqladmin ping" --health-interval=10s --health-timeout=5s --health-retries=3
637+
options: --health-cmd="healthcheck.sh --su-mysql --connect --innodb_initialized" --health-interval=10s --health-timeout=5s --health-retries=3
615638
continue-on-error: ${{ matrix.experimental == true }}
616639
strategy:
617640
fail-fast: false

bin/ci/install-wp-tests.sh

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -135,7 +135,8 @@ install_db() {
135135
fi
136136

137137
# create database
138-
mysqladmin create "$DB_NAME" --user="$DB_USER" --password="$DB_PASS""$EXTRA"
138+
mariadb-admin create $DB_NAME --user="$DB_USER" --password="$DB_PASS"$EXTRA || \
139+
mysqladmin create "$DB_NAME" --user="$DB_USER" --password="$DB_PASS"$EXTRA
139140
}
140141

141142
install_wp

includes/embeds/class-amp-core-block-handler.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -569,6 +569,7 @@ private function process_text_widgets( Document $dom ) {
569569
foreach ( $dom->xpath->query( '//div[ @class = "textwidget" ]' ) as $text_widget ) {
570570
// Restore the width/height attributes which were preserved in preserve_widget_text_element_dimensions.
571571
foreach ( $dom->xpath->query( sprintf( './/*[ @%s or @%s ]', self::AMP_PRESERVED_WIDTH_ATTRIBUTE_NAME, self::AMP_PRESERVED_HEIGHT_ATTRIBUTE_NAME ), $text_widget ) as $element ) {
572+
/** @var DOMElement $element */
572573
if ( $element->hasAttribute( self::AMP_PRESERVED_WIDTH_ATTRIBUTE_NAME ) ) {
573574
$element->setAttribute( Attribute::WIDTH, $element->getAttribute( self::AMP_PRESERVED_WIDTH_ATTRIBUTE_NAME ) );
574575
$element->removeAttribute( self::AMP_PRESERVED_WIDTH_ATTRIBUTE_NAME );
@@ -586,6 +587,7 @@ private function process_text_widgets( Document $dom ) {
586587
* responsive so this is built-in. Note also the style rule for .wp-video in amp-default.css.
587588
*/
588589
foreach ( $dom->xpath->query( './/div[ @class = "wp-video" and @style ]', $text_widget ) as $element ) {
590+
/** @var DOMElement $element */
589591
$element->removeAttribute( 'style' );
590592
}
591593
}

includes/embeds/class-amp-tumblr-embed-handler.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,8 @@ public function sanitize_raw_embeds( Document $dom ) {
8686
);
8787
$overflow_element->textContent = __( 'See more', 'amp' );
8888
$amp_element->appendChild( $overflow_element );
89+
90+
/** @var DOMElement $placeholder */
8991
$placeholder->setAttribute( Attribute::PLACEHOLDER, '' );
9092
$amp_element->appendChild( $placeholder );
9193

includes/sanitizers/class-amp-style-sanitizer.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1017,6 +1017,7 @@ public function sanitize() {
10171017
}
10181018
} else {
10191019
foreach ( $styled_elements as $element ) {
1020+
/** @var DOMElement $element */
10201021
$attr = $element->getAttributeNode( Attribute::STYLE );
10211022
if ( $attr && preg_match( '/!\s*important/i', $attr->value ) ) {
10221023
ValidationExemption::mark_node_as_px_verified( $attr );

src/ReaderThemeSupportFeatures.php

Lines changed: 33 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -579,40 +579,49 @@ public function get_relative_luminance_from_hex( $hex ) {
579579
* @return bool False if `wp_get_global_settings()` not exists or theme.json not found, true otherwise.
580580
*/
581581
private function theme_has_theme_json() {
582-
if ( function_exists( 'wp_theme_has_theme_json' ) ) {
583-
return wp_theme_has_theme_json();
582+
// @TODO: Uncomment this once `wp_theme_has_theme_json()` caching is fixed.
583+
// if ( function_exists( 'wp_theme_has_theme_json' ) ) {
584+
// return wp_theme_has_theme_json();
585+
// }
586+
587+
static $theme_has_support = null;
588+
static $prev_stylesheet_directory = null;
589+
static $prev_template_directory = null;
590+
591+
$stylesheet_directory = get_stylesheet_directory();
592+
$template_directory = get_template_directory();
593+
594+
// Make sure that the cached $theme_has_support value is reset when the theme changes.
595+
if ( null !== $theme_has_support && (
596+
$stylesheet_directory !== $prev_stylesheet_directory ||
597+
$template_directory !== $prev_template_directory
598+
) ) {
599+
$theme_has_support = null;
584600
}
585-
586-
static $theme_has_support = null;
601+
$prev_stylesheet_directory = $stylesheet_directory;
602+
$prev_template_directory = $template_directory;
587603

588604
if (
589605
null !== $theme_has_support &&
590-
591-
/*
592-
* Ignore static cache when `WP_DEBUG` is enabled. Why? To avoid interfering with
593-
* the theme developer's workflow.
594-
*
595-
* @todo Replace `WP_DEBUG` once an "in development mode" check is available in Core.
596-
*/
597-
! ( defined( 'WP_DEBUG' ) && WP_DEBUG ) &&
598-
599-
/*
600-
* Ignore cache when automated test suites are running. Why? To ensure
601-
* the static cache is reset between each test.
602-
*/
603-
! ( defined( 'WP_RUN_CORE_TESTS' ) && WP_RUN_CORE_TESTS )
606+
// Ignore static cache when the development mode is set to 'theme', to avoid interfering with
607+
// the theme developer's workflow.
608+
( function_exists( 'wp_get_development_mode' ) && wp_get_development_mode() !== 'theme' )
604609
) {
605610
return $theme_has_support;
606611
}
607612

608-
// Does the theme have its own theme.json?
609-
$theme_has_support = is_readable( get_stylesheet_directory() . '/theme.json' );
610-
611-
// Look up the parent if the child does not have a theme.json.
612-
if ( ! $theme_has_support ) {
613-
$theme_has_support = is_readable( get_template_directory() . '/theme.json' );
613+
// This is the same as get_theme_file_path(), which isn't available in load-styles.php context.
614+
if ( $stylesheet_directory !== $template_directory && file_exists( $stylesheet_directory . '/theme.json' ) ) {
615+
$path = $stylesheet_directory . '/theme.json';
616+
} else {
617+
$path = $template_directory . '/theme.json';
614618
}
615619

620+
/** This filter is documented in wp-includes/link-template.php */
621+
$path = apply_filters( 'theme_file_path', $path, 'theme.json' );
622+
623+
$theme_has_support = file_exists( $path );
624+
616625
return $theme_has_support;
617626
}
618627

templates/style.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -279,6 +279,11 @@
279279
.amp-wp-article-featured-image {
280280
margin: 0 0 1em;
281281
}
282+
.amp-wp-article-featured-image img:not(amp-img) {
283+
max-width: 100%;
284+
height: auto;
285+
margin: 0 auto;
286+
}
282287
.amp-wp-article-featured-image amp-img {
283288
margin: 0 auto;
284289
}

tests/php/src/Admin/PolyfillsTest.php

Lines changed: 25 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -85,11 +85,11 @@ public function test_registration() {
8585

8686
// These should pass in WP < 5.6.
8787
$this->assertTrue( wp_script_is( 'lodash', 'registered' ) );
88-
$this->assertStringContainsString( '_.noConflict();', wp_scripts()->print_inline_script( 'lodash', 'after', false ) );
88+
$this->assertStringContainsString( '_.noConflict();', self::get_inline_script( 'lodash', 'after' ) );
8989

9090
$this->assertTrue( wp_script_is( 'wp-api-fetch', 'registered' ) );
91-
$this->assertStringContainsString( 'createRootURLMiddleware', wp_scripts()->print_inline_script( 'wp-api-fetch', 'after', false ) );
92-
$this->assertStringContainsString( 'createNonceMiddleware', wp_scripts()->print_inline_script( 'wp-api-fetch', 'after', false ) );
91+
$this->assertStringContainsString( 'createRootURLMiddleware', self::get_inline_script( 'wp-api-fetch', 'after' ) );
92+
$this->assertStringContainsString( 'createNonceMiddleware', self::get_inline_script( 'wp-api-fetch', 'after' ) );
9393

9494
$this->assertTrue( wp_script_is( 'wp-hooks', 'registered' ) );
9595
$this->assertTrue( wp_script_is( 'wp-i18n', 'registered' ) );
@@ -99,4 +99,26 @@ public function test_registration() {
9999

100100
$this->assertTrue( wp_style_is( 'wp-components', 'registered' ) );
101101
}
102+
103+
/**
104+
* Get inline script.
105+
*
106+
* @param string $handle Script handle.
107+
* @param string $position Script position.
108+
*
109+
* @return string
110+
*/
111+
public static function get_inline_script( $handle, $position = 'after' ) {
112+
if ( method_exists( wp_scripts(), 'get_inline_script_tag' ) ) {
113+
$script = wp_scripts()->get_inline_script_tag( $handle, $position );
114+
115+
if ( ! $script ) {
116+
return false;
117+
}
118+
119+
return $script;
120+
} else {
121+
return wp_scripts()->print_inline_script( $handle, $position, false );
122+
}
123+
}
102124
}

tests/php/src/Editor/EditorSupportTest.php

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
use AmpProject\AmpWP\Infrastructure\Service;
99
use AmpProject\AmpWP\Tests\Helpers\WithBlockEditorSupport;
1010
use AmpProject\AmpWP\Tests\TestCase;
11+
use AmpProject\AmpWP\Tests\Admin\PolyfillsTest;
1112

1213
/** @coversDefaultClass \AmpProject\AmpWP\Editor\EditorSupport */
1314
final class EditorSupportTest extends TestCase {
@@ -71,15 +72,15 @@ public function test_supports_current_screen( $post_type_uses_block_editor, $pos
7172
/** @covers ::maybe_show_notice() */
7273
public function test_dont_show_notice_if_no_screen_defined() {
7374
$this->instance->maybe_show_notice();
74-
$this->assertFalse( wp_scripts()->print_inline_script( 'wp-edit-post', 'after', false ) );
75+
$this->assertFalse( PolyfillsTest::get_inline_script( 'wp-edit-post', 'after' ) );
7576
}
7677

7778
/** @covers ::maybe_show_notice() */
7879
public function test_dont_show_notice_for_unsupported_post_type() {
7980
$this->setup_environment( true, false );
8081

8182
$this->instance->maybe_show_notice();
82-
$this->assertFalse( wp_scripts()->print_inline_script( 'wp-edit-post', 'after', false ) );
83+
$this->assertFalse( PolyfillsTest::get_inline_script( 'wp-edit-post', 'after' ) );
8384
}
8485

8586
/** @covers ::maybe_show_notice() */
@@ -92,11 +93,11 @@ public function test_show_notice_for_supported_post_type() {
9293

9394
$this->instance->maybe_show_notice();
9495
if ( $this->instance->is_current_screen_block_editor_for_amp_enabled_post_type() ) {
95-
$this->assertFalse( wp_scripts()->print_inline_script( 'wp-edit-post', 'after', false ) );
96+
$this->assertFalse( PolyfillsTest::get_inline_script( 'wp-edit-post', 'after' ) );
9697
} else {
9798
$this->assertStringContainsString(
9899
'AMP functionality is not available',
99-
wp_scripts()->print_inline_script( 'wp-edit-post', 'after', false )
100+
PolyfillsTest::get_inline_script( 'wp-edit-post', 'after' )
100101
);
101102
}
102103
}
@@ -108,7 +109,7 @@ public function test_maybe_show_notice_for_unsupported_user() {
108109

109110
$this->instance->maybe_show_notice();
110111

111-
$this->assertFalse( wp_scripts()->print_inline_script( 'wp-edit-post', 'after', false ) );
112+
$this->assertFalse( PolyfillsTest::get_inline_script( 'wp-edit-post', 'after' ) );
112113
}
113114

114115
/** @covers ::maybe_show_notice() */
@@ -125,7 +126,7 @@ public function test_maybe_show_notice_for_gutenberg_4_9() {
125126
wp_set_current_user( self::factory()->user->create( [ 'role' => 'administrator' ] ) );
126127

127128
$this->instance->maybe_show_notice();
128-
$inline_script = wp_scripts()->print_inline_script( 'wp-edit-post', 'after', false );
129+
$inline_script = PolyfillsTest::get_inline_script( 'wp-edit-post', 'after' );
129130
$this->assertStringContainsString( 'AMP functionality is not available', $inline_script );
130131
}
131132
}

tests/php/src/ReaderThemeSupportFeaturesTest.php

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -483,16 +483,15 @@ public function test_print_theme_support_styles_reader( $is_legacy ) {
483483
$this->assertStringContainsString( '<style id="amp-wp-theme-support-editor-font-sizes">', $output );
484484
$this->assertStringContainsString( 'font-size: clamp(', $output );
485485
$this->assertStringContainsString( '+ ((', $output );
486-
$this->assertStringContainsString( ':root .has-small-font-size { font-size: clamp(0.875rem, 0.875rem + ((1vw - 0.48rem) * 0.24), 1rem); }', $output );
486+
$this->assertStringContainsString( ':root .has-small-font-size { font-size: clamp(0.875rem', $output );
487487
}
488488

489489
// Assert spacing size custom properties.
490490
if ( $this->call_private_method( $this->instance, 'theme_has_theme_json' ) && function_exists( 'wp_get_global_settings' ) ) {
491491
$this->assertStringContainsString( '<style id="amp-wp-theme-support-spacing-sizes-custom-properties">', $output );
492492
$this->assertStringContainsString( ':root {', $output );
493-
$this->assertStringContainsString( '--wp--preset--spacing--30: clamp(1.5rem, 5vw, 2rem);', $output );
494-
$this->assertStringContainsString( 'clamp(1.8rem, 1.8rem + ((1vw - 0.48rem) * 2.885), 3rem);', $output );
495-
$this->assertStringContainsString( '--wp--preset--spacing--80: clamp(7rem, 14vw, 11rem);', $output );
493+
$this->assertStringContainsString( '--wp--preset--spacing--30:', $output );
494+
$this->assertStringContainsString( '--wp--preset--spacing--80:', $output );
496495
$this->assertStringContainsString( '}', $output );
497496
$this->assertStringContainsString( '</style>', $output );
498497
}

0 commit comments

Comments
 (0)