diff --git a/tests/phpunit/tests/l10n.php b/tests/phpunit/tests/l10n.php index 3d23dd7f20d4..1c69fb4c23be 100644 --- a/tests/phpunit/tests/l10n.php +++ b/tests/phpunit/tests/l10n.php @@ -435,6 +435,19 @@ public function test_length_of_draft_should_be_counted_by_words() { switch_to_locale( 'en_US' ); + /* + * The recent drafts list is only displayed on the Dashboard screen for users + * with the 'edit_posts' capability. + * + * This means the current user needs to be set to Editor as a prerequisite + * for the call to the wp_dashboard_recent_drafts() function. + * + * This allows the subsequent call to get_edit_post_link() to work as expected + * and return a string instead of null, which would otherwise cause a PHP 8.1 + * "passing null to non-nullable" deprecation notice. + */ + wp_set_current_user( self::factory()->user->create( array( 'role' => 'editor' ) ) ); + $args = array( 'post_content' => $this->long_text, 'post_excerpt' => '', @@ -461,6 +474,19 @@ public function test_length_of_draft_should_be_counted_by_chars() { switch_to_locale( 'ja_JP' ); + /* + * The recent drafts list is only displayed on the Dashboard screen for users + * with the 'edit_posts' capability. + * + * This means the current user needs to be set to Editor as a prerequisite + * for the call to the wp_dashboard_recent_drafts() function. + * + * This allows the subsequent call to get_edit_post_link() to work as expected + * and return a string instead of null, which would otherwise cause a PHP 8.1 + * "passing null to non-nullable" deprecation notice. + */ + wp_set_current_user( self::factory()->user->create( array( 'role' => 'editor' ) ) ); + $args = array( 'post_content' => $this->long_text, 'post_excerpt' => '', @@ -487,6 +513,19 @@ public function test_length_of_draft_should_be_counted_by_chars_in_japanese() { switch_to_locale( 'ja_JP' ); + /* + * The recent drafts list is only displayed on the Dashboard screen for users + * with the 'edit_posts' capability. + * + * This means the current user needs to be set to Editor as a prerequisite + * for the call to the wp_dashboard_recent_drafts() function. + * + * This allows the subsequent call to get_edit_post_link() to work as expected + * and return a string instead of null, which would otherwise cause a PHP 8.1 + * "passing null to non-nullable" deprecation notice. + */ + wp_set_current_user( self::factory()->user->create( array( 'role' => 'editor' ) ) ); + $args = array( 'post_content' => str_repeat( 'あ', 200 ), 'post_excerpt' => '',