Changeset 35311 for trunk/tests/phpunit/tests/ajax/Autosave.php
- Timestamp:
- 10/21/2015 03:17:36 AM (10 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/tests/phpunit/tests/ajax/Autosave.php
r35244 r35311 22 22 protected $_post = null; 23 23 24 /** 25 * user_id 26 * @var int 27 */ 28 protected $user_id = 0; 24 protected static $admin_id = 0; 25 protected static $editor_id = 0; 26 protected static $post; 27 protected static $post_id; 28 protected static $user_ids = array(); 29 30 public static function wpSetUpBeforeClass( $factory ) { 31 self::$user_ids[] = self::$admin_id = $factory->user->create( array( 'role' => 'administrator' ) ); 32 self::$user_ids[] = self::$editor_id = $factory->user->create( array( 'role' => 'editor' ) ); 33 34 self::$post_id = $factory->post->create( array( 'post_status' => 'draft' ) ); 35 self::$post = get_post( self::$post_id ); 36 } 37 38 public static function wpTearDownAfterClass() { 39 foreach ( self::$user_ids as $user_id ) { 40 self::delete_user( $user_id ); 41 } 42 43 wp_delete_post( self::$post_id, true ); 44 } 29 45 30 46 /** … … 34 50 parent::setUp(); 35 51 // Set a user so the $post has 'post_author' 36 $this->user_id = self::factory()->user->create( array( 'role' => 'administrator' ) ); 37 wp_set_current_user( $this->user_id ); 38 39 $post_id = self::factory()->post->create( array( 'post_status' => 'draft' ) ); 40 $this->_post = get_post( $post_id ); 52 wp_set_current_user( self::$admin_id ); 41 53 } 42 54 … … 47 59 public function test_autosave_post() { 48 60 // The original post_author 49 wp_set_current_user( $this->user_id );61 wp_set_current_user( self::$admin_id ); 50 62 51 63 // Set up the $_POST request … … 56 68 'data' => array( 57 69 'wp_autosave' => array( 58 'post_id' => $this->_post->ID,59 '_wpnonce' => wp_create_nonce( 'update-post_' . $this->_post->ID ),60 'post_content' => $this->_post->post_content . PHP_EOL . $md5,70 'post_id' => self::$post_id, 71 '_wpnonce' => wp_create_nonce( 'update-post_' . self::$post->ID ), 72 'post_content' => self::$post->post_content . PHP_EOL . $md5, 61 73 'post_type' => 'post', 62 74 ), … … 79 91 80 92 // Check that the edit happened 81 $post = get_post( $this->_post->ID);82 $this->assertGreaterThanOrEqual( 0, strpos( $post->post_content, $md5 ) );93 $post = get_post( self::$post_id ); 94 $this->assertGreaterThanOrEqual( 0, strpos( self::$post->post_content, $md5 ) ); 83 95 } 84 96 … … 89 101 public function test_autosave_locked_post() { 90 102 // Lock the post to another user 91 $another_user_id = self::factory()->user->create( array( 'role' => 'editor' ) ); 92 wp_set_current_user( $another_user_id ); 93 wp_set_post_lock( $this->_post->ID ); 103 wp_set_current_user( self::$editor_id ); 104 wp_set_post_lock( self::$post_id ); 94 105 95 wp_set_current_user( $this->user_id );106 wp_set_current_user( self::$admin_id ); 96 107 97 108 // Ensure post is locked 98 $this->assertEquals( $another_user_id, wp_check_post_lock( $this->_post->ID) );109 $this->assertEquals( self::$editor_id, wp_check_post_lock( self::$post_id ) ); 99 110 100 111 // Set up the $_POST request … … 105 116 'data' => array( 106 117 'wp_autosave' => array( 107 'post_id' => $this->_post->ID,108 '_wpnonce' => wp_create_nonce( 'update-post_' . $this->_post->ID),109 'post_content' => $this->_post->post_content . PHP_EOL . $md5,118 'post_id' => self::$post_id, 119 '_wpnonce' => wp_create_nonce( 'update-post_' . self::$post_id ), 120 'post_content' => self::$post->post_content . PHP_EOL . $md5, 110 121 'post_type' => 'post', 111 122 ), … … 127 138 128 139 // Check that the original post was NOT edited 129 $post = get_post( $this->_post->ID);140 $post = get_post( self::$post_id ); 130 141 $this->assertFalse( strpos( $post->post_content, $md5 ) ); 131 142 132 143 // Check if the autosave post was created 133 $autosave = wp_get_post_autosave( $this->_post->ID, get_current_user_id() );144 $autosave = wp_get_post_autosave( self::$post_id, get_current_user_id() ); 134 145 $this->assertNotEmpty( $autosave ); 135 146 $this->assertGreaterThanOrEqual( 0, strpos( $autosave->post_content, $md5 ) ); … … 142 153 public function test_with_invalid_nonce( ) { 143 154 144 wp_set_current_user( $this->user_id );155 wp_set_current_user( self::$admin_id ); 145 156 146 157 // Set up the $_POST request … … 150 161 'data' => array( 151 162 'wp_autosave' => array( 152 'post_id' => $this->_post->ID,163 'post_id' => self::$post_id, 153 164 '_wpnonce' => substr( md5( uniqid() ), 0, 10 ), 154 165 ),
Note: See TracChangeset
for help on using the changeset viewer.