Changeset 38436 for trunk/tests/phpunit/tests/customize/nav-menus.php
- Timestamp:
- 08/29/2016 10:58:32 PM (8 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/tests/phpunit/tests/customize/nav-menus.php
r36889 r38436 46 46 function filter_item_types( $items ) { 47 47 $items[] = array( 48 'title' 49 'type' 48 'title' => 'Custom', 49 'type' => 'custom_type', 50 50 'object' => 'custom_object', 51 'type_label' => 'Custom Type', 51 52 ); 52 53 … … 85 86 $menus = new WP_Customize_Nav_Menus( $this->wp_customize ); 86 87 $this->assertInstanceOf( 'WP_Customize_Manager', $menus->manager ); 88 89 $this->assertEquals( 10, add_filter( 'customize_refresh_nonces', array( $menus, 'filter_nonces' ) ) ); 90 $this->assertEquals( 10, add_action( 'wp_ajax_load-available-menu-items-customizer', array( $menus, 'ajax_load_available_items' ) ) ); 91 $this->assertEquals( 10, add_action( 'wp_ajax_search-available-menu-items-customizer', array( $menus, 'ajax_search_available_items' ) ) ); 92 $this->assertEquals( 10, add_action( 'wp_ajax_customize-nav-menus-insert-auto-draft', array( $menus, 'ajax_insert_auto_draft_post' ) ) ); 93 $this->assertEquals( 10, add_action( 'customize_controls_enqueue_scripts', array( $menus, 'enqueue_scripts' ) ) ); 94 $this->assertEquals( 11, add_action( 'customize_register', array( $menus, 'customize_register' ) ) ); 95 $this->assertEquals( 10, add_filter( 'customize_dynamic_setting_args', array( $menus, 'filter_dynamic_setting_args' ) ) ); 96 $this->assertEquals( 10, add_filter( 'customize_dynamic_setting_class', array( $menus, 'filter_dynamic_setting_class' ) ) ); 97 $this->assertEquals( 10, add_action( 'customize_controls_print_footer_scripts', array( $menus, 'print_templates' ) ) ); 98 $this->assertEquals( 10, add_action( 'customize_controls_print_footer_scripts', array( $menus, 'available_items_template' ) ) ); 99 $this->assertEquals( 10, add_action( 'customize_preview_init', array( $menus, 'customize_preview_init' ) ) ); 100 $this->assertEquals( 10, add_action( 'customize_preview_init', array( $menus, 'make_auto_draft_status_previewable' ) ) ); 101 $this->assertEquals( 10, add_action( 'customize_save_nav_menus_created_posts', array( $menus, 'save_nav_menus_created_posts' ) ) ); 102 $this->assertEquals( 10, add_filter( 'customize_dynamic_partial_args', array( $menus, 'customize_dynamic_partial_args' ) ) ); 87 103 } 88 104 … … 445 461 'menu-item-status' => 'publish', 446 462 ) ); 447 $setting = new WP_Customize_Nav_Menu_Item_Setting( $this->wp_customize, "nav_menu_item[$item_id]");448 do_action( 'customize_register', $this->wp_customize);463 do_action( 'customize_register', $this->wp_customize ); 464 $this->assertInstanceOf( 'WP_Customize_Nav_Menu_Item_Setting', $this->wp_customize->get_setting( "nav_menu_item[$item_id]" ) ); 449 465 $this->assertEquals( 'Primary', $this->wp_customize->get_section( "nav_menu[$menu_id]" )->title ); 450 466 $this->assertEquals( 'Hello World', $this->wp_customize->get_control( "nav_menu_item[$item_id]" )->label ); 467 468 $nav_menus_created_posts_setting = $this->wp_customize->get_setting( 'nav_menus_created_posts' ); 469 $this->assertInstanceOf( 'WP_Customize_Filter_Setting', $nav_menus_created_posts_setting ); 470 $this->assertEquals( 'postMessage', $nav_menus_created_posts_setting->transport ); 471 $this->assertEquals( array(), $nav_menus_created_posts_setting->default ); 472 $this->assertEquals( array( $this->wp_customize->nav_menus, 'sanitize_nav_menus_created_posts' ), $nav_menus_created_posts_setting->sanitize_callback ); 451 473 } 452 474 … … 480 502 481 503 $expected = array( 482 array( 'title' => 'Posts', 'type' => 'post_type', 'object' => 'post' ),483 array( 'title' => 'Pages', 'type' => 'post_type', 'object' => 'page' ),484 array( 'title' => 'Categories', 'type' => 'taxonomy', 'object' => 'category' ),485 array( 'title' => 'Tags', 'type' => 'taxonomy', 'object' => 'post_tag' ),504 array( 'title' => 'Posts', 'type' => 'post_type', 'object' => 'post', 'type_label' => __( 'Post' ) ), 505 array( 'title' => 'Pages', 'type' => 'post_type', 'object' => 'page', 'type_label' => __( 'Page' ) ), 506 array( 'title' => 'Categories', 'type' => 'taxonomy', 'object' => 'category', 'type_label' => __( 'Category' ) ), 507 array( 'title' => 'Tags', 'type' => 'taxonomy', 'object' => 'post_tag', 'type_label' => __( 'Tag' ) ), 486 508 ); 487 509 488 510 if ( current_theme_supports( 'post-formats' ) ) { 489 $expected[] = array( 'title' => 'Format', 'type' => 'taxonomy', 'object' => 'post_format' );511 $expected[] = array( 'title' => 'Format', 'type' => 'taxonomy', 'object' => 'post_format', 'type_label' => __( 'Format' ) ); 490 512 } 491 513 … … 493 515 494 516 register_taxonomy( 'wptests_tax', array( 'post' ), array( 'labels' => array( 'name' => 'Foo' ) ) ); 495 $expected[] = array( 'title' => 'Foo', 'type' => 'taxonomy', 'object' => 'wptests_tax' );517 $expected[] = array( 'title' => 'Foo', 'type' => 'taxonomy', 'object' => 'wptests_tax', 'type_label' => 'Foo' ); 496 518 497 519 $this->assertEquals( $expected, $menus->available_item_types() ); 498 520 499 $expected[] = array( 'title' => 'Custom', 'type' => 'custom_type', 'object' => 'custom_object' );521 $expected[] = array( 'title' => 'Custom', 'type' => 'custom_type', 'object' => 'custom_object', 'type_label' => 'Custom Type' ); 500 522 501 523 add_filter( 'customize_nav_menu_available_item_types', array( $this, 'filter_item_types' ) ); … … 503 525 remove_filter( 'customize_nav_menu_available_item_types', array( $this, 'filter_item_types' ) ); 504 526 527 } 528 529 /** 530 * Test insert_auto_draft_post method. 531 * 532 * @covers WP_Customize_Nav_Menus::insert_auto_draft_post() 533 */ 534 public function test_insert_auto_draft_post() { 535 $menus = new WP_Customize_Nav_Menus( $this->wp_customize ); 536 537 $r = $menus->insert_auto_draft_post( array() ); 538 $this->assertInstanceOf( 'WP_Error', $r ); 539 $this->assertEquals( 'unknown_post_type', $r->get_error_code() ); 540 541 $r = $menus->insert_auto_draft_post( array( 'post_type' => 'fake' ) ); 542 $this->assertInstanceOf( 'WP_Error', $r ); 543 $this->assertEquals( 'unknown_post_type', $r->get_error_code() ); 544 545 $r = $menus->insert_auto_draft_post( array( 'post_title' => 'Hello World', 'post_type' => 'post' ) ); 546 $this->assertInstanceOf( 'WP_Post', $r ); 547 $this->assertEquals( 'Hello World', $r->post_title ); 548 $this->assertEquals( 'post', $r->post_type ); 549 $this->assertEquals( sanitize_title( $r->post_title ), $r->post_name ); 505 550 } 506 551 … … 554 599 $this->assertContains( 'data-type="post_type"', $template ); 555 600 $this->assertContains( 'data-object="' . esc_attr( $type->name ) . '"', $template ); 601 $this->assertContains( 'data-type_label="' . esc_attr( $type->labels->singular_name ) . '"', $template ); 556 602 } 557 603 } … … 564 610 $this->assertContains( 'data-type="taxonomy"', $template ); 565 611 $this->assertContains( 'data-object="' . esc_attr( $tax->name ) . '"', $template ); 612 $this->assertContains( 'data-type_label="' . esc_attr( $tax->labels->singular_name ) . '"', $template ); 566 613 } 567 614 } … … 571 618 $this->assertContains( 'data-type="custom_type"', $template ); 572 619 $this->assertContains( 'data-object="custom_object"', $template ); 620 $this->assertContains( 'data-type_label="Custom Type"', $template ); 573 621 } 574 622 … … 608 656 $this->assertEquals( 1000, has_filter( 'wp_nav_menu_args', array( $menus, 'filter_wp_nav_menu_args' ) ) ); 609 657 $this->assertEquals( 10, has_filter( 'wp_nav_menu', array( $menus, 'filter_wp_nav_menu' ) ) ); 658 } 659 660 /** 661 * Test make_auto_draft_status_previewable. 662 * 663 * @covers WP_Customize_Nav_Menus::make_auto_draft_status_previewable() 664 */ 665 function test_make_auto_draft_status_previewable() { 666 global $wp_post_statuses; 667 $menus = new WP_Customize_Nav_Menus( $this->wp_customize ); 668 $menus->make_auto_draft_status_previewable(); 669 $this->assertTrue( $wp_post_statuses['auto-draft']->protected ); 670 } 671 672 /** 673 * Test sanitize_nav_menus_created_posts. 674 * 675 * @covers WP_Customize_Nav_Menus::sanitize_nav_menus_created_posts() 676 */ 677 function test_sanitize_nav_menus_created_posts() { 678 $menus = new WP_Customize_Nav_Menus( $this->wp_customize ); 679 $contributor_user_id = $this->factory()->user->create( array( 'role' => 'contributor' ) ); 680 $author_user_id = $this->factory()->user->create( array( 'role' => 'author' ) ); 681 $administrator_user_id = $this->factory()->user->create( array( 'role' => 'administrator' ) ); 682 683 $contributor_post_id = $this->factory()->post->create( array( 684 'post_status' => 'auto-draft', 685 'post_title' => 'Contributor Post', 686 'post_type' => 'post', 687 'post_author' => $contributor_user_id, 688 ) ); 689 $author_post_id = $this->factory()->post->create( array( 690 'post_status' => 'auto-draft', 691 'post_title' => 'Author Post', 692 'post_type' => 'post', 693 'post_author' => $author_user_id, 694 ) ); 695 $administrator_post_id = $this->factory()->post->create( array( 696 'post_status' => 'auto-draft', 697 'post_title' => 'Admin Post', 698 'post_type' => 'post', 699 'post_author' => $administrator_user_id, 700 ) ); 701 702 $value = array( 703 'bad', 704 $contributor_post_id, 705 $author_post_id, 706 $administrator_post_id, 707 ); 708 709 wp_set_current_user( $contributor_user_id ); 710 $sanitized = $menus->sanitize_nav_menus_created_posts( $value ); 711 $this->assertEquals( array(), $sanitized ); 712 713 wp_set_current_user( $author_user_id ); 714 $sanitized = $menus->sanitize_nav_menus_created_posts( $value ); 715 $this->assertEquals( array( $author_post_id ), $sanitized ); 716 717 wp_set_current_user( $administrator_user_id ); 718 $sanitized = $menus->sanitize_nav_menus_created_posts( $value ); 719 $this->assertEquals( array( $contributor_post_id, $author_post_id, $administrator_post_id ), $sanitized ); 720 } 721 722 /** 723 * Test save_nav_menus_created_posts. 724 * 725 * @covers WP_Customize_Nav_Menus::save_nav_menus_created_posts() 726 */ 727 function test_save_nav_menus_created_posts() { 728 $menus = new WP_Customize_Nav_Menus( $this->wp_customize ); 729 do_action( 'customize_register', $this->wp_customize ); 730 731 $post_ids = $this->factory()->post->create_many( 3, array( 732 'post_status' => 'auto-draft', 733 'post_type' => 'post', 734 ) ); 735 $pre_published_post_id = $this->factory()->post->create( array( 'post_status' => 'publish' ) ); 736 737 $setting_id = 'nav_menus_created_posts'; 738 $this->wp_customize->set_post_value( $setting_id, array_merge( $post_ids, array( $pre_published_post_id ) ) ); 739 $setting = $this->wp_customize->get_setting( $setting_id ); 740 $this->assertInstanceOf( 'WP_Customize_Filter_Setting', $setting ); 741 $this->assertEquals( array( $menus, 'sanitize_nav_menus_created_posts' ), $setting->sanitize_callback ); 742 $this->assertEquals( $post_ids, $setting->post_value() ); 743 foreach ( $post_ids as $post_id ) { 744 $this->assertEquals( 'auto-draft', get_post_status( $post_id ) ); 745 } 746 747 $save_action_count = did_action( 'customize_save_nav_menus_created_posts' ); 748 $setting->save(); 749 $this->assertEquals( $save_action_count + 1, did_action( 'customize_save_nav_menus_created_posts' ) ); 750 foreach ( $post_ids as $post_id ) { 751 $this->assertEquals( 'publish', get_post_status( $post_id ) ); 752 } 610 753 } 611 754
Note: See TracChangeset
for help on using the changeset viewer.