Changeset 35245 for trunk/tests/phpunit/tests/admin/includesPost.php
- Timestamp:
- 10/17/2015 07:47:07 PM (9 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/tests/phpunit/tests/admin/includesPost.php
r35244 r35245 4 4 * @group admin 5 5 */ 6 class Tests_Admin_includesPost extends WP_UnitTestCase { 6 class 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 } 7 32 8 33 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 ); 13 35 14 36 // Create New Draft Post 15 37 $_post_data = array(); 16 $_post_data['post_author'] = $contributor_id;38 $_post_data['post_author'] = self::$contributor_id; 17 39 $_post_data['post_type'] = 'post'; 18 40 $_post_data['saveasdraft'] = true; … … 25 47 // Submit Post for Approval 26 48 $_post_data = array(); 27 $_post_data['post_author'] = $contributor_id;49 $_post_data['post_author'] = self::$contributor_id; 28 50 $_post_data['post_type'] = 'post'; 29 51 $_post_data['publish'] = true; … … 36 58 // Create New Draft Post for another user 37 59 $_post_data = array(); 38 $_post_data['post_author'] = $editor_id;60 $_post_data['post_author'] = self::$editor_id; 39 61 $_post_data['post_type'] = 'post'; 40 62 $_post_data['saveasdraft'] = true; … … 47 69 // Edit Draft Post for another user 48 70 $_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; 51 73 $_post_data['post_type'] = 'post'; 52 74 $_post_data['post_status'] = 'draft'; … … 60 82 61 83 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 ); 66 85 67 86 // Create New Draft Post 68 87 $_post_data = array(); 69 $_post_data['post_author'] = $editor_id;88 $_post_data['post_author'] = self::$editor_id; 70 89 $_post_data['post_type'] = 'post'; 71 90 $_post_data['saveasdraft'] = true; … … 78 97 // Publish Post 79 98 $_post_data = array(); 80 $_post_data['post_author'] = $editor_id;99 $_post_data['post_author'] = self::$editor_id; 81 100 $_post_data['post_type'] = 'post'; 82 101 $_post_data['publish'] = true; … … 89 108 // Create New Draft Post for another user 90 109 $_post_data = array(); 91 $_post_data['post_author'] = $contributor_id;110 $_post_data['post_author'] = self::$contributor_id; 92 111 $_post_data['post_type'] = 'post'; 93 112 $_post_data['saveasdraft'] = true; … … 100 119 // Edit Draft Post for another user 101 120 $_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; 104 123 $_post_data['post_type'] = 'post'; 105 124 $_post_data['post_status'] = 'draft'; … … 118 137 */ 119 138 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 ); 122 140 $post = self::factory()->post->create_and_get( array( 'post_status' => 'auto-draft' ) ); 123 141 $this->assertEquals( 'auto-draft', $post->post_status ); … … 136 154 */ 137 155 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 ); 140 157 141 158 register_taxonomy( 'wptests_tax', array( 'post' ) ); … … 151 168 ) ); 152 169 153 $p = self::factory()->post->create();154 155 170 $post_data = array( 156 'post_ID' => $p,171 'post_ID' => self::$post_id, 157 172 'tax_input' => array( 158 173 'wptests_tax' => 'foo,baz', … … 162 177 edit_post( $post_data ); 163 178 164 $found = wp_get_post_terms( $p, 'wptests_tax' );179 $found = wp_get_post_terms( self::$post_id, 'wptests_tax' ); 165 180 166 181 // Should contain the term with the name 'foo', not the slug. … … 175 190 */ 176 191 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 ); 179 193 180 194 register_taxonomy( 'wptests_tax', array( 'post' ) ); 181 $t1 =self::factory()->term->create( array(195 self::factory()->term->create( array( 182 196 'taxonomy' => 'wptests_tax', 183 197 'name' => 'foo', … … 185 199 ) ); 186 200 187 $p = self::factory()->post->create();188 189 201 $post_data = array( 190 'post_ID' => $p,202 'post_ID' => self::$post_id, 191 203 'tax_input' => array( 192 204 'wptests_tax' => ' ', … … 196 208 edit_post( $post_data ); 197 209 198 $found = wp_get_post_terms( $p, 'wptests_tax' );210 $found = wp_get_post_terms( self::$post_id, 'wptests_tax' ); 199 211 200 212 $this->assertEmpty( $found ); … … 205 217 */ 206 218 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 ); 210 220 211 221 $post1 = self::factory()->post->create( array( 212 'post_author' => $users[0],222 'post_author' => self::$author_ids[0], 213 223 'comment_status' => 'open', 214 224 'ping_status' => 'open', … … 217 227 218 228 $post2 = self::factory()->post->create( array( 219 'post_author' => $users[1],229 'post_author' => self::$author_ids[1], 220 230 'comment_status' => 'closed', 221 231 'ping_status' => 'closed', … … 232 242 ); 233 243 234 $done =bulk_edit_posts( $request );244 bulk_edit_posts( $request ); 235 245 236 246 $post = get_post( $post2 ); … … 238 248 // Check that the first post's values don't stomp the second post. 239 249 $this->assertEquals( 'draft', $post->post_status ); 240 $this->assertEquals( $users[1], $post->post_author );250 $this->assertEquals( self::$author_ids[1], $post->post_author ); 241 251 $this->assertEquals( 'closed', $post->comment_status ); 242 252 $this->assertEquals( 'closed', $post->ping_status ); … … 264 274 */ 265 275 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 ); 267 277 268 278 $future_date = date( 'Y-m-d H:i:s', time() + 100 ); … … 280 290 $this->set_permalink_structure( '/%postname%/' ); 281 291 282 wp_set_current_user( self:: factory()->user->create( array( 'role' => 'administrator' ) ));292 wp_set_current_user( self::$admin_id ); 283 293 284 294 $future_date = date( 'Y-m-d H:i:s', time() + 100 ); … … 297 307 $this->set_permalink_structure( '/%postname%/' ); 298 308 299 wp_set_current_user( self:: factory()->user->create( array( 'role' => 'administrator' ) ));309 wp_set_current_user( self::$admin_id ); 300 310 301 311 // Published posts should use published permalink
Note: See TracChangeset
for help on using the changeset viewer.