Changeset 38436 for trunk/tests/phpunit/tests/ajax/CustomizeMenus.php
- Timestamp:
- 08/29/2016 10:58:32 PM (9 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/tests/phpunit/tests/ajax/CustomizeMenus.php
r35244 r38436 527 527 ); 528 528 } 529 530 /** 531 * Testing successful ajax_insert_auto_draft_post() call. 532 * 533 * @covers WP_Customize_Nav_Menus::ajax_insert_auto_draft_post() 534 */ 535 function test_ajax_insert_auto_draft_post_success() { 536 $_POST = wp_slash( array( 537 'customize-menus-nonce' => wp_create_nonce( 'customize-menus' ), 538 'params' => array( 539 'post_type' => 'post', 540 'post_title' => 'Hello World', 541 ), 542 ) ); 543 $this->_last_response = ''; 544 $this->make_ajax_call( 'customize-nav-menus-insert-auto-draft' ); 545 $response = json_decode( $this->_last_response, true ); 546 547 $this->assertTrue( $response['success'] ); 548 $this->assertArrayHasKey( 'post_id', $response['data'] ); 549 $this->assertArrayHasKey( 'url', $response['data'] ); 550 } 551 552 /** 553 * Testing unsuccessful ajax_insert_auto_draft_post() call. 554 * 555 * @covers WP_Customize_Nav_Menus::ajax_insert_auto_draft_post() 556 */ 557 function test_ajax_insert_auto_draft_failures() { 558 // No nonce. 559 $_POST = array(); 560 $this->_last_response = ''; 561 $this->make_ajax_call( 'customize-nav-menus-insert-auto-draft' ); 562 $response = json_decode( $this->_last_response, true ); 563 $this->assertFalse( $response['success'] ); 564 $this->assertEquals( 'bad_nonce', $response['data'] ); 565 566 // Bad nonce. 567 $_POST = wp_slash( array( 568 'customize-menus-nonce' => 'bad', 569 ) ); 570 $this->_last_response = ''; 571 $this->make_ajax_call( 'customize-nav-menus-insert-auto-draft' ); 572 $response = json_decode( $this->_last_response, true ); 573 $this->assertFalse( $response['success'] ); 574 $this->assertEquals( 'bad_nonce', $response['data'] ); 575 576 // Bad nonce. 577 wp_set_current_user( $this->factory()->user->create( array( 'role' => 'subscriber' ) ) ); 578 $_POST = wp_slash( array( 579 'customize-menus-nonce' => wp_create_nonce( 'customize-menus' ), 580 ) ); 581 $this->_last_response = ''; 582 $this->make_ajax_call( 'customize-nav-menus-insert-auto-draft' ); 583 $response = json_decode( $this->_last_response, true ); 584 $this->assertFalse( $response['success'] ); 585 $this->assertEquals( 'customize_not_allowed', $response['data'] ); 586 587 // Missing params. 588 wp_set_current_user( $this->factory()->user->create( array( 'role' => 'administrator' ) ) ); 589 $_POST = wp_slash( array( 590 'customize-menus-nonce' => wp_create_nonce( 'customize-menus' ), 591 ) ); 592 $this->_last_response = ''; 593 $this->make_ajax_call( 'customize-nav-menus-insert-auto-draft' ); 594 $response = json_decode( $this->_last_response, true ); 595 $this->assertFalse( $response['success'] ); 596 $this->assertEquals( 'missing_params', $response['data'] ); 597 598 // insufficient_post_permissions. 599 register_post_type( 'privilege', array( 'capability_type' => 'privilege' ) ); 600 $_POST = wp_slash( array( 601 'customize-menus-nonce' => wp_create_nonce( 'customize-menus' ), 602 'params' => array( 603 'post_type' => 'privilege', 604 ), 605 ) ); 606 $this->_last_response = ''; 607 $this->make_ajax_call( 'customize-nav-menus-insert-auto-draft' ); 608 $response = json_decode( $this->_last_response, true ); 609 $this->assertFalse( $response['success'] ); 610 $this->assertEquals( 'insufficient_post_permissions', $response['data'] ); 611 612 // insufficient_post_permissions. 613 $_POST = wp_slash( array( 614 'customize-menus-nonce' => wp_create_nonce( 'customize-menus' ), 615 'params' => array( 616 'post_type' => 'non-existent', 617 ), 618 ) ); 619 $this->_last_response = ''; 620 $this->make_ajax_call( 'customize-nav-menus-insert-auto-draft' ); 621 $response = json_decode( $this->_last_response, true ); 622 $this->assertFalse( $response['success'] ); 623 $this->assertEquals( 'missing_post_type_param', $response['data'] ); 624 625 // missing_post_title. 626 $_POST = wp_slash( array( 627 'customize-menus-nonce' => wp_create_nonce( 'customize-menus' ), 628 'params' => array( 629 'post_type' => 'post', 630 'post_title' => ' ', 631 ), 632 ) ); 633 $this->_last_response = ''; 634 $this->make_ajax_call( 'customize-nav-menus-insert-auto-draft' ); 635 $response = json_decode( $this->_last_response, true ); 636 $this->assertFalse( $response['success'] ); 637 $this->assertEquals( 'missing_post_title', $response['data'] ); 638 } 529 639 }
Note: See TracChangeset
for help on using the changeset viewer.