Changeset 41626 for trunk/tests/phpunit/tests/ajax/CustomizeManager.php
- Timestamp:
- 09/27/2017 10:24:37 PM (7 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/tests/phpunit/tests/ajax/CustomizeManager.php
r39409 r41626 166 166 $this->assertFalse( $this->_last_response_parsed['success'] ); 167 167 $this->assertEquals( 'changeset_already_published', $this->_last_response_parsed['data']['code'] ); 168 wp_update_post( array( 'ID' => $wp_customize->changeset_post_id(), 'post_status' => 'auto-draft' ) ); 168 wp_update_post( array( 169 'ID' => $wp_customize->changeset_post_id(), 170 'post_status' => 'auto-draft', 171 ) ); 169 172 170 173 // User cannot edit. … … 223 226 $this->assertTrue( $this->_last_response_parsed['success'] ); 224 227 $this->assertEquals( 'future', get_post_status( $wp_customize->changeset_post_id() ) ); 225 wp_update_post( array( 'ID' => $wp_customize->changeset_post_id(), 'post_status' => 'auto-draft' ) ); 226 228 wp_update_post( array( 229 'ID' => $wp_customize->changeset_post_id(), 230 'post_status' => 'auto-draft', 231 ) ); 227 232 } 228 233 … … 255 260 $wp_customize = $this->set_up_valid_state(); 256 261 257 // Successful future.258 262 $_POST['customize_changeset_status'] = 'publish'; 259 263 $_POST['customize_changeset_title'] = 'Success Changeset'; … … 269 273 $this->assertEquals( 'publish', $this->_last_response_parsed['data']['changeset_status'] ); 270 274 $this->assertArrayHasKey( 'next_changeset_uuid', $this->_last_response_parsed['data'] ); 275 $this->assertTrue( wp_is_uuid( $this->_last_response_parsed['data']['next_changeset_uuid'], 4 ) ); 271 276 $this->assertEquals( 'Success Changeset', get_post( $wp_customize->changeset_post_id() )->post_title ); 272 277 $this->assertEquals( 'Successful Site Title', get_option( 'blogname' ) ); 273 274 278 } 275 279 … … 296 300 $wp_customize = $this->set_up_valid_state( $uuid ); 297 301 298 // Successful future.299 302 $_POST['customize_changeset_status'] = 'publish'; 300 303 $_POST['customize_changeset_title'] = 'Published'; … … 305 308 $this->assertEquals( 'publish', $this->_last_response_parsed['data']['changeset_status'] ); 306 309 $this->assertArrayHasKey( 'next_changeset_uuid', $this->_last_response_parsed['data'] ); 310 $this->assertTrue( wp_is_uuid( $this->_last_response_parsed['data']['next_changeset_uuid'], 4 ) ); 307 311 $this->assertEquals( 'New Site Title', get_option( 'blogname' ) ); 308 312 $this->assertEquals( 'Published', get_post( $post_id )->post_title ); … … 337 341 $this->make_ajax_call( 'customize_save' ); 338 342 $this->assertTrue( $this->_last_response_parsed['success'] ); 343 $this->assertArrayHasKey( 'changeset_date', $this->_last_response_parsed['data'] ); 339 344 $changeset_post_schedule = get_post( $post_id ); 340 345 $this->assertEquals( $future_date, $changeset_post_schedule->post_date ); … … 345 350 $this->make_ajax_call( 'customize_save' ); 346 351 $this->assertTrue( $this->_last_response_parsed['success'] ); 352 $this->assertArrayNotHasKey( 'changeset_date', $this->_last_response_parsed['data'] ); 347 353 $changeset_post_draft = get_post( $post_id ); 348 354 $this->assertEquals( $future_date, $changeset_post_draft->post_date ); … … 352 358 $this->make_ajax_call( 'customize_save' ); 353 359 $this->assertTrue( $this->_last_response_parsed['success'] ); 360 $this->assertArrayHasKey( 'changeset_date', $this->_last_response_parsed['data'] ); 354 361 $changeset_post_schedule = get_post( $post_id ); 355 362 $this->assertEquals( $future_date, $changeset_post_schedule->post_date ); … … 381 388 $this->make_ajax_call( 'customize_save' ); 382 389 $this->assertTrue( $this->_last_response_parsed['success'] ); 390 $this->assertArrayHasKey( 'next_changeset_uuid', $this->_last_response_parsed['data'] ); 391 $this->assertTrue( wp_is_uuid( $this->_last_response_parsed['data']['next_changeset_uuid'], 4 ) ); 383 392 $changeset_post_publish = get_post( $post_id ); 384 393 $this->assertNotEquals( $future_date, $changeset_post_publish->post_date ); 394 395 // Check response when trying to update an already-published post. 396 $this->assertEquals( 'trash', get_post_status( $post_id ) ); 397 $_POST['customize_changeset_status'] = 'publish'; 398 $this->make_ajax_call( 'customize_save' ); 399 $this->assertFalse( $this->_last_response_parsed['success'] ); 400 $this->assertEquals( 'changeset_already_published', $this->_last_response_parsed['data']['code'] ); 401 $this->assertArrayHasKey( 'next_changeset_uuid', $this->_last_response_parsed['data'] ); 402 $this->assertTrue( wp_is_uuid( $this->_last_response_parsed['data']['next_changeset_uuid'], 4 ) ); 403 } 404 405 /** 406 * Test WP_Customize_Manager::save(). 407 * 408 * @ticket 39896 409 * @covers WP_Customize_Manager::save() 410 */ 411 public function test_save_autosave() { 412 $uuid = wp_generate_uuid4(); 413 414 $post_id = $this->factory()->post->create( array( 415 'post_name' => $uuid, 416 'post_type' => 'customize_changeset', 417 'post_status' => 'draft', 418 'post_content' => wp_json_encode( array( 419 'blogname' => array( 420 'value' => 'New Site Title', 421 ), 422 ) ), 423 ) ); 424 $this->set_up_valid_state( $uuid ); 425 426 $this->assertFalse( wp_get_post_autosave( $post_id ) ); 427 428 $_POST['customize_changeset_data'] = wp_json_encode( array( 429 'blogname' => array( 430 'value' => 'Autosaved Site Title', 431 ), 432 ) ); 433 434 $_POST['customize_changeset_autosave'] = 'on'; 435 $this->make_ajax_call( 'customize_save' ); 436 $this->assertTrue( $this->_last_response_parsed['success'] ); 437 $this->assertEquals( 'draft', $this->_last_response_parsed['data']['changeset_status'] ); 438 $autosave_revision = wp_get_post_autosave( $post_id ); 439 $this->assertInstanceOf( 'WP_Post', $autosave_revision ); 440 441 $this->assertContains( 'New Site Title', get_post( $post_id )->post_content ); 442 $this->assertContains( 'Autosaved Site Title', $autosave_revision->post_content ); 443 } 444 445 /** 446 * Test request for dismissing autosave changesets. 447 * 448 * @ticket 39896 449 * @covers WP_Customize_Manager::handle_dismiss_changeset_autosave_request() 450 * @covers WP_Customize_Manager::dismiss_user_auto_draft_changesets() 451 */ 452 public function test_handle_dismiss_changeset_autosave_request() { 453 $uuid = wp_generate_uuid4(); 454 $wp_customize = $this->set_up_valid_state( $uuid ); 455 456 $this->make_ajax_call( 'dismiss_customize_changeset_autosave' ); 457 $this->assertFalse( $this->_last_response_parsed['success'] ); 458 $this->assertEquals( 'invalid_nonce', $this->_last_response_parsed['data'] ); 459 460 $nonce = wp_create_nonce( 'dismiss_customize_changeset_autosave' ); 461 $_POST['nonce'] = $_GET['nonce'] = $_REQUEST['nonce'] = $nonce; 462 $this->make_ajax_call( 'dismiss_customize_changeset_autosave' ); 463 $this->assertFalse( $this->_last_response_parsed['success'] ); 464 $this->assertEquals( 'no_auto_draft_to_delete', $this->_last_response_parsed['data'] ); 465 466 $other_user_id = $this->factory()->user->create(); 467 468 // Create auto-drafts. 469 $user_auto_draft_ids = array(); 470 for ( $i = 0; $i < 3; $i++ ) { 471 $user_auto_draft_ids[] = $this->factory()->post->create( array( 472 'post_name' => wp_generate_uuid4(), 473 'post_type' => 'customize_changeset', 474 'post_status' => 'auto-draft', 475 'post_author' => self::$admin_user_id, 476 'post_content' => wp_json_encode( array() ), 477 ) ); 478 } 479 $other_user_auto_draft_ids = array(); 480 for ( $i = 0; $i < 3; $i++ ) { 481 $other_user_auto_draft_ids[] = $this->factory()->post->create( array( 482 'post_name' => wp_generate_uuid4(), 483 'post_type' => 'customize_changeset', 484 'post_status' => 'auto-draft', 485 'post_author' => $other_user_id, 486 'post_content' => wp_json_encode( array() ), 487 ) ); 488 } 489 foreach ( array_merge( $user_auto_draft_ids, $other_user_auto_draft_ids ) as $post_id ) { 490 $this->assertFalse( (bool) get_post_meta( $post_id, '_customize_restore_dismissed', true ) ); 491 } 492 $this->make_ajax_call( 'dismiss_customize_changeset_autosave' ); 493 $this->assertTrue( $this->_last_response_parsed['success'] ); 494 $this->assertEquals( 'auto_draft_dismissed', $this->_last_response_parsed['data'] ); 495 foreach ( $user_auto_draft_ids as $post_id ) { 496 $this->assertEquals( 'auto-draft', get_post_status( $post_id ) ); 497 $this->assertTrue( (bool) get_post_meta( $post_id, '_customize_restore_dismissed', true ) ); 498 } 499 foreach ( $other_user_auto_draft_ids as $post_id ) { 500 $this->assertEquals( 'auto-draft', get_post_status( $post_id ) ); 501 $this->assertFalse( (bool) get_post_meta( $post_id, '_customize_restore_dismissed', true ) ); 502 } 503 504 // Subsequent test results in none dismissed. 505 $this->make_ajax_call( 'dismiss_customize_changeset_autosave' ); 506 $this->assertFalse( $this->_last_response_parsed['success'] ); 507 $this->assertEquals( 'no_auto_draft_to_delete', $this->_last_response_parsed['data'] ); 508 509 // Save a changeset as a draft. 510 $r = $wp_customize->save_changeset_post( array( 511 'data' => array( 512 'blogname' => array( 513 'value' => 'Foo', 514 ), 515 ), 516 'status' => 'draft', 517 ) ); 518 $this->assertNotInstanceOf( 'WP_Error', $r ); 519 $this->assertFalse( wp_get_post_autosave( $wp_customize->changeset_post_id() ) ); 520 $this->assertContains( 'Foo', get_post( $wp_customize->changeset_post_id() )->post_content ); 521 522 // Since no autosave yet, confirm no action. 523 $this->make_ajax_call( 'dismiss_customize_changeset_autosave' ); 524 $this->assertFalse( $this->_last_response_parsed['success'] ); 525 $this->assertEquals( 'no_autosave_revision_to_delete', $this->_last_response_parsed['data'] ); 526 527 // Add the autosave revision. 528 $r = $wp_customize->save_changeset_post( array( 529 'data' => array( 530 'blogname' => array( 531 'value' => 'Bar', 532 ), 533 ), 534 'autosave' => true, 535 ) ); 536 $this->assertNotInstanceOf( 'WP_Error', $r ); 537 $autosave_revision = wp_get_post_autosave( $wp_customize->changeset_post_id() ); 538 $this->assertInstanceOf( 'WP_Post', $autosave_revision ); 539 $this->assertContains( 'Foo', get_post( $wp_customize->changeset_post_id() )->post_content ); 540 $this->assertContains( 'Bar', $autosave_revision->post_content ); 541 542 // Confirm autosave gets deleted. 543 $this->make_ajax_call( 'dismiss_customize_changeset_autosave' ); 544 $this->assertTrue( $this->_last_response_parsed['success'] ); 545 $this->assertEquals( 'autosave_revision_deleted', $this->_last_response_parsed['data'] ); 546 $this->assertFalse( wp_get_post_autosave( $wp_customize->changeset_post_id() ) ); 547 548 // Since no autosave yet, confirm no action. 549 $this->make_ajax_call( 'dismiss_customize_changeset_autosave' ); 550 $this->assertFalse( $this->_last_response_parsed['success'] ); 551 $this->assertEquals( 'no_autosave_revision_to_delete', $this->_last_response_parsed['data'] ); 385 552 } 386 553 }
Note: See TracChangeset
for help on using the changeset viewer.