Changeset 42343 for trunk/tests/phpunit/tests/xmlrpc/wp/newPost.php
- Timestamp:
- 11/30/2017 11:09:33 PM (7 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/tests/phpunit/tests/xmlrpc/wp/newPost.php
r40417 r42343 32 32 $this->make_user_by_role( 'author' ); 33 33 34 $post = array( 'post_title' => 'Test' );34 $post = array( 'post_title' => 'Test' ); 35 35 $result = $this->myxmlrpcserver->wp_newPost( array( 1, 'author', 'author', $post ) ); 36 36 $this->assertNotIXRError( $result ); … … 41 41 $this->make_user_by_role( 'author' ); 42 42 43 $post = array( 'post_title' => 'Test', 'ID' => 103948 ); 43 $post = array( 44 'post_title' => 'Test', 45 'ID' => 103948, 46 ); 44 47 $result = $this->myxmlrpcserver->wp_newPost( array( 1, 'author', 'author', $post ) ); 45 48 $this->assertNotIXRError( $result ); … … 50 53 $this->make_user_by_role( 'author' ); 51 54 52 $post = array( 'post_title' => 'Test', 'post_status' => 'publish' ); 55 $post = array( 56 'post_title' => 'Test', 57 'post_status' => 'publish', 58 ); 53 59 $result = $this->myxmlrpcserver->wp_newPost( array( 1, 'author', 'author', $post ) ); 54 60 $this->assertNotIXRError( $result ); … … 58 64 $this->make_user_by_role( 'contributor' ); 59 65 60 $post = array( 'post_title' => 'Test', 'post_status' => 'publish' ); 66 $post = array( 67 'post_title' => 'Test', 68 'post_status' => 'publish', 69 ); 61 70 $result = $this->myxmlrpcserver->wp_newPost( array( 1, 'contributor', 'contributor', $post ) ); 62 71 $this->assertIXRError( $result ); … … 67 76 $this->make_user_by_role( 'editor' ); 68 77 69 $post = array( 'post_title' => 'Test', 'post_status' => 'private' ); 78 $post = array( 79 'post_title' => 'Test', 80 'post_status' => 'private', 81 ); 70 82 $result = $this->myxmlrpcserver->wp_newPost( array( 1, 'editor', 'editor', $post ) ); 71 83 $this->assertNotIXRError( $result ); … … 75 87 $this->make_user_by_role( 'contributor' ); 76 88 77 $post = array( 'post_title' => 'Test', 'post_status' => 'private' ); 89 $post = array( 90 'post_title' => 'Test', 91 'post_status' => 'private', 92 ); 78 93 $result = $this->myxmlrpcserver->wp_newPost( array( 1, 'contributor', 'contributor', $post ) ); 79 94 $this->assertIXRError( $result ); … … 85 100 $this->make_user_by_role( 'editor' ); 86 101 87 $post = array( 'post_title' => 'Test', 'post_author' => $other_author_id ); 102 $post = array( 103 'post_title' => 'Test', 104 'post_author' => $other_author_id, 105 ); 88 106 $result = $this->myxmlrpcserver->wp_newPost( array( 1, 'editor', 'editor', $post ) ); 89 107 $this->assertNotIXRError( $result ); … … 94 112 $this->make_user_by_role( 'contributor' ); 95 113 96 $post = array( 'post_title' => 'Test', 'post_author' => $other_author_id ); 114 $post = array( 115 'post_title' => 'Test', 116 'post_author' => $other_author_id, 117 ); 97 118 $result = $this->myxmlrpcserver->wp_newPost( array( 1, 'contributor', 'contributor', $post ) ); 98 119 $this->assertIXRError( $result ); … … 103 124 $this->make_user_by_role( 'editor' ); 104 125 105 $post = array( 'post_title' => 'Test', 'post_author' => 99999999 ); 126 $post = array( 127 'post_title' => 'Test', 128 'post_author' => 99999999, 129 ); 106 130 $result = $this->myxmlrpcserver->wp_newPost( array( 1, 'editor', 'editor', $post ) ); 107 131 $this->assertIXRError( $result ); … … 112 136 $my_author_id = $this->make_user_by_role( 'author' ); 113 137 114 $post = array( 'post_title' => 'Test' );138 $post = array( 'post_title' => 'Test' ); 115 139 $result = $this->myxmlrpcserver->wp_newPost( array( 1, 'author', 'author', $post ) ); 116 140 $this->assertNotIXRError( $result ); … … 128 152 129 153 // create attachment 130 $filename = ( DIR_TESTDATA.'/images/a2-small.jpg' );154 $filename = ( DIR_TESTDATA . '/images/a2-small.jpg' ); 131 155 $attachment_id = self::factory()->attachment->create_upload_object( $filename ); 132 156 133 $post = array( 'post_title' => 'Post Thumbnail Test', 'post_thumbnail' => $attachment_id ); 157 $post = array( 158 'post_title' => 'Post Thumbnail Test', 159 'post_thumbnail' => $attachment_id, 160 ); 134 161 $result = $this->myxmlrpcserver->wp_newPost( array( 1, 'author', 'author', $post ) ); 135 162 $this->assertNotIXRError( $result ); … … 142 169 $this->make_user_by_role( 'author' ); 143 170 144 $post = array( 'post_title' => 'Test', 'post_status' => 'foobar_status' ); 171 $post = array( 172 'post_title' => 'Test', 173 'post_status' => 'foobar_status', 174 ); 145 175 $result = $this->myxmlrpcserver->wp_newPost( array( 1, 'author', 'author', $post ) ); 146 176 $this->assertNotIXRError( $result ); … … 151 181 $this->make_user_by_role( 'contributor' ); 152 182 153 $post = array( 'post_title' => 'Test', 'sticky' => true ); 183 $post = array( 184 'post_title' => 'Test', 185 'sticky' => true, 186 ); 154 187 $result = $this->myxmlrpcserver->wp_newPost( array( 1, 'contributor', 'contributor', $post ) ); 155 188 $this->assertIXRError( $result ); … … 160 193 $this->make_user_by_role( 'editor' ); 161 194 162 $post = array( 'post_title' => 'Test', 'sticky' => true ); 195 $post = array( 196 'post_title' => 'Test', 197 'sticky' => true, 198 ); 163 199 $result = $this->myxmlrpcserver->wp_newPost( array( 1, 'editor', 'editor', $post ) ); 164 200 $this->assertNotIXRError( $result ); … … 169 205 $this->make_user_by_role( 'editor' ); 170 206 171 $post = array( 'post_title' => 'Test', 'post_status' => 'private', 'sticky' => true ); 207 $post = array( 208 'post_title' => 'Test', 209 'post_status' => 'private', 210 'sticky' => true, 211 ); 172 212 $result = $this->myxmlrpcserver->wp_newPost( array( 1, 'editor', 'editor', $post ) ); 173 213 $this->assertIXRError( $result ); … … 178 218 $this->make_user_by_role( 'editor' ); 179 219 180 $post = array( 'post_title' => 'Test', 'post_format' => 'quote' ); 220 $post = array( 221 'post_title' => 'Test', 222 'post_format' => 'quote', 223 ); 181 224 $result = $this->myxmlrpcserver->wp_newPost( array( 1, 'editor', 'editor', $post ) ); 182 225 $this->assertNotIXRError( $result ); … … 187 230 $this->make_user_by_role( 'editor' ); 188 231 189 $post = array( 'post_title' => 'Test', 'post_format' => 'tumblr' ); 232 $post = array( 233 'post_title' => 'Test', 234 'post_format' => 'tumblr', 235 ); 190 236 $result = $this->myxmlrpcserver->wp_newPost( array( 1, 'editor', 'editor', $post ) ); 191 237 $this->assertNotIXRError( $result ); … … 196 242 $this->make_user_by_role( 'editor' ); 197 243 198 $post = array(199 'post_title' => 'Test', 200 'terms' => array(201 'foobar_nonexistant' => array( 1 ) 202 ) 203 ); 204 $result = $this->myxmlrpcserver->wp_newPost( array( 1, 'editor', 'editor', $post ) ); 205 $this->assertIXRError( $result ); 206 $this->assertEquals( 401, $result->code ); 207 208 $post2 = array(209 'post_title' => 'Test',244 $post = array( 245 'post_title' => 'Test', 246 'terms' => array( 247 'foobar_nonexistant' => array( 1 ), 248 ), 249 ); 250 $result = $this->myxmlrpcserver->wp_newPost( array( 1, 'editor', 'editor', $post ) ); 251 $this->assertIXRError( $result ); 252 $this->assertEquals( 401, $result->code ); 253 254 $post2 = array( 255 'post_title' => 'Test', 210 256 'terms_names' => array( 211 'foobar_nonexistant' => array( 1 ) 212 ) 257 'foobar_nonexistant' => array( 1 ), 258 ), 213 259 ); 214 260 $result2 = $this->myxmlrpcserver->wp_newPost( array( 1, 'editor', 'editor', $post2 ) ); … … 220 266 $this->make_user_by_role( 'editor' ); 221 267 222 $post = array(223 'post_title' => 'Test', 224 'terms' => array(225 'post_tag' => array( 1390490823409 ) 226 ) 268 $post = array( 269 'post_title' => 'Test', 270 'terms' => array( 271 'post_tag' => array( 1390490823409 ), 272 ), 227 273 ); 228 274 $result = $this->myxmlrpcserver->wp_newPost( array( 1, 'editor', 'editor', $post ) ); … … 241 287 $this->assertInternalType( 'array', $tag3 ); 242 288 243 $post = array(244 'post_title' => 'Test', 245 'terms' => array(246 'post_tag' => array( $tag2['term_id'], $tag3['term_id'] ) 247 ) 289 $post = array( 290 'post_title' => 'Test', 291 'terms' => array( 292 'post_tag' => array( $tag2['term_id'], $tag3['term_id'] ), 293 ), 248 294 ); 249 295 $result = $this->myxmlrpcserver->wp_newPost( array( 1, 'editor', 'editor', $post ) ); … … 260 306 261 307 $ambiguous_name = 'foo'; 262 $parent_cat = wp_create_category( $ambiguous_name );263 $child_cat = wp_create_category( $ambiguous_name, $parent_cat );308 $parent_cat = wp_create_category( $ambiguous_name ); 309 $child_cat = wp_create_category( $ambiguous_name, $parent_cat ); 264 310 265 311 $cat1_name = 'cat1'; 266 $cat1 = wp_create_category( $cat1_name, $parent_cat );312 $cat1 = wp_create_category( $cat1_name, $parent_cat ); 267 313 $cat2_name = 'cat2'; 268 314 269 315 // first a post with valid categories; one that already exists and one to be created 270 $post = array(271 'post_title' => 'Test',316 $post = array( 317 'post_title' => 'Test', 272 318 'terms_names' => array( 273 'category' => array( $cat1_name, $cat2_name ) 274 ) 319 'category' => array( $cat1_name, $cat2_name ), 320 ), 275 321 ); 276 322 $result = $this->myxmlrpcserver->wp_newPost( array( 1, 'editor', 'editor', $post ) ); … … 285 331 286 332 // create a second post attempting to use the ambiguous name 287 $post2 = array(288 'post_title' => 'Test',333 $post2 = array( 334 'post_title' => 'Test', 289 335 'terms_names' => array( 290 'category' => array( $cat1_name, $ambiguous_name ) 291 ) 336 'category' => array( $cat1_name, $ambiguous_name ), 337 ), 292 338 ); 293 339 $result2 = $this->myxmlrpcserver->wp_newPost( array( 1, 'editor', 'editor', $post2 ) ); … … 301 347 function test_invalid_post_date_does_not_fatal() { 302 348 $this->make_user_by_role( 'author' ); 303 $date_string = 'invalid_date'; 304 $post = array( 'post_title' => 'test', 'post_content' => 'test', 'post_date' => $date_string ); 305 $result = $this->myxmlrpcserver->wp_newPost( array( 1, 'author', 'author', $post ) ); 349 $date_string = 'invalid_date'; 350 $post = array( 351 'post_title' => 'test', 352 'post_content' => 'test', 353 'post_date' => $date_string, 354 ); 355 $result = $this->myxmlrpcserver->wp_newPost( array( 1, 'author', 'author', $post ) ); 306 356 $fetched_post = get_post( $result ); 307 357 $this->assertStringMatchesFormat( '%d', $result ); … … 314 364 function test_invalid_post_date_gmt_does_not_fatal() { 315 365 $this->make_user_by_role( 'author' ); 316 $date_string = 'invalid date'; 317 $post = array( 'post_title' => 'test', 'post_content' => 'test', 'post_date_gmt' => $date_string ); 318 $result = $this->myxmlrpcserver->wp_newPost( array( 1, 'author', 'author', $post ) ); 366 $date_string = 'invalid date'; 367 $post = array( 368 'post_title' => 'test', 369 'post_content' => 'test', 370 'post_date_gmt' => $date_string, 371 ); 372 $result = $this->myxmlrpcserver->wp_newPost( array( 1, 'author', 'author', $post ) ); 319 373 $fetched_post = get_post( $result ); 320 374 $this->assertStringMatchesFormat( '%d', $result ); … … 327 381 function test_valid_string_post_date() { 328 382 $this->make_user_by_role( 'author' ); 329 $date_string = '1984-01-11 05:00:00'; 330 $post = array( 'post_title' => 'test', 'post_content' => 'test', 'post_date' => $date_string ); 331 $result = $this->myxmlrpcserver->wp_newPost( array( 1, 'author', 'author', $post ) ); 332 $fetched_post = get_post( $result ); 333 $this->assertStringMatchesFormat( '%d', $result ); 334 $this->assertEquals( $date_string , $fetched_post->post_date ); 383 $date_string = '1984-01-11 05:00:00'; 384 $post = array( 385 'post_title' => 'test', 386 'post_content' => 'test', 387 'post_date' => $date_string, 388 ); 389 $result = $this->myxmlrpcserver->wp_newPost( array( 1, 'author', 'author', $post ) ); 390 $fetched_post = get_post( $result ); 391 $this->assertStringMatchesFormat( '%d', $result ); 392 $this->assertEquals( $date_string, $fetched_post->post_date ); 335 393 } 336 394 … … 340 398 function test_valid_string_post_date_gmt() { 341 399 $this->make_user_by_role( 'author' ); 342 $date_string = '1984-01-11 05:00:00'; 343 $post = array( 'post_title' => 'test', 'post_content' => 'test', 'post_date_gmt' => $date_string ); 344 $result = $this->myxmlrpcserver->wp_newPost( array( 1, 'author', 'author', $post ) ); 345 $fetched_post = get_post( $result ); 346 $this->assertStringMatchesFormat( '%d', $result ); 347 $this->assertEquals( $date_string , $fetched_post->post_date_gmt ); 400 $date_string = '1984-01-11 05:00:00'; 401 $post = array( 402 'post_title' => 'test', 403 'post_content' => 'test', 404 'post_date_gmt' => $date_string, 405 ); 406 $result = $this->myxmlrpcserver->wp_newPost( array( 1, 'author', 'author', $post ) ); 407 $fetched_post = get_post( $result ); 408 $this->assertStringMatchesFormat( '%d', $result ); 409 $this->assertEquals( $date_string, $fetched_post->post_date_gmt ); 348 410 } 349 411 … … 353 415 function test_valid_IXR_post_date() { 354 416 $this->make_user_by_role( 'author' ); 355 $date_string = '1984-01-11 05:00:00'; 356 $post = array( 'post_title' => 'test', 'post_content' => 'test', 'post_date' => new IXR_Date( mysql2date( 'Ymd\TH:i:s', $date_string, false ) ) ); 357 $result = $this->myxmlrpcserver->wp_newPost( array( 1, 'author', 'author', $post ) ); 358 $fetched_post = get_post( $result ); 359 $this->assertStringMatchesFormat( '%d', $result ); 360 $this->assertEquals( $date_string , $fetched_post->post_date ); 417 $date_string = '1984-01-11 05:00:00'; 418 $post = array( 419 'post_title' => 'test', 420 'post_content' => 'test', 421 'post_date' => new IXR_Date( mysql2date( 'Ymd\TH:i:s', $date_string, false ) ), 422 ); 423 $result = $this->myxmlrpcserver->wp_newPost( array( 1, 'author', 'author', $post ) ); 424 $fetched_post = get_post( $result ); 425 $this->assertStringMatchesFormat( '%d', $result ); 426 $this->assertEquals( $date_string, $fetched_post->post_date ); 361 427 } 362 428 … … 366 432 function test_valid_IXR_post_date_gmt() { 367 433 $this->make_user_by_role( 'author' ); 368 $date_string = '1984-01-11 05:00:00'; 369 $post = array( 'post_title' => 'test', 'post_content' => 'test', 'post_date_gmt' => new IXR_Date( mysql2date( 'Ymd\TH:i:s', $date_string, false ) ) ); 370 $result = $this->myxmlrpcserver->wp_newPost( array( 1, 'author', 'author', $post ) ); 371 $fetched_post = get_post( $result ); 372 $this->assertStringMatchesFormat( '%d', $result ); 373 $this->assertEquals( $date_string , $fetched_post->post_date_gmt ); 434 $date_string = '1984-01-11 05:00:00'; 435 $post = array( 436 'post_title' => 'test', 437 'post_content' => 'test', 438 'post_date_gmt' => new IXR_Date( mysql2date( 'Ymd\TH:i:s', $date_string, false ) ), 439 ); 440 $result = $this->myxmlrpcserver->wp_newPost( array( 1, 'author', 'author', $post ) ); 441 $fetched_post = get_post( $result ); 442 $this->assertStringMatchesFormat( '%d', $result ); 443 $this->assertEquals( $date_string, $fetched_post->post_date_gmt ); 374 444 } 375 445
Note: See TracChangeset
for help on using the changeset viewer.