Make WordPress Core


Ignore:
Timestamp:
04/14/2014 07:47:10 AM (12 years ago)
Author:
nacin
Message:

Avoid stomping of bulk postdata inside the bulk_edit_posts() loop.

Reverts [27990] which did not fix it for authors and comment/ping status.

props dd32, DrewAPicture.
fixes #27792.

File:
1 edited

Legend:

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

    r27405 r28113  
    55 */
    66class Tests_Admin_includesPost extends WP_UnitTestCase {
     7
     8        function tearDown() {
     9                wp_set_current_user( 0 );
     10                parent::tearDown();
     11        }
    712
    813        function test__wp_translate_postdata_cap_checks_contributor() {
    … …  
    5762                $this->assertEquals( 'edit_others_posts', $_results->get_error_code() );
    5863                $this->assertEquals( 'You are not allowed to edit posts as this user.', $_results->get_error_message() );
    59 
    60                 wp_set_current_user( 0 );
    6164        }
    6265
    … …  
    112115                $this->assertEquals( $_post_data['post_author'], $_results['post_author'] );
    113116                $this->assertEquals( 'draft', $_results['post_status'] );
    114 
    115                 wp_set_current_user( 0 );
    116117        }
    117118
    … …  
    134135                edit_post( $post_data );
    135136                $this->assertEquals( 'draft', get_post( $post->ID )->post_status );
    136                 wp_set_current_user( 0 );
     137        }
     138
     139        /**
     140         * @ticket 27792
     141         */
     142        function test_bulk_edit_posts_stomping() {
     143                $admin = $this->factory->user->create( array( 'role' => 'administrator' ) );
     144                $users = $this->factory->user->create_many( 2, array( 'role' => 'author' ) );
     145                wp_set_current_user( $admin );
     146
     147                $post1 = $this->factory->post->create( array(
     148                        'post_author'    => $users[0],
     149                        'comment_status' => 'open',
     150                        'ping_status'    => 'open',
     151                        'post_status'    => 'publish',
     152                ) );
     153
     154                $post2 = $this->factory->post->create( array(
     155                        'post_author'    => $users[1],
     156                        'comment_status' => 'closed',
     157                        'ping_status'    => 'closed',
     158                        'post_status'    => 'draft',
     159                ) );
     160
     161                $request = array(
     162                        'post_type'        => 'post',
     163                        'post_author'      => -1,
     164                        'ping_status'      => -1,
     165                        'comment_status'   => -1,
     166                        '_status'          => -1,
     167                        'post'             => array( $post1, $post2 ),
     168                );
     169
     170                $done = bulk_edit_posts( $request );
     171
     172                $post = get_post( $post2 );
     173
     174                // Check that the first post's values don't stomp the second post.
     175                $this->assertEquals( 'draft', $post->post_status );
     176                $this->assertEquals( $users[1], $post->post_author );
     177                $this->assertEquals( 'closed', $post->comment_status );
     178                $this->assertEquals( 'closed', $post->ping_status );
    137179        }
    138180
Note: See TracChangeset for help on using the changeset viewer.