Make WordPress Core


Ignore:
Timestamp:
10/16/2015 09:04:12 PM (11 years ago)
Author:
wonderboymusic
Message:

Unit Tests: one $factory to rule them all, and it shall be static.

Using more than one instance of WP_UnitTest_Factory causes all kinds of craziness, due to out-of-sync internal generator sequences. Since we want to use setUpBeforeClass, we were creating ad hoc instances. To avoid that, we were injecting one static instance via Dependency Injection in wpSetUpBeforeClass. All tests should really use the static instance, so we will remove the instance prop $factory.

Replace $this->factory with self::$factory over 2000 times.
Rewrite all of the tests that were hard-coding dynamic values.

#YOLOFriday

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/tests/phpunit/tests/post/formats.php

    r25002 r35225  
    1010
    1111    function test_set_get_post_format_for_post() {
    12         $post_id = $this->factory->post->create();
     12        $post_id = self::$factory->post->create();
    1313
    1414        $format = get_post_format( $post_id );
     
    3838     */
    3939    function test_set_get_post_format_for_page() {
    40         $post_id = $this->factory->post->create( array( 'post_type' => 'page' ) );
     40        $post_id = self::$factory->post->create( array( 'post_type' => 'page' ) );
    4141
    4242        $format = get_post_format( $post_id );
     
    7070
    7171    function test_has_format() {
    72         $post_id = $this->factory->post->create();
     72        $post_id = self::$factory->post->create();
    7373
    7474        $this->assertFalse( has_post_format( 'standard', $post_id ) );
     
    112112$commentary
    113113DATA;
    114         $link_post_id = $this->factory->post->create( array( 'post_content' => $link ) );
     114        $link_post_id = self::$factory->post->create( array( 'post_content' => $link ) );
    115115        $content_link = get_url_in_content( get_post_field( 'post_content', $link_post_id ) );
    116116        $this->assertEquals( false, $content_link );
    117117
    118         $link_with_post_id = $this->factory->post->create( array( 'post_content' => $link_with_commentary ) );
     118        $link_with_post_id = self::$factory->post->create( array( 'post_content' => $link_with_commentary ) );
    119119        $content_link = get_url_in_content( get_post_field( 'post_content', $link_with_post_id ) );
    120120        $this->assertEquals( false, $content_link );
     
    126126        $this->assertEquals( false, $content_link );
    127127
    128         $empty_post_id = $this->factory->post->create( array( 'post_content' => '' ) );
     128        $empty_post_id = self::$factory->post->create( array( 'post_content' => '' ) );
    129129        $content_link = get_url_in_content( get_post_field( 'post_content', $empty_post_id ) );
    130130        $this->assertEquals( false, $content_link );
    131131
    132         $comm_post_id = $this->factory->post->create( array( 'post_content' => $commentary ) );
     132        $comm_post_id = self::$factory->post->create( array( 'post_content' => $commentary ) );
    133133        $content_link = get_url_in_content( get_post_field( 'post_content', $comm_post_id ) );
    134134        $this->assertEquals( false, $content_link );
    135135
    136136        // Now with an href
    137         $href_post_id = $this->factory->post->create( array( 'post_content' => $href ) );
     137        $href_post_id = self::$factory->post->create( array( 'post_content' => $href ) );
    138138        $content_link = get_url_in_content( get_post_field( 'post_content', $href_post_id ) );
    139139        $this->assertEquals( $link, $content_link );
    140140
    141         $href_with_post_id = $this->factory->post->create( array( 'post_content' => $href_with_commentary ) );
     141        $href_with_post_id = self::$factory->post->create( array( 'post_content' => $href_with_commentary ) );
    142142        $content_link = get_url_in_content( get_post_field( 'post_content', $href_with_post_id ) );
    143143        $this->assertEquals( $link, $content_link );
     
    149149        $this->assertEquals( $link, $content_link );
    150150
    151         $empty_post_id = $this->factory->post->create( array( 'post_content' => '' ) );
     151        $empty_post_id = self::$factory->post->create( array( 'post_content' => '' ) );
    152152        $content_link = get_url_in_content( get_post_field( 'post_content', $empty_post_id ) );
    153153        $this->assertEquals( false, $content_link );
    154154
    155         $comm_post_id = $this->factory->post->create( array( 'post_content' => $commentary ) );
     155        $comm_post_id = self::$factory->post->create( array( 'post_content' => $commentary ) );
    156156        $content_link = get_url_in_content( get_post_field( 'post_content', $comm_post_id ) );
    157157        $this->assertEquals( false, $content_link );
Note: See TracChangeset for help on using the changeset viewer.