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/revisions.php

    r35224 r35225  
    145145     */
    146146    function test_revision_view_caps_post() {
    147         $post_id = $this->factory->post->create( array( 'post_type' => 'post', 'post_author' => self::$editor_user_id ) );
     147        $post_id = self::$factory->post->create( array( 'post_type' => 'post', 'post_author' => self::$editor_user_id ) );
    148148        wp_update_post( array( 'post_content' => 'This content is much better', 'ID' => $post_id ) );
    149149
     
    167167     */
    168168    function test_revision_restore_caps_post() {
    169         $post_id = $this->factory->post->create( array( 'post_type' => 'post', 'post_author' => self::$editor_user_id ) );
     169        $post_id = self::$factory->post->create( array( 'post_type' => 'post', 'post_author' => self::$editor_user_id ) );
    170170        wp_update_post( array( 'post_content' => 'This content is much better', 'ID' => $post_id ) );
    171171
     
    187187     */
    188188    function test_revision_diff_caps_post() {
    189         $post_id = $this->factory->post->create( array( 'post_type' => 'post', 'post_author' => self::$editor_user_id ) );
     189        $post_id = self::$factory->post->create( array( 'post_type' => 'post', 'post_author' => self::$editor_user_id ) );
    190190        wp_update_post( array( 'post_content' => 'This content is much better', 'ID' => $post_id ) );
    191191        wp_update_post( array( 'post_content' => 'This content is even better', 'ID' => $post_id ) );
     
    215215        ) );
    216216
    217         $post_id = $this->factory->post->create( array( 'post_type' => $this->post_type, 'post_author' => self::$editor_user_id ) );
     217        $post_id = self::$factory->post->create( array( 'post_type' => $this->post_type, 'post_author' => self::$editor_user_id ) );
    218218        wp_update_post( array( 'post_content' => 'This content is much better', 'ID' => $post_id ) );
    219219
     
    248248
    249249        //create a post as Editor
    250         $post_id = $this->factory->post->create( array( 'post_type' => $this->post_type, 'post_author' => self::$editor_user_id ) );
     250        $post_id = self::$factory->post->create( array( 'post_type' => $this->post_type, 'post_author' => self::$editor_user_id ) );
    251251        wp_update_post( array( 'post_content' => 'This content is much better', 'ID' => $post_id ) );
    252252
     
    283283        wp_set_current_user( self::$editor_user_id );
    284284
    285         $post_id = $this->factory->post->create( array( 'post_type' => $this->post_type, 'post_status' => 'draft' ) );
     285        $post_id = self::$factory->post->create( array( 'post_type' => $this->post_type, 'post_status' => 'draft' ) );
    286286        wp_update_post( array( 'post_content' => 'This content is much better', 'ID' => $post_id ) );
    287287
     
    315315        ) );
    316316
    317         $post_id = $this->factory->post->create( array( 'post_type' => $this->post_type, 'post_author' => self::$editor_user_id ) );
     317        $post_id = self::$factory->post->create( array( 'post_type' => $this->post_type, 'post_author' => self::$editor_user_id ) );
    318318        wp_update_post( array( 'post_content' => 'This content is much better', 'ID' => $post_id ) );
    319319        wp_update_post( array( 'post_content' => 'This content is even better', 'ID' => $post_id ) );
     
    338338        global $wpdb;
    339339
    340         $post = $this->factory->post->create_and_get( array( 'post_title' => 'some-post', 'post_type' => 'post', 'post_content' => 'some_content' ) );
     340        $post = self::$factory->post->create_and_get( array( 'post_title' => 'some-post', 'post_type' => 'post', 'post_content' => 'some_content' ) );
    341341
    342342        $post = (array) $post;
     
    366366     */
    367367    function test_wp_get_post_revisions_should_order_by_ID_when_post_date_matches() {
    368         $post = $this->factory->post->create_and_get( array( 'post_title' => 'some-post', 'post_type' => 'post', 'post_content' => 'some_content' ) );
     368        $post = self::$factory->post->create_and_get( array( 'post_title' => 'some-post', 'post_type' => 'post', 'post_content' => 'some_content' ) );
    369369
    370370        $post = (array) $post;
Note: See TracChangeset for help on using the changeset viewer.