Skip to content

Commit 9cee595

Browse files
committed
Tests: Prevent unconditional HTTP request in PluralFormsTest data provider.
Developed in WordPress#11382 Follow-up to r41722. Props westonruter, swissspidy, SergeyBiryukov. See #41562. Fixes #41562. git-svn-id: https://develop.svn.wordpress.org/trunk@62174 602fd350-edb4-49c9-b593-d223f7449a82
1 parent 1967f10 commit 9cee595

File tree

1 file changed

+22
-13
lines changed

1 file changed

+22
-13
lines changed

tests/phpunit/tests/pomo/pluralForms.php

Lines changed: 22 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -39,25 +39,26 @@ protected static function parenthesize_plural_expression( $expression ) {
3939

4040
/**
4141
* @ticket 41562
42-
* @dataProvider data_locales
4342
* @group external-http
4443
*/
45-
public function test_regression( $lang, $nplurals, $expression ) {
44+
public function test_regression(): void {
4645
require_once dirname( __DIR__, 2 ) . '/includes/plural-form-function.php';
4746

48-
$parenthesized = self::parenthesize_plural_expression( $expression );
49-
$old_style = tests_make_plural_form_function( $nplurals, $parenthesized );
50-
$plural_forms = new Plural_Forms( $expression );
47+
foreach ( self::data_locales() as list( $lang, $nplurals, $expression ) ) {
48+
$parenthesized = self::parenthesize_plural_expression( $expression );
49+
$old_style = tests_make_plural_form_function( $nplurals, $parenthesized );
50+
$plural_forms = new Plural_Forms( $expression );
5151

52-
$generated_old = array();
53-
$generated_new = array();
52+
$generated_old = array();
53+
$generated_new = array();
5454

55-
foreach ( range( 0, 200 ) as $i ) {
56-
$generated_old[] = $old_style( $i );
57-
$generated_new[] = $plural_forms->get( $i );
58-
}
55+
foreach ( range( 0, 200 ) as $i ) {
56+
$generated_old[] = $old_style( $i );
57+
$generated_new[] = $plural_forms->get( $i );
58+
}
5959

60-
$this->assertSame( $generated_old, $generated_new );
60+
$this->assertSame( $generated_old, $generated_new );
61+
}
6162
}
6263

6364
/**
@@ -70,7 +71,15 @@ public function test_locales_file_not_empty() {
7071
$this->assertNotEmpty( $locales, 'Unable to retrieve GP_Locales file' );
7172
}
7273

73-
public static function data_locales() {
74+
/**
75+
* Gets locale data.
76+
*
77+
* Note: Do not use this method directly as a data provider, or else it may cause an unconditional HTTP request
78+
* during PHPUnit initialization. See <https://core.trac.wordpress.org/ticket/64963>.
79+
*
80+
* @return array<int, array{ 0: string, 1: int, 2: string }>
81+
*/
82+
public static function data_locales(): array {
7483
if ( ! class_exists( 'GP_Locales' ) ) {
7584
$filename = download_url( 'https://raw.githubusercontent.com/GlotPress/GlotPress-WP/develop/locales/locales.php' );
7685
if ( is_wp_error( $filename ) ) {

0 commit comments

Comments
 (0)