Make WordPress Core

Changeset 35164


Ignore:
Timestamp:
10/14/2015 09:40:44 PM (11 years ago)
Author:
boonebgorges
Message:

Share fixtures in Tests_Admin_includesListTable tests.

See #30017, #33968.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/tests/phpunit/tests/admin/includesListTable.php

    r31730 r35164  
    55 */
    66class Tests_Admin_includesListTable extends WP_UnitTestCase {
     7        protected static $top;
     8        protected static $children;
     9        protected static $grandchildren;
     10        protected static $post_ids;
     11
    712        function setUp() {
     13                parent::setUp();
    814                set_current_screen( 'edit-page' );
    915                $GLOBALS['hook_suffix'] = '';
    1016                $this->table = _get_list_table( 'WP_Posts_List_Table' );
    11 
    12                 parent::setUp();
     17        }
     18
     19        public static function setUpBeforeClass() {
     20                $factory = new WP_UnitTest_Factory();
    1321
    1422                // note that our top/children/grandchildren arrays are 1-indexed
    … …  
    1725                $num_posts = 5;
    1826                foreach ( range( 1, $num_posts ) as $i ) {
    19                         $this->top[$i] = $this->factory->post->create_and_get( array(
     27                        $p = $factory->post->create_and_get( array(
    2028                                'post_type'  => 'page',
    2129                                'post_title' => sprintf( 'Top Level Page %d', $i ),
    2230                        ) );
     31
     32                        self::$top[ $i ] = $p;
     33                        self::$post_ids[] = $p;
    2334                }
    2435
    2536                // create child pages
    2637                $num_children = 3;
    27                 foreach ( $this->top as $top => $top_page ) {
     38                foreach ( self::$top as $top => $top_page ) {
    2839                        foreach ( range( 1, $num_children ) as $i ) {
    29                                 $this->children[$top][$i] = $this->factory->post->create_and_get( array(
     40                                $p = $factory->post->create_and_get( array(
    3041                                        'post_type'   => 'page',
    3142                                        'post_parent' => $top_page->ID,
    3243                                        'post_title'  => sprintf( 'Child %d', $i ),
    3344                                ) );
     45
     46                                self::$children[ $top ][ $i ] = $p;
     47                                self::$post_ids[] = $p;
    3448                        }
    3549                }
    … …  
    3852                $num_grandchildren = 3;
    3953                foreach ( range( 3, 4 ) as $top ) {
    40                         foreach ( $this->children[$top] as $child => $child_page ) {
     54                        foreach ( self::$children[ $top ] as $child => $child_page ) {
    4155                                foreach ( range( 1, $num_grandchildren ) as $i ) {
    42                                         $this->grandchildren[$top][$child][$i] = $this->factory->post->create_and_get( array(
     56                                        $p = $factory->post->create_and_get( array(
    4357                                                'post_type'   => 'page',
    4458                                                'post_parent' => $child_page->ID,
    4559                                                'post_title'  => sprintf( 'Grandchild %d', $i ),
    4660                                        ) );
     61
     62                                        self::$grandchildren[ $top ][ $child ][ $i ] = $p;
     63                                        self::$post_ids = $p;
    4764                                }
    4865                        }
    4966                }
     67
     68                self::commit_transaction();
     69        }
     70
     71        public static function tearDownAfterClass() {
     72                foreach ( self::$post_ids as $post_id ) {
     73                        wp_delete_post( $post_id, true );
     74                }
     75
     76                self::commit_transaction();
    5077        }
    5178
    … …  
    5885                        'posts_per_page' => 2,
    5986                ), array(
    60                         $this->top[1]->ID,
    61                         $this->children[1][1]->ID,
     87                        self::$top[1]->ID,
     88                        self::$children[1][1]->ID,
    6289                ) );
    6390        }
    … …  
    7198                        'posts_per_page' => 2,
    7299                ), array(
    73                         $this->top[1]->ID,
    74                         $this->children[1][2]->ID,
    75                         $this->children[1][3]->ID,
     100                        self::$top[1]->ID,
     101                        self::$children[1][2]->ID,
     102                        self::$children[1][3]->ID,
    76103                ) );
    77104        }
    … …  
    86113                        's'              => 'Child',
    87114                ), array(
    88                         $this->children[1][1]->ID,
    89                         $this->children[1][2]->ID,
     115                        self::$children[1][1]->ID,
     116                        self::$children[1][2]->ID,
    90117                ) );
    91118        }
    … …  
    100127                        's'              => 'Top',
    101128                ), array(
    102                         $this->top[3]->ID,
    103                         $this->top[4]->ID,
     129                        self::$top[3]->ID,
     130                        self::$top[4]->ID,
    104131                ) );
    105132        }
    … …  
    114141                        'posts_per_page' => 2,
    115142                ), array(
    116                         $this->top[3]->ID,
    117                         $this->children[3][1]->ID,
    118                         $this->grandchildren[3][1][1]->ID,
    119                         $this->grandchildren[3][1][2]->ID,
     143                        self::$top[3]->ID,
     144                        self::$children[3][1]->ID,
     145                        self::$grandchildren[3][1][1]->ID,
     146                        self::$grandchildren[3][1][2]->ID,
    120147                ) );
    121148        }
    … …  
    130157                        'posts_per_page' => 2,
    131158                ), array(
    132                         $this->top[3]->ID,
    133                         $this->children[3][1]->ID,
    134                         $this->grandchildren[3][1][3]->ID,
    135                         $this->children[3][2]->ID,
     159                        self::$top[3]->ID,
     160                        self::$children[3][1]->ID,
     161                        self::$grandchildren[3][1][3]->ID,
     162                        self::$children[3][2]->ID,
    136163                ) );
    137164        }
Note: See TracChangeset for help on using the changeset viewer.