Changeset 55562 for trunk/tests/phpunit/tests/pomo/pluralForms.php
- Timestamp:
- 03/19/2023 12:03:30 PM (2 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/tests/phpunit/tests/pomo/pluralForms.php
r48999 r55562 40 40 /** 41 41 * @ticket 41562 42 * @dataProvider data_locales 42 43 * @group external-http 43 44 */ 44 public function test_locales_provider() { 45 $locales = self::locales_provider(); 45 public function test_regression( $lang, $nplurals, $expression ) { 46 require_once dirname( dirname( __DIR__ ) ) . '/includes/plural-form-function.php'; 47 48 $parenthesized = self::parenthesize_plural_expression( $expression ); 49 $old_style = tests_make_plural_form_function( $nplurals, $parenthesized ); 50 $plural_forms = new Plural_Forms( $expression ); 51 52 $generated_old = array(); 53 $generated_new = array(); 54 55 foreach ( range( 0, 200 ) as $i ) { 56 $generated_old[] = $old_style( $i ); 57 $generated_new[] = $plural_forms->get( $i ); 58 } 59 60 $this->assertSame( $generated_old, $generated_new ); 61 } 62 63 /** 64 * @ticket 41562 65 * @group external-http 66 */ 67 public function test_locales_file_not_empty() { 68 $locales = self::data_locales(); 46 69 47 70 $this->assertNotEmpty( $locales, 'Unable to retrieve GP_Locales file' ); 48 71 } 49 72 50 public static function locales_provider() {73 public static function data_locales() { 51 74 if ( ! class_exists( 'GP_Locales' ) ) { 52 75 $filename = download_url( 'https://raw.githubusercontent.com/GlotPress/GlotPress-WP/develop/locales/locales.php' ); … … 71 94 /** 72 95 * @ticket 41562 73 * @dataProvider locales_provider 74 * @group external-http 75 */ 76 public function test_regression( $lang, $nplurals, $expression ) { 77 require_once dirname( dirname( __DIR__ ) ) . '/includes/plural-form-function.php'; 78 79 $parenthesized = self::parenthesize_plural_expression( $expression ); 80 $old_style = tests_make_plural_form_function( $nplurals, $parenthesized ); 81 $plural_forms = new Plural_Forms( $expression ); 82 83 $generated_old = array(); 84 $generated_new = array(); 85 86 foreach ( range( 0, 200 ) as $i ) { 87 $generated_old[] = $old_style( $i ); 88 $generated_new[] = $plural_forms->get( $i ); 89 } 90 91 $this->assertSame( $generated_old, $generated_new ); 92 } 93 94 public static function simple_provider() { 96 * @dataProvider data_simple 97 */ 98 public function test_simple( $expression, $expected ) { 99 $plural_forms = new Plural_Forms( $expression ); 100 $actual = array(); 101 foreach ( array_keys( $expected ) as $num ) { 102 $actual[ $num ] = $plural_forms->get( $num ); 103 } 104 105 $this->assertSame( $expected, $actual ); 106 } 107 108 public static function data_simple() { 95 109 return array( 96 110 array( … … 144 158 145 159 /** 146 * @ticket 41562 147 * @dataProvider simple_provider 148 */ 149 public function test_simple( $expression, $expected ) { 160 * Ensures that an exception is thrown when an invalid plural form is encountered. 161 * 162 * @ticket 41562 163 * @dataProvider data_exceptions 164 */ 165 public function test_exceptions( $expression, $expected_message, $call_get ) { 166 $this->expectException( 'Exception' ); 167 $this->expectExceptionMessage( $expected_message ); 168 150 169 $plural_forms = new Plural_Forms( $expression ); 151 $actual = array(); 152 foreach ( array_keys( $expected ) as $num ) { 153 $actual[ $num ] = $plural_forms->get( $num ); 154 } 155 156 $this->assertSame( $expected, $actual ); 170 if ( $call_get ) { 171 $plural_forms->get( 1 ); 172 } 157 173 } 158 174 … … 195 211 ), 196 212 ); 197 }198 199 /**200 * Ensures that an exception is thrown when an invalid plural form is encountered.201 *202 * @ticket 41562203 * @dataProvider data_exceptions204 */205 public function test_exceptions( $expression, $expected_message, $call_get ) {206 $this->expectException( 'Exception' );207 $this->expectExceptionMessage( $expected_message );208 209 $plural_forms = new Plural_Forms( $expression );210 if ( $call_get ) {211 $plural_forms->get( 1 );212 }213 213 } 214 214
Note: See TracChangeset
for help on using the changeset viewer.