mirror of
https://github.com/gosticks/wordpress-develop.git
synced 2026-06-28 14:20:15 +00:00
Add menu management to the Customizer.
This brings in the Menu Customizer plugin: https://wordpress.org/plugins/menu-customizer/. props celloexpressions, westonruter, valendesigns, voldemortensen, ocean90, adamsilverstein, kucrut, jorbin, designsimply, afercia, davidakennedy, obenland. see #32576. git-svn-id: https://develop.svn.wordpress.org/trunk@32806 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
625
tests/phpunit/tests/customize/nav-menu-item-setting.php
Normal file
625
tests/phpunit/tests/customize/nav-menu-item-setting.php
Normal file
@@ -0,0 +1,625 @@
|
||||
<?php
|
||||
/**
|
||||
* Tests WP_Customize_Nav_Menu_Item_Setting.
|
||||
*
|
||||
* @group customize
|
||||
*/
|
||||
class Test_WP_Customize_Nav_Menu_Item_Setting extends WP_UnitTestCase {
|
||||
|
||||
/**
|
||||
* Instance of WP_Customize_Manager which is reset for each test.
|
||||
*
|
||||
* @var WP_Customize_Manager
|
||||
*/
|
||||
public $wp_customize;
|
||||
|
||||
/**
|
||||
* Set up a test case.
|
||||
*
|
||||
* @see WP_UnitTestCase::setup()
|
||||
*/
|
||||
function setUp() {
|
||||
parent::setUp();
|
||||
require_once ABSPATH . WPINC . '/class-wp-customize-manager.php';
|
||||
wp_set_current_user( $this->factory->user->create( array( 'role' => 'administrator' ) ) );
|
||||
|
||||
global $wp_customize;
|
||||
$this->wp_customize = new WP_Customize_Manager();
|
||||
$wp_customize = $this->wp_customize;
|
||||
}
|
||||
|
||||
/**
|
||||
* Delete the $wp_customize global when cleaning up scope.
|
||||
*/
|
||||
function clean_up_global_scope() {
|
||||
global $wp_customize;
|
||||
$wp_customize = null;
|
||||
parent::clean_up_global_scope();
|
||||
}
|
||||
|
||||
/**
|
||||
* Test constants and statics.
|
||||
*/
|
||||
function test_constants() {
|
||||
do_action( 'customize_register', $this->wp_customize );
|
||||
$this->assertTrue( post_type_exists( WP_Customize_Nav_Menu_Item_Setting::POST_TYPE ) );
|
||||
}
|
||||
|
||||
/**
|
||||
* Test constructor.
|
||||
*
|
||||
* @see WP_Customize_Nav_Menu_Item_Setting::__construct()
|
||||
*/
|
||||
function test_construct() {
|
||||
do_action( 'customize_register', $this->wp_customize );
|
||||
|
||||
$setting = new WP_Customize_Nav_Menu_Item_Setting( $this->wp_customize, 'nav_menu_item[123]' );
|
||||
$this->assertEquals( 'nav_menu_item', $setting->type );
|
||||
$this->assertEquals( 'postMessage', $setting->transport );
|
||||
$this->assertEquals( 123, $setting->post_id );
|
||||
$this->assertNull( $setting->previous_post_id );
|
||||
$this->assertNull( $setting->update_status );
|
||||
$this->assertNull( $setting->update_error );
|
||||
$this->assertInternalType( 'array', $setting->default );
|
||||
|
||||
$default = array(
|
||||
'object_id' => 0,
|
||||
'object' => '',
|
||||
'menu_item_parent' => 0,
|
||||
'position' => 0,
|
||||
'type' => 'custom',
|
||||
'title' => '',
|
||||
'url' => '',
|
||||
'target' => '',
|
||||
'attr_title' => '',
|
||||
'description' => '',
|
||||
'classes' => '',
|
||||
'xfn' => '',
|
||||
'status' => 'publish',
|
||||
'original_title' => '',
|
||||
'nav_menu_term_id' => 0,
|
||||
);
|
||||
$this->assertEquals( $default, $setting->default );
|
||||
|
||||
$exception = null;
|
||||
try {
|
||||
$bad_setting = new WP_Customize_Nav_Menu_Item_Setting( $this->wp_customize, 'foo_bar_baz' );
|
||||
unset( $bad_setting );
|
||||
} catch ( Exception $e ) {
|
||||
$exception = $e;
|
||||
}
|
||||
$this->assertInstanceOf( 'Exception', $exception );
|
||||
}
|
||||
|
||||
/**
|
||||
* Test empty constructor.
|
||||
*/
|
||||
function test_construct_empty_menus() {
|
||||
do_action( 'customize_register', $this->wp_customize );
|
||||
$_wp_customize = $this->wp_customize;
|
||||
unset($_wp_customize->nav_menus);
|
||||
|
||||
$exception = null;
|
||||
try {
|
||||
$bad_setting = new WP_Customize_Nav_Menu_Item_Setting( $_wp_customize, 'nav_menu_item[123]' );
|
||||
unset( $bad_setting );
|
||||
} catch ( Exception $e ) {
|
||||
$exception = $e;
|
||||
}
|
||||
$this->assertInstanceOf( 'Exception', $exception );
|
||||
}
|
||||
|
||||
/**
|
||||
* Test constructor for placeholder (draft) menu.
|
||||
*
|
||||
* @see WP_Customize_Nav_Menu_Item_Setting::__construct()
|
||||
*/
|
||||
function test_construct_placeholder() {
|
||||
do_action( 'customize_register', $this->wp_customize );
|
||||
$default = array(
|
||||
'title' => 'Lorem',
|
||||
'description' => 'ipsum',
|
||||
'menu_item_parent' => 123,
|
||||
);
|
||||
$setting = new WP_Customize_Nav_Menu_Item_Setting( $this->wp_customize, 'nav_menu_item[-5]', compact( 'default' ) );
|
||||
$this->assertEquals( -5, $setting->post_id );
|
||||
$this->assertNull( $setting->previous_post_id );
|
||||
$this->assertEquals( $default, $setting->default );
|
||||
}
|
||||
|
||||
/**
|
||||
* Test value method with post.
|
||||
*
|
||||
* @see WP_Customize_Nav_Menu_Item_Setting::value()
|
||||
*/
|
||||
function test_value_type_post_type() {
|
||||
do_action( 'customize_register', $this->wp_customize );
|
||||
|
||||
$post_id = $this->factory->post->create( array( 'post_title' => 'Hello World' ) );
|
||||
|
||||
$menu_id = wp_create_nav_menu( 'Menu' );
|
||||
$item_title = 'Greetings';
|
||||
$item_id = wp_update_nav_menu_item( $menu_id, 0, array(
|
||||
'menu-item-type' => 'post_type',
|
||||
'menu-item-object' => 'post',
|
||||
'menu-item-object-id' => $post_id,
|
||||
'menu-item-title' => $item_title,
|
||||
'menu-item-status' => 'publish',
|
||||
) );
|
||||
|
||||
$post = get_post( $item_id );
|
||||
$menu_item = wp_setup_nav_menu_item( $post );
|
||||
$this->assertEquals( $item_title, $menu_item->title );
|
||||
|
||||
$setting_id = "nav_menu_item[$item_id]";
|
||||
$setting = new WP_Customize_Nav_Menu_Item_Setting( $this->wp_customize, $setting_id );
|
||||
|
||||
$value = $setting->value();
|
||||
$this->assertEquals( $menu_item->title, $value['title'] );
|
||||
$this->assertEquals( $menu_item->type, $value['type'] );
|
||||
$this->assertEquals( $menu_item->object_id, $value['object_id'] );
|
||||
$this->assertEquals( $menu_id, $value['nav_menu_term_id'] );
|
||||
$this->assertEquals( 'Hello World', $value['original_title'] );
|
||||
|
||||
$other_menu_id = wp_create_nav_menu( 'Menu2' );
|
||||
wp_update_nav_menu_item( $other_menu_id, $item_id, array(
|
||||
'menu-item-title' => 'Hola',
|
||||
) );
|
||||
$value = $setting->value();
|
||||
$this->assertEquals( 'Hola', $value['title'] );
|
||||
$this->assertEquals( $other_menu_id, $value['nav_menu_term_id'] );
|
||||
}
|
||||
|
||||
/**
|
||||
* Test value method with taxonomy.
|
||||
*
|
||||
* @see WP_Customize_Nav_Menu_Item_Setting::value()
|
||||
*/
|
||||
function test_value_type_taxonomy() {
|
||||
do_action( 'customize_register', $this->wp_customize );
|
||||
|
||||
$tax_id = $this->factory->category->create( array( 'name' => 'Salutations' ) );
|
||||
|
||||
$menu_id = wp_create_nav_menu( 'Menu' );
|
||||
$item_title = 'Greetings';
|
||||
$item_id = wp_update_nav_menu_item( $menu_id, 0, array(
|
||||
'menu-item-type' => 'taxonomy',
|
||||
'menu-item-object' => 'category',
|
||||
'menu-item-object-id' => $tax_id,
|
||||
'menu-item-title' => $item_title,
|
||||
'menu-item-status' => 'publish',
|
||||
) );
|
||||
|
||||
$post = get_post( $item_id );
|
||||
$menu_item = wp_setup_nav_menu_item( $post );
|
||||
$this->assertEquals( $item_title, $menu_item->title );
|
||||
|
||||
$setting_id = "nav_menu_item[$item_id]";
|
||||
$setting = new WP_Customize_Nav_Menu_Item_Setting( $this->wp_customize, $setting_id );
|
||||
|
||||
$value = $setting->value();
|
||||
$this->assertEquals( $menu_item->title, $value['title'] );
|
||||
$this->assertEquals( $menu_item->type, $value['type'] );
|
||||
$this->assertEquals( $menu_item->object_id, $value['object_id'] );
|
||||
$this->assertEquals( $menu_id, $value['nav_menu_term_id'] );
|
||||
$this->assertEquals( 'Salutations', $value['original_title'] );
|
||||
}
|
||||
|
||||
/**
|
||||
* Test value method returns zero for nav_menu_term_id when previewing a new menu.
|
||||
*
|
||||
* @see WP_Customize_Nav_Menu_Item_Setting::value()
|
||||
*/
|
||||
function test_value_nav_menu_term_id_returns_zero() {
|
||||
do_action( 'customize_register', $this->wp_customize );
|
||||
|
||||
$menu_id = -123;
|
||||
$post_value = array(
|
||||
'name' => 'Secondary',
|
||||
'description' => '',
|
||||
'parent' => 0,
|
||||
'auto_add' => false,
|
||||
);
|
||||
$setting_id = "nav_menu[$menu_id]";
|
||||
$menu = new WP_Customize_Nav_Menu_Setting( $this->wp_customize, $setting_id );
|
||||
|
||||
$this->wp_customize->set_post_value( $menu->id, $post_value );
|
||||
$menu->preview();
|
||||
$value = $menu->value();
|
||||
$this->assertEquals( $post_value, $value );
|
||||
|
||||
$post_id = $this->factory->post->create( array( 'post_title' => 'Hello World' ) );
|
||||
$item_id = wp_update_nav_menu_item( $menu_id, 0, array(
|
||||
'menu-item-type' => 'post_type',
|
||||
'menu-item-object' => 'post',
|
||||
'menu-item-object-id' => $post_id,
|
||||
'menu-item-title' => 'Hello World',
|
||||
'menu-item-status' => 'publish',
|
||||
) );
|
||||
|
||||
$post = get_post( $item_id );
|
||||
$menu_item = wp_setup_nav_menu_item( $post );
|
||||
|
||||
$setting_id = "nav_menu_item[$item_id]";
|
||||
$setting = new WP_Customize_Nav_Menu_Item_Setting( $this->wp_customize, $setting_id );
|
||||
$value = $setting->value();
|
||||
$this->assertEquals( 0, $value['nav_menu_term_id'] );
|
||||
}
|
||||
|
||||
/**
|
||||
* Test preview method for updated menu.
|
||||
*
|
||||
* @see WP_Customize_Nav_Menu_Item_Setting::preview()
|
||||
*/
|
||||
function test_preview_updated() {
|
||||
do_action( 'customize_register', $this->wp_customize );
|
||||
|
||||
$first_post_id = $this->factory->post->create( array( 'post_title' => 'Hello World' ) );
|
||||
$second_post_id = $this->factory->post->create( array( 'post_title' => 'Hola Muno' ) );
|
||||
|
||||
$primary_menu_id = wp_create_nav_menu( 'Primary' );
|
||||
$secondary_menu_id = wp_create_nav_menu( 'Secondary' );
|
||||
$item_title = 'Greetings';
|
||||
$item_id = wp_update_nav_menu_item( $primary_menu_id, 0, array(
|
||||
'menu-item-type' => 'post_type',
|
||||
'menu-item-object' => 'post',
|
||||
'menu-item-object-id' => $first_post_id,
|
||||
'menu-item-title' => $item_title,
|
||||
'menu-item-status' => 'publish',
|
||||
) );
|
||||
$this->assertNotEmpty( wp_get_nav_menu_items( $primary_menu_id, array( 'post_status' => 'publish,draft' ) ) );
|
||||
|
||||
$post_value = array(
|
||||
'type' => 'post_type',
|
||||
'object' => 'post',
|
||||
'object_id' => $second_post_id,
|
||||
'title' => 'Saludos',
|
||||
'status' => 'publish',
|
||||
'nav_menu_term_id' => $secondary_menu_id,
|
||||
);
|
||||
$setting_id = "nav_menu_item[$item_id]";
|
||||
$setting = new WP_Customize_Nav_Menu_Item_Setting( $this->wp_customize, $setting_id );
|
||||
$this->wp_customize->set_post_value( $setting_id, $post_value );
|
||||
unset( $post_value['nav_menu_term_id'] );
|
||||
$setting->preview();
|
||||
|
||||
// Make sure the menu item appears in the new menu.
|
||||
$this->assertNotContains( $item_id, wp_list_pluck( wp_get_nav_menu_items( $primary_menu_id ), 'db_id' ) );
|
||||
$menu_items = wp_get_nav_menu_items( $secondary_menu_id );
|
||||
$db_ids = wp_list_pluck( $menu_items, 'db_id' );
|
||||
$this->assertContains( $item_id, $db_ids );
|
||||
$i = array_search( $item_id, $db_ids );
|
||||
$updated_item = $menu_items[ $i ];
|
||||
$post_value['post_status'] = $post_value['status'];
|
||||
unset( $post_value['status'] );
|
||||
foreach ( $post_value as $key => $value ) {
|
||||
$this->assertEquals( $value, $updated_item->$key, "Key $key mismatch" );
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Test preview method for inserted menu.
|
||||
*
|
||||
* @see WP_Customize_Nav_Menu_Item_Setting::preview()
|
||||
*/
|
||||
function test_preview_inserted() {
|
||||
do_action( 'customize_register', $this->wp_customize );
|
||||
|
||||
$menu_id = wp_create_nav_menu( 'Primary' );
|
||||
$post_id = $this->factory->post->create( array( 'post_title' => 'Hello World' ) );
|
||||
$item_ids = array();
|
||||
for ( $i = 0; $i < 5; $i += 1 ) {
|
||||
$item_id = wp_update_nav_menu_item( $menu_id, 0, array(
|
||||
'menu-item-type' => 'post_type',
|
||||
'menu-item-object' => 'post',
|
||||
'menu-item-object-id' => $post_id,
|
||||
'menu-item-title' => "Item $i",
|
||||
'menu-item-status' => 'publish',
|
||||
'menu-item-position' => $i + 1,
|
||||
) );
|
||||
$item_ids[] = $item_id;
|
||||
}
|
||||
|
||||
$post_value = array(
|
||||
'type' => 'post_type',
|
||||
'object' => 'post',
|
||||
'object_id' => $post_id,
|
||||
'title' => 'Inserted item',
|
||||
'status' => 'publish',
|
||||
'nav_menu_term_id' => $menu_id,
|
||||
'position' => count( $item_ids ) + 1,
|
||||
);
|
||||
|
||||
$new_item_id = -10;
|
||||
$setting_id = "nav_menu_item[$new_item_id]";
|
||||
$setting = new WP_Customize_Nav_Menu_Item_Setting( $this->wp_customize, $setting_id );
|
||||
$this->wp_customize->set_post_value( $setting_id, $post_value );
|
||||
unset( $post_value['nav_menu_term_id'] );
|
||||
|
||||
$current_items = wp_get_nav_menu_items( $menu_id );
|
||||
$setting->preview();
|
||||
$preview_items = wp_get_nav_menu_items( $menu_id );
|
||||
$this->assertNotEquals( count( $current_items ), count( $preview_items ) );
|
||||
|
||||
$last_item = array_pop( $preview_items );
|
||||
$this->assertEquals( $new_item_id, $last_item->db_id );
|
||||
$post_value['post_status'] = $post_value['status'];
|
||||
unset( $post_value['status'] );
|
||||
$post_value['menu_order'] = $post_value['position'];
|
||||
unset( $post_value['position'] );
|
||||
foreach ( $post_value as $key => $value ) {
|
||||
$this->assertEquals( $value, $last_item->$key, "Mismatch for $key property." );
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Test preview method for deleted menu.
|
||||
*
|
||||
* @see WP_Customize_Nav_Menu_Item_Setting::preview()
|
||||
*/
|
||||
function test_preview_deleted() {
|
||||
do_action( 'customize_register', $this->wp_customize );
|
||||
|
||||
$menu_id = wp_create_nav_menu( 'Primary' );
|
||||
$post_id = $this->factory->post->create( array( 'post_title' => 'Hello World' ) );
|
||||
$item_ids = array();
|
||||
for ( $i = 0; $i < 5; $i += 1 ) {
|
||||
$item_id = wp_update_nav_menu_item( $menu_id, 0, array(
|
||||
'menu-item-type' => 'post_type',
|
||||
'menu-item-object' => 'post',
|
||||
'menu-item-object-id' => $post_id,
|
||||
'menu-item-title' => "Item $i",
|
||||
'menu-item-status' => 'publish',
|
||||
'menu-item-position' => $i + 1,
|
||||
) );
|
||||
$item_ids[] = $item_id;
|
||||
}
|
||||
|
||||
$delete_item_id = $item_ids[2];
|
||||
$setting_id = "nav_menu_item[$delete_item_id]";
|
||||
$setting = new WP_Customize_Nav_Menu_Item_Setting( $this->wp_customize, $setting_id );
|
||||
$this->wp_customize->set_post_value( $setting_id, false );
|
||||
|
||||
$current_items = wp_get_nav_menu_items( $menu_id );
|
||||
$this->assertContains( $delete_item_id, wp_list_pluck( $current_items, 'db_id' ) );
|
||||
$setting->preview();
|
||||
$preview_items = wp_get_nav_menu_items( $menu_id );
|
||||
$this->assertNotEquals( count( $current_items ), count( $preview_items ) );
|
||||
$this->assertContains( $delete_item_id, wp_list_pluck( $current_items, 'db_id' ) );
|
||||
}
|
||||
|
||||
/**
|
||||
* Test sanitize method.
|
||||
*
|
||||
* @see WP_Customize_Nav_Menu_Item_Setting::sanitize()
|
||||
*/
|
||||
function test_sanitize() {
|
||||
do_action( 'customize_register', $this->wp_customize );
|
||||
$setting = new WP_Customize_Nav_Menu_Item_Setting( $this->wp_customize, 'nav_menu_item[123]' );
|
||||
|
||||
$this->assertNull( $setting->sanitize( 'not an array' ) );
|
||||
$this->assertNull( $setting->sanitize( 123 ) );
|
||||
|
||||
$unsanitized = array(
|
||||
'object_id' => 'bad',
|
||||
'object' => '<b>hello</b>',
|
||||
'menu_item_parent' => 'asdasd',
|
||||
'position' => -123,
|
||||
'type' => 'custom<b>',
|
||||
'title' => 'Hi<script>alert(1)</script>',
|
||||
'url' => 'javascript:alert(1)',
|
||||
'target' => '" onclick="',
|
||||
'attr_title' => '<b>evil</b>',
|
||||
'description' => '<b>Hello world</b>',
|
||||
'classes' => 'hello " inject="',
|
||||
'xfn' => 'hello " inject="',
|
||||
'status' => 'forbidden',
|
||||
'original_title' => 'Hi<script>alert(1)</script>',
|
||||
'nav_menu_term_id' => 'heilo',
|
||||
);
|
||||
|
||||
$sanitized = $setting->sanitize( $unsanitized );
|
||||
$this->assertEqualSets( array_keys( $unsanitized ), array_keys( $sanitized ) );
|
||||
|
||||
$this->assertEquals( 0, $sanitized['object_id'] );
|
||||
$this->assertEquals( 'bhellob', $sanitized['object'] );
|
||||
$this->assertEquals( 0, $sanitized['menu_item_parent'] );
|
||||
$this->assertEquals( 0, $sanitized['position'] );
|
||||
$this->assertEquals( 'customb', $sanitized['type'] );
|
||||
$this->assertEquals( 'Hi', $sanitized['title'] );
|
||||
$this->assertEquals( '', $sanitized['url'] );
|
||||
$this->assertEquals( 'onclick', $sanitized['target'] );
|
||||
$this->assertEquals( 'evil', $sanitized['attr_title'] );
|
||||
$this->assertEquals( 'Hello world', $sanitized['description'] );
|
||||
$this->assertEquals( 'hello inject', $sanitized['classes'] );
|
||||
$this->assertEquals( 'hello inject', $sanitized['xfn'] );
|
||||
$this->assertEquals( 'publish', $sanitized['status'] );
|
||||
$this->assertEquals( 'Hi', $sanitized['original_title'] );
|
||||
$this->assertEquals( 0, $sanitized['nav_menu_term_id'] );
|
||||
}
|
||||
|
||||
/**
|
||||
* Test protected update() method via the save() method, for updated menu.
|
||||
*
|
||||
* @see WP_Customize_Nav_Menu_Item_Setting::update()
|
||||
*/
|
||||
function test_save_updated() {
|
||||
do_action( 'customize_register', $this->wp_customize );
|
||||
|
||||
$first_post_id = $this->factory->post->create( array( 'post_title' => 'Hello World' ) );
|
||||
$second_post_id = $this->factory->post->create( array( 'post_title' => 'Hola Muno' ) );
|
||||
|
||||
$primary_menu_id = wp_create_nav_menu( 'Primary' );
|
||||
$secondary_menu_id = wp_create_nav_menu( 'Secondary' );
|
||||
$item_title = 'Greetings';
|
||||
$item_id = wp_update_nav_menu_item( $primary_menu_id, 0, array(
|
||||
'menu-item-type' => 'post_type',
|
||||
'menu-item-object' => 'post',
|
||||
'menu-item-object-id' => $first_post_id,
|
||||
'menu-item-title' => $item_title,
|
||||
'menu-item-status' => 'publish',
|
||||
) );
|
||||
$this->assertNotEmpty( wp_get_nav_menu_items( $primary_menu_id, array( 'post_status' => 'publish,draft' ) ) );
|
||||
|
||||
$post_value = array(
|
||||
'type' => 'post_type',
|
||||
'object' => 'post',
|
||||
'object_id' => $second_post_id,
|
||||
'title' => 'Saludos',
|
||||
'status' => 'publish',
|
||||
'nav_menu_term_id' => $secondary_menu_id,
|
||||
);
|
||||
$setting_id = "nav_menu_item[$item_id]";
|
||||
$setting = new WP_Customize_Nav_Menu_Item_Setting( $this->wp_customize, $setting_id );
|
||||
$this->wp_customize->set_post_value( $setting_id, $post_value );
|
||||
unset( $post_value['nav_menu_term_id'] );
|
||||
$setting->save();
|
||||
|
||||
// Make sure the menu item appears in the new menu.
|
||||
$this->assertNotContains( $item_id, wp_list_pluck( wp_get_nav_menu_items( $primary_menu_id ), 'db_id' ) );
|
||||
$menu_items = wp_get_nav_menu_items( $secondary_menu_id );
|
||||
$db_ids = wp_list_pluck( $menu_items, 'db_id' );
|
||||
$this->assertContains( $item_id, $db_ids );
|
||||
$i = array_search( $item_id, $db_ids );
|
||||
$updated_item = $menu_items[ $i ];
|
||||
$post_value['post_status'] = $post_value['status'];
|
||||
unset( $post_value['status'] );
|
||||
foreach ( $post_value as $key => $value ) {
|
||||
$this->assertEquals( $value, $updated_item->$key, "Key $key mismatch" );
|
||||
}
|
||||
|
||||
// Verify the Ajax responses is being amended.
|
||||
$save_response = apply_filters( 'customize_save_response', array() );
|
||||
$this->assertArrayHasKey( 'nav_menu_item_updates', $save_response );
|
||||
$update_result = array_shift( $save_response['nav_menu_item_updates'] );
|
||||
$this->assertArrayHasKey( 'post_id', $update_result );
|
||||
$this->assertArrayHasKey( 'previous_post_id', $update_result );
|
||||
$this->assertArrayHasKey( 'error', $update_result );
|
||||
$this->assertArrayHasKey( 'status', $update_result );
|
||||
|
||||
$this->assertEquals( $item_id, $update_result['post_id'] );
|
||||
$this->assertNull( $update_result['previous_post_id'] );
|
||||
$this->assertNull( $update_result['error'] );
|
||||
$this->assertEquals( 'updated', $update_result['status'] );
|
||||
}
|
||||
|
||||
/**
|
||||
* Test protected update() method via the save() method, for inserted menu.
|
||||
*
|
||||
* @see WP_Customize_Nav_Menu_Item_Setting::update()
|
||||
*/
|
||||
function test_save_inserted() {
|
||||
do_action( 'customize_register', $this->wp_customize );
|
||||
|
||||
$menu_id = wp_create_nav_menu( 'Primary' );
|
||||
$post_id = $this->factory->post->create( array( 'post_title' => 'Hello World' ) );
|
||||
$item_ids = array();
|
||||
for ( $i = 0; $i < 5; $i += 1 ) {
|
||||
$item_id = wp_update_nav_menu_item( $menu_id, 0, array(
|
||||
'menu-item-type' => 'post_type',
|
||||
'menu-item-object' => 'post',
|
||||
'menu-item-object-id' => $post_id,
|
||||
'menu-item-title' => "Item $i",
|
||||
'menu-item-status' => 'publish',
|
||||
'menu-item-position' => $i + 1,
|
||||
) );
|
||||
$item_ids[] = $item_id;
|
||||
}
|
||||
|
||||
$post_value = array(
|
||||
'type' => 'post_type',
|
||||
'object' => 'post',
|
||||
'object_id' => $post_id,
|
||||
'title' => 'Inserted item',
|
||||
'status' => 'publish',
|
||||
'nav_menu_term_id' => $menu_id,
|
||||
'position' => count( $item_ids ) + 1,
|
||||
);
|
||||
|
||||
$new_item_id = -10;
|
||||
$setting_id = "nav_menu_item[$new_item_id]";
|
||||
$setting = new WP_Customize_Nav_Menu_Item_Setting( $this->wp_customize, $setting_id );
|
||||
$this->wp_customize->set_post_value( $setting_id, $post_value );
|
||||
unset( $post_value['nav_menu_term_id'] );
|
||||
|
||||
$current_items = wp_get_nav_menu_items( $menu_id );
|
||||
$setting->save();
|
||||
$preview_items = wp_get_nav_menu_items( $menu_id );
|
||||
$this->assertNotEquals( count( $current_items ), count( $preview_items ) );
|
||||
|
||||
$last_item = array_pop( $preview_items );
|
||||
$this->assertEquals( $setting->post_id, $last_item->db_id );
|
||||
$post_value['post_status'] = $post_value['status'];
|
||||
unset( $post_value['status'] );
|
||||
$post_value['menu_order'] = $post_value['position'];
|
||||
unset( $post_value['position'] );
|
||||
foreach ( $post_value as $key => $value ) {
|
||||
$this->assertEquals( $value, $last_item->$key, "Mismatch for $key property." );
|
||||
}
|
||||
|
||||
// Verify the Ajax responses is being amended.
|
||||
$save_response = apply_filters( 'customize_save_response', array() );
|
||||
$this->assertArrayHasKey( 'nav_menu_item_updates', $save_response );
|
||||
$update_result = array_shift( $save_response['nav_menu_item_updates'] );
|
||||
$this->assertArrayHasKey( 'post_id', $update_result );
|
||||
$this->assertArrayHasKey( 'previous_post_id', $update_result );
|
||||
$this->assertArrayHasKey( 'error', $update_result );
|
||||
$this->assertArrayHasKey( 'status', $update_result );
|
||||
|
||||
$this->assertEquals( $setting->post_id, $update_result['post_id'] );
|
||||
$this->assertEquals( $new_item_id, $update_result['previous_post_id'] );
|
||||
$this->assertNull( $update_result['error'] );
|
||||
$this->assertEquals( 'inserted', $update_result['status'] );
|
||||
}
|
||||
|
||||
/**
|
||||
* Test protected update() method via the save() method, for deleted menu.
|
||||
*
|
||||
* @see WP_Customize_Nav_Menu_Item_Setting::update()
|
||||
*/
|
||||
function test_save_deleted() {
|
||||
do_action( 'customize_register', $this->wp_customize );
|
||||
|
||||
$menu_id = wp_create_nav_menu( 'Primary' );
|
||||
$post_id = $this->factory->post->create( array( 'post_title' => 'Hello World' ) );
|
||||
$item_ids = array();
|
||||
for ( $i = 0; $i < 5; $i += 1 ) {
|
||||
$item_id = wp_update_nav_menu_item( $menu_id, 0, array(
|
||||
'menu-item-type' => 'post_type',
|
||||
'menu-item-object' => 'post',
|
||||
'menu-item-object-id' => $post_id,
|
||||
'menu-item-title' => "Item $i",
|
||||
'menu-item-status' => 'publish',
|
||||
'menu-item-position' => $i + 1,
|
||||
) );
|
||||
$item_ids[] = $item_id;
|
||||
}
|
||||
|
||||
$delete_item_id = $item_ids[2];
|
||||
$setting_id = "nav_menu_item[$delete_item_id]";
|
||||
$setting = new WP_Customize_Nav_Menu_Item_Setting( $this->wp_customize, $setting_id );
|
||||
$this->wp_customize->set_post_value( $setting_id, false );
|
||||
|
||||
$current_items = wp_get_nav_menu_items( $menu_id );
|
||||
$this->assertContains( $delete_item_id, wp_list_pluck( $current_items, 'db_id' ) );
|
||||
$setting->save();
|
||||
$preview_items = wp_get_nav_menu_items( $menu_id );
|
||||
$this->assertNotEquals( count( $current_items ), count( $preview_items ) );
|
||||
$this->assertContains( $delete_item_id, wp_list_pluck( $current_items, 'db_id' ) );
|
||||
|
||||
// Verify the Ajax responses is being amended.
|
||||
$save_response = apply_filters( 'customize_save_response', array() );
|
||||
$this->assertArrayHasKey( 'nav_menu_item_updates', $save_response );
|
||||
$update_result = array_shift( $save_response['nav_menu_item_updates'] );
|
||||
$this->assertArrayHasKey( 'post_id', $update_result );
|
||||
$this->assertArrayHasKey( 'previous_post_id', $update_result );
|
||||
$this->assertArrayHasKey( 'error', $update_result );
|
||||
$this->assertArrayHasKey( 'status', $update_result );
|
||||
|
||||
$this->assertEquals( $delete_item_id, $update_result['post_id'] );
|
||||
$this->assertNull( $update_result['previous_post_id'] );
|
||||
$this->assertNull( $update_result['error'] );
|
||||
$this->assertEquals( 'deleted', $update_result['status'] );
|
||||
}
|
||||
|
||||
}
|
||||
461
tests/phpunit/tests/customize/nav-menu-setting.php
Normal file
461
tests/phpunit/tests/customize/nav-menu-setting.php
Normal file
@@ -0,0 +1,461 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* Tests WP_Customize_Nav_Menu_Setting.
|
||||
*
|
||||
* @group customize
|
||||
*/
|
||||
class Test_WP_Customize_Nav_Menu_Setting extends WP_UnitTestCase {
|
||||
|
||||
/**
|
||||
* Instance of WP_Customize_Manager which is reset for each test.
|
||||
*
|
||||
* @var WP_Customize_Manager
|
||||
*/
|
||||
public $wp_customize;
|
||||
|
||||
/**
|
||||
* Set up a test case.
|
||||
*
|
||||
* @see WP_UnitTestCase::setup()
|
||||
*/
|
||||
function setUp() {
|
||||
parent::setUp();
|
||||
require_once ABSPATH . WPINC . '/class-wp-customize-manager.php';
|
||||
wp_set_current_user( $this->factory->user->create( array( 'role' => 'administrator' ) ) );
|
||||
|
||||
global $wp_customize;
|
||||
$this->wp_customize = new WP_Customize_Manager();
|
||||
$wp_customize = $this->wp_customize;
|
||||
}
|
||||
|
||||
/**
|
||||
* Delete the $wp_customize global when cleaning up scope.
|
||||
*/
|
||||
function clean_up_global_scope() {
|
||||
global $wp_customize;
|
||||
$wp_customize = null;
|
||||
parent::clean_up_global_scope();
|
||||
}
|
||||
|
||||
/**
|
||||
* Helper for getting the nav_menu_options option.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
function get_nav_menu_items_option() {
|
||||
return get_option( 'nav_menu_options', array( 'auto_add' => array() ) );
|
||||
}
|
||||
|
||||
/**
|
||||
* Test constants and statics.
|
||||
*/
|
||||
function test_constants() {
|
||||
do_action( 'customize_register', $this->wp_customize );
|
||||
$this->assertTrue( taxonomy_exists( WP_Customize_Nav_Menu_Setting::TAXONOMY ) );
|
||||
}
|
||||
|
||||
/**
|
||||
* Test constructor.
|
||||
*
|
||||
* @see WP_Customize_Nav_Menu_Setting::__construct()
|
||||
*/
|
||||
function test_construct() {
|
||||
do_action( 'customize_register', $this->wp_customize );
|
||||
|
||||
$setting = new WP_Customize_Nav_Menu_Setting( $this->wp_customize, 'nav_menu[123]' );
|
||||
$this->assertEquals( 'nav_menu', $setting->type );
|
||||
$this->assertEquals( 'postMessage', $setting->transport );
|
||||
$this->assertEquals( 123, $setting->term_id );
|
||||
$this->assertNull( $setting->previous_term_id );
|
||||
$this->assertNull( $setting->update_status );
|
||||
$this->assertNull( $setting->update_error );
|
||||
$this->assertInternalType( 'array', $setting->default );
|
||||
foreach ( array( 'name', 'description', 'parent' ) as $key ) {
|
||||
$this->assertArrayHasKey( $key, $setting->default );
|
||||
}
|
||||
$this->assertEquals( '', $setting->default['name'] );
|
||||
$this->assertEquals( '', $setting->default['description'] );
|
||||
$this->assertEquals( 0, $setting->default['parent'] );
|
||||
|
||||
$exception = null;
|
||||
try {
|
||||
$bad_setting = new WP_Customize_Nav_Menu_Setting( $this->wp_customize, 'foo_bar_baz' );
|
||||
unset( $bad_setting );
|
||||
} catch ( Exception $e ) {
|
||||
$exception = $e;
|
||||
}
|
||||
$this->assertInstanceOf( 'Exception', $exception );
|
||||
}
|
||||
|
||||
/**
|
||||
* Test empty constructor.
|
||||
*/
|
||||
function test_construct_empty_menus() {
|
||||
do_action( 'customize_register', $this->wp_customize );
|
||||
$_wp_customize = $this->wp_customize;
|
||||
unset($_wp_customize->nav_menus);
|
||||
|
||||
$exception = null;
|
||||
try {
|
||||
$bad_setting = new WP_Customize_Nav_Menu_Setting( $_wp_customize, 'nav_menu_item[123]' );
|
||||
unset( $bad_setting );
|
||||
} catch ( Exception $e ) {
|
||||
$exception = $e;
|
||||
}
|
||||
$this->assertInstanceOf( 'Exception', $exception );
|
||||
}
|
||||
|
||||
/**
|
||||
* Test constructor for placeholder (draft) menu.
|
||||
*
|
||||
* @see WP_Customize_Nav_Menu_Setting::__construct()
|
||||
*/
|
||||
function test_construct_placeholder() {
|
||||
do_action( 'customize_register', $this->wp_customize );
|
||||
$default = array(
|
||||
'name' => 'Lorem',
|
||||
'description' => 'ipsum',
|
||||
'parent' => 123,
|
||||
);
|
||||
$setting = new WP_Customize_Nav_Menu_Setting( $this->wp_customize, 'nav_menu[-5]', compact( 'default' ) );
|
||||
$this->assertEquals( -5, $setting->term_id );
|
||||
$this->assertEquals( $default, $setting->default );
|
||||
}
|
||||
|
||||
/**
|
||||
* Test value method.
|
||||
*
|
||||
* @see WP_Customize_Nav_Menu_Setting::value()
|
||||
*/
|
||||
function test_value() {
|
||||
do_action( 'customize_register', $this->wp_customize );
|
||||
|
||||
$menu_name = 'Test 123';
|
||||
$parent_menu_id = wp_create_nav_menu( "Parent $menu_name" );
|
||||
$description = 'Hello my world.';
|
||||
$menu_id = wp_update_nav_menu_object( 0, array(
|
||||
'menu-name' => $menu_name,
|
||||
'parent' => $parent_menu_id,
|
||||
'description' => $description,
|
||||
) );
|
||||
|
||||
$setting_id = "nav_menu[$menu_id]";
|
||||
$setting = new WP_Customize_Nav_Menu_Setting( $this->wp_customize, $setting_id );
|
||||
|
||||
$value = $setting->value();
|
||||
$this->assertInternalType( 'array', $value );
|
||||
foreach ( array( 'name', 'description', 'parent' ) as $key ) {
|
||||
$this->assertArrayHasKey( $key, $value );
|
||||
}
|
||||
$this->assertEquals( $menu_name, $value['name'] );
|
||||
$this->assertEquals( $description, $value['description'] );
|
||||
$this->assertEquals( $parent_menu_id, $value['parent'] );
|
||||
|
||||
$new_menu_name = 'Foo';
|
||||
wp_update_nav_menu_object( $menu_id, array( 'menu-name' => $new_menu_name ) );
|
||||
$updated_value = $setting->value();
|
||||
$this->assertEquals( $new_menu_name, $updated_value['name'] );
|
||||
}
|
||||
|
||||
/**
|
||||
* Test preview method for updated menu.
|
||||
*
|
||||
* @see WP_Customize_Nav_Menu_Setting::preview()
|
||||
*/
|
||||
function test_preview_updated() {
|
||||
do_action( 'customize_register', $this->wp_customize );
|
||||
|
||||
$menu_id = wp_update_nav_menu_object( 0, array(
|
||||
'menu-name' => 'Name 1',
|
||||
'description' => 'Description 1',
|
||||
'parent' => 0,
|
||||
) );
|
||||
$setting_id = "nav_menu[$menu_id]";
|
||||
$setting = new WP_Customize_Nav_Menu_Setting( $this->wp_customize, $setting_id );
|
||||
|
||||
$nav_menu_options = $this->get_nav_menu_items_option();
|
||||
$this->assertNotContains( $menu_id, $nav_menu_options['auto_add'] );
|
||||
|
||||
$post_value = array(
|
||||
'name' => 'Name 2',
|
||||
'description' => 'Description 2',
|
||||
'parent' => 1,
|
||||
'auto_add' => true,
|
||||
);
|
||||
$this->wp_customize->set_post_value( $setting_id, $post_value );
|
||||
|
||||
$value = $setting->value();
|
||||
$this->assertEquals( 'Name 1', $value['name'] );
|
||||
$this->assertEquals( 'Description 1', $value['description'] );
|
||||
$this->assertEquals( 0, $value['parent'] );
|
||||
|
||||
$term = (array) wp_get_nav_menu_object( $menu_id );
|
||||
|
||||
$this->assertEqualSets(
|
||||
wp_array_slice_assoc( $value, array( 'name', 'description', 'parent' ) ),
|
||||
wp_array_slice_assoc( $term, array( 'name', 'description', 'parent' ) )
|
||||
);
|
||||
|
||||
$setting->preview();
|
||||
$value = $setting->value();
|
||||
$this->assertEquals( 'Name 2', $value['name'] );
|
||||
$this->assertEquals( 'Description 2', $value['description'] );
|
||||
$this->assertEquals( 1, $value['parent'] );
|
||||
$term = (array) wp_get_nav_menu_object( $menu_id );
|
||||
$this->assertEqualSets( $value, wp_array_slice_assoc( $term, array_keys( $value ) ) );
|
||||
|
||||
$menu_object = wp_get_nav_menu_object( $menu_id );
|
||||
$this->assertEquals( (object) $term, $menu_object );
|
||||
$this->assertEquals( $post_value['name'], $menu_object->name );
|
||||
|
||||
$nav_menu_options = get_option( 'nav_menu_options', array( 'auto_add' => array() ) );
|
||||
$this->assertContains( $menu_id, $nav_menu_options['auto_add'] );
|
||||
}
|
||||
|
||||
/**
|
||||
* Test preview method for inserted menu.
|
||||
*
|
||||
* @see WP_Customize_Nav_Menu_Setting::preview()
|
||||
*/
|
||||
function test_preview_inserted() {
|
||||
do_action( 'customize_register', $this->wp_customize );
|
||||
|
||||
$menu_id = -123;
|
||||
$post_value = array(
|
||||
'name' => 'New Menu Name 1',
|
||||
'description' => 'New Menu Description 1',
|
||||
'parent' => 0,
|
||||
'auto_add' => false,
|
||||
);
|
||||
$setting_id = "nav_menu[$menu_id]";
|
||||
$setting = new WP_Customize_Nav_Menu_Setting( $this->wp_customize, $setting_id );
|
||||
|
||||
$this->wp_customize->set_post_value( $setting->id, $post_value );
|
||||
$setting->preview();
|
||||
$value = $setting->value();
|
||||
$this->assertEquals( $post_value, $value );
|
||||
|
||||
$term = (array) wp_get_nav_menu_object( $menu_id );
|
||||
$this->assertNotEmpty( $term );
|
||||
$this->assertNotInstanceOf( 'WP_Error', $term );
|
||||
$this->assertEqualSets( $post_value, wp_array_slice_assoc( $term, array_keys( $value ) ) );
|
||||
$this->assertEquals( $menu_id, $term['term_id'] );
|
||||
$this->assertEquals( $menu_id, $term['term_taxonomy_id'] );
|
||||
|
||||
$menu_object = wp_get_nav_menu_object( $menu_id );
|
||||
$this->assertEquals( (object) $term, $menu_object );
|
||||
$this->assertEquals( $post_value['name'], $menu_object->name );
|
||||
|
||||
$nav_menu_options = $this->get_nav_menu_items_option();
|
||||
$this->assertNotContains( $menu_id, $nav_menu_options['auto_add'] );
|
||||
}
|
||||
|
||||
/**
|
||||
* Test preview method for deleted menu.
|
||||
*
|
||||
* @see WP_Customize_Nav_Menu_Setting::preview()
|
||||
*/
|
||||
function test_preview_deleted() {
|
||||
do_action( 'customize_register', $this->wp_customize );
|
||||
|
||||
$menu_id = wp_update_nav_menu_object( 0, array(
|
||||
'menu-name' => 'Name 1',
|
||||
'description' => 'Description 1',
|
||||
'parent' => 0,
|
||||
) );
|
||||
$setting_id = "nav_menu[$menu_id]";
|
||||
$setting = new WP_Customize_Nav_Menu_Setting( $this->wp_customize, $setting_id );
|
||||
$nav_menu_options = $this->get_nav_menu_items_option();
|
||||
$nav_menu_options['auto_add'][] = $menu_id;
|
||||
update_option( 'nav_menu_options', $nav_menu_options );
|
||||
|
||||
$nav_menu_options = $this->get_nav_menu_items_option();
|
||||
$this->assertContains( $menu_id, $nav_menu_options['auto_add'] );
|
||||
|
||||
$this->wp_customize->set_post_value( $setting_id, false );
|
||||
|
||||
$this->assertInternalType( 'array', $setting->value() );
|
||||
$this->assertInternalType( 'object', wp_get_nav_menu_object( $menu_id ) );
|
||||
$setting->preview();
|
||||
$this->assertFalse( $setting->value() );
|
||||
$this->assertFalse( wp_get_nav_menu_object( $menu_id ) );
|
||||
|
||||
$nav_menu_options = $this->get_nav_menu_items_option();
|
||||
$this->assertNotContains( $menu_id, $nav_menu_options['auto_add'] );
|
||||
}
|
||||
|
||||
/**
|
||||
* Test sanitize method.
|
||||
*
|
||||
* @see WP_Customize_Nav_Menu_Setting::sanitize()
|
||||
*/
|
||||
function test_sanitize() {
|
||||
do_action( 'customize_register', $this->wp_customize );
|
||||
$setting = new WP_Customize_Nav_Menu_Setting( $this->wp_customize, 'nav_menu[123]' );
|
||||
|
||||
$this->assertNull( $setting->sanitize( 'not an array' ) );
|
||||
$this->assertNull( $setting->sanitize( 123 ) );
|
||||
|
||||
$value = array(
|
||||
'name' => ' Hello <b>world</b> ',
|
||||
'description' => "New\nline",
|
||||
'parent' => -12,
|
||||
'auto_add' => true,
|
||||
'extra' => 'ignored',
|
||||
);
|
||||
$sanitized = $setting->sanitize( $value );
|
||||
$this->assertEquals( 'Hello <b>world</b>', $sanitized['name'] );
|
||||
$this->assertEquals( 'New line', $sanitized['description'] );
|
||||
$this->assertEquals( 0, $sanitized['parent'] );
|
||||
$this->assertEquals( true, $sanitized['auto_add'] );
|
||||
$this->assertEqualSets( array( 'name', 'description', 'parent', 'auto_add' ), array_keys( $sanitized ) );
|
||||
}
|
||||
|
||||
/**
|
||||
* Test protected update() method via the save() method, for updated menu.
|
||||
*
|
||||
* @see WP_Customize_Nav_Menu_Setting::update()
|
||||
*/
|
||||
function test_save_updated() {
|
||||
do_action( 'customize_register', $this->wp_customize );
|
||||
|
||||
$menu_id = wp_update_nav_menu_object( 0, array(
|
||||
'menu-name' => 'Name 1',
|
||||
'description' => 'Description 1',
|
||||
'parent' => 0,
|
||||
) );
|
||||
$nav_menu_options = $this->get_nav_menu_items_option();
|
||||
$nav_menu_options['auto_add'][] = $menu_id;
|
||||
update_option( 'nav_menu_options', $nav_menu_options );
|
||||
|
||||
$setting_id = "nav_menu[$menu_id]";
|
||||
$setting = new WP_Customize_Nav_Menu_Setting( $this->wp_customize, $setting_id );
|
||||
|
||||
$auto_add = false;
|
||||
$new_value = array(
|
||||
'name' => 'Name 2',
|
||||
'description' => 'Description 2',
|
||||
'parent' => 1,
|
||||
'auto_add' => $auto_add,
|
||||
);
|
||||
|
||||
$this->wp_customize->set_post_value( $setting_id, $new_value );
|
||||
$setting->save();
|
||||
|
||||
$menu_object = wp_get_nav_menu_object( $menu_id );
|
||||
foreach ( array( 'name', 'description', 'parent' ) as $key ) {
|
||||
$this->assertEquals( $new_value[ $key ], $menu_object->$key );
|
||||
}
|
||||
$this->assertEqualSets(
|
||||
wp_array_slice_assoc( $new_value, array( 'name', 'description', 'parent' ) ),
|
||||
wp_array_slice_assoc( (array) $menu_object, array( 'name', 'description', 'parent' ) )
|
||||
);
|
||||
$this->assertEquals( $new_value, $setting->value() );
|
||||
|
||||
$save_response = apply_filters( 'customize_save_response', array() );
|
||||
$this->assertArrayHasKey( 'nav_menu_updates', $save_response );
|
||||
$update_result = array_shift( $save_response['nav_menu_updates'] );
|
||||
$this->assertArrayHasKey( 'term_id', $update_result );
|
||||
$this->assertArrayHasKey( 'previous_term_id', $update_result );
|
||||
$this->assertArrayHasKey( 'error', $update_result );
|
||||
$this->assertArrayHasKey( 'status', $update_result );
|
||||
|
||||
$this->assertEquals( $menu_id, $update_result['term_id'] );
|
||||
$this->assertNull( $update_result['previous_term_id'] );
|
||||
$this->assertNull( $update_result['error'] );
|
||||
$this->assertEquals( 'updated', $update_result['status'] );
|
||||
|
||||
$nav_menu_options = $this->get_nav_menu_items_option();
|
||||
$this->assertNotContains( $menu_id, $nav_menu_options['auto_add'] );
|
||||
}
|
||||
|
||||
/**
|
||||
* Test protected update() method via the save() method, for inserted menu.
|
||||
*
|
||||
* @see WP_Customize_Nav_Menu_Setting::update()
|
||||
*/
|
||||
function test_save_inserted() {
|
||||
do_action( 'customize_register', $this->wp_customize );
|
||||
|
||||
$menu_id = -123;
|
||||
$post_value = array(
|
||||
'name' => 'New Menu Name 1',
|
||||
'description' => 'New Menu Description 1',
|
||||
'parent' => 0,
|
||||
'auto_add' => true,
|
||||
);
|
||||
$setting_id = "nav_menu[$menu_id]";
|
||||
$setting = new WP_Customize_Nav_Menu_Setting( $this->wp_customize, $setting_id );
|
||||
|
||||
$this->wp_customize->set_post_value( $setting->id, $post_value );
|
||||
|
||||
$this->assertNull( $setting->previous_term_id );
|
||||
$this->assertLessThan( 0, $setting->term_id );
|
||||
$setting->save();
|
||||
$this->assertEquals( $menu_id, $setting->previous_term_id );
|
||||
$this->assertGreaterThan( 0, $setting->term_id );
|
||||
|
||||
$nav_menu_options = $this->get_nav_menu_items_option();
|
||||
$this->assertContains( $setting->term_id, $nav_menu_options['auto_add'] );
|
||||
|
||||
$menu = wp_get_nav_menu_object( $setting->term_id );
|
||||
unset( $post_value['auto_add'] );
|
||||
$this->assertEqualSets( $post_value, wp_array_slice_assoc( (array) $menu, array_keys( $post_value ) ) );
|
||||
|
||||
$save_response = apply_filters( 'customize_save_response', array() );
|
||||
$this->assertArrayHasKey( 'nav_menu_updates', $save_response );
|
||||
$update_result = array_shift( $save_response['nav_menu_updates'] );
|
||||
$this->assertArrayHasKey( 'term_id', $update_result );
|
||||
$this->assertArrayHasKey( 'previous_term_id', $update_result );
|
||||
$this->assertArrayHasKey( 'error', $update_result );
|
||||
$this->assertArrayHasKey( 'status', $update_result );
|
||||
|
||||
$this->assertEquals( $menu->term_id, $update_result['term_id'] );
|
||||
$this->assertEquals( $menu_id, $update_result['previous_term_id'] );
|
||||
$this->assertNull( $update_result['error'] );
|
||||
$this->assertEquals( 'inserted', $update_result['status'] );
|
||||
}
|
||||
|
||||
/**
|
||||
* Test protected update() method via the save() method, for deleted menu.
|
||||
*
|
||||
* @see WP_Customize_Nav_Menu_Setting::update()
|
||||
*/
|
||||
function test_save_deleted() {
|
||||
do_action( 'customize_register', $this->wp_customize );
|
||||
|
||||
$menu_name = 'Lorem Ipsum';
|
||||
$menu_id = wp_create_nav_menu( $menu_name );
|
||||
$setting_id = "nav_menu[$menu_id]";
|
||||
$setting = new WP_Customize_Nav_Menu_Setting( $this->wp_customize, $setting_id );
|
||||
$nav_menu_options = $this->get_nav_menu_items_option();
|
||||
$nav_menu_options['auto_add'][] = $menu_id;
|
||||
update_option( 'nav_menu_options', $nav_menu_options );
|
||||
|
||||
$menu = wp_get_nav_menu_object( $menu_id );
|
||||
$this->assertEquals( $menu_name, $menu->name );
|
||||
|
||||
$this->wp_customize->set_post_value( $setting_id, false );
|
||||
$setting->save();
|
||||
|
||||
$this->assertFalse( wp_get_nav_menu_object( $menu_id ) );
|
||||
|
||||
$save_response = apply_filters( 'customize_save_response', array() );
|
||||
$this->assertArrayHasKey( 'nav_menu_updates', $save_response );
|
||||
$update_result = array_shift( $save_response['nav_menu_updates'] );
|
||||
$this->assertArrayHasKey( 'term_id', $update_result );
|
||||
$this->assertArrayHasKey( 'previous_term_id', $update_result );
|
||||
$this->assertArrayHasKey( 'error', $update_result );
|
||||
$this->assertArrayHasKey( 'status', $update_result );
|
||||
|
||||
$this->assertEquals( $menu_id, $update_result['term_id'] );
|
||||
$this->assertNull( $update_result['previous_term_id'] );
|
||||
$this->assertNull( $update_result['error'] );
|
||||
$this->assertEquals( 'deleted', $update_result['status'] );
|
||||
|
||||
$nav_menu_options = $this->get_nav_menu_items_option();
|
||||
$this->assertNotContains( $menu_id, $nav_menu_options['auto_add'] );
|
||||
}
|
||||
|
||||
}
|
||||
456
tests/phpunit/tests/customize/nav-menus.php
Normal file
456
tests/phpunit/tests/customize/nav-menus.php
Normal file
@@ -0,0 +1,456 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* Tests WP_Customize_Nav_Menus.
|
||||
*
|
||||
* @group customize
|
||||
*/
|
||||
class Test_WP_Customize_Nav_Menus extends WP_UnitTestCase {
|
||||
|
||||
/**
|
||||
* Instance of WP_Customize_Manager which is reset for each test.
|
||||
*
|
||||
* @var WP_Customize_Manager
|
||||
*/
|
||||
public $wp_customize;
|
||||
|
||||
/**
|
||||
* Set up a test case.
|
||||
*
|
||||
* @see WP_UnitTestCase::setup()
|
||||
*/
|
||||
function setUp() {
|
||||
parent::setUp();
|
||||
require_once ABSPATH . WPINC . '/class-wp-customize-manager.php';
|
||||
wp_set_current_user( $this->factory->user->create( array( 'role' => 'administrator' ) ) );
|
||||
global $wp_customize;
|
||||
$this->wp_customize = new WP_Customize_Manager();
|
||||
$wp_customize = $this->wp_customize;
|
||||
}
|
||||
|
||||
/**
|
||||
* Delete the $wp_customize global when cleaning up scope.
|
||||
*/
|
||||
function clean_up_global_scope() {
|
||||
global $wp_customize;
|
||||
$wp_customize = null;
|
||||
parent::clean_up_global_scope();
|
||||
}
|
||||
|
||||
/**
|
||||
* Test constructor.
|
||||
*
|
||||
* @see WP_Customize_Nav_Menus::__construct()
|
||||
*/
|
||||
function test_construct() {
|
||||
do_action( 'customize_register', $this->wp_customize );
|
||||
$menus = new WP_Customize_Nav_Menus( $this->wp_customize );
|
||||
$this->assertInstanceOf( 'WP_Customize_Manager', $menus->manager );
|
||||
}
|
||||
|
||||
/**
|
||||
* Test the test_load_available_items_ajax method.
|
||||
*
|
||||
* @see WP_Customize_Nav_Menus::load_available_items_ajax()
|
||||
*/
|
||||
function test_load_available_items_ajax() {
|
||||
|
||||
$this->markTestIncomplete( 'This test has not been implemented.' );
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Test the search_available_items_ajax method.
|
||||
*
|
||||
* @see WP_Customize_Nav_Menus::search_available_items_ajax()
|
||||
*/
|
||||
function test_search_available_items_ajax() {
|
||||
|
||||
$this->markTestIncomplete( 'This test has not been implemented.' );
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Test the search_available_items_query method.
|
||||
*
|
||||
* @see WP_Customize_Nav_Menus::search_available_items_query()
|
||||
*/
|
||||
function test_search_available_items_query() {
|
||||
$menus = new WP_Customize_Nav_Menus( $this->wp_customize );
|
||||
|
||||
// Create posts
|
||||
$post_ids = array();
|
||||
$post_ids[] = $this->factory->post->create( array( 'post_title' => 'Search & Test' ) );
|
||||
$post_ids[] = $this->factory->post->create( array( 'post_title' => 'Some Other Title' ) );
|
||||
|
||||
// Create terms
|
||||
$term_ids = array();
|
||||
$term_ids[] = $this->factory->category->create( array( 'name' => 'Dogs Are Cool' ) );
|
||||
$term_ids[] = $this->factory->category->create( array( 'name' => 'Cats Drool' ) );
|
||||
|
||||
// Test empty results
|
||||
$expected = array();
|
||||
$results = $menus->search_available_items_query( array( 'pagenum' => 1, 's' => 'This Does NOT Exist' ) );
|
||||
$this->assertEquals( $expected, $results );
|
||||
|
||||
// Test posts
|
||||
foreach ( $post_ids as $post_id ) {
|
||||
$expected = array(
|
||||
'id' => 'post-' . $post_id,
|
||||
'type' => 'post_type',
|
||||
'type_label' => get_post_type_object( 'post' )->labels->singular_name,
|
||||
'object' => 'post',
|
||||
'object_id' => intval( $post_id ),
|
||||
'title' => html_entity_decode( get_the_title( $post_id ) ),
|
||||
);
|
||||
wp_set_object_terms( $post_id, $term_ids, 'category' );
|
||||
$search = $post_id === $post_ids[0] ? 'test & search' : 'other title';
|
||||
$s = sanitize_text_field( wp_unslash( $search ) );
|
||||
$results = $menus->search_available_items_query( array( 'pagenum' => 1, 's' => $s ) );
|
||||
$this->assertEquals( $expected, $results[0] );
|
||||
}
|
||||
|
||||
// Test terms
|
||||
foreach ( $term_ids as $term_id ) {
|
||||
$term = get_term_by( 'id', $term_id, 'category' );
|
||||
$expected = array(
|
||||
'id' => 'term-' . $term_id,
|
||||
'type' => 'taxonomy',
|
||||
'type_label' => get_taxonomy( 'category' )->labels->singular_name,
|
||||
'object' => 'category',
|
||||
'object_id' => intval( $term_id ),
|
||||
'title' => $term->name,
|
||||
);
|
||||
$s = sanitize_text_field( wp_unslash( $term->name ) );
|
||||
$results = $menus->search_available_items_query( array( 'pagenum' => 1, 's' => $s ) );
|
||||
$this->assertEquals( $expected, $results[0] );
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Test the enqueue method.
|
||||
*
|
||||
* @see WP_Customize_Nav_Menus::enqueue_scripts()
|
||||
*/
|
||||
function test_enqueue_scripts() {
|
||||
do_action( 'customize_register', $this->wp_customize );
|
||||
$menus = new WP_Customize_Nav_Menus( $this->wp_customize );
|
||||
$menus->enqueue_scripts();
|
||||
$this->assertTrue( wp_script_is( 'customize-nav-menus' ) );
|
||||
}
|
||||
|
||||
/**
|
||||
* Test the filter_dynamic_setting_args method.
|
||||
*
|
||||
* @see WP_Customize_Nav_Menus::filter_dynamic_setting_args()
|
||||
*/
|
||||
function test_filter_dynamic_setting_args() {
|
||||
$menus = new WP_Customize_Nav_Menus( $this->wp_customize );
|
||||
|
||||
$expected = array( 'type' => 'nav_menu_item' );
|
||||
$results = $menus->filter_dynamic_setting_args( $this->wp_customize, 'nav_menu_item[123]' );
|
||||
$this->assertEquals( $expected, $results );
|
||||
|
||||
$expected = array( 'type' => 'nav_menu' );
|
||||
$results = $menus->filter_dynamic_setting_args( $this->wp_customize, 'nav_menu[123]' );
|
||||
$this->assertEquals( $expected, $results );
|
||||
}
|
||||
|
||||
/**
|
||||
* Test the filter_dynamic_setting_class method.
|
||||
*
|
||||
* @see WP_Customize_Nav_Menus::filter_dynamic_setting_class()
|
||||
*/
|
||||
function test_filter_dynamic_setting_class() {
|
||||
do_action( 'customize_register', $this->wp_customize );
|
||||
$menus = new WP_Customize_Nav_Menus( $this->wp_customize );
|
||||
|
||||
$expected = 'WP_Customize_Nav_Menu_Item_Setting';
|
||||
$results = $menus->filter_dynamic_setting_class( 'WP_Customize_Setting', 'nav_menu_item[123]', array( 'type' => 'nav_menu_item' ) );
|
||||
$this->assertEquals( $expected, $results );
|
||||
|
||||
$expected = 'WP_Customize_Nav_Menu_Setting';
|
||||
$results = $menus->filter_dynamic_setting_class( 'WP_Customize_Setting', 'nav_menu[123]', array( 'type' => 'nav_menu' ) );
|
||||
$this->assertEquals( $expected, $results );
|
||||
}
|
||||
|
||||
/**
|
||||
* Test the customize_register method.
|
||||
*
|
||||
* @see WP_Customize_Nav_Menus::customize_register()
|
||||
*/
|
||||
function test_customize_register() {
|
||||
do_action( 'customize_register', $this->wp_customize );
|
||||
$menu_id = wp_create_nav_menu( 'Primary' );
|
||||
$post_id = $this->factory->post->create( array( 'post_title' => 'Hello World' ) );
|
||||
$item_id = wp_update_nav_menu_item( $menu_id, 0, array(
|
||||
'menu-item-type' => 'post_type',
|
||||
'menu-item-object' => 'post',
|
||||
'menu-item-object-id' => $post_id,
|
||||
'menu-item-title' => 'Hello World',
|
||||
'menu-item-status' => 'publish',
|
||||
) );
|
||||
$setting = new WP_Customize_Nav_Menu_Item_Setting( $this->wp_customize, "nav_menu_item[$item_id]" );
|
||||
do_action( 'customize_register', $this->wp_customize );
|
||||
$this->assertEquals( 'Primary', $this->wp_customize->get_section( "nav_menu[$menu_id]" )->title );
|
||||
$this->assertEquals( 'Hello World', $this->wp_customize->get_control( "nav_menu_item[$item_id]" )->label );
|
||||
}
|
||||
|
||||
/**
|
||||
* Test the intval_base10 method.
|
||||
*
|
||||
* @see WP_Customize_Nav_Menus::intval_base10()
|
||||
*/
|
||||
function test_intval_base10() {
|
||||
|
||||
$menus = new WP_Customize_Nav_Menus( $this->wp_customize );
|
||||
|
||||
$this->assertEquals( 2, $menus->intval_base10( 2 ) );
|
||||
$this->assertEquals( 4, $menus->intval_base10( 4.1 ) );
|
||||
$this->assertEquals( 4, $menus->intval_base10( '4' ) );
|
||||
$this->assertEquals( 4, $menus->intval_base10( '04' ) );
|
||||
$this->assertEquals( 42, $menus->intval_base10( +42 ) );
|
||||
$this->assertEquals( -42, $menus->intval_base10( -42 ) );
|
||||
$this->assertEquals( 26, $menus->intval_base10( 0x1A ) );
|
||||
$this->assertEquals( 0, $menus->intval_base10( array() ) );
|
||||
}
|
||||
|
||||
/**
|
||||
* Test the available_item_types method.
|
||||
*
|
||||
* @see WP_Customize_Nav_Menus::available_item_types()
|
||||
*/
|
||||
function test_available_item_types() {
|
||||
|
||||
$menus = new WP_Customize_Nav_Menus( $this->wp_customize );
|
||||
$expected = array(
|
||||
'postTypes' => array(
|
||||
'post' => array( 'label' => 'Post' ),
|
||||
'page' => array( 'label' => 'Page' ),
|
||||
),
|
||||
'taxonomies' => array(
|
||||
'category' => array( 'label' => 'Category' ),
|
||||
'post_tag' => array( 'label' => 'Tag' ),
|
||||
),
|
||||
);
|
||||
if ( current_theme_supports( 'post-formats' ) ) {
|
||||
$expected['taxonomies']['post_format'] = array( 'label' => 'Format' );
|
||||
}
|
||||
$this->assertEquals( $expected, $menus->available_item_types() );
|
||||
|
||||
register_taxonomy( 'wptests_tax', array( 'post' ), array( 'labels' => array( 'name' => 'Foo' ) ) );
|
||||
$expected = array(
|
||||
'postTypes' => array(
|
||||
'post' => array( 'label' => 'Post' ),
|
||||
'page' => array( 'label' => 'Page' ),
|
||||
),
|
||||
'taxonomies' => array(
|
||||
'category' => array( 'label' => 'Category' ),
|
||||
'post_tag' => array( 'label' => 'Tag' ),
|
||||
'wptests_tax' => array( 'label' => 'Foo' ),
|
||||
),
|
||||
);
|
||||
if ( current_theme_supports( 'post-formats' ) ) {
|
||||
$wptests_tax = array_pop( $expected['taxonomies'] );
|
||||
$expected['taxonomies']['post_format'] = array( 'label' => 'Format' );
|
||||
$expected['taxonomies']['wptests_tax'] = $wptests_tax;
|
||||
}
|
||||
$this->assertEquals( $expected, $menus->available_item_types() );
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Test the print_templates method.
|
||||
*
|
||||
* @see WP_Customize_Nav_Menus::print_templates()
|
||||
*/
|
||||
function test_print_templates() {
|
||||
do_action( 'customize_register', $this->wp_customize );
|
||||
$menus = new WP_Customize_Nav_Menus( $this->wp_customize );
|
||||
|
||||
ob_start();
|
||||
$menus->print_templates();
|
||||
$template = ob_get_clean();
|
||||
|
||||
$expected = sprintf(
|
||||
'<button type="button" class="menus-move-up">%1$s</button><button type="button" class="menus-move-down">%2$s</button><button type="button" class="menus-move-left">%3$s</button><button type="button" class="menus-move-right">%4$s</button>',
|
||||
esc_html( 'Move up' ),
|
||||
esc_html( 'Move down' ),
|
||||
esc_html( 'Move one level up' ),
|
||||
esc_html( 'Move one level down' )
|
||||
);
|
||||
|
||||
$this->assertContains( $expected, $template );
|
||||
}
|
||||
|
||||
/**
|
||||
* Test the available_items_template method.
|
||||
*
|
||||
* @see WP_Customize_Nav_Menus::available_items_template()
|
||||
*/
|
||||
function test_available_items_template() {
|
||||
do_action( 'customize_register', $this->wp_customize );
|
||||
$menus = new WP_Customize_Nav_Menus( $this->wp_customize );
|
||||
|
||||
ob_start();
|
||||
$menus->available_items_template();
|
||||
$template = ob_get_clean();
|
||||
|
||||
$expected = sprintf( 'Customizing ▸ %s', esc_html( $this->wp_customize->get_panel( 'nav_menus' )->title ) );
|
||||
|
||||
$this->assertContains( $expected, $template );
|
||||
|
||||
$post_types = get_post_types( array( 'show_in_nav_menus' => true ), 'object' );
|
||||
if ( $post_types ) {
|
||||
foreach ( $post_types as $type ) {
|
||||
$this->assertContains( 'available-menu-items-' . esc_attr( $type->name ), $template );
|
||||
$this->assertContains( '<h4 class="accordion-section-title">' . esc_html( $type->label ), $template );
|
||||
$this->assertContains( 'data-type="' . esc_attr( $type->name ) . '" data-obj_type="post_type"', $template );
|
||||
}
|
||||
}
|
||||
|
||||
$taxonomies = get_taxonomies( array( 'show_in_nav_menus' => true ), 'object' );
|
||||
if ( $taxonomies ) {
|
||||
foreach ( $taxonomies as $tax ) {
|
||||
$this->assertContains( 'available-menu-items-' . esc_attr( $tax->name ), $template );
|
||||
$this->assertContains( '<h4 class="accordion-section-title">' . esc_html( $tax->label ), $template );
|
||||
$this->assertContains( 'data-type="' . esc_attr( $tax->name ) . '" data-obj_type="taxonomy"', $template );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Test the customize_preview_init method.
|
||||
*
|
||||
* @see WP_Customize_Nav_Menus::customize_preview_init()
|
||||
*/
|
||||
function test_customize_preview_init() {
|
||||
do_action( 'customize_register', $this->wp_customize );
|
||||
$menus = new WP_Customize_Nav_Menus( $this->wp_customize );
|
||||
|
||||
$menus->customize_preview_init();
|
||||
$this->assertEquals( 10, has_action( 'template_redirect', array( $menus, 'render_menu' ) ) );
|
||||
$this->assertEquals( 10, has_action( 'wp_enqueue_scripts', array( $menus, 'customize_preview_enqueue_deps' ) ) );
|
||||
|
||||
if ( ! isset( $_REQUEST[ WP_Customize_Nav_Menus::RENDER_QUERY_VAR ] ) ) {
|
||||
$this->assertEquals( 1000, has_filter( 'wp_nav_menu_args', array( $menus, 'filter_wp_nav_menu_args' ) ) );
|
||||
$this->assertEquals( 10, has_filter( 'wp_nav_menu', array( $menus, 'filter_wp_nav_menu' ) ) );
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Test the filter_wp_nav_menu_args method.
|
||||
*
|
||||
* @see WP_Customize_Nav_Menus::filter_wp_nav_menu_args()
|
||||
*/
|
||||
function test_filter_wp_nav_menu_args() {
|
||||
do_action( 'customize_register', $this->wp_customize );
|
||||
$menus = new WP_Customize_Nav_Menus( $this->wp_customize );
|
||||
|
||||
$results = $menus->filter_wp_nav_menu_args( array(
|
||||
'echo' => true,
|
||||
'fallback_cb' => 'wp_page_menu',
|
||||
'walker' => '',
|
||||
) );
|
||||
$this->assertEquals( 1, $results['can_partial_refresh'] );
|
||||
|
||||
$expected = array(
|
||||
'echo',
|
||||
'args_hash',
|
||||
'can_partial_refresh',
|
||||
'instance_number',
|
||||
);
|
||||
$results = $menus->filter_wp_nav_menu_args( array(
|
||||
'echo' => false,
|
||||
'fallback_cb' => 'wp_page_menu',
|
||||
'walker' => new Walker_Nav_Menu(),
|
||||
) );
|
||||
$this->assertEqualSets( $expected, array_keys( $results ) );
|
||||
$this->assertEquals( 0, $results['can_partial_refresh'] );
|
||||
}
|
||||
|
||||
/**
|
||||
* Test the filter_wp_nav_menu method.
|
||||
*
|
||||
* @see WP_Customize_Nav_Menus::filter_wp_nav_menu()
|
||||
*/
|
||||
function test_filter_wp_nav_menu() {
|
||||
do_action( 'customize_register', $this->wp_customize );
|
||||
$menus = new WP_Customize_Nav_Menus( $this->wp_customize );
|
||||
|
||||
$args = $menus->filter_wp_nav_menu_args( array(
|
||||
'echo' => true,
|
||||
'fallback_cb' => 'wp_page_menu',
|
||||
'walker' => '',
|
||||
) );
|
||||
|
||||
ob_start();
|
||||
wp_nav_menu( $args );
|
||||
$nav_menu_content = ob_get_clean();
|
||||
|
||||
$object_args = json_decode( json_encode( $args ), false );
|
||||
$result = $menus->filter_wp_nav_menu( $nav_menu_content, $object_args );
|
||||
$expected = sprintf(
|
||||
'<div id="partial-refresh-menu-container-%1$d" class="partial-refresh-menu-container" data-instance-number="%1$d">%2$s</div>',
|
||||
$args['instance_number'],
|
||||
$nav_menu_content
|
||||
);
|
||||
$this->assertEquals( $expected, $result );
|
||||
}
|
||||
|
||||
/**
|
||||
* Test the customize_preview_enqueue_deps method.
|
||||
*
|
||||
* @see WP_Customize_Nav_Menus::customize_preview_enqueue_deps()
|
||||
*/
|
||||
function test_customize_preview_enqueue_deps() {
|
||||
do_action( 'customize_register', $this->wp_customize );
|
||||
$menus = new WP_Customize_Nav_Menus( $this->wp_customize );
|
||||
|
||||
$menus->customize_preview_enqueue_deps();
|
||||
|
||||
$this->assertTrue( wp_script_is( 'customize-preview-nav-menus' ) );
|
||||
$this->assertEquals( 10, has_action( 'wp_print_footer_scripts', array( $menus, 'export_preview_data' ) ) );
|
||||
}
|
||||
|
||||
/**
|
||||
* Test the export_preview_data method.
|
||||
*
|
||||
* @see WP_Customize_Nav_Menus::export_preview_data()
|
||||
*/
|
||||
function test_export_preview_data() {
|
||||
do_action( 'customize_register', $this->wp_customize );
|
||||
$menus = new WP_Customize_Nav_Menus( $this->wp_customize );
|
||||
|
||||
$request_uri = $_SERVER['REQUEST_URI'];
|
||||
|
||||
ob_start();
|
||||
$_SERVER['REQUEST_URI'] = '/wp-admin';
|
||||
$menus->export_preview_data();
|
||||
$data = ob_get_clean();
|
||||
|
||||
$_SERVER['REQUEST_URI'] = $request_uri;
|
||||
|
||||
$this->assertContains( '_wpCustomizePreviewNavMenusExports', $data );
|
||||
$this->assertContains( 'renderQueryVar', $data );
|
||||
$this->assertContains( 'renderNonceValue', $data );
|
||||
$this->assertContains( 'renderNoncePostKey', $data );
|
||||
$this->assertContains( 'requestUri', $data );
|
||||
$this->assertContains( 'theme', $data );
|
||||
$this->assertContains( 'previewCustomizeNonce', $data );
|
||||
$this->assertContains( 'navMenuInstanceArgs', $data );
|
||||
$this->assertContains( 'requestUri', $data );
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Test the render_menu method.
|
||||
*
|
||||
* @see WP_Customize_Nav_Menus::render_menu()
|
||||
*/
|
||||
function test_render_menu() {
|
||||
|
||||
$this->markTestIncomplete( 'This test has not been implemented.' );
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user