Make WordPress Core

Changeset 53686


Ignore:
Timestamp:
07/07/2022 11:55:13 PM (3 years ago)
Author:
SergeyBiryukov
Message:

Tests: Separate the tests in basic.php for clarity.

There were two kinds of tests in this file:

  • Tests for content of some files in the root directory:
    • license.txt
    • SECURITY.md
    • package.json
  • Tests for some utility functions of the test framework itself:
    • strip_ws()
    • test_mask_input_value()

The latter are now moved to their own file, utils.php.

Follow-up to [22/tests], [81/tests], [103/tests], [25240], [26940], [28064], [28480], [28493], [28523], [28631], [42381], [47403], [53683].

See #39265, #55652.

Location:
trunk/tests/phpunit/tests
Files:
1 edited
1 copied

Legend:

Unmodified
Added
Removed
  • trunk/tests/phpunit/tests/basic.php

    r53683 r53686  
    22
    33/**
    4  * just make sure the test framework is working
     4 * Test the content in some root directory files.
    55 *
    6  * No Covers as this checks for content in files
    7  *
    8  * @group testsuite
     6 * @group basic
    97 */
    108class Tests_Basic extends WP_UnitTestCase {
     
    6866        $this->assertArrayHasKey( 'node', $package_json['engines'] );
    6967    }
    70 
    71     /**
    72      * Test some helper utility functions.
    73      *
    74      * @coversNothing
    75      */
    76     public function test_strip_ws() {
    77         $this->assertSame( '', strip_ws( '' ) );
    78         $this->assertSame( 'foo', strip_ws( 'foo' ) );
    79         $this->assertSame( '', strip_ws( "\r\n\t  \n\r\t" ) );
    80 
    81         $in  = "asdf\n";
    82         $in .= "asdf asdf\n";
    83         $in .= "asdf     asdf\n";
    84         $in .= "\tasdf\n";
    85         $in .= "\tasdf\t\n";
    86         $in .= "\t\tasdf\n";
    87         $in .= "foo bar\n\r\n";
    88         $in .= "foo\n";
    89 
    90         $expected  = "asdf\n";
    91         $expected .= "asdf asdf\n";
    92         $expected .= "asdf     asdf\n";
    93         $expected .= "asdf\n";
    94         $expected .= "asdf\n";
    95         $expected .= "asdf\n";
    96         $expected .= "foo bar\n";
    97         $expected .= 'foo';
    98 
    99         $this->assertSame( $expected, strip_ws( $in ) );
    100 
    101     }
    102 
    103     /**
    104      * @coversNothing
    105      */
    106     public function test_mask_input_value() {
    107         $in = <<<EOF
    108 <h2>Assign Authors</h2>
    109 <p>To make it easier for you to edit and save the imported posts and drafts, you may want to change the name of the author of the posts. For example, you may want to import all the entries as <code>admin</code>s entries.</p>
    110 <p>If a new user is created by WordPress, the password will be set, by default, to "changeme". Quite suggestive, eh? ;)</p>
    111         <ol id="authors"><form action="?import=wordpress&amp;step=2&amp;id=" method="post"><input type="hidden" name="_wpnonce" value="855ae98911" /><input type="hidden" name="_wp_http_referer" value="wp-test.php" /><li>Current author: <strong>Alex Shiels</strong><br />Create user  <input type="text" value="Alex Shiels" name="user[]" maxlength="30"> <br /> or map to existing<select name="userselect[0]">
    112 EOF;
    113         // _wpnonce value should be replaced with 'xxx'.
    114         $expected = <<<EOF
    115 <h2>Assign Authors</h2>
    116 <p>To make it easier for you to edit and save the imported posts and drafts, you may want to change the name of the author of the posts. For example, you may want to import all the entries as <code>admin</code>s entries.</p>
    117 <p>If a new user is created by WordPress, the password will be set, by default, to "changeme". Quite suggestive, eh? ;)</p>
    118         <ol id="authors"><form action="?import=wordpress&amp;step=2&amp;id=" method="post"><input type="hidden" name="_wpnonce" value="***" /><input type="hidden" name="_wp_http_referer" value="wp-test.php" /><li>Current author: <strong>Alex Shiels</strong><br />Create user  <input type="text" value="Alex Shiels" name="user[]" maxlength="30"> <br /> or map to existing<select name="userselect[0]">
    119 EOF;
    120         $this->assertSame( $expected, mask_input_value( $in ) );
    121     }
    12268}
  • trunk/tests/phpunit/tests/utils.php

    r53684 r53686  
    22
    33/**
    4  * just make sure the test framework is working
    5  *
    6  * No Covers as this checks for content in files
     4 * Test some helper utility functions of the test framework.
    75 *
    86 * @group testsuite
    97 */
    10 class Tests_Basic extends WP_UnitTestCase {
     8class Tests_Utils extends WP_UnitTestCase {
    119
    1210    /**
    13      * @coversNothing
    14      */
    15     public function test_license() {
    16         // This test is designed to only run on trunk.
    17         $this->skipOnAutomatedBranches();
    18 
    19         $license = file_get_contents( ABSPATH . 'license.txt' );
    20         preg_match( '#Copyright 2011-(\d+) by the contributors#', $license, $matches );
    21         $license_year = trim( $matches[1] );
    22         $this_year    = gmdate( 'Y' );
    23 
    24         $this->assertSame( $this_year, $license_year, "license.txt's year needs to be updated to $this_year." );
    25     }
    26 
    27     /**
    28      * @coversNothing
    29      */
    30     public function test_security_md() {
    31         // This test is designed to only run on trunk.
    32         $this->skipOnAutomatedBranches();
    33 
    34         $security = file_get_contents( dirname( ABSPATH ) . '/SECURITY.md' );
    35         preg_match_all( '#\d.\d.x#', $security, $matches );
    36         $supported_versions = $matches[0];
    37         $current_version    = substr( $GLOBALS['wp_version'], 0, 3 );
    38         $latest_stable      = number_format( (float) $current_version - 0.1, 1 ) . '.x';
    39 
    40         $this->assertContains( $latest_stable, $supported_versions, "SECURITY.md's version needs to be updated to $latest_stable." );
    41     }
    42 
    43     /**
    44      * @coversNothing
    45      */
    46     public function test_package_json() {
    47         $package_json    = file_get_contents( dirname( ABSPATH ) . '/package.json' );
    48         $package_json    = json_decode( $package_json, true );
    49         list( $version ) = explode( '-', $GLOBALS['wp_version'] );
    50 
    51         // package.json uses x.y.z, so fill cleaned $wp_version for .0 releases.
    52         if ( 1 === substr_count( $version, '.' ) ) {
    53             $version .= '.0';
    54         }
    55 
    56         $this->assertSame( $version, $package_json['version'], "package.json's version needs to be updated to $version." );
    57 
    58         return $package_json;
    59     }
    60 
    61     /**
    62      * @depends test_package_json
    63      *
    64      * @coversNothing
    65      */
    66     public function test_package_json_node_engine( $package_json ) {
    67         $this->assertArrayHasKey( 'engines', $package_json );
    68         $this->assertArrayHasKey( 'node', $package_json['engines'] );
    69     }
    70 
    71     /**
    72      * Test some helper utility functions.
    73      *
    74      * @coversNothing
     11     * @covers ::test_strip_ws
    7512     */
    7613    public function test_strip_ws() {
     
    10239
    10340    /**
    104      * @coversNothing
     41     * @covers ::mask_input_value
    10542     */
    10643    public function test_mask_input_value() {
Note: See TracChangeset for help on using the changeset viewer.