Changeset 42343 for trunk/tests/phpunit/tests/ajax/CustomizeMenus.php
- Timestamp:
- 11/30/2017 11:09:33 PM (8 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/tests/phpunit/tests/ajax/CustomizeMenus.php
r41887 r42343 26 26 global $wp_customize; 27 27 $this->wp_customize = new WP_Customize_Manager(); 28 $wp_customize = $this->wp_customize;28 $wp_customize = $this->wp_customize; 29 29 } 30 30 … … 87 87 * @return array { 88 88 * @type array { 89 * @string string $role The role that will test caps for.90 * @array array $expected_results The expected results from the ajax call.89 * @string string $role The role that will test caps for. 90 * @array array $expected_results The expected results from the ajax call. 91 91 * } 92 92 * } … … 130 130 function test_ajax_load_available_items_error_messages( $post_args, $expected_results ) { 131 131 132 $_POST = array_merge( array( 133 'action' => 'load-available-menu-items-customizer', 134 'customize-menus-nonce' => wp_create_nonce( 'customize-menus' ), 135 ), $post_args ); 132 $_POST = array_merge( 133 array( 134 'action' => 'load-available-menu-items-customizer', 135 'customize-menus-nonce' => wp_create_nonce( 'customize-menus' ), 136 ), $post_args 137 ); 136 138 137 139 // Make the request. … … 154 156 * @return array { 155 157 * @type array { 156 * @array array $post_args The arguments that will merged with the $_POST array.157 * @array array $expected_results The expected results from the ajax call.158 * @array array $post_args The arguments that will merged with the $_POST array. 159 * @array array $expected_results The expected results from the ajax call. 158 160 * } 159 161 * } … … 164 166 array( 165 167 array( 166 'type' => '',167 'object' => '',168 ), 169 array( 170 'success' => false,171 'data' => 'nav_menus_missing_type_or_object_parameter',168 'type' => '', 169 'object' => '', 170 ), 171 array( 172 'success' => false, 173 'data' => 'nav_menus_missing_type_or_object_parameter', 172 174 ), 173 175 ), … … 175 177 array( 176 178 array( 177 'type' => 'post_type',178 'object' => '',179 ), 180 array( 181 'success' => false,182 'data' => 'nav_menus_missing_type_or_object_parameter',179 'type' => 'post_type', 180 'object' => '', 181 ), 182 array( 183 'success' => false, 184 'data' => 'nav_menus_missing_type_or_object_parameter', 183 185 ), 184 186 ), … … 186 188 array( 187 189 array( 188 'type' => '',189 'object' => 'post',190 ), 191 array( 192 'success' => false,193 'data' => 'nav_menus_missing_type_or_object_parameter',190 'type' => '', 191 'object' => 'post', 192 ), 193 array( 194 'success' => false, 195 'data' => 'nav_menus_missing_type_or_object_parameter', 194 196 ), 195 197 ), … … 199 201 'item_types' => array( 200 202 array( 201 'type' => 'post_type',202 'object' => 'post',203 'type' => 'post_type', 204 'object' => 'post', 203 205 ), 204 206 array( 205 'type' => 'post_type',206 'object' => '',207 'type' => 'post_type', 208 'object' => '', 207 209 ), 208 210 ), 209 211 ), 210 212 array( 211 'success' => false,212 'data' => 'nav_menus_missing_type_or_object_parameter',213 'success' => false, 214 'data' => 'nav_menus_missing_type_or_object_parameter', 213 215 ), 214 216 ), … … 216 218 array( 217 219 array( 218 'type' => 'post_type',219 'object' => 'invalid',220 ), 221 array( 222 'success' => false,223 'data' => 'nav_menus_invalid_post_type',220 'type' => 'post_type', 221 'object' => 'invalid', 222 ), 223 array( 224 'success' => false, 225 'data' => 'nav_menus_invalid_post_type', 224 226 ), 225 227 ), … … 237 239 function test_ajax_load_available_items_success_status( $post_args, $success_status ) { 238 240 239 $_POST = array_merge( array( 240 'action' => 'load-available-menu-items-customizer', 241 'customize-menus-nonce' => wp_create_nonce( 'customize-menus' ), 242 ), $post_args ); 241 $_POST = array_merge( 242 array( 243 'action' => 'load-available-menu-items-customizer', 244 'customize-menus-nonce' => wp_create_nonce( 'customize-menus' ), 245 ), $post_args 246 ); 243 247 244 248 // Make the request. … … 270 274 array( 271 275 array( 272 'type' => 'post_type',273 'object' => 'post',276 'type' => 'post_type', 277 'object' => 'post', 274 278 ), 275 279 true, … … 277 281 array( 278 282 array( 279 'type' => 'post_type',280 'object' => 'page',283 'type' => 'post_type', 284 'object' => 'page', 281 285 ), 282 286 true, … … 284 288 array( 285 289 array( 286 'type' => 'post_type',287 'object' => 'custom',290 'type' => 'post_type', 291 'object' => 'custom', 288 292 ), 289 293 false, … … 291 295 array( 292 296 array( 293 'type' => 'taxonomy',294 'object' => 'post_tag',297 'type' => 'taxonomy', 298 'object' => 'post_tag', 295 299 ), 296 300 true, … … 301 305 'item_types' => array( 302 306 array( 303 'type' => 'post_type',304 'object' => 'post',307 'type' => 'post_type', 308 'object' => 'post', 305 309 ), 306 310 array( 307 'type' => 'post_type',308 'object' => 'page',311 'type' => 'post_type', 312 'object' => 'page', 309 313 ), 310 314 ), … … 338 342 self::factory()->term->create_many( 5 ); 339 343 self::factory()->post->create_many( 5, array( 'post_type' => 'page' ) ); 340 $auto_draft_post = $this->wp_customize->nav_menus->insert_auto_draft_post( array( 'post_title' => 'Test Auto Draft', 'post_type' => 'post' ) ); 344 $auto_draft_post = $this->wp_customize->nav_menus->insert_auto_draft_post( 345 array( 346 'post_title' => 'Test Auto Draft', 347 'post_type' => 'post', 348 ) 349 ); 341 350 $this->wp_customize->set_post_value( 'nav_menus_created_posts', array( $auto_draft_post->ID ) ); 342 351 $this->wp_customize->get_setting( 'nav_menus_created_posts' )->preview(); 343 352 344 $_POST = array_merge( array( 345 'action' => 'load-available-menu-items-customizer', 346 'customize-menus-nonce' => wp_create_nonce( 'customize-menus' ), 347 ), $post_args ); 353 $_POST = array_merge( 354 array( 355 'action' => 'load-available-menu-items-customizer', 356 'customize-menus-nonce' => wp_create_nonce( 'customize-menus' ), 357 ), $post_args 358 ); 348 359 349 360 // Make the request. … … 357 368 // Get the second index to avoid the home page edge case. 358 369 $first_prop = current( $response['data']['items'] ); 359 $test_item = $first_prop[1];370 $test_item = $first_prop[1]; 360 371 361 372 foreach ( $expected_keys as $key ) { … … 367 378 if ( 'page' === $test_item['object'] ) { 368 379 $first_prop = current( $response['data']['items'] ); 369 $home = $first_prop[0];380 $home = $first_prop[0]; 370 381 foreach ( $expected_keys as $key ) { 371 382 if ( 'object_id' !== $key ) { … … 399 410 array( 400 411 array( 401 'type' => 'post_type',402 'object' => 'post',403 ), 404 ), 405 array( 406 array( 407 'type' => 'post_type',408 'object' => 'page',409 ), 410 ), 411 array( 412 array( 413 'type' => 'taxonomy',414 'object' => 'post_tag',412 'type' => 'post_type', 413 'object' => 'post', 414 ), 415 ), 416 array( 417 array( 418 'type' => 'post_type', 419 'object' => 'page', 420 ), 421 ), 422 array( 423 array( 424 'type' => 'taxonomy', 425 'object' => 'post_tag', 415 426 ), 416 427 ), … … 463 474 * @return array { 464 475 * @type array { 465 * @string string $role The role that will test caps for.466 * @array array $expected_results The expected results from the ajax call.476 * @string string $role The role that will test caps for. 477 * @array array $expected_results The expected results from the ajax call. 467 478 * } 468 479 * } … … 508 519 509 520 self::factory()->post->create_many( 5, array( 'post_title' => 'Test Post' ) ); 510 $included_auto_draft_post = $this->wp_customize->nav_menus->insert_auto_draft_post( array( 'post_title' => 'Test Included Auto Draft', 'post_type' => 'post' ) ); 511 $excluded_auto_draft_post = $this->wp_customize->nav_menus->insert_auto_draft_post( array( 'post_title' => 'Excluded Auto Draft', 'post_type' => 'post' ) ); 521 $included_auto_draft_post = $this->wp_customize->nav_menus->insert_auto_draft_post( 522 array( 523 'post_title' => 'Test Included Auto Draft', 524 'post_type' => 'post', 525 ) 526 ); 527 $excluded_auto_draft_post = $this->wp_customize->nav_menus->insert_auto_draft_post( 528 array( 529 'post_title' => 'Excluded Auto Draft', 530 'post_type' => 'post', 531 ) 532 ); 512 533 $this->wp_customize->set_post_value( 'nav_menus_created_posts', array( $included_auto_draft_post->ID, $excluded_auto_draft_post->ID ) ); 513 534 $this->wp_customize->get_setting( 'nav_menus_created_posts' )->preview(); 514 535 515 $_POST = array_merge( array( 516 'action' => 'search-available-menu-items-customizer', 517 'customize-menus-nonce' => wp_create_nonce( 'customize-menus' ), 518 ), $post_args ); 536 $_POST = array_merge( 537 array( 538 'action' => 'search-available-menu-items-customizer', 539 'customize-menus-nonce' => wp_create_nonce( 'customize-menus' ), 540 ), $post_args 541 ); 519 542 520 543 $this->make_ajax_call( 'search-available-menu-items-customizer' ); … … 542 565 * @return array { 543 566 * @type array { 544 * @string string $post_args The args that will be passed to ajax.545 * @array array $expected_results The expected results from the ajax call.567 * @string string $post_args The args that will be passed to ajax. 568 * @array array $expected_results The expected results from the ajax call. 546 569 * } 547 570 * } … … 558 581 array( 559 582 array( 560 'search' => 'all_the_things',583 'search' => 'all_the_things', 561 584 ), 562 585 array( … … 569 592 array( 570 593 array( 571 'search' => 'test',594 'search' => 'test', 572 595 ), 573 596 array( … … 585 608 */ 586 609 function test_ajax_insert_auto_draft_post_success() { 587 $_POST = wp_slash( array( 588 'customize-menus-nonce' => wp_create_nonce( 'customize-menus' ), 589 'params' => array( 590 'post_type' => 'post', 591 'post_title' => 'Hello World', 592 ), 593 ) ); 610 $_POST = wp_slash( 611 array( 612 'customize-menus-nonce' => wp_create_nonce( 'customize-menus' ), 613 'params' => array( 614 'post_type' => 'post', 615 'post_title' => 'Hello World', 616 ), 617 ) 618 ); 594 619 $this->_last_response = ''; 595 620 $this->make_ajax_call( 'customize-nav-menus-insert-auto-draft' ); … … 614 639 function test_ajax_insert_auto_draft_failures() { 615 640 // No nonce. 616 $_POST = array();641 $_POST = array(); 617 642 $this->_last_response = ''; 618 643 $this->make_ajax_call( 'customize-nav-menus-insert-auto-draft' ); … … 622 647 623 648 // Bad nonce. 624 $_POST = wp_slash( array( 625 'customize-menus-nonce' => 'bad', 626 ) ); 649 $_POST = wp_slash( 650 array( 651 'customize-menus-nonce' => 'bad', 652 ) 653 ); 627 654 $this->_last_response = ''; 628 655 $this->make_ajax_call( 'customize-nav-menus-insert-auto-draft' ); … … 633 660 // Bad nonce. 634 661 wp_set_current_user( $this->factory()->user->create( array( 'role' => 'subscriber' ) ) ); 635 $_POST = wp_slash( array( 636 'customize-menus-nonce' => wp_create_nonce( 'customize-menus' ), 637 ) ); 662 $_POST = wp_slash( 663 array( 664 'customize-menus-nonce' => wp_create_nonce( 'customize-menus' ), 665 ) 666 ); 638 667 $this->_last_response = ''; 639 668 $this->make_ajax_call( 'customize-nav-menus-insert-auto-draft' ); … … 644 673 // Missing params. 645 674 wp_set_current_user( $this->factory()->user->create( array( 'role' => 'administrator' ) ) ); 646 $_POST = wp_slash( array( 647 'customize-menus-nonce' => wp_create_nonce( 'customize-menus' ), 648 ) ); 675 $_POST = wp_slash( 676 array( 677 'customize-menus-nonce' => wp_create_nonce( 'customize-menus' ), 678 ) 679 ); 649 680 $this->_last_response = ''; 650 681 $this->make_ajax_call( 'customize-nav-menus-insert-auto-draft' ); … … 655 686 // insufficient_post_permissions. 656 687 register_post_type( 'privilege', array( 'capability_type' => 'privilege' ) ); 657 $_POST = wp_slash( array( 658 'customize-menus-nonce' => wp_create_nonce( 'customize-menus' ), 659 'params' => array( 660 'post_type' => 'privilege', 661 ), 662 ) ); 688 $_POST = wp_slash( 689 array( 690 'customize-menus-nonce' => wp_create_nonce( 'customize-menus' ), 691 'params' => array( 692 'post_type' => 'privilege', 693 ), 694 ) 695 ); 663 696 $this->_last_response = ''; 664 697 $this->make_ajax_call( 'customize-nav-menus-insert-auto-draft' ); … … 668 701 669 702 // insufficient_post_permissions. 670 $_POST = wp_slash( array( 671 'customize-menus-nonce' => wp_create_nonce( 'customize-menus' ), 672 'params' => array( 673 'post_type' => 'non-existent', 674 ), 675 ) ); 703 $_POST = wp_slash( 704 array( 705 'customize-menus-nonce' => wp_create_nonce( 'customize-menus' ), 706 'params' => array( 707 'post_type' => 'non-existent', 708 ), 709 ) 710 ); 676 711 $this->_last_response = ''; 677 712 $this->make_ajax_call( 'customize-nav-menus-insert-auto-draft' ); … … 681 716 682 717 // missing_post_title. 683 $_POST = wp_slash( array( 684 'customize-menus-nonce' => wp_create_nonce( 'customize-menus' ), 685 'params' => array( 686 'post_type' => 'post', 687 'post_title' => ' ', 688 ), 689 ) ); 718 $_POST = wp_slash( 719 array( 720 'customize-menus-nonce' => wp_create_nonce( 'customize-menus' ), 721 'params' => array( 722 'post_type' => 'post', 723 'post_title' => ' ', 724 ), 725 ) 726 ); 690 727 $this->_last_response = ''; 691 728 $this->make_ajax_call( 'customize-nav-menus-insert-auto-draft' ); … … 695 732 696 733 // illegal_params. 697 $_POST = wp_slash( array( 698 'customize-menus-nonce' => wp_create_nonce( 'customize-menus' ), 699 'params' => array( 700 'post_type' => 'post', 701 'post_title' => 'OK', 702 'post_name' => 'bad', 703 'post_content' => 'bad', 704 ), 705 ) ); 734 $_POST = wp_slash( 735 array( 736 'customize-menus-nonce' => wp_create_nonce( 'customize-menus' ), 737 'params' => array( 738 'post_type' => 'post', 739 'post_title' => 'OK', 740 'post_name' => 'bad', 741 'post_content' => 'bad', 742 ), 743 ) 744 ); 706 745 $this->_last_response = ''; 707 746 $this->make_ajax_call( 'customize-nav-menus-insert-auto-draft' );
Note: See TracChangeset
for help on using the changeset viewer.