Changeset 41730
- Timestamp:
- 10/04/2017 01:26:15 PM (7 years ago)
- Location:
- trunk/tests/phpunit
- Files:
-
- 1 added
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/tests/phpunit/tests/pomo/pluralForms.php
r41725 r41730 5 5 */ 6 6 class PluralFormsTest extends WP_UnitTestCase { 7 /**8 * Legacy plural form function.9 *10 * @param int $nplurals11 * @param string $expression12 */13 protected static function make_plural_form_function($nplurals, $expression) {14 $expression = str_replace('n', '$n', $expression);15 $func_body = "16 \$index = (int)($expression);17 return (\$index < $nplurals)? \$index : $nplurals - 1;";18 return create_function('$n', $func_body);19 }20 21 7 /** 22 8 * Parenthesize plural expression. … … 52 38 } 53 39 40 /** 41 * @ticket 41562 42 * @group external-http 43 */ 44 public function test_locales_provider() { 45 $locales = self::locales_provider(); 46 47 $this->assertNotEmpty( $locales, 'Unable to retrieve GP_Locales file' ); 48 } 49 54 50 public static function locales_provider() { 55 51 if ( ! class_exists( 'GP_Locales' ) ) { 56 52 $filename = download_url( 'https://raw.githubusercontent.com/GlotPress/GlotPress-WP/develop/locales/locales.php' ); 57 53 if ( is_wp_error( $filename ) ) { 58 self::markTestSkipped( 'Unable to retrieve GP_Locales file');54 return array(); 59 55 } 60 56 require_once $filename; … … 74 70 75 71 /** 72 * @ticket 41562 76 73 * @dataProvider locales_provider 77 74 * @group external-http 78 75 */ 79 76 public function test_regression( $lang, $nplurals, $expression ) { 77 if ( version_compare( phpversion(), '7.2', '>=' ) ) { 78 $this->markTestSkipped( 'Lambda functions are deprecated in PHP 7.2' ); 79 } 80 81 require_once dirname( dirname( dirname( __FILE__ ) ) ) . '/includes/plural-form-function.php'; 82 80 83 $parenthesized = self::parenthesize_plural_expression( $expression ); 81 $old_style = self::make_plural_form_function( $nplurals, $parenthesized );84 $old_style = tests_make_plural_form_function( $nplurals, $parenthesized ); 82 85 $pluralForms = new Plural_Forms( $expression ); 83 86 … … 145 148 146 149 /** 150 * @ticket 41562 147 151 * @dataProvider simple_provider 148 152 */ … … 198 202 199 203 /** 204 * Ensures that an exception is thrown when an invalid plural form is encountered. 205 * 206 * The `@expectedException Exception` notation for PHPUnit cannot be used because expecting an 207 * exception of type `Exception` is not supported before PHPUnit 3.7. The CI tests for PHP 5.2 208 * run on PHPUnit 3.6. 209 * 210 * @ticket 41562 200 211 * @dataProvider data_exceptions 201 212 */ … … 208 219 } catch ( Exception $e ) { 209 220 $this->assertEquals( $expected_exception, $e->getMessage() ); 210 } 211 } 212 221 return; 222 } 223 224 $this->fail( 'Expected exception was not thrown.' ); 225 } 226 227 /** 228 * @ticket 41562 229 */ 213 230 public function test_cache() { 214 231 $mock = $this->getMockBuilder( 'Plural_Forms' )
Note: See TracChangeset
for help on using the changeset viewer.