Changeset 39189
- Timestamp:
- 11/10/2016 01:53:08 AM (8 years ago)
- Location:
- trunk/tests/phpunit/tests
- Files:
-
- 13 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/tests/phpunit/tests/user/author.php
r37306 r39189 8 8 */ 9 9 class Tests_User_Author_Template extends WP_UnitTestCase { 10 protected $author_id = 0;11 protected $post_id = 0;10 protected static $author_id = 0; 11 protected static $post_id = 0; 12 12 13 13 private $permalink_structure; 14 15 public static function wpSetUpBeforeClass( WP_UnitTest_Factory $factory ) { 16 self::$author_id = $factory->user->create( array( 17 'role' => 'author', 18 'user_login' => 'test_author', 19 'description' => 'test_author', 20 ) ); 21 22 self::$post_id = $factory->post->create( array( 23 'post_author' => self::$author_id, 24 'post_status' => 'publish', 25 'post_content' => rand_str(), 26 'post_title' => rand_str(), 27 'post_type' => 'post' 28 ) ); 29 } 14 30 15 31 function setUp() { 16 32 parent::setUp(); 17 33 18 $this->author_id = self::factory()->user->create( array( 19 'role' => 'author', 20 'user_login' => 'test_author', 21 'description' => 'test_author', 22 ) ); 23 $user = new WP_User( $this->author_id ); 24 25 $post = array( 26 'post_author' => $this->author_id, 27 'post_status' => 'publish', 28 'post_content' => rand_str(), 29 'post_title' => rand_str(), 30 'post_type' => 'post' 31 ); 32 33 // insert a post and make sure the ID is ok 34 $this->post_id = self::factory()->post->create( $post ); 35 36 setup_postdata( get_post( $this->post_id ) ); 34 setup_postdata( get_post( self::$post_id ) ); 37 35 } 38 36 … … 44 42 function test_get_the_author() { 45 43 $author_name = get_the_author(); 46 $user = new WP_User( $this->author_id );44 $user = new WP_User( self::$author_id ); 47 45 48 46 $this->assertEquals( $user->display_name, $author_name ); … … 57 55 $this->assertEquals( 'test_author', get_the_author_meta( 'description' ) ); 58 56 $this->assertEquals( 'test_author', get_the_author_meta( 'user_description' ) ); 59 add_user_meta( $this->author_id, 'user_description', 'user description' );60 $this->assertEquals( 'user description', get_user_meta( $this->author_id, 'user_description', true ) );57 add_user_meta( self::$author_id, 'user_description', 'user description' ); 58 $this->assertEquals( 'user description', get_user_meta( self::$author_id, 'user_description', true ) ); 61 59 // user_description in meta is ignored. The content of description is returned instead. 62 60 // See #20285 63 61 $this->assertEquals( 'test_author', get_the_author_meta( 'user_description' ) ); 64 62 $this->assertEquals( 'test_author', get_the_author_meta( 'description' ) ); 65 update_user_meta( $this->author_id, 'user_description', '' );66 $this->assertEquals( '', get_user_meta( $this->author_id, 'user_description', true ) );63 update_user_meta( self::$author_id, 'user_description', '' ); 64 $this->assertEquals( '', get_user_meta( self::$author_id, 'user_description', true ) ); 67 65 $this->assertEquals( 'test_author', get_the_author_meta( 'user_description' ) ); 68 66 $this->assertEquals( 'test_author', get_the_author_meta( 'description' ) ); … … 81 79 // Test with no global post, result should be 0 because no author is found 82 80 $this->assertEquals( 0, get_the_author_posts() ); 83 $GLOBALS['post'] = $this->post_id;81 $GLOBALS['post'] = self::$post_id; 84 82 $this->assertEquals( 1, get_the_author_posts() ); 85 83 } … … 92 90 93 91 $cpt_ids = self::factory()->post->create_many( 2, array( 94 'post_author' => $this->author_id,92 'post_author' => self::$author_id, 95 93 'post_type' => 'wptests_pt', 96 94 ) ); -
trunk/tests/phpunit/tests/user/mapMetaCap.php
r38378 r39189 6 6 */ 7 7 class Tests_User_MapMetaCap extends WP_UnitTestCase { 8 var $super_admins = null; 9 10 function setUp() { 11 parent::setUp(); 12 13 $this->user_ids = array(); 14 15 $this->user_id = self::factory()->user->create( array( 'role' => 'administrator' ) ); 16 $this->author_id = self::factory()->user->create( array( 'role' => 'administrator' ) ); 17 18 if ( isset( $GLOBALS['super_admins'] ) ) 19 $this->super_admins = $GLOBALS['super_admins']; 20 $user = new WP_User( $this->user_id ); 8 9 protected static $post_type = 'mapmetacap'; 10 protected static $super_admins = null; 11 protected static $user_id = null; 12 protected static $author_id = null; 13 protected static $post_id = null; 14 15 public static function wpSetUpBeforeClass( WP_UnitTest_Factory $factory ) { 16 self::$user_id = self::factory()->user->create( array( 'role' => 'administrator' ) ); 17 self::$author_id = self::factory()->user->create( array( 'role' => 'administrator' ) ); 18 19 if ( isset( $GLOBALS['super_admins'] ) ) { 20 self::$super_admins = $GLOBALS['super_admins']; 21 } 22 $user = new WP_User( self::$user_id ); 21 23 $GLOBALS['super_admins'] = array( $user->user_login ); 22 24 23 $this->post_type = rand_str( 20 ); 24 register_post_type( $this->post_type ); 25 26 $this->post_id = wp_insert_post( array( 27 'post_title' => rand_str(), 28 'post_type' => $this->post_type, 25 register_post_type( self::$post_type ); 26 27 self::$post_id = $factory->post->create( array( 28 'post_type' => self::$post_type, 29 29 'post_status' => 'private', 30 'post_author' => $this->author_id, 31 ) ); 32 } 33 34 function tearDown() { 35 $GLOBALS['super_admins'] = $this->super_admins; 36 unset( $GLOBALS['wp_post_types'][ $this->post_type ] ); 37 parent::tearDown(); 30 'post_author' => self::$author_id, 31 ) ); 32 } 33 34 public static function wpTearDownAfterClass() { 35 $GLOBALS['super_admins'] = self::$super_admins; 36 unset( $GLOBALS['wp_post_types'][ self::$post_type ] ); 38 37 } 39 38 … … 44 43 $this->assertEquals( 45 44 array( 'do_not_allow' ), 46 map_meta_cap( 'edit_post', $this->user_id, $this->post_id + 1 )45 map_meta_cap( 'edit_post', self::$user_id, self::$post_id + 1 ) 47 46 ); 48 47 } … … 50 49 function test_capability_type_post_with_no_extra_caps() { 51 50 52 register_post_type( $this->post_type, array(53 'capability_type' => 'post', 54 ) ); 55 $post_type_object = get_post_type_object( $this->post_type );51 register_post_type( self::$post_type, array( 52 'capability_type' => 'post', 53 ) ); 54 $post_type_object = get_post_type_object( self::$post_type ); 56 55 57 56 $this->assertTrue( $post_type_object->map_meta_cap ); 58 57 59 58 $this->assertEquals( array( 'edit_others_posts', 'edit_private_posts' ), 60 map_meta_cap( 'edit_post', $this->user_id, $this->post_id ) );61 $this->assertEquals( array( 'edit_others_posts', 'edit_private_posts' ), 62 map_meta_cap( $post_type_object->cap->edit_post, $this->user_id, $this->post_id ) );63 64 $this->assertEquals( array( 'read_private_posts' ), 65 map_meta_cap( 'read_post', $this->user_id, $this->post_id ) );66 $this->assertEquals( array( 'read_private_posts' ), 67 map_meta_cap( $post_type_object->cap->read_post, $this->user_id, $this->post_id ) );68 69 $this->assertEquals( array( 'delete_others_posts', 'delete_private_posts' ), 70 map_meta_cap( 'delete_post', $this->user_id, $this->post_id ) );71 $this->assertEquals( array( 'delete_others_posts', 'delete_private_posts' ), 72 map_meta_cap( $post_type_object->cap->delete_post, $this->user_id, $this->post_id ) );59 map_meta_cap( 'edit_post', self::$user_id, self::$post_id ) ); 60 $this->assertEquals( array( 'edit_others_posts', 'edit_private_posts' ), 61 map_meta_cap( $post_type_object->cap->edit_post, self::$user_id, self::$post_id ) ); 62 63 $this->assertEquals( array( 'read_private_posts' ), 64 map_meta_cap( 'read_post', self::$user_id, self::$post_id ) ); 65 $this->assertEquals( array( 'read_private_posts' ), 66 map_meta_cap( $post_type_object->cap->read_post, self::$user_id, self::$post_id ) ); 67 68 $this->assertEquals( array( 'delete_others_posts', 'delete_private_posts' ), 69 map_meta_cap( 'delete_post', self::$user_id, self::$post_id ) ); 70 $this->assertEquals( array( 'delete_others_posts', 'delete_private_posts' ), 71 map_meta_cap( $post_type_object->cap->delete_post, self::$user_id, self::$post_id ) ); 73 72 } 74 73 75 74 function test_custom_capability_type_with_map_meta_cap() { 76 register_post_type( $this->post_type, array(75 register_post_type( self::$post_type, array( 77 76 'capability_type' => 'book', 78 77 'map_meta_cap' => true, 79 78 ) ); 80 79 81 $post_type_object = get_post_type_object( $this->post_type );80 $post_type_object = get_post_type_object( self::$post_type ); 82 81 83 82 $this->assertEquals( array( 'edit_others_books', 'edit_private_books' ), 84 map_meta_cap( 'edit_post', $this->user_id, $this->post_id ) );83 map_meta_cap( 'edit_post', self::$user_id, self::$post_id ) ); 85 84 $this->assertEquals( array( 'edit_others_books', 'edit_private_books' ), 86 map_meta_cap( $post_type_object->cap->edit_post, $this->user_id, $this->post_id ) );85 map_meta_cap( $post_type_object->cap->edit_post, self::$user_id, self::$post_id ) ); 87 86 88 87 $this->assertEquals( array( 'read_private_books' ), 89 map_meta_cap( 'read_post', $this->user_id, $this->post_id ) );88 map_meta_cap( 'read_post', self::$user_id, self::$post_id ) ); 90 89 $this->assertEquals( array( 'read_private_books' ), 91 map_meta_cap( $post_type_object->cap->read_post, $this->user_id, $this->post_id ) );90 map_meta_cap( $post_type_object->cap->read_post, self::$user_id, self::$post_id ) ); 92 91 93 92 $this->assertEquals( array( 'delete_others_books', 'delete_private_books' ), 94 map_meta_cap( 'delete_post', $this->user_id, $this->post_id ) );93 map_meta_cap( 'delete_post', self::$user_id, self::$post_id ) ); 95 94 $this->assertEquals( array( 'delete_others_books', 'delete_private_books' ), 96 map_meta_cap( $post_type_object->cap->delete_post, $this->user_id, $this->post_id ) );95 map_meta_cap( $post_type_object->cap->delete_post, self::$user_id, self::$post_id ) ); 97 96 } 98 97 99 98 function test_capability_type_post_with_one_renamed_cap() { 100 register_post_type( $this->post_type, array(99 register_post_type( self::$post_type, array( 101 100 'capability_type' => 'post', 102 101 'capabilities' => array( 'edit_posts' => 'edit_books' ), 103 102 ) ); 104 103 105 $post_type_object = get_post_type_object( $this->post_type );104 $post_type_object = get_post_type_object( self::$post_type ); 106 105 107 106 $this->assertFalse( $post_type_object->map_meta_cap ); 108 107 109 108 $this->assertEquals( array( 'edit_post' ), 110 map_meta_cap( 'edit_post', $this->user_id, $this->post_id ) );109 map_meta_cap( 'edit_post', self::$user_id, self::$post_id ) ); 111 110 $this->assertEquals( array( 'edit_post' ), 112 map_meta_cap( $post_type_object->cap->edit_post, $this->user_id, $this->post_id ) );111 map_meta_cap( $post_type_object->cap->edit_post, self::$user_id, self::$post_id ) ); 113 112 114 113 $this->assertEquals( array( 'read_post' ), 115 map_meta_cap( 'read_post', $this->user_id, $this->post_id ) );114 map_meta_cap( 'read_post', self::$user_id, self::$post_id ) ); 116 115 $this->assertEquals( array( 'read_post' ), 117 map_meta_cap( $post_type_object->cap->read_post, $this->user_id, $this->post_id ) );116 map_meta_cap( $post_type_object->cap->read_post, self::$user_id, self::$post_id ) ); 118 117 119 118 $this->assertEquals( array( 'delete_post' ), 120 map_meta_cap( 'delete_post', $this->user_id, $this->post_id ) );119 map_meta_cap( 'delete_post', self::$user_id, self::$post_id ) ); 121 120 $this->assertEquals( array( 'delete_post' ), 122 map_meta_cap( $post_type_object->cap->delete_post, $this->user_id, $this->post_id ) );121 map_meta_cap( $post_type_object->cap->delete_post, self::$user_id, self::$post_id ) ); 123 122 } 124 123 125 124 function test_capability_type_post_map_meta_cap_true_with_renamed_cap() { 126 register_post_type( $this->post_type, array(125 register_post_type( self::$post_type, array( 127 126 'capability_type' => 'post', 128 127 'map_meta_cap' => true, … … 133 132 ) ); 134 133 135 $post_type_object = get_post_type_object( $this->post_type );134 $post_type_object = get_post_type_object( self::$post_type ); 136 135 137 136 $this->assertTrue( $post_type_object->map_meta_cap ); 138 137 139 138 $this->assertEquals( array( 'edit_others_books', 'edit_private_posts' ), 140 map_meta_cap( 'edit_post', $this->user_id, $this->post_id ) );139 map_meta_cap( 'edit_post', self::$user_id, self::$post_id ) ); 141 140 $this->assertEquals( array( 'edit_others_books', 'edit_private_posts' ), 142 map_meta_cap( $post_type_object->cap->edit_post, $this->user_id, $this->post_id ) );143 144 $this->assertEquals( array( 'read_private_posts' ), 145 map_meta_cap( 'read_post', $this->user_id, $this->post_id ) );146 $this->assertEquals( array( 'read_private_posts' ), 147 map_meta_cap( $post_type_object->cap->read_post, $this->user_id, $this->post_id ) );148 149 $this->assertEquals( array( 'delete_others_posts', 'delete_private_posts' ), 150 map_meta_cap( 'delete_post', $this->user_id, $this->post_id ) );151 $this->assertEquals( array( 'delete_others_posts', 'delete_private_posts' ), 152 map_meta_cap( $post_type_object->cap->delete_post, $this->user_id, $this->post_id ) );141 map_meta_cap( $post_type_object->cap->edit_post, self::$user_id, self::$post_id ) ); 142 143 $this->assertEquals( array( 'read_private_posts' ), 144 map_meta_cap( 'read_post', self::$user_id, self::$post_id ) ); 145 $this->assertEquals( array( 'read_private_posts' ), 146 map_meta_cap( $post_type_object->cap->read_post, self::$user_id, self::$post_id ) ); 147 148 $this->assertEquals( array( 'delete_others_posts', 'delete_private_posts' ), 149 map_meta_cap( 'delete_post', self::$user_id, self::$post_id ) ); 150 $this->assertEquals( array( 'delete_others_posts', 'delete_private_posts' ), 151 map_meta_cap( $post_type_object->cap->delete_post, self::$user_id, self::$post_id ) ); 153 152 } 154 153 155 154 function test_capability_type_post_with_all_meta_caps_renamed() { 156 register_post_type( $this->post_type, array(155 register_post_type( self::$post_type, array( 157 156 'capability_type' => 'post', 158 157 'capabilities' => array( … … 163 162 ) ); 164 163 165 $post_type_object = get_post_type_object( $this->post_type );164 $post_type_object = get_post_type_object( self::$post_type ); 166 165 167 166 $this->assertFalse( $post_type_object->map_meta_cap ); 168 167 169 168 $this->assertEquals( array( 'edit_book' ), 170 map_meta_cap( 'edit_post', $this->user_id, $this->post_id ) );169 map_meta_cap( 'edit_post', self::$user_id, self::$post_id ) ); 171 170 $this->assertEquals( array( 'edit_book' ), 172 map_meta_cap( $post_type_object->cap->edit_post, $this->user_id, $this->post_id ) );171 map_meta_cap( $post_type_object->cap->edit_post, self::$user_id, self::$post_id ) ); 173 172 174 173 $this->assertEquals( array( 'read_book' ), 175 map_meta_cap( 'read_post', $this->user_id, $this->post_id ) );174 map_meta_cap( 'read_post', self::$user_id, self::$post_id ) ); 176 175 $this->assertEquals( array( 'read_book' ), 177 map_meta_cap( $post_type_object->cap->read_post, $this->user_id, $this->post_id ) );176 map_meta_cap( $post_type_object->cap->read_post, self::$user_id, self::$post_id ) ); 178 177 179 178 $this->assertEquals( array( 'delete_book' ), 180 map_meta_cap( 'delete_post', $this->user_id, $this->post_id ) );179 map_meta_cap( 'delete_post', self::$user_id, self::$post_id ) ); 181 180 $this->assertEquals( array( 'delete_book' ), 182 map_meta_cap( $post_type_object->cap->delete_post, $this->user_id, $this->post_id ) );181 map_meta_cap( $post_type_object->cap->delete_post, self::$user_id, self::$post_id ) ); 183 182 } 184 183 185 184 function test_capability_type_post_with_all_meta_caps_renamed_mapped() { 186 register_post_type( $this->post_type, array(185 register_post_type( self::$post_type, array( 187 186 'capability_type' => 'post', 188 187 'map_meta_cap' => true, … … 194 193 ) ); 195 194 196 $post_type_object = get_post_type_object( $this->post_type );195 $post_type_object = get_post_type_object( self::$post_type ); 197 196 198 197 $this->assertTrue( $post_type_object->map_meta_cap ); 199 198 200 199 $this->assertEquals( array( 'edit_others_posts', 'edit_private_posts' ), 201 map_meta_cap( 'edit_post', $this->user_id, $this->post_id ) );202 $this->assertEquals( array( 'edit_others_posts', 'edit_private_posts' ), 203 map_meta_cap( $post_type_object->cap->edit_post, $this->user_id, $this->post_id ) );204 205 $this->assertEquals( array( 'read_private_posts' ), 206 map_meta_cap( 'read_post', $this->user_id, $this->post_id ) );207 $this->assertEquals( array( 'read_private_posts' ), 208 map_meta_cap( $post_type_object->cap->read_post, $this->user_id, $this->post_id ) );209 210 $this->assertEquals( array( 'delete_others_posts', 'delete_private_posts' ), 211 map_meta_cap( 'delete_post', $this->user_id, $this->post_id ) );212 $this->assertEquals( array( 'delete_others_posts', 'delete_private_posts' ), 213 map_meta_cap( $post_type_object->cap->delete_post, $this->user_id, $this->post_id ) );200 map_meta_cap( 'edit_post', self::$user_id, self::$post_id ) ); 201 $this->assertEquals( array( 'edit_others_posts', 'edit_private_posts' ), 202 map_meta_cap( $post_type_object->cap->edit_post, self::$user_id, self::$post_id ) ); 203 204 $this->assertEquals( array( 'read_private_posts' ), 205 map_meta_cap( 'read_post', self::$user_id, self::$post_id ) ); 206 $this->assertEquals( array( 'read_private_posts' ), 207 map_meta_cap( $post_type_object->cap->read_post, self::$user_id, self::$post_id ) ); 208 209 $this->assertEquals( array( 'delete_others_posts', 'delete_private_posts' ), 210 map_meta_cap( 'delete_post', self::$user_id, self::$post_id ) ); 211 $this->assertEquals( array( 'delete_others_posts', 'delete_private_posts' ), 212 map_meta_cap( $post_type_object->cap->delete_post, self::$user_id, self::$post_id ) ); 214 213 } 215 214 … … 219 218 if ( is_multisite() ) { 220 219 $this->assertEquals( array( 'do_not_allow' ), map_meta_cap( 'unfiltered_html', 0 ) ); 221 $this->assertEquals( array( 'unfiltered_html' ), map_meta_cap( 'unfiltered_html', $this->user_id ) );220 $this->assertEquals( array( 'unfiltered_html' ), map_meta_cap( 'unfiltered_html', self::$user_id ) ); 222 221 } else { 223 $this->assertEquals( array( 'unfiltered_html' ), map_meta_cap( 'unfiltered_html', $this->user_id ) );222 $this->assertEquals( array( 'unfiltered_html' ), map_meta_cap( 'unfiltered_html', self::$user_id ) ); 224 223 } 225 224 } … … 239 238 } 240 239 241 $this->assertEquals( array( 'update_core' ), map_meta_cap( 'update_core', $this->user_id ) );242 $this->assertEquals( array( 'edit_plugins' ), map_meta_cap( 'edit_plugins', $this->user_id ) );240 $this->assertEquals( array( 'update_core' ), map_meta_cap( 'update_core', self::$user_id ) ); 241 $this->assertEquals( array( 'edit_plugins' ), map_meta_cap( 'edit_plugins', self::$user_id ) ); 243 242 } 244 243 … … 269 268 270 269 update_option( 'page_on_front', $post_id ); 271 $caps = map_meta_cap( 'delete_page', $this->user_id, $post_id );270 $caps = map_meta_cap( 'delete_page', self::$user_id, $post_id ); 272 271 delete_option( 'page_on_front' ); 273 272 … … 287 286 288 287 update_option( 'page_for_posts', $post_id ); 289 $caps = map_meta_cap( 'delete_page', $this->user_id, $post_id );288 $caps = map_meta_cap( 'delete_page', self::$user_id, $post_id ); 290 289 delete_option( 'page_for_posts' ); 291 290 -
trunk/tests/phpunit/tests/xmlrpc/mw/getPost.php
r35242 r39189 5 5 */ 6 6 class Tests_XMLRPC_mw_getPost extends WP_XMLRPC_UnitTestCase { 7 var $post_data; 8 var $post_id; 9 var $post_date_ts; 7 protected static $post_id; 10 8 11 function setUp() { 12 parent::setUp(); 13 14 $author_id = $this->make_user_by_role( 'author' ); 15 $this->post_date_ts = strtotime( '+1 day' ); 16 $this->post_data = array( 17 'post_title' => rand_str(), 18 'post_content' => rand_str( 2000 ), 19 'post_excerpt' => rand_str( 100 ), 20 'post_author' => $author_id, 21 'post_date' => strftime( "%Y-%m-%d %H:%M:%S", $this->post_date_ts ), 22 ); 23 $this->post_id = wp_insert_post( $this->post_data ); 9 public static function wpSetUpBeforeClass( WP_UnitTest_Factory $factory ) { 10 self::$post_id = $factory->post->create( array( 11 'post_author' => $factory->user->create( array( 12 'user_login' => 'author', 13 'user_pass' => 'author', 14 'role' => 'author' 15 ) ), 16 'post_date' => strftime( "%Y-%m-%d %H:%M:%S", strtotime( '+1 day' ) ), 17 ) ); 24 18 } 25 19 26 20 function test_invalid_username_password() { 27 $result = $this->myxmlrpcserver->mw_getPost( array( $this->post_id, 'username', 'password' ) );21 $result = $this->myxmlrpcserver->mw_getPost( array( self::$post_id, 'username', 'password' ) ); 28 22 $this->assertInstanceOf( 'IXR_Error', $result ); 29 23 $this->assertEquals( 403, $result->code ); … … 33 27 $this->make_user_by_role( 'subscriber' ); 34 28 35 $result = $this->myxmlrpcserver->mw_getPost( array( $this->post_id, 'subscriber', 'subscriber' ) );29 $result = $this->myxmlrpcserver->mw_getPost( array( self::$post_id, 'subscriber', 'subscriber' ) ); 36 30 $this->assertInstanceOf( 'IXR_Error', $result ); 37 31 $this->assertEquals( 401, $result->code ); … … 51 45 52 46 $fields = array( 'post' ); 53 $result = $this->myxmlrpcserver->mw_getPost( array( $this->post_id, 'author', 'author' ) );47 $result = $this->myxmlrpcserver->mw_getPost( array( self::$post_id, 'author', 'author' ) ); 54 48 $this->assertNotInstanceOf( 'IXR_Error', $result ); 55 49 … … 77 71 $this->assertInternalType( 'bool', $result['sticky'] ); 78 72 73 $post_data = get_post( self::$post_id ); 79 74 80 75 // Check expected values 81 76 $this->assertStringMatchesFormat( '%d', $result['userid'] ); 82 $this->assertEquals( $ this->post_data['post_title'], $result['title'] );83 $this->assertEquals( ' draft', $result['post_status'] );77 $this->assertEquals( $post_data->post_title, $result['title'] ); 78 $this->assertEquals( 'publish', $result['post_status'] ); 84 79 $this->assertStringMatchesFormat( '%d', $result['wp_author_id'] ); 85 $this->assertEquals( $ this->post_data['post_excerpt'], $result['mt_excerpt'] );86 $this->assertEquals( url_to_postid( $result['link'] ), $this->post_id );80 $this->assertEquals( $post_data->post_excerpt, $result['mt_excerpt'] ); 81 $this->assertEquals( url_to_postid( $result['link'] ), self::$post_id ); 87 82 88 83 $this->assertEquals( '', $result['wp_post_thumbnail'] ); … … 98 93 $attachment_id = self::factory()->attachment->create_upload_object( $filename ); 99 94 100 set_post_thumbnail( $this->post_id, $attachment_id );95 set_post_thumbnail( self::$post_id, $attachment_id ); 101 96 102 97 $fields = array( 'post' ); 103 $result = $this->myxmlrpcserver->mw_getPost( array( $this->post_id, 'author', 'author' ) );98 $result = $this->myxmlrpcserver->mw_getPost( array( self::$post_id, 'author', 'author' ) ); 104 99 $this->assertNotInstanceOf( 'IXR_Error', $result ); 105 100 … … 113 108 function test_date() { 114 109 $fields = array( 'post' ); 115 $result = $this->myxmlrpcserver->mw_getPost( array( $this->post_id, 'author', 'author' ) );110 $result = $this->myxmlrpcserver->mw_getPost( array( self::$post_id, 'author', 'author' ) ); 116 111 $this->assertNotInstanceOf( 'IXR_Error', $result ); 117 112 … … 121 116 $this->assertInstanceOf( 'IXR_Date', $result['date_modified_gmt'] ); 122 117 123 $this->assertEquals( $this->post_date_ts, $result['dateCreated']->getTimestamp() ); 124 $this->assertEquals( $this->post_date_ts, $result['date_modified']->getTimestamp() ); 118 $post_data = get_post( self::$post_id ); 125 119 126 $post_date_gmt = strtotime( get_gmt_from_date( mysql2date( 'Y-m-d H:i:s', $this->post_data['post_date'], false ), 'Ymd\TH:i:s' ) ); 127 $post_modified_gmt = strtotime( get_gmt_from_date( mysql2date( 'Y-m-d H:i:s', $this->post_data['post_date'], false ), 'Ymd\TH:i:s' ) ); 120 $this->assertEquals( strtotime( $post_data->post_date ), $result['dateCreated']->getTimestamp() ); 121 $this->assertEquals( strtotime( $post_data->post_date ), $result['date_modified']->getTimestamp() ); 122 123 $post_date_gmt = strtotime( get_gmt_from_date( mysql2date( 'Y-m-d H:i:s', $post_data->post_date, false ), 'Ymd\TH:i:s' ) ); 124 $post_modified_gmt = strtotime( get_gmt_from_date( mysql2date( 'Y-m-d H:i:s', $post_data->post_date, false ), 'Ymd\TH:i:s' ) ); 128 125 129 126 $this->assertEquals( $post_date_gmt, $result['date_created_gmt']->getTimestamp() ); -
trunk/tests/phpunit/tests/xmlrpc/mw/getRecentPosts.php
r35244 r39189 5 5 */ 6 6 class Tests_XMLRPC_mw_getRecentPosts extends WP_XMLRPC_UnitTestCase { 7 var $post_data; 8 var $post_id; 9 var $post_date_ts; 7 protected static $post_id; 10 8 11 function setUp() { 12 parent::setUp(); 13 14 $author_id = $this->make_user_by_role( 'author' ); 15 $this->post_date_ts = strtotime( '+1 day' ); 16 $this->post_data = array( 17 'post_title' => rand_str(), 18 'post_content' => rand_str( 2000 ), 19 'post_excerpt' => rand_str( 100 ), 20 'post_author' => $author_id, 21 'post_date' => strftime( "%Y-%m-%d %H:%M:%S", $this->post_date_ts ), 22 ); 23 $this->post_id = wp_insert_post( $this->post_data ); 9 public static function wpSetUpBeforeClass( WP_UnitTest_Factory $factory ) { 10 self::$post_id = $factory->post->create( array( 11 'post_type' => 'page', 12 'post_author' => $factory->user->create( array( 13 'user_login' => 'author', 14 'user_pass' => 'author', 15 'role' => 'author' 16 ) ), 17 'post_date' => strftime( "%Y-%m-%d %H:%M:%S", strtotime( '+1 day' ) ), 18 ) ); 24 19 } 25 20 … … 42 37 43 38 function test_no_editable_posts() { 44 wp_delete_post( $this->post_id, true );39 wp_delete_post( self::$post_id, true ); 45 40 46 41 $result = $this->myxmlrpcserver->mw_getRecentPosts( array( 1, 'author', 'author' ) ); … … 101 96 // create attachment 102 97 $filename = ( DIR_TESTDATA.'/images/a2-small.jpg' ); 103 $attachment_id = self::factory()->attachment->create_upload_object( $filename, $this->post_id );104 set_post_thumbnail( $this->post_id, $attachment_id );98 $attachment_id = self::factory()->attachment->create_upload_object( $filename, self::$post_id ); 99 set_post_thumbnail( self::$post_id, $attachment_id ); 105 100 106 $results = $this->myxmlrpcserver->mw_getRecentPosts( array( $this->post_id, 'author', 'author' ) );101 $results = $this->myxmlrpcserver->mw_getRecentPosts( array( self::$post_id, 'author', 'author' ) ); 107 102 $this->assertNotInstanceOf( 'IXR_Error', $results ); 108 103 … … 111 106 $this->assertStringMatchesFormat( '%d', $result['wp_post_thumbnail'] ); 112 107 113 if( ! empty( $result['wp_post_thumbnail'] ) || $result['postid'] == $this->post_id ) {108 if( ! empty( $result['wp_post_thumbnail'] ) || $result['postid'] == self::$post_id ) { 114 109 $attachment_id = get_post_meta( $result['postid'], '_thumbnail_id', true ); 115 110 -
trunk/tests/phpunit/tests/xmlrpc/wp/deleteTerm.php
r38698 r39189 5 5 */ 6 6 class Tests_XMLRPC_wp_deleteTerm extends WP_XMLRPC_UnitTestCase { 7 var $term;7 protected static $term_id; 8 8 9 function setUp() { 10 parent::setUp(); 11 12 $this->term = wp_insert_term( 'term' . rand_str() , 'category' ); 13 $this->assertInternalType( 'array', $this->term ); 9 public static function wpSetUpBeforeClass( WP_UnitTest_Factory $factory ) { 10 self::$term_id = $factory->term->create( array( 11 'taxonomy' => 'category', 12 ) ); 14 13 } 15 14 … … 41 40 $this->make_user_by_role( 'subscriber' ); 42 41 43 $result = $this->myxmlrpcserver->wp_deleteTerm( array( 1, 'subscriber', 'subscriber', 'category', $this->term['term_id']) );42 $result = $this->myxmlrpcserver->wp_deleteTerm( array( 1, 'subscriber', 'subscriber', 'category', self::$term_id ) ); 44 43 $this->assertInstanceOf( 'IXR_Error', $result ); 45 44 $this->assertEquals( 401, $result->code ); … … 68 67 $this->make_user_by_role( 'editor' ); 69 68 70 $result = $this->myxmlrpcserver->wp_deleteTerm( array( 1, 'editor', 'editor', 'category', $this->term['term_id']) );69 $result = $this->myxmlrpcserver->wp_deleteTerm( array( 1, 'editor', 'editor', 'category', self::$term_id ) ); 71 70 $this->assertNotInstanceOf( 'IXR_Error', $result ); 72 71 $this->assertInternalType( 'boolean', $result ); -
trunk/tests/phpunit/tests/xmlrpc/wp/editTerm.php
r38698 r39189 5 5 */ 6 6 class Tests_XMLRPC_wp_editTerm extends WP_XMLRPC_UnitTestCase { 7 var$parent_term;8 var$child_term;9 var$post_tag;7 protected static $parent_term; 8 protected static $child_term; 9 protected static $post_tag; 10 10 11 function setUp() { 12 parent::setUp(); 13 14 $this->parent_term = wp_insert_term( 'parent' . rand_str() , 'category' ); 15 $this->assertInternalType( 'array', $this->parent_term ); 16 $this->child_term = wp_insert_term( 'child' . rand_str() , 'category' ); 17 $this->assertInternalType( 'array', $this->child_term ); 18 $this->post_tag = wp_insert_term( 'test' . rand_str() , 'post_tag' ); 19 $this->assertInternalType( 'array', $this->post_tag ); 11 public static function wpSetUpBeforeClass( WP_UnitTest_Factory $factory ) { 12 self::$parent_term = $factory->term->create( array( 13 'taxonomy' => 'category', 14 ) ); 15 self::$child_term = $factory->term->create( array( 16 'taxonomy' => 'category', 17 ) ); 18 self::$post_tag = $factory->term->create( array( 19 'taxonomy' => 'post_tag', 20 ) ); 20 21 } 21 22 … … 38 39 $this->make_user_by_role( 'subscriber' ); 39 40 40 $result = $this->myxmlrpcserver->wp_editTerm( array( 1, 'subscriber', 'subscriber', $this->parent_term['term_id'], array( 'taxonomy' => 'not_existing' ) ) );41 $result = $this->myxmlrpcserver->wp_editTerm( array( 1, 'subscriber', 'subscriber', self::$parent_term, array( 'taxonomy' => 'not_existing' ) ) ); 41 42 $this->assertInstanceOf( 'IXR_Error', $result ); 42 43 $this->assertEquals( 403, $result->code ); … … 47 48 $this->make_user_by_role( 'subscriber' ); 48 49 49 $result = $this->myxmlrpcserver->wp_editTerm( array( 1, 'subscriber', 'subscriber', $this->parent_term['term_id'], array( 'taxonomy' => 'category' ) ) );50 $result = $this->myxmlrpcserver->wp_editTerm( array( 1, 'subscriber', 'subscriber', self::$parent_term, array( 'taxonomy' => 'category' ) ) ); 50 51 $this->assertInstanceOf( 'IXR_Error', $result ); 51 52 $this->assertEquals( 401, $result->code ); … … 74 75 $this->make_user_by_role( 'editor' ); 75 76 76 $result = $this->myxmlrpcserver->wp_editTerm( array( 1, 'editor', 'editor', $this->parent_term['term_id'], array( 'taxonomy' => 'category', 'name' => '' ) ) );77 $result = $this->myxmlrpcserver->wp_editTerm( array( 1, 'editor', 'editor', self::$parent_term, array( 'taxonomy' => 'category', 'name' => '' ) ) ); 77 78 $this->assertInstanceOf( 'IXR_Error', $result ); 78 79 $this->assertEquals( 403, $result->code ); … … 83 84 $this->make_user_by_role( 'editor' ); 84 85 85 $result = $this->myxmlrpcserver->wp_editTerm( array( 1, 'editor', 'editor', $this->post_tag['term_id'], array( 'taxonomy' => 'post_tag', 'parent' => $this->parent_term['term_id']) ) );86 $result = $this->myxmlrpcserver->wp_editTerm( array( 1, 'editor', 'editor', self::$post_tag, array( 'taxonomy' => 'post_tag', 'parent' => self::$parent_term ) ) ); 86 87 $this->assertInstanceOf( 'IXR_Error', $result ); 87 88 $this->assertEquals( 403, $result->code ); … … 92 93 $this->make_user_by_role( 'editor' ); 93 94 94 $result = $this->myxmlrpcserver->wp_editTerm( array( 1, 'editor', 'editor', $this->child_term['term_id'], array( 'taxonomy' => 'category', 'parent' => '', 'name' => 'test' ) ) );95 $result = $this->myxmlrpcserver->wp_editTerm( array( 1, 'editor', 'editor', self::$child_term, array( 'taxonomy' => 'category', 'parent' => '', 'name' => 'test' ) ) ); 95 96 $this->assertNotInstanceOf( 'IXR_Error', $result ); 96 97 $this->assertTrue( $result ); … … 100 101 $this->make_user_by_role( 'editor' ); 101 102 102 $result = $this->myxmlrpcserver->wp_editTerm( array( 1, 'editor', 'editor', $this->child_term['term_id'], array( 'taxonomy' => 'category', 'parent' => NULL, 'name' => 'test' ) ) );103 $result = $this->myxmlrpcserver->wp_editTerm( array( 1, 'editor', 'editor', self::$child_term, array( 'taxonomy' => 'category', 'parent' => NULL, 'name' => 'test' ) ) ); 103 104 104 105 $this->assertNotInstanceOf( 'IXR_Error', $result ); 105 106 $this->assertInternalType( 'boolean', $result ); 106 107 107 $term = get_term( $this->child_term['term_id'], 'category' );108 $term = get_term( self::$child_term, 'category' ); 108 109 $this->assertEquals( '0', $term->parent ); 109 110 } … … 112 113 $this->make_user_by_role( 'editor' ); 113 114 114 $result = $this->myxmlrpcserver->wp_editTerm( array( 1, 'editor', 'editor', $this->child_term['term_id'], array( 'taxonomy' => 'category', 'parent' => 'dasda', 'name' => 'test' ) ) );115 $result = $this->myxmlrpcserver->wp_editTerm( array( 1, 'editor', 'editor', self::$child_term, array( 'taxonomy' => 'category', 'parent' => 'dasda', 'name' => 'test' ) ) ); 115 116 $this->assertInstanceOf( 'IXR_Error', $result ); 116 117 $this->assertEquals( 500, $result->code ); … … 120 121 $this->make_user_by_role( 'editor' ); 121 122 122 $result = $this->myxmlrpcserver->wp_editTerm( array( 1, 'editor', 'editor', $this->child_term['term_id'], array( 'taxonomy' => 'category', 'parent' => 9999, 'name' => 'test' ) ) );123 $result = $this->myxmlrpcserver->wp_editTerm( array( 1, 'editor', 'editor', self::$child_term, array( 'taxonomy' => 'category', 'parent' => 9999, 'name' => 'test' ) ) ); 123 124 $this->assertInstanceOf( 'IXR_Error', $result ); 124 125 $this->assertEquals( 403, $result->code ); … … 129 130 $this->make_user_by_role( 'editor' ); 130 131 131 $parent_term = get_term_by( 'id', $this->parent_term['term_id'], 'category' );132 $result = $this->myxmlrpcserver->wp_editTerm( array( 1, 'editor', 'editor', $this->child_term['term_id'], array( 'taxonomy' => 'category', 'slug' => $parent_term->slug ) ) );132 $parent_term = get_term_by( 'id', self::$parent_term, 'category' ); 133 $result = $this->myxmlrpcserver->wp_editTerm( array( 1, 'editor', 'editor', self::$child_term, array( 'taxonomy' => 'category', 'slug' => $parent_term->slug ) ) ); 133 134 $this->assertInstanceOf( 'IXR_Error', $result ); 134 135 $this->assertEquals( 500, $result->code ); … … 139 140 $this->make_user_by_role( 'editor' ); 140 141 141 $fields = array( 'taxonomy' => 'category', 'name' => 'Child 2', 'parent' => $this->parent_term['term_id'], 'description' => 'Child term', 'slug' => 'child_2' );142 $result = $this->myxmlrpcserver->wp_editTerm( array( 1, 'editor', 'editor', $this->child_term['term_id'], $fields ) );142 $fields = array( 'taxonomy' => 'category', 'name' => 'Child 2', 'parent' => self::$parent_term, 'description' => 'Child term', 'slug' => 'child_2' ); 143 $result = $this->myxmlrpcserver->wp_editTerm( array( 1, 'editor', 'editor', self::$child_term, $fields ) ); 143 144 144 145 $this->assertNotInstanceOf( 'IXR_Error', $result ); -
trunk/tests/phpunit/tests/xmlrpc/wp/getComment.php
r35242 r39189 5 5 */ 6 6 class Tests_XMLRPC_wp_getComment extends WP_XMLRPC_UnitTestCase { 7 var$post_id;8 var$parent_comment_id;9 var$parent_comment_data;10 var$child_comment_id;11 var$child_comment_data;7 protected static $post_id; 8 protected static $parent_comment_id; 9 protected static $parent_comment_data; 10 protected static $child_comment_id; 11 protected static $child_comment_data; 12 12 13 function setUp() {14 parent::setUp();13 public static function wpSetUpBeforeClass( WP_UnitTest_Factory $factory ) { 14 self::$post_id = $factory->post->create(); 15 15 16 $this->post_id = self::factory()->post->create(); 17 18 $this->parent_comment_data = array( 19 'comment_post_ID' => $this->post_id, 16 self::$parent_comment_data = array( 17 'comment_post_ID' => self::$post_id, 20 18 'comment_author' => 'Test commenter', 21 19 'comment_author_url' => 'http://example.com/', … … 23 21 'comment_content' => rand_str( 100 ), 24 22 ); 25 $this->parent_comment_id = wp_insert_comment( $this->parent_comment_data );23 self::$parent_comment_id = wp_insert_comment( self::$parent_comment_data ); 26 24 27 $this->child_comment_data = array(28 'comment_post_ID' => $this->post_id,25 self::$child_comment_data = array( 26 'comment_post_ID' => self::$post_id, 29 27 'comment_author' => 'Test commenter 2', 30 28 'comment_author_url' => 'http://example.org/', 31 29 'comment_author_email' => 'example@example.org', 32 'comment_parent' => $this->parent_comment_id,30 'comment_parent' => self::$parent_comment_id, 33 31 'comment_content' => rand_str( 100 ) 34 32 ); 35 $this->child_comment_id = wp_insert_comment( $this->child_comment_data );33 self::$child_comment_id = wp_insert_comment( self::$child_comment_data ); 36 34 } 37 35 38 36 function test_invalid_username_password() { 39 $result = $this->myxmlrpcserver->wp_getComment( array( 1, 'username', 'password', $this->parent_comment_id ) );37 $result = $this->myxmlrpcserver->wp_getComment( array( 1, 'username', 'password', self::$parent_comment_id ) ); 40 38 $this->assertInstanceOf( 'IXR_Error', $result ); 41 39 $this->assertEquals( 403, $result->code ); … … 45 43 $this->make_user_by_role( 'contributor' ); 46 44 47 $result = $this->myxmlrpcserver->wp_getComment( array( 1, 'contributor', 'contributor', $this->parent_comment_id ) );45 $result = $this->myxmlrpcserver->wp_getComment( array( 1, 'contributor', 'contributor', self::$parent_comment_id ) ); 48 46 $this->assertInstanceOf( 'IXR_Error', $result ); 49 47 $this->assertEquals( 403, $result->code ); … … 53 51 $this->make_user_by_role( 'editor' ); 54 52 55 $result = $this->myxmlrpcserver->wp_getComment( array( 1, 'editor', 'editor', $this->parent_comment_id ) );53 $result = $this->myxmlrpcserver->wp_getComment( array( 1, 'editor', 'editor', self::$parent_comment_id ) ); 56 54 $this->assertNotInstanceOf( 'IXR_Error', $result ); 57 55 … … 77 75 $this->assertStringMatchesFormat( '%d', $result['parent'] ); 78 76 $this->assertStringMatchesFormat( '%d', $result['post_id'] ); 79 $this->assertEquals( $this->parent_comment_id, $result['comment_id'] );77 $this->assertEquals( self::$parent_comment_id, $result['comment_id'] ); 80 78 $this->assertEquals( 0, $result['parent'] ); 81 $this->assertEquals( $this->parent_comment_data['comment_content'], $result['content'] );82 $this->assertEquals( $this->post_id, $result['post_id'] );83 $this->assertEquals( $this->parent_comment_data['comment_author'], $result['author'] );84 $this->assertEquals( $this->parent_comment_data['comment_author_url'], $result['author_url'] );85 $this->assertEquals( $this->parent_comment_data['comment_author_email'], $result['author_email'] );79 $this->assertEquals( self::$parent_comment_data['comment_content'], $result['content'] ); 80 $this->assertEquals( self::$post_id, $result['post_id'] ); 81 $this->assertEquals( self::$parent_comment_data['comment_author'], $result['author'] ); 82 $this->assertEquals( self::$parent_comment_data['comment_author_url'], $result['author_url'] ); 83 $this->assertEquals( self::$parent_comment_data['comment_author_email'], $result['author_email'] ); 86 84 } 87 85 … … 89 87 $this->make_user_by_role( 'editor' ); 90 88 91 $result = $this->myxmlrpcserver->wp_getComment( array( 1, 'editor', 'editor', $this->child_comment_id ) );89 $result = $this->myxmlrpcserver->wp_getComment( array( 1, 'editor', 'editor', self::$child_comment_id ) ); 92 90 $this->assertNotInstanceOf( 'IXR_Error', $result ); 93 91 94 $this->assertEquals( $this->child_comment_id, $result['comment_id'] );95 $this->assertEquals( $this->parent_comment_id, $result['parent'] );92 $this->assertEquals( self::$child_comment_id, $result['comment_id'] ); 93 $this->assertEquals( self::$parent_comment_id, $result['parent'] ); 96 94 } 97 95 -
trunk/tests/phpunit/tests/xmlrpc/wp/getMediaItem.php
r35309 r39189 5 5 */ 6 6 class Tests_XMLRPC_wp_getMediaItem extends WP_XMLRPC_UnitTestCase { 7 var $post_id; 7 protected static $post_id; 8 8 9 var $attachment_data; 9 10 var $attachment_id; 11 12 public static function wpSetUpBeforeClass( WP_UnitTest_Factory $factory ) { 13 self::$post_id = $factory->post->create(); 14 } 10 15 11 16 function setUp() { … … 14 19 add_theme_support( 'post-thumbnails' ); 15 20 16 $this->post_id = wp_insert_post( array(17 'post_title' => rand_str(),18 'post_content' => rand_str(),19 'post_status' => 'publish'20 ));21 22 21 $filename = ( DIR_TESTDATA.'/images/waffles.jpg' ); 23 22 $contents = file_get_contents( $filename ); 24 23 $upload = wp_upload_bits(basename($filename), null, $contents); 25 24 26 $this->attachment_id = $this->_make_attachment( $upload, $this->post_id );25 $this->attachment_id = $this->_make_attachment( $upload, self::$post_id ); 27 26 $this->attachment_data = get_post( $this->attachment_id, ARRAY_A ); 28 27 29 set_post_thumbnail( $this->post_id, $this->attachment_id );28 set_post_thumbnail( self::$post_id, $this->attachment_id ); 30 29 } 31 30 -
trunk/tests/phpunit/tests/xmlrpc/wp/getPage.php
r35244 r39189 5 5 */ 6 6 class Tests_XMLRPC_wp_getPage extends WP_XMLRPC_UnitTestCase { 7 var $post_data; 8 var $post_id; 9 var $post_date_ts; 7 protected static $post_id; 10 8 11 function setUp() { 12 parent::setUp(); 13 14 $this->post_date_ts = strtotime( '+1 day' ); 15 $this->post_data = array( 16 'post_type' => 'page', 17 'post_title' => rand_str(), 18 'post_content' => rand_str( 2000 ), 19 'post_excerpt' => rand_str( 100 ), 20 'post_author' => $this->make_user_by_role( 'author' ), 21 'post_date' => strftime( "%Y-%m-%d %H:%M:%S", $this->post_date_ts ), 22 ); 23 $this->post_id = wp_insert_post( $this->post_data ); 9 public static function wpSetUpBeforeClass( WP_UnitTest_Factory $factory ) { 10 self::$post_id = $factory->post->create( array( 11 'post_type' => 'page', 12 'post_author' => $factory->user->create( array( 13 'user_login' => 'author', 14 'user_pass' => 'author', 15 'role' => 'author' 16 ) ), 17 'post_date' => strftime( "%Y-%m-%d %H:%M:%S", strtotime( '+1 day' ) ), 18 ) ); 24 19 } 25 20 26 21 function test_invalid_username_password() { 27 $result = $this->myxmlrpcserver->wp_getPage( array( 1, $this->post_id, 'username', 'password' ) );22 $result = $this->myxmlrpcserver->wp_getPage( array( 1, self::$post_id, 'username', 'password' ) ); 28 23 $this->assertInstanceOf( 'IXR_Error', $result ); 29 24 $this->assertEquals( 403, $result->code ); … … 44 39 $this->make_user_by_role( 'editor' ); 45 40 46 $result = $this->myxmlrpcserver->wp_getPage( array( 1, $this->post_id, 'editor', 'editor' ) );41 $result = $this->myxmlrpcserver->wp_getPage( array( 1, self::$post_id, 'editor', 'editor' ) ); 47 42 $this->assertNotInstanceOf( 'IXR_Error', $result ); 48 43 … … 71 66 $this->assertInternalType( 'string', $result['wp_page_template'] ); 72 67 68 $post_data = get_post( self::$post_id ); 69 73 70 // Check expected values 74 71 $this->assertStringMatchesFormat( '%d', $result['userid'] ); 75 $this->assertEquals( ' draft', $result['page_status'] );76 $this->assertEquals( $ this->post_data['post_title'], $result['title'] );77 $this->assertEquals( url_to_postid( $result['link'] ), $this->post_id );78 $this->assertEquals( $ this->post_data['post_excerpt'], $result['excerpt'] );72 $this->assertEquals( 'future', $result['page_status'] ); 73 $this->assertEquals( $post_data->post_title, $result['title'] ); 74 $this->assertEquals( url_to_postid( $result['link'] ), self::$post_id ); 75 $this->assertEquals( $post_data->post_excerpt, $result['excerpt'] ); 79 76 $this->assertStringMatchesFormat( '%d', $result['wp_author_id'] ); 80 77 } … … 83 80 $this->make_user_by_role( 'editor' ); 84 81 85 $result = $this->myxmlrpcserver->wp_getPage( array( 1, $this->post_id, 'editor', 'editor' ) );82 $result = $this->myxmlrpcserver->wp_getPage( array( 1, self::$post_id, 'editor', 'editor' ) ); 86 83 $this->assertNotInstanceOf( 'IXR_Error', $result ); 87 84 … … 89 86 $this->assertInstanceOf( 'IXR_Date', $result['date_created_gmt'] ); 90 87 91 $ date_gmt = strtotime( get_gmt_from_date( mysql2date( 'Y-m-d H:i:s', $this->post_data['post_date'], false ), 'Ymd\TH:i:s' ));88 $post_data = get_post( self::$post_id ); 92 89 93 $this->assertEquals( $this->post_date_ts, $result['dateCreated']->getTimestamp() ); 90 $date_gmt = strtotime( get_gmt_from_date( mysql2date( 'Y-m-d H:i:s', $post_data->post_date, false ), 'Ymd\TH:i:s' ) ); 91 92 $this->assertEquals( strtotime( $post_data->post_date ), $result['dateCreated']->getTimestamp() ); 94 93 $this->assertEquals( $date_gmt, $result['date_created_gmt']->getTimestamp() ); 95 94 } -
trunk/tests/phpunit/tests/xmlrpc/wp/getPageList.php
r25002 r39189 5 5 */ 6 6 class Tests_XMLRPC_wp_getPageList extends WP_XMLRPC_UnitTestCase { 7 var $post_data; 8 var $post_id; 9 var $post_date_ts; 7 protected static $post_id; 10 8 11 function setUp() { 12 parent::setUp(); 13 14 $this->post_date_ts = strtotime( '+1 day' ); 15 $this->post_data = array( 16 'post_type' => 'page', 17 'post_title' => rand_str(), 18 'post_content' => rand_str( 2000 ), 19 'post_excerpt' => rand_str( 100 ), 20 'post_author' => $this->make_user_by_role( 'author' ), 21 'post_date' => strftime( "%Y-%m-%d %H:%M:%S", $this->post_date_ts ), 22 ); 23 $this->post_id = wp_insert_post( $this->post_data ); 9 public static function wpSetUpBeforeClass( WP_UnitTest_Factory $factory ) { 10 self::$post_id = $factory->post->create( array( 11 'post_type' => 'page', 12 'post_author' => $factory->user->create( array( 13 'user_login' => 'author', 14 'user_pass' => 'author', 15 'role' => 'author' 16 ) ), 17 'post_date' => strftime( "%Y-%m-%d %H:%M:%S", strtotime( '+1 day' ) ), 18 ) ); 24 19 } 25 20 -
trunk/tests/phpunit/tests/xmlrpc/wp/getPages.php
r25002 r39189 5 5 */ 6 6 class Tests_XMLRPC_wp_getPages extends WP_XMLRPC_UnitTestCase { 7 var $post_data; 8 var $post_id; 9 var $post_date_ts; 10 var $editor_id; 7 protected static $post_id; 8 protected static $editor_id; 11 9 12 function setUp() { 13 parent::setUp(); 10 public static function wpSetUpBeforeClass( WP_UnitTest_Factory $factory ) { 11 self::$post_id = $factory->post->create( array( 12 'post_type' => 'page', 13 'post_author' => $factory->user->create( array( 14 'user_login' => 'administrator', 15 'user_pass' => 'administrator', 16 'role' => 'administrator' 17 ) ), 18 'post_date' => strftime( "%Y-%m-%d %H:%M:%S", strtotime( '+1 day' ) ), 19 ) ); 20 self::$editor_id = $factory->user->create( array( 21 'user_login' => 'editor', 22 'user_pass' => 'editor', 23 'role' => 'editor' 24 ) ); 25 } 14 26 15 $this->post_date_ts = strtotime( '+1 day' ); 16 $this->post_data = array( 17 'post_type' => 'page', 18 'post_title' => rand_str(), 19 'post_content' => rand_str( 2000 ), 20 'post_excerpt' => rand_str( 100 ), 21 'post_author' => $this->make_user_by_role( 'administrator' ), 22 'post_date' => strftime( "%Y-%m-%d %H:%M:%S", $this->post_date_ts ), 23 ); 24 $this->post_id = wp_insert_post( $this->post_data ); 25 $this->editor_id = $this->make_user_by_role( 'editor' ); 26 } 27 function test_invalid_username_password() { 28 $result = $this->myxmlrpcserver->wp_getPages( array( 1, 'username', 'password' ) ); 29 $this->assertInstanceOf( 'IXR_Error', $result ); 30 $this->assertEquals( 403, $result->code ); 31 } 27 32 28 function test_invalid_username_password() { 29 $result = $this->myxmlrpcserver->wp_getPages( array( 1, 'username', 'password' ) ); 30 $this->assertInstanceOf( 'IXR_Error', $result ); 31 $this->assertEquals( 403, $result->code ); 32 } 33 34 function test_incapable_user() { 33 function test_incapable_user() { 35 34 $this->make_user_by_role( 'contributor' ); 36 35 37 38 39 40 36 $result = $this->myxmlrpcserver->wp_getPages( array( 1, 'contributor', 'contributor' ) ); 37 $this->assertInstanceOf( 'IXR_Error', $result ); 38 $this->assertEquals( 401, $result->code ); 39 } 41 40 42 43 44 41 function test_capable_user() { 42 $results = $this->myxmlrpcserver->wp_getPages( array( 1, 'administrator', 'administrator' ) ); 43 $this->assertNotInstanceOf( 'IXR_Error', $results ); 45 44 46 47 48 49 50 45 foreach( $results as $result ) { 46 $page = get_post( $result['page_id'] ); 47 $this->assertEquals( $page->post_type, 'page' ); 48 } 49 } 51 50 52 53 54 if ( $user_id == $this->editor_id && $args[0] == $this->post_id ) {55 56 57 51 function remove_editor_edit_page_cap( $caps, $cap, $user_id, $args ) { 52 if ( in_array( $cap, array( 'edit_page', 'edit_others_pages' ) ) ) { 53 if ( $user_id == self::$editor_id && $args[0] == self::$post_id ) { 54 return array( false ); 55 } 56 } 58 57 59 60 58 return $caps; 59 } 61 60 62 61 /** … … 64 63 */ 65 64 function test_semi_capable_user() { 66 65 add_filter( 'map_meta_cap', array( $this, 'remove_editor_edit_page_cap') , 10, 4 ); 67 66 68 69 67 $results = $this->myxmlrpcserver->wp_getPages( array( 1, 'editor', 'editor' ) ); 68 $this->assertNotInstanceOf( 'IXR_Error', $results ); 70 69 71 72 73 74 70 $found_incapable = false; 71 foreach( $results as $result ) { 72 // WP#20629 73 $this->assertNotInstanceOf( 'IXR_Error', $result ); 75 74 76 if ( $result['page_id'] == $this->post_id ) {77 78 79 80 81 75 if ( $result['page_id'] == self::$post_id ) { 76 $found_incapable = true; 77 break; 78 } 79 } 80 $this->assertFalse( $found_incapable ); 82 81 83 84 82 remove_filter( 'map_meta_cap', array( $this, 'remove_editor_edit_page_cap' ), 10, 4 ); 83 } 85 84 86 85 } -
trunk/tests/phpunit/tests/xmlrpc/wp/getTerm.php
r38698 r39189 5 5 */ 6 6 class Tests_XMLRPC_wp_getTerm extends WP_XMLRPC_UnitTestCase { 7 var $term;8 7 9 function setUp() { 10 parent::setUp(); 8 protected static $term_id; 11 9 12 $this->term = wp_insert_term( 'term' . rand_str() , 'category' ); 13 $this->assertInternalType( 'array', $this->term ); 10 public static function wpSetUpBeforeClass( WP_UnitTest_Factory $factory ) { 11 self::$term_id = $factory->term->create( array( 12 'taxonomy' => 'category', 13 ) ); 14 14 } 15 15 … … 41 41 $this->make_user_by_role( 'subscriber' ); 42 42 43 $result = $this->myxmlrpcserver->wp_getTerm( array( 1, 'subscriber', 'subscriber', 'category', $this->term['term_id']) );43 $result = $this->myxmlrpcserver->wp_getTerm( array( 1, 'subscriber', 'subscriber', 'category', self::$term_id ) ); 44 44 $this->assertInstanceOf( 'IXR_Error', $result ); 45 45 $this->assertEquals( 401, $result->code ); … … 69 69 $this->make_user_by_role( 'editor' ); 70 70 71 $term = get_term( $this->term['term_id'], 'category', ARRAY_A );71 $term = get_term( self::$term_id, 'category', ARRAY_A ); 72 72 73 $result = $this->myxmlrpcserver->wp_getTerm( array( 1, 'editor', 'editor', 'category', $this->term['term_id']) );73 $result = $this->myxmlrpcserver->wp_getTerm( array( 1, 'editor', 'editor', 'category', self::$term_id ) ); 74 74 75 75 $this->assertNotInstanceOf( 'IXR_Error', $result ); -
trunk/tests/phpunit/tests/xmlrpc/wp/newTerm.php
r38078 r39189 5 5 */ 6 6 class Tests_XMLRPC_wp_newTerm extends WP_XMLRPC_UnitTestCase { 7 var $parent_term;8 7 9 function setUp() { 10 parent::setUp(); 8 protected static $parent_term_id; 11 9 12 $this->parent_term = wp_insert_term( 'parent' . rand_str(), 'category' ); 13 $this->assertInternalType( 'array', $this->parent_term ); 14 $this->parent_term = $this->parent_term['term_id']; 10 public static function wpSetUpBeforeClass( WP_UnitTest_Factory $factory ) { 11 self::$parent_term_id = $factory->term->create( array( 12 'taxonomy' => 'category', 13 ) ); 15 14 } 16 15 … … 60 59 $this->make_user_by_role( 'editor' ); 61 60 62 $result = $this->myxmlrpcserver->wp_newTerm( array( 1, 'editor', 'editor', array( 'taxonomy' => 'post_tag', 'parent' => $this->parent_term, 'name' => 'test' ) ) );61 $result = $this->myxmlrpcserver->wp_newTerm( array( 1, 'editor', 'editor', array( 'taxonomy' => 'post_tag', 'parent' => self::$parent_term_id, 'name' => 'test' ) ) ); 63 62 $this->assertInstanceOf( 'IXR_Error', $result ); 64 63 $this->assertEquals( 403, $result->code ); … … 95 94 $this->make_user_by_role( 'editor' ); 96 95 97 $result = $this->myxmlrpcserver->wp_newTerm( array( 1, 'editor', 'editor', array( 'taxonomy' => 'category', 'parent' => $this->parent_term, 'name' => 'test' ) ) );96 $result = $this->myxmlrpcserver->wp_newTerm( array( 1, 'editor', 'editor', array( 'taxonomy' => 'category', 'parent' => self::$parent_term_id, 'name' => 'test' ) ) ); 98 97 $this->assertNotInstanceOf( 'IXR_Error', $result ); 99 98 $this->assertStringMatchesFormat( '%d', $result ); … … 103 102 $this->make_user_by_role( 'editor' ); 104 103 105 $taxonomy = array( 'taxonomy' => 'category', 'parent' => $this->parent_term, 'name' => 'test_all', 'description' => 'Test all', 'slug' => 'test_all' );104 $taxonomy = array( 'taxonomy' => 'category', 'parent' => self::$parent_term_id, 'name' => 'test_all', 'description' => 'Test all', 'slug' => 'test_all' ); 106 105 $result = $this->myxmlrpcserver->wp_newTerm( array( 1, 'editor', 'editor', $taxonomy ) ); 107 106 $this->assertNotInstanceOf( 'IXR_Error', $result );
Note: See TracChangeset
for help on using the changeset viewer.