WordPress.org

Make WordPress Core


Ignore:
Timestamp:
09/02/2020 12:35:36 AM (17 months ago)
Author:
SergeyBiryukov
Message:

Tests: First pass at using assertSame() instead of assertEquals() in most of the unit tests.

This ensures that not only the return values match the expected results, but also that their type is the same.

Going forward, stricter type checking by using assertSame() should generally be preferred to assertEquals() where appropriate, to make the tests more reliable.

Props johnbillion, jrf, SergeyBiryukov.
See #38266.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/tests/phpunit/tests/dependencies/scripts.php

    r48892 r48937  
    5252        $expected .= "<script type='text/javascript' src='http://example.com' id='empty-deps-null-version-js'></script>\n";
    5353
    54         $this->assertEquals( $expected, get_echo( 'wp_print_scripts' ) );
     54        $this->assertSame( $expected, get_echo( 'wp_print_scripts' ) );
    5555
    5656        // No scripts left to print.
    57         $this->assertEquals( '', get_echo( 'wp_print_scripts' ) );
     57        $this->assertSame( '', get_echo( 'wp_print_scripts' ) );
    5858    }
    5959
     
    7272        $expected = "<script src='http://example.com?ver=$ver' id='empty-deps-no-version-js'></script>\n";
    7373
    74         $this->assertEquals( $expected, get_echo( 'wp_print_scripts' ) );
     74        $this->assertSame( $expected, get_echo( 'wp_print_scripts' ) );
    7575    }
    7676
     
    111111
    112112        // Go!
    113         $this->assertEquals( $expected, get_echo( 'wp_print_scripts' ) );
     113        $this->assertSame( $expected, get_echo( 'wp_print_scripts' ) );
    114114
    115115        // No scripts left to print.
    116         $this->assertEquals( '', get_echo( 'wp_print_scripts' ) );
     116        $this->assertSame( '', get_echo( 'wp_print_scripts' ) );
    117117
    118118        // Cleanup.
     
    139139        $expected = "<script type='text/javascript' src='/wp-admin/load-scripts.php?c=0&amp;load%5Bchunk_0%5D=one,two,three&amp;ver={$ver}'></script>\n";
    140140
    141         $this->assertEquals( $expected, $print_scripts );
     141        $this->assertSame( $expected, $print_scripts );
    142142    }
    143143
     
    155155
    156156        // Go!
    157         $this->assertEquals( $expected, get_echo( 'wp_print_scripts' ) );
     157        $this->assertSame( $expected, get_echo( 'wp_print_scripts' ) );
    158158
    159159        // No scripts left to print.
    160         $this->assertEquals( '', get_echo( 'wp_print_scripts' ) );
     160        $this->assertSame( '', get_echo( 'wp_print_scripts' ) );
    161161    }
    162162
     
    173173
    174174        // Go!
    175         $this->assertEquals( $expected, get_echo( 'wp_print_scripts' ) );
     175        $this->assertSame( $expected, get_echo( 'wp_print_scripts' ) );
    176176
    177177        // No scripts left to print.
    178         $this->assertEquals( '', get_echo( 'wp_print_scripts' ) );
     178        $this->assertSame( '', get_echo( 'wp_print_scripts' ) );
    179179    }
    180180
     
    193193
    194194        // Go!
    195         $this->assertEquals( $expected, get_echo( 'wp_print_scripts' ) );
     195        $this->assertSame( $expected, get_echo( 'wp_print_scripts' ) );
    196196
    197197        // No scripts left to print.
    198         $this->assertEquals( '', get_echo( 'wp_print_scripts' ) );
     198        $this->assertSame( '', get_echo( 'wp_print_scripts' ) );
    199199    }
    200200
     
    211211
    212212        // Go!
    213         $this->assertEquals( $expected, get_echo( 'wp_print_scripts' ) );
     213        $this->assertSame( $expected, get_echo( 'wp_print_scripts' ) );
    214214
    215215        // No scripts left to print.
    216         $this->assertEquals( '', get_echo( 'wp_print_scripts' ) );
     216        $this->assertSame( '', get_echo( 'wp_print_scripts' ) );
    217217    }
    218218
     
    240240        wp_enqueue_script( 'handle-three' );
    241241
    242         $this->assertEquals( $expected, get_echo( 'wp_print_scripts' ) );
     242        $this->assertSame( $expected, get_echo( 'wp_print_scripts' ) );
    243243    }
    244244
     
    324324        $expected_footer  = "<script type='text/javascript' src='/parent.js' id='parent-js'></script>\n";
    325325
    326         $this->assertEquals( $expected_header, $header );
    327         $this->assertEquals( $expected_footer, $footer );
     326        $this->assertSame( $expected_header, $header );
     327        $this->assertSame( $expected_footer, $footer );
    328328    }
    329329
     
    345345        $expected_footer .= "<script type='text/javascript' src='/parent.js' id='parent-js'></script>\n";
    346346
    347         $this->assertEquals( $expected_header, $header );
    348         $this->assertEquals( $expected_footer, $footer );
     347        $this->assertSame( $expected_header, $header );
     348        $this->assertSame( $expected_footer, $footer );
    349349    }
    350350
     
    376376        $expected_footer .= "<script type='text/javascript' src='/parent-footer.js' id='parent-footer-js'></script>\n";
    377377
    378         $this->assertEquals( $expected_header, $header );
    379         $this->assertEquals( $expected_footer, $footer );
     378        $this->assertSame( $expected_header, $header );
     379        $this->assertSame( $expected_footer, $footer );
    380380    }
    381381
     
    394394    function test_wp_add_inline_script_unknown_handle() {
    395395        $this->assertFalse( wp_add_inline_script( 'test-invalid', 'console.log("before");', 'before' ) );
    396         $this->assertEquals( '', get_echo( 'wp_print_scripts' ) );
     396        $this->assertSame( '', get_echo( 'wp_print_scripts' ) );
    397397    }
    398398
     
    407407        $expected .= "<script type='text/javascript' src='http://example.com' id='test-example-js'></script>\n";
    408408
    409         $this->assertEquals( $expected, get_echo( 'wp_print_scripts' ) );
     409        $this->assertSame( $expected, get_echo( 'wp_print_scripts' ) );
    410410    }
    411411
     
    420420        $expected .= "<script type='text/javascript' id='test-example-js-after'>\nconsole.log(\"after\");\n</script>\n";
    421421
    422         $this->assertEquals( $expected, get_echo( 'wp_print_scripts' ) );
     422        $this->assertSame( $expected, get_echo( 'wp_print_scripts' ) );
    423423    }
    424424
     
    435435        $expected .= "<script type='text/javascript' id='test-example-js-after'>\nconsole.log(\"after\");\n</script>\n";
    436436
    437         $this->assertEquals( $expected, get_echo( 'wp_print_scripts' ) );
     437        $this->assertSame( $expected, get_echo( 'wp_print_scripts' ) );
    438438    }
    439439
     
    448448        $expected = "<script type='text/javascript' id='test-example-js-before'>\nconsole.log(\"before\");\n</script>\n";
    449449
    450         $this->assertEquals( $expected, get_echo( 'wp_print_scripts' ) );
     450        $this->assertSame( $expected, get_echo( 'wp_print_scripts' ) );
    451451    }
    452452
     
    461461        $expected = "<script type='text/javascript' id='test-example-js-after'>\nconsole.log(\"after\");\n</script>\n";
    462462
    463         $this->assertEquals( $expected, get_echo( 'wp_print_scripts' ) );
     463        $this->assertSame( $expected, get_echo( 'wp_print_scripts' ) );
    464464    }
    465465
     
    476476        $expected .= "<script type='text/javascript' id='test-example-js-after'>\nconsole.log(\"after\");\n</script>\n";
    477477
    478         $this->assertEquals( $expected, get_echo( 'wp_print_scripts' ) );
     478        $this->assertSame( $expected, get_echo( 'wp_print_scripts' ) );
    479479    }
    480480
     
    493493        $expected .= "<script type='text/javascript' id='test-example-js-after'>\nconsole.log(\"after\");\nconsole.log(\"after\");\n</script>\n";
    494494
    495         $this->assertEquals( $expected, get_echo( 'wp_print_scripts' ) );
     495        $this->assertSame( $expected, get_echo( 'wp_print_scripts' ) );
    496496    }
    497497
     
    510510        $expected .= "<script type='text/javascript' id='test-example-js-after'>\nconsole.log(\"after\");\n</script>\n";
    511511
    512         $this->assertEquals( $expected, get_echo( 'wp_print_scripts' ) );
     512        $this->assertSame( $expected, get_echo( 'wp_print_scripts' ) );
    513513    }
    514514
     
    536536        $expected .= "<script type='text/javascript' src='/directory/three.js?ver={$ver}' id='three-js'></script>\n";
    537537
    538         $this->assertEquals( $expected, get_echo( 'wp_print_scripts' ) );
     538        $this->assertSame( $expected, get_echo( 'wp_print_scripts' ) );
    539539    }
    540540
     
    560560        $expected .= "<script type='text/javascript' src='/directory/three.js?ver={$ver}' id='three-js'></script>\n";
    561561
    562         $this->assertEquals( $expected, get_echo( 'wp_print_scripts' ) );
     562        $this->assertSame( $expected, get_echo( 'wp_print_scripts' ) );
    563563    }
    564564
     
    588588        $expected .= "<script type='text/javascript' src='/directory/four.js?ver={$ver}' id='four-js'></script>\n";
    589589
    590         $this->assertEquals( $expected, get_echo( 'wp_print_scripts' ) );
     590        $this->assertSame( $expected, get_echo( 'wp_print_scripts' ) );
    591591    }
    592592
     
    616616        wp_script_add_data( 'test-example', 'conditional', 'gte IE 9' );
    617617
    618         $this->assertEquals( $expected_localized, get_echo( 'wp_print_scripts' ) );
    619         $this->assertEquals( $expected, $wp_scripts->print_html );
     618        $this->assertSame( $expected_localized, get_echo( 'wp_print_scripts' ) );
     619        $this->assertSame( $expected, $wp_scripts->print_html );
    620620        $this->assertTrue( $wp_scripts->do_concat );
    621621    }
     
    643643        $print_scripts = get_echo( '_print_scripts' );
    644644
    645         $this->assertEquals( $expected, $print_scripts );
     645        $this->assertSame( $expected, $print_scripts );
    646646    }
    647647
     
    671671        $print_scripts = get_echo( '_print_scripts' );
    672672
    673         $this->assertEquals( $expected, $print_scripts );
     673        $this->assertSame( $expected, $print_scripts );
    674674    }
    675675
     
    697697        $print_scripts = get_echo( '_print_scripts' );
    698698
    699         $this->assertEquals( $expected, $print_scripts );
     699        $this->assertSame( $expected, $print_scripts );
    700700    }
    701701
     
    753753        );
    754754
    755         $this->assertEqualsIgnoreEOL( $expected, $print_scripts );
     755        $this->assertSameIgnoreEOL( $expected, $print_scripts );
    756756    }
    757757
     
    781781
    782782        $tail = substr( $print_scripts, strrpos( $print_scripts, "<script type='text/javascript' src='/customize-dependency.js' id='customize-dependency-js'>" ) );
    783         $this->assertEquals( $expected_tail, $tail );
     783        $this->assertSame( $expected_tail, $tail );
    784784    }
    785785
     
    806806        $expected .= "<script type='text/javascript' src='/wp-includes/js/script4.js?ver={$ver}' id='four-js'></script>\n";
    807807
    808         $this->assertEquals( $expected, get_echo( 'wp_print_scripts' ) );
     808        $this->assertSame( $expected, get_echo( 'wp_print_scripts' ) );
    809809    }
    810810
     
    830830        $expected .= "<script type='text/javascript' src='/wp-includes/js/script4.js?ver={$ver}' id='four-js'></script>\n";
    831831
    832         $this->assertEquals( $expected, get_echo( 'wp_print_scripts' ) );
     832        $this->assertSame( $expected, get_echo( 'wp_print_scripts' ) );
    833833    }
    834834
     
    857857        $expected .= "<script type='text/javascript' src='/wp-includes/js/script.js' id='test-example-js'></script>\n";
    858858
    859         $this->assertEqualsIgnoreEOL( $expected, get_echo( 'wp_print_scripts' ) );
     859        $this->assertSameIgnoreEOL( $expected, get_echo( 'wp_print_scripts' ) );
    860860    }
    861861
     
    884884        $expected .= "<script type='text/javascript' src='/wp-content/plugins/my-plugin/js/script.js' id='plugin-example-js'></script>\n";
    885885
    886         $this->assertEqualsIgnoreEOL( $expected, get_echo( 'wp_print_scripts' ) );
     886        $this->assertSameIgnoreEOL( $expected, get_echo( 'wp_print_scripts' ) );
    887887    }
    888888
     
    911911        $expected .= "<script type='text/javascript' src='/wp-content/themes/my-theme/js/script.js' id='theme-example-js'></script>\n";
    912912
    913         $this->assertEqualsIgnoreEOL( $expected, get_echo( 'wp_print_scripts' ) );
     913        $this->assertSameIgnoreEOL( $expected, get_echo( 'wp_print_scripts' ) );
    914914    }
    915915
     
    938938        $expected .= "<script type='text/javascript' src='/wp-admin/js/script.js' id='script-handle-js'></script>\n";
    939939
    940         $this->assertEqualsIgnoreEOL( $expected, get_echo( 'wp_print_scripts' ) );
     940        $this->assertSameIgnoreEOL( $expected, get_echo( 'wp_print_scripts' ) );
    941941    }
    942942
     
    980980        $expected .= "<script type='text/javascript' src='/wp-admin/js/script.js' id='test-example-js'></script>\n";
    981981
    982         $this->assertEqualsIgnoreEOL( $expected, get_echo( 'wp_print_scripts' ) );
     982        $this->assertSameIgnoreEOL( $expected, get_echo( 'wp_print_scripts' ) );
    983983    }
    984984
     
    10091009        $expected .= "<script type='text/javascript' src='/wp-includes/js/script.js' id='test-example-js'></script>\n";
    10101010
    1011         $this->assertEqualsIgnoreEOL( $expected, get_echo( 'wp_print_scripts' ) );
     1011        $this->assertSameIgnoreEOL( $expected, get_echo( 'wp_print_scripts' ) );
    10121012    }
    10131013
     
    10391039        $expected .= "<script type='text/javascript' src='/wp-includes/js/script2.js' id='test-example-js'></script>\n";
    10401040
    1041         $this->assertEqualsIgnoreEOL( $expected, get_echo( 'wp_print_scripts' ) );
     1041        $this->assertSameIgnoreEOL( $expected, get_echo( 'wp_print_scripts' ) );
    10421042    }
    10431043
Note: See TracChangeset for help on using the changeset viewer.