Make WordPress Core


Ignore:
Timestamp:
03/19/2023 12:03:30 PM (3 years ago)
Author:
SergeyBiryukov
Message:

Tests: Use the data_ prefix for various data provider methods.

This aims to bring more consistency to the test suite, as the vast majority of data providers already use that prefix.

Includes moving some data providers next to the tests they are used in.

Follow-up to [55464].

See #57841.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/tests/phpunit/tests/pomo/pluralForms.php

    r48999 r55562  
    4040        /**
    4141         * @ticket 41562
     42         * @dataProvider data_locales
    4243         * @group external-http
    4344         */
    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();
    4669
    4770                $this->assertNotEmpty( $locales, 'Unable to retrieve GP_Locales file' );
    4871        }
    4972
    50         public static function locales_provider() {
     73        public static function data_locales() {
    5174                if ( ! class_exists( 'GP_Locales' ) ) {
    5275                        $filename = download_url( 'https://raw.githubusercontent.com/GlotPress/GlotPress-WP/develop/locales/locales.php' );
     
    7194        /**
    7295         * @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() {
    95109                return array(
    96110                        array(
     
    144158
    145159        /**
    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
    150169                $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                }
    157173        }
    158174
     
    195211                        ),
    196212                );
    197         }
    198 
    199         /**
    200          * Ensures that an exception is thrown when an invalid plural form is encountered.
    201          *
    202          * @ticket 41562
    203          * @dataProvider data_exceptions
    204          */
    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                 }
    213213        }
    214214
Note: See TracChangeset for help on using the changeset viewer.