Skip to content

Commit 2462614

Browse files
authored
Merge pull request #7419 from ampproject/fix/php-tests
Fix failing PHPUnit tests
2 parents 7f9b28b + 3be7426 commit 2462614

File tree

3 files changed

+28
-7
lines changed

3 files changed

+28
-7
lines changed

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

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -502,7 +502,10 @@ jobs:
502502
composer require --ignore-platform-reqs --no-interaction --no-scripts phpunit/phpunit:^8.5 --with-dependencies
503503
echo "Downgrading phpunit/php-token-stream because the latest version requires PHP 7.3"
504504
composer require --ignore-platform-reqs --no-interaction --no-scripts phpunit/php-token-stream:^3.1.3 --with-dependencies
505-
elif [[ $WP_VERSION == "latest" || $WP_VERSION == "trunk" || $PHP_VERSION == "7.4" ]]; then
505+
elif [[ $PHP_VERSION == "7.3" || $PHP_VERSION == "7.4" || $PHP_VERSION == "8.0" ]]; then
506+
echo "Installing PHPUnit 9.3"
507+
composer require --dev --ignore-platform-reqs phpunit/phpunit:"9.3.*" --with-dependencies
508+
elif [[ $WP_VERSION == "latest" || $WP_VERSION == "trunk" || $PHP_VERSION == "8.1" || $PHP_VERSION == "8.2" ]]; then
506509
echo "Installing latest version of PHPUnit"
507510
composer update --ignore-platform-reqs --no-interaction --no-scripts yoast/phpunit-polyfills --with-dependencies
508511
fi
@@ -619,8 +622,8 @@ jobs:
619622
if: needs.pre-run.outputs.changed-php-count > 0
620623
run: |
621624
# We are using PHP 7.4 and WP Latest.
622-
echo "Installing latest version of PHPUnit"
623-
composer update --ignore-platform-reqs --no-interaction --no-scripts yoast/phpunit-polyfills --with-dependencies
625+
echo "Installing PHPUnit 9.3"
626+
composer require --dev --ignore-platform-reqs phpunit/phpunit:"9.3.*" --with-dependencies
624627
625628
- name: Build plugin
626629
run: npm run build:js

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ node_modules
1818
/.vscode/
1919
/phpcs.xml
2020
/phpunit.xml
21+
/.phpunit.result.cache
2122
/*.sql
2223
/.wp-env.override.json
2324

tests/php/test-amp-tumblr-embed-handler.php

Lines changed: 21 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@ public function test__conversion( $url, $expected ) {
111111
$dom = AMP_DOM_Utils::get_dom_from_content( $content );
112112
$embed->sanitize_raw_embeds( $dom );
113113
$content = AMP_DOM_Utils::get_content_from_dom( $dom );
114-
$this->assertEqualMarkup( $expected, $content );
114+
$this->assertEqualMarkup( $expected, $this->maybe_replace_embed_urls( $content ) );
115115

116116
if ( $url && function_exists( 'do_blocks' ) ) {
117117
$embed_block = "<!-- wp:embed {\"url\":\"{$url}\",\"type\":\"rich\",\"providerNameSlug\":\"tumblr\",\"responsive\":true} -->\n<figure class=\"wp-block-embed is-type-rich is-provider-tumblr wp-block-embed-tumblr\"><div class=\"wp-block-embed__wrapper\">\n{$url}\n</div></figure>\n<!-- /wp:embed -->";
@@ -122,23 +122,40 @@ public function test__conversion( $url, $expected ) {
122122

123123
$this->assertEqualMarkup(
124124
'<figure class="wp-block-embed is-type-rich is-provider-tumblr wp-block-embed-tumblr"><div class="wp-block-embed__wrapper">' . $expected . '</div></figure>',
125-
$content
125+
$this->maybe_replace_embed_urls( $content )
126126
);
127127
}
128128

129129
// Check with no filters applied.
130130
$dom = AMP_DOM_Utils::get_dom_from_content( ( new WP_Embed() )->shortcode( [], $url ) );
131131
$embed->sanitize_raw_embeds( $dom );
132132
$content = AMP_DOM_Utils::get_content_from_dom( $dom );
133-
$this->assertEqualMarkup( $expected, $content );
133+
$this->assertEqualMarkup( $expected, $this->maybe_replace_embed_urls( $content ) );
134134

135135
// Check with no filters applied and with the script pre-remoevd.
136136
$content = ( new WP_Embed() )->shortcode( [], $url );
137137
$content = preg_replace( '#<script.+?</script>#', '', $content );
138138
$dom = AMP_DOM_Utils::get_dom_from_content( $content );
139139
$embed->sanitize_raw_embeds( $dom );
140140
$content = AMP_DOM_Utils::get_content_from_dom( $dom );
141-
$this->assertEqualMarkup( $expected, $content );
141+
$this->assertEqualMarkup( $expected, $this->maybe_replace_embed_urls( $content ) );
142+
}
143+
144+
/**
145+
* Replace new embeds URLs with old ones.
146+
*
147+
* @param string $content Content.
148+
*
149+
* @return string Content.
150+
*/
151+
private function maybe_replace_embed_urls( $content ) {
152+
// Replace new embeds url to old ones to maintain consistency.
153+
$content = str_replace( 'https://embed.tumblr.com/embed/post/t:-iO5APHPiXyOXM0LJ2Zeqg/92003045635/v2', 'https://embed.tumblr.com/embed/post/2JT2XTaiTxO08wh21dqQrw/92003045635', $content );
154+
$content = str_replace( 'https://www.tumblr.com/ifpaintingscouldtext/92003045635/grant-wood-american-gothic-1930', 'https://ifpaintingscouldtext.tumblr.com/post/92003045635/grant-wood-american-gothic-1930', $content );
155+
$content = str_replace( 'https://embed.tumblr.com/embed/post/t:F33OkAxLKX6A89MkL0LO6g/184736320764/v2', 'https://embed.tumblr.com/embed/post/O6_eRR6K-z9QGTzdU5HrhQ/184736320764', $content );
156+
$content = str_replace( 'https://www.tumblr.com/teded/184736320764/how-do-vaccines-work', 'https://teded.tumblr.com/post/184736320764/how-do-vaccines-work', $content );
157+
158+
return $content;
142159
}
143160

144161
/**

0 commit comments

Comments
 (0)