Make WordPress Core

Changeset 62208


Ignore:
Timestamp:
04/05/2026 11:13:50 PM (4 months ago)
Author:
SergeyBiryukov
Message:

Tests: Move wp_dropdown_languages() tests to their own file.

This aims to make the tests more discoverable and easier to expand.

Follow-up to [36631], [39169], [43359], [44514].

See #64225.

Location:
trunk/tests/phpunit/tests
Files:
1 edited
1 copied

Legend:

Unmodified
Added
Removed
  • trunk/tests/phpunit/tests/l10n.php

    r60253 r62208  
    128128
    129129        /**
    130          * @ticket 35294
    131          *
    132          * @covers ::wp_dropdown_languages
    133          */
    134         public function test_wp_dropdown_languages() {
    135                 $args   = array(
    136                         'id'           => 'foo',
    137                         'name'         => 'bar',
    138                         'languages'    => array( 'de_DE' ),
    139                         'translations' => $this->wp_dropdown_languages_filter(),
    140                         'selected'     => 'de_DE',
    141                         'echo'         => false,
    142                 );
    143                 $actual = wp_dropdown_languages( $args );
    144 
    145                 $this->assertStringContainsString( 'id="foo"', $actual );
    146                 $this->assertStringContainsString( 'name="bar"', $actual );
    147                 $this->assertStringContainsString( '<option value="" lang="en" data-installed="1">English (United States)</option>', $actual );
    148                 $this->assertStringContainsString( '<option value="de_DE" lang="de" selected=\'selected\' data-installed="1">Deutsch</option>', $actual );
    149                 $this->assertStringContainsString( '<option value="it_IT" lang="it">Italiano</option>', $actual );
    150                 $this->assertStringContainsString( '<option value="ja_JP" lang="ja">日本語</option>', $actual );
    151         }
    152 
    153         /**
    154          * @ticket 38632
    155          *
    156          * @covers ::wp_dropdown_languages
    157          */
    158         public function test_wp_dropdown_languages_site_default() {
    159                 $args   = array(
    160                         'id'                       => 'foo',
    161                         'name'                     => 'bar',
    162                         'languages'                => array( 'de_DE' ),
    163                         'translations'             => $this->wp_dropdown_languages_filter(),
    164                         'selected'                 => 'de_DE',
    165                         'echo'                     => false,
    166                         'show_option_site_default' => true,
    167                 );
    168                 $actual = wp_dropdown_languages( $args );
    169 
    170                 $this->assertStringContainsString( 'id="foo"', $actual );
    171                 $this->assertStringContainsString( 'name="bar"', $actual );
    172                 $this->assertStringContainsString( '<option value="site-default" data-installed="1">Site Default</option>', $actual );
    173                 $this->assertStringContainsString( '<option value="" lang="en" data-installed="1">English (United States)</option>', $actual );
    174                 $this->assertStringContainsString( '<option value="de_DE" lang="de" selected=\'selected\' data-installed="1">Deutsch</option>', $actual );
    175                 $this->assertStringContainsString( '<option value="it_IT" lang="it">Italiano</option>', $actual );
    176                 $this->assertStringContainsString( '<option value="ja_JP" lang="ja">日本語</option>', $actual );
    177         }
    178 
    179         /**
    180          * @ticket 44494
    181          *
    182          * @covers ::wp_dropdown_languages
    183          */
    184         public function test_wp_dropdown_languages_exclude_en_us() {
    185                 $args   = array(
    186                         'id'                => 'foo',
    187                         'name'              => 'bar',
    188                         'languages'         => array( 'de_DE' ),
    189                         'translations'      => $this->wp_dropdown_languages_filter(),
    190                         'selected'          => 'de_DE',
    191                         'echo'              => false,
    192                         'show_option_en_us' => false,
    193                 );
    194                 $actual = wp_dropdown_languages( $args );
    195 
    196                 $this->assertStringNotContainsString( '<option value="" lang="en" data-installed="1">English (United States)</option>', $actual );
    197         }
    198 
    199         /**
    200          * @ticket 38632
    201          *
    202          * @covers ::wp_dropdown_languages
    203          */
    204         public function test_wp_dropdown_languages_en_US_selected() {
    205                 $args   = array(
    206                         'id'           => 'foo',
    207                         'name'         => 'bar',
    208                         'languages'    => array( 'de_DE' ),
    209                         'translations' => $this->wp_dropdown_languages_filter(),
    210                         'selected'     => 'en_US',
    211                         'echo'         => false,
    212                 );
    213                 $actual = wp_dropdown_languages( $args );
    214 
    215                 $this->assertStringContainsString( 'id="foo"', $actual );
    216                 $this->assertStringContainsString( 'name="bar"', $actual );
    217                 $this->assertStringContainsString( '<option value="" lang="en" data-installed="1" selected=\'selected\'>English (United States)</option>', $actual );
    218                 $this->assertStringContainsString( '<option value="de_DE" lang="de" data-installed="1">Deutsch</option>', $actual );
    219                 $this->assertStringContainsString( '<option value="it_IT" lang="it">Italiano</option>', $actual );
    220                 $this->assertStringContainsString( '<option value="ja_JP" lang="ja">日本語</option>', $actual );
    221         }
    222 
    223         /**
    224          * Add site default language to ja_JP in dropdown
    225          *
    226          * @covers ::wp_dropdown_languages
    227          */
    228         public function test_wp_dropdown_languages_site_default_ja_JP() {
    229                 $args   = array(
    230                         'id'                       => 'foo',
    231                         'name'                     => 'bar',
    232                         'languages'                => array( 'ja_JP' ),
    233                         'translations'             => $this->wp_dropdown_languages_filter(),
    234                         'selected'                 => 'ja_JP',
    235                         'echo'                     => false,
    236                         'show_option_site_default' => true,
    237                 );
    238                 $actual = wp_dropdown_languages( $args );
    239 
    240                 $this->assertStringContainsString( 'id="foo"', $actual );
    241                 $this->assertStringContainsString( 'name="bar"', $actual );
    242                 $this->assertStringContainsString( '<option value="site-default" data-installed="1">Site Default</option>', $actual );
    243                 $this->assertStringContainsString( '<option value="" lang="en" data-installed="1">English (United States)</option>', $actual );
    244                 $this->assertStringContainsString( '<option value="de_DE" lang="de">Deutsch</option>', $actual );
    245                 $this->assertStringContainsString( '<option value="it_IT" lang="it">Italiano</option>', $actual );
    246                 $this->assertStringContainsString( '<option value="ja_JP" lang="ja" selected=\'selected\' data-installed="1">日本語</option>', $actual );
    247         }
    248 
    249         /**
    250          * Select dropdown language from de_DE to ja_JP
    251          *
    252          * @covers ::wp_dropdown_languages
    253          */
    254         public function test_wp_dropdown_languages_ja_JP_selected() {
    255                 $args   = array(
    256                         'id'           => 'foo',
    257                         'name'         => 'bar',
    258                         'languages'    => array( 'de_DE' ),
    259                         'translations' => $this->wp_dropdown_languages_filter(),
    260                         'selected'     => 'ja_JP',
    261                         'echo'         => false,
    262                 );
    263                 $actual = wp_dropdown_languages( $args );
    264 
    265                 $this->assertStringContainsString( 'id="foo"', $actual );
    266                 $this->assertStringContainsString( 'name="bar"', $actual );
    267                 $this->assertStringContainsString( '<option value="" lang="en" data-installed="1">English (United States)</option>', $actual );
    268                 $this->assertStringContainsString( '<option value="de_DE" lang="de" data-installed="1">Deutsch</option>', $actual );
    269                 $this->assertStringContainsString( '<option value="it_IT" lang="it">Italiano</option>', $actual );
    270                 $this->assertStringContainsString( '<option value="ja_JP" lang="ja" selected=\'selected\'>日本語</option>', $actual );
    271         }
    272 
    273         /**
    274          * We don't want to call the API when testing.
    275          *
    276          * @return array
    277          */
    278         private function wp_dropdown_languages_filter() {
    279                 return array(
    280                         'de_DE' => array(
    281                                 'language'    => 'de_DE',
    282                                 'native_name' => 'Deutsch',
    283                                 'iso'         => array( 'de' ),
    284                         ),
    285                         'it_IT' => array(
    286                                 'language'    => 'it_IT',
    287                                 'native_name' => 'Italiano',
    288                                 'iso'         => array( 'it', 'ita' ),
    289                         ),
    290                         'ja_JP' => array(
    291                                 'language'    => 'ja_JP',
    292                                 'native_name' => '日本語',
    293                                 'iso'         => array( 'ja' ),
    294                         ),
    295                 );
    296         }
    297 
    298         /**
    299130         * @ticket 35284
    300131         *
  • trunk/tests/phpunit/tests/l10n/wpDropdownLanguages.php

    r54642 r62208  
    44 * @group l10n
    55 * @group i18n
     6 *
     7 * @covers ::wp_dropdown_languages
    68 */
    7 class Tests_L10n extends WP_UnitTestCase {
    8 
    9         /**
    10          * Long Dummy Text.
    11          *
    12          * @since 5.0.0
    13          *
    14          * @var string $long_text
    15          */
    16         private $long_text = 'Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.';
    17 
    18         /**
    19          * @ticket 35961
    20          *
    21          * @covers ::_n_noop
    22          */
    23         public function test_n_noop() {
    24                 $text_domain   = 'text-domain';
    25                 $nooped_plural = _n_noop( '%s post', '%s posts', $text_domain );
    26 
    27                 $this->assertSame( 'text-domain', $nooped_plural['domain'] );
    28                 $this->assertSame( '%s posts', translate_nooped_plural( $nooped_plural, 0, $text_domain ) );
    29                 $this->assertSame( '%s post', translate_nooped_plural( $nooped_plural, 1, $text_domain ) );
    30                 $this->assertSame( '%s posts', translate_nooped_plural( $nooped_plural, 2, $text_domain ) );
    31         }
    32 
    33         /**
    34          * @ticket 35961
    35          *
    36          * @covers ::_nx_noop
    37          */
    38         public function test_nx_noop() {
    39                 $text_domain   = 'text-domain';
    40                 $nooped_plural = _nx_noop( '%s post', '%s posts', 'my-context', $text_domain );
    41 
    42                 $this->assertSame( 'text-domain', $nooped_plural['domain'] );
    43                 $this->assertSame( 'my-context', $nooped_plural['context'] );
    44                 $this->assertSame( '%s posts', translate_nooped_plural( $nooped_plural, 0, $text_domain ) );
    45                 $this->assertSame( '%s post', translate_nooped_plural( $nooped_plural, 1, $text_domain ) );
    46                 $this->assertSame( '%s posts', translate_nooped_plural( $nooped_plural, 2, $text_domain ) );
    47         }
    48 
    49         /**
    50          * @ticket 35073
    51          *
    52          * @covers ::before_last_bar
    53          */
    54         public function test_before_last_bar() {
    55                 $this->assertSame( 'no-bar-at-all', before_last_bar( 'no-bar-at-all' ) );
    56                 $this->assertSame( 'before-last-bar', before_last_bar( 'before-last-bar|after-bar' ) );
    57                 $this->assertSame( 'first-before-bar|second-before-bar', before_last_bar( 'first-before-bar|second-before-bar|after-last-bar' ) );
    58         }
    59 
    60         /**
    61          * @ticket 35950
    62          *
    63          * @covers ::get_available_languages
    64          */
    65         public function test_get_available_languages() {
    66                 $array = get_available_languages();
    67                 $this->assertIsArray( $array );
    68 
    69                 $array = get_available_languages( '.' );
    70                 $this->assertEmpty( $array );
    71 
    72                 $array = get_available_languages( DIR_TESTDATA . '/languages/' );
    73                 $this->assertSame( array( 'de_DE', 'en_GB', 'es_ES', 'ja_JP' ), $array );
    74         }
    75 
    76         /**
    77          * @ticket 35284
    78          *
    79          * @covers ::wp_get_installed_translations
    80          */
    81         public function test_wp_get_installed_translations_for_core() {
    82                 $installed_translations = wp_get_installed_translations( 'core' );
    83                 $this->assertIsArray( $installed_translations );
    84                 $textdomains_expected = array( 'admin', 'admin-network', 'continents-cities', 'default' );
    85                 $this->assertSameSets( $textdomains_expected, array_keys( $installed_translations ) );
    86 
    87                 $this->assertNotEmpty( $installed_translations['default']['en_GB'] );
    88                 $data_en_gb = $installed_translations['default']['en_GB'];
    89                 $this->assertSame( '2016-10-26 00:01+0200', $data_en_gb['PO-Revision-Date'] );
    90                 $this->assertSame( 'Development (4.4.x)', $data_en_gb['Project-Id-Version'] );
    91                 $this->assertSame( 'Poedit 1.8.10', $data_en_gb['X-Generator'] );
    92 
    93                 $this->assertNotEmpty( $installed_translations['admin']['es_ES'] );
    94                 $data_es_es = $installed_translations['admin']['es_ES'];
    95                 $this->assertSame( '2016-10-25 18:29+0200', $data_es_es['PO-Revision-Date'] );
    96                 $this->assertSame( 'Administration', $data_es_es['Project-Id-Version'] );
    97                 $this->assertSame( 'Poedit 1.8.10', $data_es_es['X-Generator'] );
    98         }
     9class Tests_L10n_wpDropdownLanguages extends WP_UnitTestCase {
    9910
    10011        /**
    10112         * @ticket 35294
    102          *
    103          * @covers ::wp_dropdown_languages
    10413         */
    10514        public function test_wp_dropdown_languages() {
     
    12433        /**
    12534         * @ticket 38632
    126          *
    127          * @covers ::wp_dropdown_languages
    12835         */
    12936        public function test_wp_dropdown_languages_site_default() {
     
    15057        /**
    15158         * @ticket 44494
    152          *
    153          * @covers ::wp_dropdown_languages
    15459         */
    15560        public function test_wp_dropdown_languages_exclude_en_us() {
     
    17075        /**
    17176         * @ticket 38632
    172          *
    173          * @covers ::wp_dropdown_languages
    17477         */
    17578        public function test_wp_dropdown_languages_en_US_selected() {
     
    19497        /**
    19598         * Add site default language to ja_JP in dropdown
    196          *
    197          * @covers ::wp_dropdown_languages
    19899         */
    199100        public function test_wp_dropdown_languages_site_default_ja_JP() {
     
    220121        /**
    221122         * Select dropdown language from de_DE to ja_JP
    222          *
    223          * @covers ::wp_dropdown_languages
    224123         */
    225124        public function test_wp_dropdown_languages_ja_JP_selected() {
     
    266165                );
    267166        }
    268 
    269         /**
    270          * @ticket 35284
    271          *
    272          * @covers ::wp_get_pomo_file_data
    273          */
    274         public function test_wp_get_pomo_file_data() {
    275                 $file  = DIR_TESTDATA . '/pomo/empty.po';
    276                 $array = wp_get_pomo_file_data( $file );
    277                 $this->assertArrayHasKey( 'POT-Creation-Date', $array );
    278                 $this->assertArrayHasKey( 'PO-Revision-Date', $array );
    279                 $this->assertArrayHasKey( 'Project-Id-Version', $array );
    280                 $this->assertArrayHasKey( 'X-Generator', $array );
    281 
    282                 $file  = DIR_TESTDATA . '/pomo/mo.pot';
    283                 $array = wp_get_pomo_file_data( $file );
    284                 $this->assertNotEmpty( $array['POT-Creation-Date'] );
    285                 $this->assertNotEmpty( $array['PO-Revision-Date'] );
    286                 $this->assertNotEmpty( $array['Project-Id-Version'] );
    287                 $this->assertArrayHasKey( 'X-Generator', $array );
    288 
    289                 $file  = DIR_TESTDATA . '/languages/es_ES.po';
    290                 $array = wp_get_pomo_file_data( $file );
    291                 $this->assertArrayHasKey( 'POT-Creation-Date', $array );
    292                 $this->assertNotEmpty( $array['PO-Revision-Date'] );
    293                 $this->assertNotEmpty( $array['Project-Id-Version'] );
    294                 $this->assertNotEmpty( $array['X-Generator'] );
    295         }
    296 
    297         /**
    298          * @ticket 44541
    299          *
    300          * @covers ::the_excerpt
    301          */
    302         public function test_length_of_excerpt_should_be_counted_by_words() {
    303                 global $post;
    304 
    305                 switch_to_locale( 'en_US' );
    306 
    307                 $args = array(
    308                         'post_content' => $this->long_text,
    309                         'post_excerpt' => '',
    310                 );
    311 
    312                 $post = self::factory()->post->create_and_get( $args );
    313                 setup_postdata( $post );
    314 
    315                 $expect = "<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat [&hellip;]</p>\n";
    316                 the_excerpt();
    317 
    318                 restore_previous_locale();
    319 
    320                 $this->expectOutputString( $expect );
    321         }
    322 
    323         /**
    324          * @ticket 44541
    325          *
    326          * @covers ::the_excerpt
    327          */
    328         public function test_length_of_excerpt_should_be_counted_by_chars() {
    329                 global $post;
    330 
    331                 switch_to_locale( 'ja_JP' );
    332 
    333                 $args = array(
    334                         'post_content' => $this->long_text,
    335                         'post_excerpt' => '',
    336                 );
    337 
    338                 $post = self::factory()->post->create_and_get( $args );
    339                 setup_postdata( $post );
    340 
    341                 $expect = "<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore  [&hellip;]</p>\n";
    342                 the_excerpt();
    343 
    344                 restore_previous_locale();
    345 
    346                 $this->expectOutputString( $expect );
    347         }
    348 
    349         /**
    350          * @ticket 44541
    351          *
    352          * @covers ::the_excerpt
    353          */
    354         public function test_length_of_excerpt_should_be_counted_by_chars_in_japanese() {
    355                 global $post;
    356 
    357                 switch_to_locale( 'ja_JP' );
    358 
    359                 $args = array(
    360                         'post_content' => str_repeat( 'あ', 200 ),
    361                         'post_excerpt' => '',
    362                 );
    363 
    364                 $post = self::factory()->post->create_and_get( $args );
    365                 setup_postdata( $post );
    366 
    367                 $expect = '<p>' . str_repeat( 'あ', 110 ) . " [&hellip;]</p>\n";
    368                 the_excerpt();
    369 
    370                 restore_previous_locale();
    371 
    372                 $this->expectOutputString( $expect );
    373         }
    374 
    375         /**
    376          * @ticket 44541
    377          *
    378          * @covers ::the_excerpt_rss
    379          */
    380         public function test_length_of_excerpt_rss_should_be_counted_by_words() {
    381                 global $post;
    382 
    383                 switch_to_locale( 'en_US' );
    384 
    385                 $args = array(
    386                         'post_content' => $this->long_text,
    387                         'post_excerpt' => '',
    388                 );
    389 
    390                 $post = self::factory()->post->create_and_get( $args );
    391                 setup_postdata( $post );
    392 
    393                 $expect = 'Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat [&#8230;]';
    394                 the_excerpt_rss();
    395 
    396                 restore_previous_locale();
    397 
    398                 $this->expectOutputString( $expect );
    399         }
    400 
    401         /**
    402          * @ticket 44541
    403          *
    404          * @covers ::the_excerpt_rss
    405          */
    406         public function test_length_of_excerpt_rss_should_be_counted_by_chars() {
    407                 global $post;
    408 
    409                 switch_to_locale( 'ja_JP' );
    410 
    411                 $args = array(
    412                         'post_content' => $this->long_text,
    413                         'post_excerpt' => '',
    414                 );
    415 
    416                 $post = self::factory()->post->create_and_get( $args );
    417                 setup_postdata( $post );
    418 
    419                 $expect = 'Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore  [&#8230;]';
    420 
    421                 the_excerpt_rss();
    422 
    423                 restore_previous_locale();
    424 
    425                 $this->expectOutputString( $expect );
    426         }
    427 
    428         /**
    429          * @ticket 44541
    430          *
    431          * @covers ::wp_dashboard_recent_drafts
    432          */
    433         public function test_length_of_draft_should_be_counted_by_words() {
    434                 require_once ABSPATH . 'wp-admin/includes/dashboard.php';
    435 
    436                 switch_to_locale( 'en_US' );
    437 
    438                 /*
    439                  * The recent drafts list is only displayed on the Dashboard screen for users
    440                  * with the 'edit_posts' capability.
    441                  *
    442                  * This means the current user needs to be set to Editor as a prerequisite
    443                  * for the call to the wp_dashboard_recent_drafts() function.
    444                  *
    445                  * This allows the subsequent call to get_edit_post_link() to work as expected
    446                  * and return a string instead of null, which would otherwise cause a PHP 8.1
    447                  * "passing null to non-nullable" deprecation notice.
    448                  */
    449                 wp_set_current_user( self::factory()->user->create( array( 'role' => 'editor' ) ) );
    450 
    451                 $args = array(
    452                         'post_content' => $this->long_text,
    453                         'post_excerpt' => '',
    454                         'post_status'  => 'draft',
    455                 );
    456 
    457                 self::factory()->post->create( $args );
    458 
    459                 $expect = 'Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do&hellip;';
    460                 $this->expectOutputRegex( '/' . $expect . '/' );
    461 
    462                 wp_dashboard_recent_drafts();
    463 
    464                 restore_previous_locale();
    465         }
    466 
    467         /**
    468          * @ticket 44541
    469          *
    470          * @covers ::wp_dashboard_recent_drafts
    471          */
    472         public function test_length_of_draft_should_be_counted_by_chars() {
    473                 require_once ABSPATH . 'wp-admin/includes/dashboard.php';
    474 
    475                 switch_to_locale( 'ja_JP' );
    476 
    477                 /*
    478                  * The recent drafts list is only displayed on the Dashboard screen for users
    479                  * with the 'edit_posts' capability.
    480                  *
    481                  * This means the current user needs to be set to Editor as a prerequisite
    482                  * for the call to the wp_dashboard_recent_drafts() function.
    483                  *
    484                  * This allows the subsequent call to get_edit_post_link() to work as expected
    485                  * and return a string instead of null, which would otherwise cause a PHP 8.1
    486                  * "passing null to non-nullable" deprecation notice.
    487                  */
    488                 wp_set_current_user( self::factory()->user->create( array( 'role' => 'editor' ) ) );
    489 
    490                 $args = array(
    491                         'post_content' => $this->long_text,
    492                         'post_excerpt' => '',
    493                         'post_status'  => 'draft',
    494                 );
    495 
    496                 $post = self::factory()->post->create( $args );
    497 
    498                 $expect = 'Lorem ipsum dolor sit amet, consectetur &hellip;';
    499                 $this->expectOutputRegex( '/' . $expect . '/' );
    500 
    501                 wp_dashboard_recent_drafts();
    502 
    503                 restore_previous_locale();
    504         }
    505 
    506         /**
    507          * @ticket 44541
    508          *
    509          * @covers ::wp_dashboard_recent_drafts
    510          */
    511         public function test_length_of_draft_should_be_counted_by_chars_in_japanese() {
    512                 require_once ABSPATH . 'wp-admin/includes/dashboard.php';
    513 
    514                 switch_to_locale( 'ja_JP' );
    515 
    516                 /*
    517                  * The recent drafts list is only displayed on the Dashboard screen for users
    518                  * with the 'edit_posts' capability.
    519                  *
    520                  * This means the current user needs to be set to Editor as a prerequisite
    521                  * for the call to the wp_dashboard_recent_drafts() function.
    522                  *
    523                  * This allows the subsequent call to get_edit_post_link() to work as expected
    524                  * and return a string instead of null, which would otherwise cause a PHP 8.1
    525                  * "passing null to non-nullable" deprecation notice.
    526                  */
    527                 wp_set_current_user( self::factory()->user->create( array( 'role' => 'editor' ) ) );
    528 
    529                 $args = array(
    530                         'post_content' => str_repeat( 'あ', 200 ),
    531                         'post_excerpt' => '',
    532                         'post_status'  => 'draft',
    533                 );
    534 
    535                 self::factory()->post->create( $args );
    536 
    537                 $expect = str_repeat( 'あ', 40 ) . '&hellip;';
    538                 $this->expectOutputRegex( '/' . $expect . '/' );
    539 
    540                 wp_dashboard_recent_drafts();
    541 
    542                 restore_previous_locale();
    543         }
    544 
    545         /**
    546          * @ticket 44541
    547          *
    548          * @covers ::get_comment_excerpt
    549          */
    550         public function test_length_of_comment_excerpt_should_be_counted_by_words() {
    551                 switch_to_locale( 'en_US' );
    552 
    553                 $args            = array(
    554                         'comment_content' => $this->long_text,
    555                 );
    556                 $comment_id      = self::factory()->comment->create( $args );
    557                 $expect          = 'Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut&hellip;';
    558                 $comment_excerpt = get_comment_excerpt( $comment_id );
    559 
    560                 restore_previous_locale();
    561 
    562                 $this->assertSame( $expect, $comment_excerpt );
    563         }
    564 
    565         /**
    566          * @ticket 44541
    567          *
    568          * @covers ::get_comment_excerpt
    569          */
    570         public function test_length_of_comment_excerpt_should_be_counted_by_chars() {
    571                 switch_to_locale( 'ja_JP' );
    572 
    573                 $args            = array(
    574                         'comment_content' => $this->long_text,
    575                 );
    576                 $comment_id      = self::factory()->comment->create( $args );
    577                 $expect          = 'Lorem ipsum dolor sit amet, consectetur &hellip;';
    578                 $comment_excerpt = get_comment_excerpt( $comment_id );
    579 
    580                 restore_previous_locale();
    581 
    582                 $this->assertSame( $expect, $comment_excerpt );
    583         }
    584 
    585         /**
    586          * @ticket 44541
    587          *
    588          * @covers ::get_comment_excerpt
    589          */
    590         public function test_length_of_comment_excerpt_should_be_counted_by_chars_in_Japanese() {
    591                 switch_to_locale( 'ja_JP' );
    592 
    593                 $args            = array(
    594                         'comment_content' => str_repeat( 'あ', 200 ),
    595                 );
    596                 $comment_id      = self::factory()->comment->create( $args );
    597                 $expect          = str_repeat( 'あ', 40 ) . '&hellip;';
    598                 $comment_excerpt = get_comment_excerpt( $comment_id );
    599 
    600                 restore_previous_locale();
    601 
    602                 $this->assertSame( $expect, $comment_excerpt );
    603         }
    604167}
Note: See TracChangeset for help on using the changeset viewer.