Changeset 35183
- Timestamp:
- 10/15/2015 03:30:09 AM (9 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/tests/phpunit/tests/post.php
r35162 r35183 7 7 */ 8 8 class Tests_Post extends WP_UnitTestCase { 9 protected static $editor_id; 10 protected static $grammarian_id; 11 12 public static function setUpBeforeClass() { 13 parent::setUpBeforeClass(); 14 15 $factory = new WP_UnitTest_Factory(); 16 17 self::$editor_id = $factory->user->create( array( 'role' => 'editor' ) ); 18 19 add_role( 'grammarian', 'Grammarian', array( 20 'read' => true, 21 'edit_posts' => true, 22 'edit_others_posts' => true, 23 'edit_published_posts' => true, 24 ) ); 25 26 self::$grammarian_id = $factory->user->create( array( 'role' => 'grammarian' ) ); 27 28 self::commit_transaction(); 29 } 30 31 public static function tearDownAfterClass() { 32 parent::tearDownAfterClass(); 33 34 $ids = array( self::$editor_id, self::$grammarian_id ); 35 foreach ( $ids as $id ) { 36 if ( is_multisite() ) { 37 wpmu_delete_user( $id ); 38 } else { 39 wp_delete_user( $id ); 40 } 41 } 42 43 self::commit_transaction(); 44 } 45 9 46 function setUp() { 10 47 parent::setUp(); 11 $this->author_id = $this->factory->user->create( array( 'role' => 'editor' ) ); 12 $this->old_current_user = get_current_user_id();13 wp_set_current_user( $this->author_id);14 _set_cron_array(array()); 48 49 wp_set_current_user( self::$editor_id ); 50 _set_cron_array( array() ); 51 15 52 $this->post_ids = array(); 16 }17 18 function tearDown() {19 wp_set_current_user( $this->old_current_user );20 parent::tearDown();21 53 } 22 54 … … 41 73 foreach ( $post_types as $post_type ) { 42 74 $post = array( 43 'post_author' => $this->author_id,75 'post_author' => self::$editor_id, 44 76 'post_status' => 'publish', 45 77 'post_content' => rand_str(), … … 95 127 96 128 $post = array( 97 'post_author' => $this->author_id,129 'post_author' => self::$editor_id, 98 130 'post_status' => 'publish', 99 131 'post_content' => rand_str(), … … 130 162 131 163 $post = array( 132 'post_author' => $this->author_id,164 'post_author' => self::$editor_id, 133 165 'post_status' => 'publish', 134 166 'post_content' => rand_str(), … … 172 204 173 205 $post = array( 174 'post_author' => $this->author_id,206 'post_author' => self::$editor_id, 175 207 'post_status' => 'publish', 176 208 'post_content' => rand_str(), … … 212 244 213 245 $post = array( 214 'post_author' => $this->author_id,246 'post_author' => self::$editor_id, 215 247 'post_status' => 'draft', 216 248 'post_content' => rand_str(), … … 244 276 245 277 $post = array( 246 'post_author' => $this->author_id,278 'post_author' => self::$editor_id, 247 279 'post_status' => 'publish', 248 280 'post_content' => rand_str(), … … 285 317 foreach ($statuses as $status) { 286 318 $post = array( 287 'post_author' => $this->author_id,319 'post_author' => self::$editor_id, 288 320 'post_status' => 'publish', 289 321 'post_content' => rand_str(), … … 325 357 326 358 $post = array( 327 'post_author' => $this->author_id,359 'post_author' => self::$editor_id, 328 360 'post_status' => 'private', 329 361 'post_content' => rand_str(), … … 358 390 359 391 $post = array( 360 'post_author' => $this->author_id,392 'post_author' => self::$editor_id, 361 393 'post_status' => 'public', 362 394 'post_content' => rand_str(), … … 379 411 380 412 $post = array( 381 'post_author' => $this->author_id,413 'post_author' => self::$editor_id, 382 414 'post_status' => 'publish', 383 415 'post_content' => rand_str(), … … 477 509 478 510 $post = array( 479 'post_author' => $this->author_id,511 'post_author' => self::$editor_id, 480 512 'post_status' => 'publish', 481 513 'post_content' => rand_str(), … … 506 538 507 539 $post = array( 508 'post_author' => $this->author_id,540 'post_author' => self::$editor_id, 509 541 'post_status' => 'publish', 510 542 'post_content' => rand_str(), … … 770 802 $title = rand_str(); 771 803 $post_data = array( 772 'post_author' => $this->author_id,804 'post_author' => self::$editor_id, 773 805 'post_status' => 'public', 774 806 'post_content' => rand_str(), … … 782 814 783 815 $post = get_post( $insert_post_id ); 784 $this->assertEquals( $post->post_author, $this->author_id );816 $this->assertEquals( $post->post_author, self::$editor_id ); 785 817 $this->assertEquals( $post->post_title, $title ); 786 818 } … … 794 826 $this->factory->post->create( array( 795 827 'post_type' => $post_type, 796 'post_author' => $this->author_id828 'post_author' => self::$editor_id 797 829 ) ); 798 830 $count = wp_count_posts( $post_type, 'readable' ); … … 807 839 $this->factory->post->create_many( 3, array( 808 840 'post_type' => $post_type, 809 'post_author' => $this->author_id841 'post_author' => self::$editor_id 810 842 ) ); 811 843 $count1 = wp_count_posts( $post_type, 'readable' ); … … 1027 1059 function test_wp_insert_post_default_comment_ping_status_open() { 1028 1060 $post_id = $this->factory->post->create( array( 1029 'post_author' => $this->author_id,1061 'post_author' => self::$editor_id, 1030 1062 'post_status' => 'public', 1031 1063 'post_content' => rand_str(), … … 1043 1075 function test_wp_insert_post_page_default_comment_ping_status_closed() { 1044 1076 $post_id = $this->factory->post->create( array( 1045 'post_author' => $this->author_id,1077 'post_author' => self::$editor_id, 1046 1078 'post_status' => 'public', 1047 1079 'post_content' => rand_str(), … … 1062 1094 register_post_type( $post_type, array( 'supports' => array( 'comments', 'trackbacks' ) ) ); 1063 1095 $post_id = $this->factory->post->create( array( 1064 'post_author' => $this->author_id,1096 'post_author' => self::$editor_id, 1065 1097 'post_status' => 'public', 1066 1098 'post_content' => rand_str(), … … 1082 1114 register_post_type( $post_type ); 1083 1115 $post_id = $this->factory->post->create( array( 1084 'post_author' => $this->author_id,1116 'post_author' => self::$editor_id, 1085 1117 'post_status' => 'public', 1086 1118 'post_content' => rand_str(), … … 1102 1134 */ 1103 1135 function test_user_without_publish_cannot_affect_sticky() { 1104 // Create a role with edit_others_posts. 1105 add_role( 'grammarian', 'Grammarian', array( 1106 'read' => true, 1107 'edit_posts' => true, 1108 'edit_others_posts' => true, 1109 'edit_published_posts' => true, 1110 ) ); 1111 $editor_user = $this->factory->user->create( array( 'role' => 'grammarian' ) ); 1112 $old_uid = get_current_user_id(); 1113 wp_set_current_user( $editor_user ); 1136 wp_set_current_user( self::$grammarian_id ); 1114 1137 1115 1138 // Sanity Check. … … 1138 1161 $this->assertEquals( 'Updated', $saved_post->post_title ); 1139 1162 $this->assertEquals( 'Updated', $saved_post->post_content ); 1140 1141 // Teardown1142 wp_set_current_user( $old_uid );1143 1163 } 1144 1164 … … 1160 1180 $this->assertTrue( is_sticky( $post->ID ) ); 1161 1181 1162 // Create a role with edit_others_posts. 1163 add_role( 'grammarian', 'Grammarian', array( 1164 'read' => true, 1165 'edit_posts' => true, 1166 'edit_others_posts' => true, 1167 'edit_published_posts' => true, 1168 ) ); 1169 $editor_user = $this->factory->user->create( array( 'role' => 'grammarian' ) ); 1170 $old_uid = get_current_user_id(); 1171 wp_set_current_user( $editor_user ); 1182 wp_set_current_user( self::$grammarian_id ); 1172 1183 1173 1184 // Sanity Check. … … 1189 1200 $this->assertEquals( 'Updated', $saved_post->post_title ); 1190 1201 $this->assertEquals( 'Updated', $saved_post->post_content ); 1191 1192 // Teardown1193 wp_set_current_user( $old_uid );1194 1202 } 1195 1203 … … 1209 1217 $post_id = $this->factory->post->create( array( 'post_author' => null ) ); 1210 1218 1211 $this->assertEquals( $this->author_id, get_post( $post_id )->post_author );1219 $this->assertEquals( self::$editor_id, get_post( $post_id )->post_author ); 1212 1220 } 1213 1221 … … 1217 1225 function test_wp_insert_post_should_respect_post_date_gmt() { 1218 1226 $post = array( 1219 'post_author' => $this->author_id,1227 'post_author' => self::$editor_id, 1220 1228 'post_status' => 'publish', 1221 1229 'post_content' => rand_str(),
Note: See TracChangeset
for help on using the changeset viewer.