From ca2b4936b3e9650749e4600095d685808d8b8962 Mon Sep 17 00:00:00 2001 From: Sergey Biryukov Date: Sat, 27 Nov 2021 16:16:15 +0000 Subject: [PATCH] Tests: Use a simpler approach to test the output in some tests. Instead of ignoring the output and catching it later with `getActualOutput()`, we can use `expectOutputRegex()` directly, which evaluates the output after the rest of the test code has run, if no unexpected errors were encountered. Follow-up to [52173], [52253]. Props jrf. See #53635, #53363. git-svn-id: https://develop.svn.wordpress.org/trunk@52259 602fd350-edb4-49c9-b593-d223f7449a82 --- tests/phpunit/tests/l10n.php | 27 ++++++--------------------- tests/phpunit/tests/widgets.php | 7 +------ 2 files changed, 7 insertions(+), 27 deletions(-) diff --git a/tests/phpunit/tests/l10n.php b/tests/phpunit/tests/l10n.php index 51bb0468d4..b31c165692 100644 --- a/tests/phpunit/tests/l10n.php +++ b/tests/phpunit/tests/l10n.php @@ -407,17 +407,12 @@ class Tests_L10n extends WP_UnitTestCase { $this->factory()->post->create( $args ); - // Effectively ignore the output until retrieving it later via `getActualOutput()`. - $this->expectOutputRegex( '`.`' ); - $expect = 'Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do…'; + $this->expectOutputRegex( '/' . $expect . '/' ); + wp_dashboard_recent_drafts(); - $actual = $this->getActualOutput(); - restore_previous_locale(); - - $this->assertMatchesRegularExpression( '/' . $expect . '/', $actual ); } /** @@ -436,17 +431,12 @@ class Tests_L10n extends WP_UnitTestCase { $post = $this->factory()->post->create( $args ); - // Effectively ignore the output until retrieving it later via `getActualOutput()`. - $this->expectOutputRegex( '`.`' ); - $expect = 'Lorem ipsum dolor sit amet, consectetur …'; + $this->expectOutputRegex( '/' . $expect . '/' ); + wp_dashboard_recent_drafts(); - $actual = $this->getActualOutput(); - restore_previous_locale(); - - $this->assertMatchesRegularExpression( '/' . $expect . '/', $actual ); } /** @@ -465,17 +455,12 @@ class Tests_L10n extends WP_UnitTestCase { $this->factory()->post->create( $args ); - // Effectively ignore the output until retrieving it later via `getActualOutput()`. - $this->expectOutputRegex( '`.`' ); - $expect = str_repeat( 'あ', 40 ) . '…'; + $this->expectOutputRegex( '/' . $expect . '/' ); + wp_dashboard_recent_drafts(); - $actual = $this->getActualOutput(); - restore_previous_locale(); - - $this->assertMatchesRegularExpression( '/' . $expect . '/', $actual ); } /** diff --git a/tests/phpunit/tests/widgets.php b/tests/phpunit/tests/widgets.php index 36e9b684f6..7cfce4719b 100644 --- a/tests/phpunit/tests/widgets.php +++ b/tests/phpunit/tests/widgets.php @@ -611,8 +611,7 @@ class Tests_Widgets extends WP_UnitTestCase { } ); - // Effectively ignore the output until retrieving it later via `getActualOutput()`. - $this->expectOutputRegex( '`.`' ); + $this->expectOutputRegex( '/Test Title/' ); $widget->display_callback( array( @@ -624,11 +623,7 @@ class Tests_Widgets extends WP_UnitTestCase { 2 ); - $actual = $this->getActualOutput(); - unregister_widget( $widget ); - - $this->assertStringContainsString( 'Test Title', $actual ); } /**