Make WordPress Core

Changeset 35244


Ignore:
Timestamp:
10/17/2015 07:24:20 PM (8 years ago)
Author:
wonderboymusic
Message:

Unit Tests: WP_UnitTest_Generator_Sequence needs a static incrementer - otherwise, it assumes every test class is a reset, which it no longer is (it is now static).

While we're at it, remove unnecessary tearDown() code.

See #30017, #33968.

Location:
trunk/tests/phpunit
Files:
33 edited

Legend:

Unmodified
Added
Removed
  • trunk/tests/phpunit/includes/factory.php

    r34855 r35244  
    402402
    403403class WP_UnitTest_Generator_Sequence {
    404     var $next;
    405     var $template_string;
    406 
    407     function __construct( $template_string = '%s', $start = 1 ) {
    408         $this->next = $start;
     404    static $incr = -1;
     405    public $next;
     406    public $template_string;
     407
     408    function __construct( $template_string = '%s', $start = null ) {
     409        if ( $start ) {
     410            $this->next = $start;
     411        } else {
     412            self::$incr++;
     413            $this->next = self::$incr;
     414        }
    409415        $this->template_string = $template_string;
    410416    }
  • trunk/tests/phpunit/includes/testcase-canonical.php

    r35242 r35244  
    135135     */
    136136    public static function delete_shared_fixtures() {
    137         if ( is_multisite() ) {
    138             wpmu_delete_user( self::$author_id );
    139         } else {
    140             wp_delete_user( self::$author_id );
    141         }
     137        self::delete_user( self::$author_id );
    142138
    143139        foreach ( self::$post_ids as $pid ) {
  • trunk/tests/phpunit/tests/admin/includesPost.php

    r35242 r35244  
    55 */
    66class Tests_Admin_includesPost extends WP_UnitTestCase {
    7 
    8     function tearDown() {
    9         wp_set_current_user( 0 );
    10         parent::tearDown();
    11     }
    127
    138    function test__wp_translate_postdata_cap_checks_contributor() {
  • trunk/tests/phpunit/tests/ajax/Autosave.php

    r35242 r35244  
    3939        $post_id = self::factory()->post->create( array( 'post_status' => 'draft' ) );
    4040        $this->_post = get_post( $post_id );
    41     }
    42 
    43     /**
    44      * Tear down the test fixture.
    45      * Reset the current user
    46      */
    47     public function tearDown() {
    48         wp_set_current_user( 0 );
    49         parent::tearDown();
    5041    }
    5142
  • trunk/tests/phpunit/tests/ajax/CustomizeMenus.php

    r35242 r35244  
    2727        $this->wp_customize = new WP_Customize_Manager();
    2828        $wp_customize = $this->wp_customize;
    29     }
    30 
    31     /**
    32      * Tear down the test fixture.
    33      */
    34     public function tearDown() {
    35         wp_set_current_user( 0 );
    36         parent::tearDown();
    3729    }
    3830
  • trunk/tests/phpunit/tests/attachment/slashes.php

    r35242 r35244  
    1010        parent::setUp();
    1111        $this->author_id = self::factory()->user->create( array( 'role' => 'editor' ) );
    12         $this->old_current_user = get_current_user_id();
    1312        wp_set_current_user( $this->author_id );
    1413
     
    2221        $this->slash_6 = 'String with 6 slashes \\\\\\\\\\\\';
    2322        $this->slash_7 = 'String with 7 slashes \\\\\\\\\\\\\\';
    24     }
    25 
    26     function tearDown() {
    27         wp_set_current_user( $this->old_current_user );
    28         wp_delete_user( $this->author_id );
    29         parent::tearDown();
    3023    }
    3124
  • trunk/tests/phpunit/tests/basic.php

    r35172 r35244  
    66 */
    77class Tests_Basic extends WP_UnitTestCase {
    8     var $val;
    9 
    10     function setUp() {
    11         parent::setUp();
    12         $this->val = true;
    13     }
    14 
    15     function tearDown() {
    16         $this->val = false;
    17         parent::tearDown();
    18     }
    19 
    20     function test_true() {
    21         $this->assertTrue($this->val);
    22     }
    238
    249    function test_license() {
  • trunk/tests/phpunit/tests/cache.php

    r35108 r35244  
    55 */
    66class Tests_Cache extends WP_UnitTestCase {
    7     var $cache = NULL;
     7    var $cache = null;
    88
    99    function setUp() {
  • trunk/tests/phpunit/tests/comment-submission.php

    r35242 r35244  
    1111    }
    1212
    13     function tearDown() {
    14         wp_set_current_user( 0 );
    15         parent::tearDown();
    16     }
    17 
    1813    public function test_submitting_comment_to_invalid_post_returns_error() {
    19 
    2014        $error = 'comment_id_not_found';
    2115
  • trunk/tests/phpunit/tests/comment.php

    r35242 r35244  
    1616
    1717    public static function wpTearDownAfterClass() {
    18         wp_delete_post( self::$post_id );
     18        wp_delete_post( self::$post_id, true );
    1919
    2020        self::delete_user( self::$user_id );
  • trunk/tests/phpunit/tests/comment/slashes.php

    r35242 r35244  
    1111        // we need an admin user to bypass comment flood protection
    1212        $this->author_id = self::factory()->user->create( array( 'role' => 'administrator' ) );
    13         $this->old_current_user = get_current_user_id();
    1413        wp_set_current_user( $this->author_id );
    1514
     
    2322        $this->slash_6 = 'String with 6 slashes \\\\\\\\\\\\';
    2423        $this->slash_7 = 'String with 7 slashes \\\\\\\\\\\\\\';
    25     }
    26 
    27     function tearDown() {
    28         wp_set_current_user( $this->old_current_user );
    29         parent::tearDown();
    3024    }
    3125
  • trunk/tests/phpunit/tests/link.php

    r35242 r35244  
    44 */
    55class Tests_Link extends WP_UnitTestCase {
    6 
    7     function tearDown() {
    8         global $wp_rewrite;
    9         $wp_rewrite->init();
    10         parent::tearDown();
    11     }
    126
    137    function _get_pagenum_link_cb( $url ) {
  • trunk/tests/phpunit/tests/meta/slashes.php

    r35242 r35244  
    1111        $this->author_id = self::factory()->user->create( array( 'role' => 'editor' ) );
    1212        $this->post_id = self::factory()->post->create();
    13         $this->old_current_user = get_current_user_id();
     13
    1414        wp_set_current_user( $this->author_id );
    1515
     
    2121        $this->slash_6 = 'String with 6 slashes \\\\\\\\\\\\';
    2222        $this->slash_7 = 'String with 7 slashes \\\\\\\\\\\\\\';
    23     }
    24 
    25     function tearDown() {
    26         wp_set_current_user( $this->old_current_user );
    27         parent::tearDown();
    2823    }
    2924
  • trunk/tests/phpunit/tests/multisite/getSpaceAllowed.php

    r35016 r35244  
    1919        self::$original_site_blog_upload_space = get_site_option( 'blog_upload_space' );
    2020        self::$original_blog_upload_space = get_option( 'blog_upload_space' );
    21 
    2221    }
    2322
  • trunk/tests/phpunit/tests/multisite/site.php

    r35242 r35244  
    675675        $this->assertEquals( 2, get_blog_details()->post_count );
    676676
    677         wp_delete_post( $post2 );
     677        wp_delete_post( $post2, true );
    678678        $this->assertEquals( 1, get_blog_details()->post_count );
    679679    }
  • trunk/tests/phpunit/tests/option/userSettings.php

    r35242 r35244  
    1515    function tearDown() {
    1616        unset( $GLOBALS['_updated_user_settings'] );
    17         delete_user_option( $this->user_id, 'user-settings' );
    1817
    1918        parent::tearDown();
  • trunk/tests/phpunit/tests/post/getPages.php

    r35242 r35244  
    7979
    8080        // This should bump last_changed.
    81         wp_delete_post( $pages[0]->ID );
     81        wp_delete_post( $pages[0]->ID, true );
    8282        $old_changed_float = $this->_microtime_to_float( $last_changed );
    8383        $new_changed_float = $this->_microtime_to_float( wp_cache_get( 'last_changed', 'posts' ) );
  • trunk/tests/phpunit/tests/post/meta.php

    r35242 r35244  
    3131        // insert a post
    3232        $this->post_id_2 = wp_insert_post($post);
    33     }
    34 
    35     function tearDown() {
    36         wp_delete_post($this->post_id);
    37         wp_delete_post($this->post_id_2);
    38         parent::tearDown();
    3933    }
    4034
  • trunk/tests/phpunit/tests/post/slashes.php

    r35242 r35244  
    1010        parent::setUp();
    1111        $this->author_id = self::factory()->user->create( array( 'role' => 'editor' ) );
    12         $this->old_current_user = get_current_user_id();
     12
    1313        wp_set_current_user( $this->author_id );
    1414
     
    2222        $this->slash_6 = 'String with 6 slashes \\\\\\\\\\\\';
    2323        $this->slash_7 = 'String with 7 slashes \\\\\\\\\\\\\\';
    24     }
    25 
    26     function tearDown() {
    27         wp_set_current_user( $this->old_current_user );
    28         parent::tearDown();
    2924    }
    3025
  • trunk/tests/phpunit/tests/post/thumbnails.php

    r35194 r35244  
    1818
    1919    public static function wpTearDownAfterClass() {
    20         wp_delete_post( self::$post->ID );
    21         wp_delete_attachment( self::$attachment_id );
     20        wp_delete_post( self::$post->ID, true );
     21        wp_delete_attachment( self::$attachment_id, true );
    2222    }
    2323
  • trunk/tests/phpunit/tests/query/conditionals.php

    r35242 r35244  
    2626
    2727        $this->set_permalink_structure( '/%year%/%monthnum%/%day%/%postname%/' );
    28     }
    29 
    30     function tearDown() {
    31         global $wp_rewrite;
    32         $wp_rewrite->init();
    33 
    34         parent::tearDown();
    3528    }
    3629
  • trunk/tests/phpunit/tests/query/setupPostdata.php

    r35242 r35244  
    2222            }
    2323        }
    24     }
    25 
    26     public function tearDown() {
    27         parent::tearDown();
    28         return;
    29 
    30         foreach ( $this->global_keys as $global_key ) {
    31             if ( ! is_null( $this->global_data[ $global_key ] ) ) {
    32                 $GLOBALS[ $global_key ] = $this->global_data[ $global_key ];
    33             } else {
    34                 unset( $GLOBALS[ $global_key ] );
    35             }
    36         }
    37 
    38         $this->global_data = array();
    3924    }
    4025
  • trunk/tests/phpunit/tests/shortcode.php

    r34933 r35244  
    2121    function tearDown() {
    2222        global $shortcode_tags;
    23         foreach ( $this->shortcodes as $shortcode )
     23        foreach ( $this->shortcodes as $shortcode ) {
    2424            unset( $shortcode_tags[ $shortcode ] );
     25        }
    2526        parent::tearDown();
    2627    }
  • trunk/tests/phpunit/tests/term.php

    r35242 r35244  
    1313
    1414    public static function wpTearDownAfterClass() {
    15         array_map( 'wp_delete_post', self::$post_ids );
     15        foreach ( self::$post_ids as $post_id ) {
     16            wp_delete_post( $post_id, true );
     17        }
    1618    }
    1719
  • trunk/tests/phpunit/tests/term/slashes.php

    r35242 r35244  
    1010        parent::setUp();
    1111        $this->author_id = self::factory()->user->create( array( 'role' => 'administrator' ) );
    12         $this->old_current_user = get_current_user_id();
     12
    1313        wp_set_current_user( $this->author_id );
    1414
     
    2020        $this->slash_6 = 'String with 6 slashes \\\\\\\\\\\\';
    2121        $this->slash_7 = 'String with 7 slashes \\\\\\\\\\\\\\';
    22     }
    23 
    24     function tearDown() {
    25         wp_set_current_user( $this->old_current_user );
    26         parent::tearDown();
    2722    }
    2823
  • trunk/tests/phpunit/tests/user.php

    r35242 r35244  
    245245
    246246        foreach ( $roles as $role => $level ) {
    247             $user_id = self::factory()->user->create( array( 'role' => $role ) );
     247            $user_id = self::factory()->user->create( array(
     248                'user_email' => 'user_19265_' . $role . '@burritos.com',
     249                'user_login' => 'user_19265_' . $role,
     250                'role' => $role
     251            ) );
    248252            $user = new WP_User( $user_id );
    249253
     
    776780        ) );
    777781
     782        $user1 = new WP_User( $u1 );
     783
     784        $expected = str_repeat( 'a', 50 );
     785        $this->assertSame( $expected, $user1->user_nicename );
     786
    778787        $user_login = str_repeat( 'a', 55 );
    779788        $u = wp_insert_user( array(
     
    784793
    785794        $this->assertNotEmpty( $u );
    786         $user = new WP_User( $u );
     795        $user2 = new WP_User( $u );
    787796        $expected = str_repeat( 'a', 48 ) . '-2';
    788         $this->assertSame( $expected, $user->user_nicename );
     797        $this->assertSame( $expected, $user2->user_nicename );
    789798    }
    790799
     
    793802     */
    794803    public function test_wp_insert_user_should_not_truncate_to_a_duplicate_user_nicename_when_suffix_has_more_than_one_character() {
    795         $users = self::factory()->user->create_many( 4, array(
     804        $user_ids = self::factory()->user->create_many( 4, array(
    796805            'user_nicename' => str_repeat( 'a', 50 ),
    797806        ) );
     807
     808        foreach ( $user_ids as $i => $user_id ) {
     809            $user = new WP_User( $user_id );
     810            if ( 0 === $i ) {
     811                $expected = str_repeat( 'a', 50 );
     812            } else {
     813                $expected = str_repeat( 'a', 48 ) . '-' . ( $i + 1 );
     814            }
     815            $this->assertSame( $expected, $user->user_nicename );
     816        }
    798817
    799818        $user_login = str_repeat( 'a', 55 );
  • trunk/tests/phpunit/tests/user/countUserPosts.php

    r35224 r35244  
    2828            'post_type'   => 'wptests_pt',
    2929        ) ) );
    30         self::$post_ids = array_merge( self::$post_ids, $factory->post->create_many( 1, array(
     30       
     31        self::$post_ids[] = $factory->post->create( array(
    3132            'post_author' => 12345,
    3233            'post_type'   => 'wptests_pt',
    33         ) ) );
     34        ) );
    3435    }
    3536
  • trunk/tests/phpunit/tests/user/listAuthors.php

    r35242 r35244  
    55 */
    66class Tests_User_ListAuthors extends WP_UnitTestCase {
    7     static $users = array();
     7    static $user_ids = array();
    88    static $fred_id;
    99    static $posts = array();
     
    2525        */
    2626    public static function wpSetUpBeforeClass( $factory ) {
    27         self::$users[] = $factory->user->create( array( 'user_login' => 'zack', 'display_name' => 'zack', 'role' => 'author', 'first_name' => 'zack', 'last_name' => 'moon' ) );
    28         self::$users[] = $factory->user->create( array( 'user_login' => 'bob', 'display_name' => 'bob', 'role' => 'author', 'first_name' => 'bob', 'last_name' => 'reno' ) );
    29         self::$users[] = $factory->user->create( array( 'user_login' => 'paul', 'display_name' => 'paul', 'role' => 'author', 'first_name' => 'paul', 'last_name' => 'norris' ) );
     27        self::$user_ids[] = $factory->user->create( array( 'user_login' => 'zack', 'display_name' => 'zack', 'role' => 'author', 'first_name' => 'zack', 'last_name' => 'moon' ) );
     28        self::$user_ids[] = $factory->user->create( array( 'user_login' => 'bob', 'display_name' => 'bob', 'role' => 'author', 'first_name' => 'bob', 'last_name' => 'reno' ) );
     29        self::$user_ids[] = $factory->user->create( array( 'user_login' => 'paul', 'display_name' => 'paul', 'role' => 'author', 'first_name' => 'paul', 'last_name' => 'norris' ) );
    3030        self::$fred_id = $factory->user->create( array( 'user_login' => 'fred', 'role' => 'author' ) );
    3131
    3232        $count = 0;
    33         foreach ( self::$users as $userid ) {
     33        foreach ( self::$user_ids as $userid ) {
    3434            $count = $count + 1;
    3535            for ( $i = 0; $i < $count; $i++ ) {
     
    4242
    4343    public static function wpTearDownAfterClass() {
    44         foreach ( array_merge( self::$users, array( self::$fred_id ) ) as $user_id ) {
     44        self::$user_ids[] = self::$fred_id;
     45
     46        foreach ( self::$user_ids as $user_id ) {
    4547            self::delete_user( $user_id );
    4648        }
     
    9799
    98100    function test_wp_list_authors_feed() {
    99         $url0 = get_author_feed_link( self::$users[0] );
    100         $url1 = get_author_feed_link( self::$users[1] );
    101         $url2 = get_author_feed_link( self::$users[2] );
     101        $url0 = get_author_feed_link( self::$user_ids[0] );
     102        $url1 = get_author_feed_link( self::$user_ids[1] );
     103        $url2 = get_author_feed_link( self::$user_ids[2] );
    102104        $expected['feed'] = '<li><a href="' . self::$user_urls[1] . '" title="Posts by bob">bob</a> (<a href="' . $url1 . '">link to feed</a>)</li><li><a href="' . self::$user_urls[2] . '" title="Posts by paul">paul</a> (<a href="' .  $url2 . '">link to feed</a>)</li><li><a href="' . self::$user_urls[0] . '" title="Posts by zack">zack</a> (<a href="' . $url0 . '">link to feed</a>)</li>';
    103105        $this->AssertEquals( $expected['feed'], wp_list_authors( array( 'echo' => false, 'feed' => 'link to feed' ) ) );
     
    105107
    106108    function test_wp_list_authors_feed_image() {
    107         $url0 = get_author_feed_link( self::$users[0] );
    108         $url1 = get_author_feed_link( self::$users[1] );
    109         $url2 = get_author_feed_link( self::$users[2] );
     109        $url0 = get_author_feed_link( self::$user_ids[0] );
     110        $url1 = get_author_feed_link( self::$user_ids[1] );
     111        $url2 = get_author_feed_link( self::$user_ids[2] );
    110112        $expected['feed_image'] = '<li><a href="' . self::$user_urls[1] . '" title="Posts by bob">bob</a> <a href="' . $url1 . '"><img src="http://' . WP_TESTS_DOMAIN . '/path/to/a/graphic.png" style="border: none;" /></a></li><li><a href="' . self::$user_urls[2] . '" title="Posts by paul">paul</a> <a href="' .  $url2 . '"><img src="http://' . WP_TESTS_DOMAIN . '/path/to/a/graphic.png" style="border: none;" /></a></li><li><a href="' . self::$user_urls[0] . '" title="Posts by zack">zack</a> <a href="' .  $url0 . '"><img src="http://' . WP_TESTS_DOMAIN . '/path/to/a/graphic.png" style="border: none;" /></a></li>';
    111113        $this->AssertEquals( $expected['feed_image'], wp_list_authors( array( 'echo' => false, 'feed_image' => WP_TESTS_DOMAIN . '/path/to/a/graphic.png' ) ) );
     
    116118     */
    117119    function test_wp_list_authors_feed_type() {
    118         $url0 = get_author_feed_link( self::$users[0], 'atom' );
    119         $url1 = get_author_feed_link( self::$users[1], 'atom' );
    120         $url2 = get_author_feed_link( self::$users[2], 'atom' );
     120        $url0 = get_author_feed_link( self::$user_ids[0], 'atom' );
     121        $url1 = get_author_feed_link( self::$user_ids[1], 'atom' );
     122        $url2 = get_author_feed_link( self::$user_ids[2], 'atom' );
    121123        $expected['feed_type'] = '<li><a href="' . self::$user_urls[1] . '" title="Posts by bob">bob</a> (<a href="' . $url1 . '">link to feed</a>)</li><li><a href="' . self::$user_urls[2] . '" title="Posts by paul">paul</a> (<a href="' . $url2 . '">link to feed</a>)</li><li><a href="' . self::$user_urls[0] . '" title="Posts by zack">zack</a> (<a href="' . $url0 . '">link to feed</a>)</li>';
    122124        $this->AssertEquals( $expected['feed_type'], wp_list_authors( array( 'echo' => false, 'feed' => 'link to feed', 'feed_type' => 'atom' ) ) );
  • trunk/tests/phpunit/tests/user/query.php

    r35242 r35244  
    933933    public function test_get_single_role_by_string_which_is_similar() {
    934934        $another_editor = self::factory()->user->create( array(
     935            'user_email' => 'another_editor@another_editor.com',
     936            'user_login' => 'another_editor',
    935937            'role' => 'another-editor',
    936938        ) );
  • trunk/tests/phpunit/tests/user/slashes.php

    r35242 r35244  
    1010        parent::setUp();
    1111        $this->author_id = self::factory()->user->create( array( 'role' => 'administrator' ) );
    12         $this->old_current_user = get_current_user_id();
     12
    1313        wp_set_current_user( $this->author_id );
    1414
     
    2424    }
    2525
    26     function tearDown() {
    27         wp_set_current_user( $this->old_current_user );
    28         parent::tearDown();
    29     }
    30 
    3126    /**
    3227     * Tests the controller function that expects slashed data
  • trunk/tests/phpunit/tests/xmlrpc/mw/getRecentPosts.php

    r35242 r35244  
    4242
    4343    function test_no_editable_posts() {
    44         wp_delete_post( $this->post_id );
     44        wp_delete_post( $this->post_id, true );
    4545
    4646        $result = $this->myxmlrpcserver->mw_getRecentPosts( array( 1, 'author', 'author' ) );
  • trunk/tests/phpunit/tests/xmlrpc/wp/getPage.php

    r31622 r35244  
    2222        );
    2323        $this->post_id = wp_insert_post( $this->post_data );
    24     }
    25 
    26     function tearDown() {
    27         wp_delete_post( $this->post_id );
    28         parent::tearDown();
    2924    }
    3025
  • trunk/tests/phpunit/tests/xmlrpc/wp/getUser.php

    r25394 r35244  
    1818
    1919    function tearDown() {
    20         if ( is_multisite() )
     20        if ( is_multisite() ) {
    2121            revoke_super_admin( $this->administrator_id );
    22 
     22        }
    2323        parent::tearDown();
    2424    }
Note: See TracChangeset for help on using the changeset viewer.