Changeset 41667 for trunk/tests/phpunit/tests/ajax/CustomizeManager.php
- Timestamp:
- 10/02/2017 03:36:18 AM (9 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/tests/phpunit/tests/ajax/CustomizeManager.php
r41626 r41667 444 444 445 445 /** 446 * Test request for dismissing autosave changesets.446 * Test request for trashing a changeset. 447 447 * 448 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() { 449 * @covers WP_Customize_Manager::handle_changeset_trash_request() 450 */ 451 public function test_handle_changeset_trash_request() { 453 452 $uuid = wp_generate_uuid4(); 454 453 $wp_customize = $this->set_up_valid_state( $uuid ); 455 454 456 $this->make_ajax_call( 'dismiss_customize_changeset_autosave' ); 455 $this->make_ajax_call( 'customize_trash' ); 456 $this->assertFalse( $this->_last_response_parsed['success'] ); 457 $this->assertEquals( 'invalid_nonce', $this->_last_response_parsed['data']['code'] ); 458 459 $nonce = wp_create_nonce( 'trash_customize_changeset' ); 460 $_POST['nonce'] = $_GET['nonce'] = $_REQUEST['nonce'] = $nonce; 461 $this->make_ajax_call( 'customize_trash' ); 462 $this->assertFalse( $this->_last_response_parsed['success'] ); 463 $this->assertEquals( 'non_existent_changeset', $this->_last_response_parsed['data']['code'] ); 464 465 $wp_customize->register_controls(); // And settings too. 466 $wp_customize->set_post_value( 'blogname', 'HELLO' ); 467 $wp_customize->save_changeset_post( array( 468 'status' => 'save', 469 ) ); 470 471 add_filter( 'map_meta_cap', array( $this, 'return_do_not_allow' ) ); 472 $this->make_ajax_call( 'customize_trash' ); 473 $this->assertFalse( $this->_last_response_parsed['success'] ); 474 $this->assertEquals( 'changeset_trash_unauthorized', $this->_last_response_parsed['data']['code'] ); 475 remove_filter( 'map_meta_cap', array( $this, 'return_do_not_allow' ) ); 476 477 wp_update_post( array( 478 'ID' => $wp_customize->changeset_post_id(), 479 'post_status' => 'trash', 480 ) ); 481 $this->make_ajax_call( 'customize_trash' ); 482 $this->assertFalse( $this->_last_response_parsed['success'] ); 483 $this->assertEquals( 'changeset_already_trashed', $this->_last_response_parsed['data']['code'] ); 484 485 wp_update_post( array( 486 'ID' => $wp_customize->changeset_post_id(), 487 'post_status' => 'draft', 488 ) ); 489 490 $wp_trash_post_count = did_action( 'wp_trash_post' ); 491 add_filter( 'pre_trash_post', '__return_false' ); 492 $this->make_ajax_call( 'customize_trash' ); 493 $this->assertFalse( $this->_last_response_parsed['success'] ); 494 $this->assertEquals( 'changeset_trash_failure', $this->_last_response_parsed['data']['code'] ); 495 remove_filter( 'pre_trash_post', '__return_false' ); 496 $this->assertEquals( $wp_trash_post_count, did_action( 'wp_trash_post' ) ); 497 498 $wp_trash_post_count = did_action( 'wp_trash_post' ); 499 $this->assertEquals( 'draft', get_post_status( $wp_customize->changeset_post_id() ) ); 500 $this->make_ajax_call( 'customize_trash' ); 501 $this->assertTrue( $this->_last_response_parsed['success'] ); 502 $this->assertEquals( 'trash', get_post_status( $wp_customize->changeset_post_id() ) ); 503 $this->assertEquals( $wp_trash_post_count + 1, did_action( 'wp_trash_post' ) ); 504 } 505 506 /** 507 * Return caps array containing 'do_not_allow'. 508 * 509 * @return array Caps. 510 */ 511 public function return_do_not_allow() { 512 return array( 'do_not_allow' ); 513 } 514 515 /** 516 * Test request for dismissing autosave changesets. 517 * 518 * @ticket 39896 519 * @covers WP_Customize_Manager::handle_dismiss_autosave_request() 520 * @covers WP_Customize_Manager::dismiss_user_auto_draft_changesets() 521 */ 522 public function test_handle_dismiss_autosave_request() { 523 $uuid = wp_generate_uuid4(); 524 $wp_customize = $this->set_up_valid_state( $uuid ); 525 526 $this->make_ajax_call( 'customize_dismiss_autosave' ); 457 527 $this->assertFalse( $this->_last_response_parsed['success'] ); 458 528 $this->assertEquals( 'invalid_nonce', $this->_last_response_parsed['data'] ); 459 529 460 $nonce = wp_create_nonce( ' dismiss_customize_changeset_autosave' );530 $nonce = wp_create_nonce( 'customize_dismiss_autosave' ); 461 531 $_POST['nonce'] = $_GET['nonce'] = $_REQUEST['nonce'] = $nonce; 462 $this->make_ajax_call( ' dismiss_customize_changeset_autosave' );532 $this->make_ajax_call( 'customize_dismiss_autosave' ); 463 533 $this->assertFalse( $this->_last_response_parsed['success'] ); 464 534 $this->assertEquals( 'no_auto_draft_to_delete', $this->_last_response_parsed['data'] ); … … 490 560 $this->assertFalse( (bool) get_post_meta( $post_id, '_customize_restore_dismissed', true ) ); 491 561 } 492 $this->make_ajax_call( ' dismiss_customize_changeset_autosave' );562 $this->make_ajax_call( 'customize_dismiss_autosave' ); 493 563 $this->assertTrue( $this->_last_response_parsed['success'] ); 494 564 $this->assertEquals( 'auto_draft_dismissed', $this->_last_response_parsed['data'] ); … … 503 573 504 574 // Subsequent test results in none dismissed. 505 $this->make_ajax_call( ' dismiss_customize_changeset_autosave' );575 $this->make_ajax_call( 'customize_dismiss_autosave' ); 506 576 $this->assertFalse( $this->_last_response_parsed['success'] ); 507 577 $this->assertEquals( 'no_auto_draft_to_delete', $this->_last_response_parsed['data'] ); … … 521 591 522 592 // Since no autosave yet, confirm no action. 523 $this->make_ajax_call( ' dismiss_customize_changeset_autosave' );593 $this->make_ajax_call( 'customize_dismiss_autosave' ); 524 594 $this->assertFalse( $this->_last_response_parsed['success'] ); 525 595 $this->assertEquals( 'no_autosave_revision_to_delete', $this->_last_response_parsed['data'] ); … … 541 611 542 612 // Confirm autosave gets deleted. 543 $this->make_ajax_call( ' dismiss_customize_changeset_autosave' );613 $this->make_ajax_call( 'customize_dismiss_autosave' ); 544 614 $this->assertTrue( $this->_last_response_parsed['success'] ); 545 615 $this->assertEquals( 'autosave_revision_deleted', $this->_last_response_parsed['data'] ); … … 547 617 548 618 // Since no autosave yet, confirm no action. 549 $this->make_ajax_call( ' dismiss_customize_changeset_autosave' );619 $this->make_ajax_call( 'customize_dismiss_autosave' ); 550 620 $this->assertFalse( $this->_last_response_parsed['success'] ); 551 621 $this->assertEquals( 'no_autosave_revision_to_delete', $this->_last_response_parsed['data'] );
Note:
See TracChangeset
for help on using the changeset viewer.
![(please configure the [header_logo] section in trac.ini)](/chrome/site/your_project_logo.png)