Skip to content

Fix failing PHPUnit tests #7419

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 7 commits into from
Jan 25, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 6 additions & 3 deletions .github/workflows/build-test-measure.yml
Original file line number Diff line number Diff line change
Expand Up @@ -502,7 +502,10 @@ jobs:
composer require --ignore-platform-reqs --no-interaction --no-scripts phpunit/phpunit:^8.5 --with-dependencies
echo "Downgrading phpunit/php-token-stream because the latest version requires PHP 7.3"
composer require --ignore-platform-reqs --no-interaction --no-scripts phpunit/php-token-stream:^3.1.3 --with-dependencies
elif [[ $WP_VERSION == "latest" || $WP_VERSION == "trunk" || $PHP_VERSION == "7.4" ]]; then
elif [[ $PHP_VERSION == "7.3" || $PHP_VERSION == "7.4" || $PHP_VERSION == "8.0" ]]; then
echo "Installing PHPUnit 9.3"
composer require --dev --ignore-platform-reqs phpunit/phpunit:"9.3.*" --with-dependencies
elif [[ $WP_VERSION == "latest" || $WP_VERSION == "trunk" || $PHP_VERSION == "8.1" || $PHP_VERSION == "8.2" ]]; then
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What about when PHP 8.3 comes out?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I guess this will depend on us updating the matrix, so nevermind.

echo "Installing latest version of PHPUnit"
composer update --ignore-platform-reqs --no-interaction --no-scripts yoast/phpunit-polyfills --with-dependencies
fi
Expand Down Expand Up @@ -619,8 +622,8 @@ jobs:
if: needs.pre-run.outputs.changed-php-count > 0
run: |
# We are using PHP 7.4 and WP Latest.
echo "Installing latest version of PHPUnit"
composer update --ignore-platform-reqs --no-interaction --no-scripts yoast/phpunit-polyfills --with-dependencies
echo "Installing PHPUnit 9.3"
composer require --dev --ignore-platform-reqs phpunit/phpunit:"9.3.*" --with-dependencies

- name: Build plugin
run: npm run build:js
Expand Down
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ node_modules
/.vscode/
/phpcs.xml
/phpunit.xml
/.phpunit.result.cache
/*.sql
/.wp-env.override.json

Expand Down
25 changes: 21 additions & 4 deletions tests/php/test-amp-tumblr-embed-handler.php
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ public function test__conversion( $url, $expected ) {
$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 );
$this->assertEqualMarkup( $expected, $this->maybe_replace_embed_urls( $content ) );

if ( $url && function_exists( 'do_blocks' ) ) {
$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 -->";
Expand All @@ -122,23 +122,40 @@ public function test__conversion( $url, $expected ) {

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

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

// Check with no filters applied and with the script pre-remoevd.
$content = ( new WP_Embed() )->shortcode( [], $url );
$content = preg_replace( '#<script.+?</script>#', '', $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 );
$this->assertEqualMarkup( $expected, $this->maybe_replace_embed_urls( $content ) );
}

/**
* Replace new embeds URLs with old ones.
*
* @param string $content Content.
*
* @return string Content.
*/
private function maybe_replace_embed_urls( $content ) {
// Replace new embeds url to old ones to maintain consistency.
$content = str_replace( 'https://embed.tumblr.com/embed/post/t:-iO5APHPiXyOXM0LJ2Zeqg/92003045635/v2', 'https://embed.tumblr.com/embed/post/2JT2XTaiTxO08wh21dqQrw/92003045635', $content );
$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 );
$content = str_replace( 'https://embed.tumblr.com/embed/post/t:F33OkAxLKX6A89MkL0LO6g/184736320764/v2', 'https://embed.tumblr.com/embed/post/O6_eRR6K-z9QGTzdU5HrhQ/184736320764', $content );
$content = str_replace( 'https://www.tumblr.com/teded/184736320764/how-do-vaccines-work', 'https://teded.tumblr.com/post/184736320764/how-do-vaccines-work', $content );

return $content;
}

/**
Expand Down