Make WordPress Core

Changeset 53850


Ignore:
Timestamp:
08/07/2022 01:56:35 PM (2 years ago)
Author:
SergeyBiryukov
Message:

Code Modernization: Remove dynamic properties in Tests_POMO_PO.

In this particular case, the test class contains a set_up() method which sets properties only used by select tests, while the fixture method is being run for all tests.

There were a few ways this could be fixed:

  • As the values do not change across tests, use set_up_before_class() to set (static) properties instead.
  • For those values which are set up without a function call or variable interpolation, set the values in class constants.
  • Or set these values as local variables for those tests which actually use them.

The implemented solution is a combination of options 2 and 3.

Follow-up to [1106/tests], [53557], [53558].

Props jrf.
See #56033.

File:
1 edited

Legend:

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

    r52010 r53850  
    66class Tests_POMO_PO extends WP_UnitTestCase {
    77
    8     public static function set_up_before_class() {
    9         parent::set_up_before_class();
    10 
    11         require_once ABSPATH . '/wp-includes/pomo/po.php';
    12     }
    13 
    14     public function set_up() {
    15         parent::set_up();
    16 
    17         // Not so random wordpress.pot string -- multiple lines.
    18         $this->mail    = 'Your new WordPress blog has been successfully set up at:
     8    /**
     9     * Mail content.
     10     *
     11     * @var string
     12     */
     13    const MAIL_TEXT = 'Your new WordPress blog has been successfully set up at:
    1914
    2015%1$s
     
    3025http://wordpress.org/
    3126';
    32         $this->mail    = str_replace( "\r\n", "\n", $this->mail );
    33         $this->po_mail = '""
     27
     28    /**
     29     * Mail content for translation readiness.
     30     *
     31     * @var string
     32     */
     33    const PO_MAIL = '""
    3434"Your new WordPress blog has been successfully set up at:\n"
    3535"\n"
     
    4545"--The WordPress Team\n"
    4646"http://wordpress.org/\n"';
    47         $this->a90     = str_repeat( 'a', 90 );
    48         $this->po_a90  = "\"$this->a90\"";
     47
     48    public static function set_up_before_class() {
     49        parent::set_up_before_class();
     50
     51        require_once ABSPATH . '/wp-includes/pomo/po.php';
    4952    }
    5053
     
    6164        $this->assertSame( '"baba"', $po->poify( 'baba' ) );
    6265        // Long word.
    63         $this->assertSame( $this->po_a90, $po->poify( $this->a90 ) );
     66        $long_word    = str_repeat( 'a', 90 );
     67        $po_long_word = "\"$long_word\"";
     68        $this->assertSame( $po_long_word, $po->poify( $long_word ) );
    6469        // Tab.
    6570        $this->assertSame( '"ba\tba"', $po->poify( "ba\tba" ) );
     
    7277        $this->assertSame( '"Categories can be selectively converted to tags using the <a href=\\"%s\\">category to tag converter</a>."', $po->poify( $src ) );
    7378
    74         $this->assertSameIgnoreEOL( $this->po_mail, $po->poify( $this->mail ) );
     79        $mail = str_replace( "\r\n", "\n", self::MAIL_TEXT );
     80        $this->assertSameIgnoreEOL( self::PO_MAIL, $po->poify( $mail ) );
    7581    }
    7682
     
    7985        $this->assertSame( 'baba', $po->unpoify( '"baba"' ) );
    8086        $this->assertSame( "baba\ngugu", $po->unpoify( '"baba\n"' . "\t\t\t\n" . '"gugu"' ) );
    81         $this->assertSame( $this->a90, $po->unpoify( $this->po_a90 ) );
     87
     88        $long_word    = str_repeat( 'a', 90 );
     89        $po_long_word = "\"$long_word\"";
     90        $this->assertSame( $long_word, $po->unpoify( $po_long_word ) );
    8291        $this->assertSame( '\\t\\n', $po->unpoify( '"\\\\t\\\\n"' ) );
    8392        // Wordwrapped.
    8493        $this->assertSame( 'babadyado', $po->unpoify( "\"\"\n\"baba\"\n\"dyado\"" ) );
    85         $this->assertSameIgnoreEOL( $this->mail, $po->unpoify( $this->po_mail ) );
     94
     95        $mail = str_replace( "\r\n", "\n", self::MAIL_TEXT );
     96        $this->assertSameIgnoreEOL( $mail, $po->unpoify( self::PO_MAIL ) );
    8697    }
    8798
Note: See TracChangeset for help on using the changeset viewer.