Make WordPress Core

Changeset 35245


Ignore:
Timestamp:
10/17/2015 07:47:07 PM (11 years ago)
Author:
wonderboymusic
Message:

Unit Tests: better fixtures for Tests_Admin_Includes_Post.

See #30017, #33968.

Location:
trunk/tests/phpunit/tests
Files:
2 edited

Legend:

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

    r35244 r35245  
    44 * @group admin
    55 */
    6 class Tests_Admin_includesPost extends WP_UnitTestCase {
     6class Tests_Admin_Includes_Post extends WP_UnitTestCase {
     7        protected static $contributor_id;
     8        protected static $author_ids;
     9        protected static $editor_id;
     10        protected static $admin_id;
     11        protected static $post_id;
     12
     13        protected static $user_ids = array();
     14
     15        public static function wpSetUpBeforeClass( $factory ) {
     16                self::$user_ids = self::$author_ids = $factory->user->create_many( 2, array( 'role' => 'author' ) );
     17
     18                self::$user_ids[] = self::$contributor_id = $factory->user->create( array( 'role' => 'contributor' ) );
     19                self::$user_ids[] = self::$editor_id = $factory->user->create( array( 'role' => 'editor' ) );
     20                self::$user_ids[] = self::$admin_id = $factory->user->create( array( 'role' => 'administrator' ) );
     21
     22                self::$post_id = $factory->post->create();
     23        }
     24
     25        public static function wpTearDownAfterClass() {
     26                foreach ( self::$user_ids as $id ) {
     27                        self::delete_user( $id );
     28                }
     29
     30                wp_delete_post( self::$post_id, true );
     31        }
    732
    833        function test__wp_translate_postdata_cap_checks_contributor() {
    9                 $contributor_id = self::factory()->user->create( array( 'role' => 'contributor' ) );
    10                 $editor_id = self::factory()->user->create( array( 'role' => 'editor' ) );
    11 
    12                 wp_set_current_user( $contributor_id );
     34                wp_set_current_user( self::$contributor_id );
    1335
    1436                // Create New Draft Post
    1537                $_post_data = array();
    16                 $_post_data['post_author'] = $contributor_id;
     38                $_post_data['post_author'] = self::$contributor_id;
    1739                $_post_data['post_type'] = 'post';
    1840                $_post_data['saveasdraft'] = true;
     
    2547                // Submit Post for Approval
    2648                $_post_data = array();
    27                 $_post_data['post_author'] = $contributor_id;
     49                $_post_data['post_author'] = self::$contributor_id;
    2850                $_post_data['post_type'] = 'post';
    2951                $_post_data['publish'] = true;
     
    3658                // Create New Draft Post for another user
    3759                $_post_data = array();
    38                 $_post_data['post_author'] = $editor_id;
     60                $_post_data['post_author'] = self::$editor_id;
    3961                $_post_data['post_type'] = 'post';
    4062                $_post_data['saveasdraft'] = true;
     
    4769                // Edit Draft Post for another user
    4870                $_post_data = array();
    49                 $_post_data['post_ID'] = self::factory()->post->create( array( 'post_author' => $editor_id ) );
    50                 $_post_data['post_author'] = $editor_id;
     71                $_post_data['post_ID'] = self::factory()->post->create( array( 'post_author' => self::$editor_id ) );
     72                $_post_data['post_author'] = self::$editor_id;
    5173                $_post_data['post_type'] = 'post';
    5274                $_post_data['post_status'] = 'draft';
     
    6082
    6183        function test__wp_translate_postdata_cap_checks_editor() {
    62                 $contributor_id = self::factory()->user->create( array( 'role' => 'contributor' ) );
    63                 $editor_id = self::factory()->user->create( array( 'role' => 'editor' ) );
    64 
    65                 wp_set_current_user( $editor_id );
     84                wp_set_current_user( self::$editor_id );
    6685
    6786                // Create New Draft Post
    6887                $_post_data = array();
    69                 $_post_data['post_author'] = $editor_id;
     88                $_post_data['post_author'] = self::$editor_id;
    7089                $_post_data['post_type'] = 'post';
    7190                $_post_data['saveasdraft'] = true;
     
    7897                // Publish Post
    7998                $_post_data = array();
    80                 $_post_data['post_author'] = $editor_id;
     99                $_post_data['post_author'] = self::$editor_id;
    81100                $_post_data['post_type'] = 'post';
    82101                $_post_data['publish'] = true;
     
    89108                // Create New Draft Post for another user
    90109                $_post_data = array();
    91                 $_post_data['post_author'] = $contributor_id;
     110                $_post_data['post_author'] = self::$contributor_id;
    92111                $_post_data['post_type'] = 'post';
    93112                $_post_data['saveasdraft'] = true;
     
    100119                // Edit Draft Post for another user
    101120                $_post_data = array();
    102                 $_post_data['post_ID'] = self::factory()->post->create( array( 'post_author' => $contributor_id ) );
    103                 $_post_data['post_author'] = $contributor_id;
     121                $_post_data['post_ID'] = self::factory()->post->create( array( 'post_author' => self::$contributor_id ) );
     122                $_post_data['post_author'] = self::$contributor_id;
    104123                $_post_data['post_type'] = 'post';
    105124                $_post_data['post_status'] = 'draft';
     
    118137         */
    119138        function test_edit_post_auto_draft() {
    120                 $user_id = self::factory()->user->create( array( 'role' => 'editor' ) );
    121                 wp_set_current_user( $user_id );
     139                wp_set_current_user( self::$editor_id );
    122140                $post = self::factory()->post->create_and_get( array( 'post_status' => 'auto-draft' ) );
    123141                $this->assertEquals( 'auto-draft', $post->post_status );
     
    136154         */
    137155        public function test_edit_post_should_parse_tax_input_by_name_rather_than_slug_for_nonhierarchical_taxonomies() {
    138                 $u = self::factory()->user->create( array( 'role' => 'editor' ) );
    139                 wp_set_current_user( $u );
     156                wp_set_current_user( self::$editor_id );
    140157
    141158                register_taxonomy( 'wptests_tax', array( 'post' ) );
     
    151168                ) );
    152169
    153                 $p = self::factory()->post->create();
    154 
    155170                $post_data = array(
    156                         'post_ID' => $p,
     171                        'post_ID' => self::$post_id,
    157172                        'tax_input' => array(
    158173                                'wptests_tax' => 'foo,baz',
     
    162177                edit_post( $post_data );
    163178
    164                 $found = wp_get_post_terms( $p, 'wptests_tax' );
     179                $found = wp_get_post_terms( self::$post_id, 'wptests_tax' );
    165180
    166181                // Should contain the term with the name 'foo', not the slug.
     
    175190         */
    176191        public function test_edit_post_should_not_create_terms_for_an_empty_tag_input_field() {
    177                 $u = self::factory()->user->create( array( 'role' => 'editor' ) );
    178                 wp_set_current_user( $u );
     192                wp_set_current_user( self::$editor_id );
    179193
    180194                register_taxonomy( 'wptests_tax', array( 'post' ) );
    181                 $t1 = self::factory()->term->create( array(
     195                self::factory()->term->create( array(
    182196                        'taxonomy' => 'wptests_tax',
    183197                        'name' => 'foo',
     
    185199                ) );
    186200
    187                 $p = self::factory()->post->create();
    188 
    189201                $post_data = array(
    190                         'post_ID' => $p,
     202                        'post_ID' => self::$post_id,
    191203                        'tax_input' => array(
    192204                                'wptests_tax' => ' ',
     
    196208                edit_post( $post_data );
    197209
    198                 $found = wp_get_post_terms( $p, 'wptests_tax' );
     210                $found = wp_get_post_terms( self::$post_id, 'wptests_tax' );
    199211
    200212                $this->assertEmpty( $found );
     
    205217         */
    206218        function test_bulk_edit_posts_stomping() {
    207                 $admin = self::factory()->user->create( array( 'role' => 'administrator' ) );
    208                 $users = self::factory()->user->create_many( 2, array( 'role' => 'author' ) );
    209                 wp_set_current_user( $admin );
     219                wp_set_current_user( self::$admin_id );
    210220
    211221                $post1 = self::factory()->post->create( array(
    212                         'post_author'    => $users[0],
     222                        'post_author'    => self::$author_ids[0],
    213223                        'comment_status' => 'open',
    214224                        'ping_status'    => 'open',
     
    217227
    218228                $post2 = self::factory()->post->create( array(
    219                         'post_author'    => $users[1],
     229                        'post_author'    => self::$author_ids[1],
    220230                        'comment_status' => 'closed',
    221231                        'ping_status'    => 'closed',
     
    232242                );
    233243
    234                 $done = bulk_edit_posts( $request );
     244                bulk_edit_posts( $request );
    235245
    236246                $post = get_post( $post2 );
     
    238248                // Check that the first post's values don't stomp the second post.
    239249                $this->assertEquals( 'draft', $post->post_status );
    240                 $this->assertEquals( $users[1], $post->post_author );
     250                $this->assertEquals( self::$author_ids[1], $post->post_author );
    241251                $this->assertEquals( 'closed', $post->comment_status );
    242252                $this->assertEquals( 'closed', $post->ping_status );
     
    264274         */
    265275        public function test_get_sample_permalink_html_should_use_default_permalink_for_view_post_link_when_pretty_permalinks_are_disabled() {
    266                 wp_set_current_user( self::factory()->user->create( array( 'role' => 'administrator' ) ) );
     276                wp_set_current_user( self::$admin_id );
    267277
    268278                $future_date = date( 'Y-m-d H:i:s', time() + 100 );
     
    280290                $this->set_permalink_structure( '/%postname%/' );
    281291
    282                 wp_set_current_user( self::factory()->user->create( array( 'role' => 'administrator' ) ) );
     292                wp_set_current_user( self::$admin_id );
    283293
    284294                $future_date = date( 'Y-m-d H:i:s', time() + 100 );
     
    297307                $this->set_permalink_structure( '/%postname%/' );
    298308
    299                 wp_set_current_user( self::factory()->user->create( array( 'role' => 'administrator' ) ) );
     309                wp_set_current_user( self::$admin_id );
    300310
    301311                // Published posts should use published permalink
  • trunk/tests/phpunit/tests/user.php

    r35244 r35245  
    245245
    246246                foreach ( $roles as $role => $level ) {
    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                         ) );
     247                        $user_id = self::factory()->user->create( array( 'role' => $role ) );
    252248                        $user = new WP_User( $user_id );
    253249
Note: See TracChangeset for help on using the changeset viewer.