WordPress.org

Make WordPress Core


Ignore:
Timestamp:
09/17/2016 09:49:49 PM (21 months ago)
Author:
westonruter
Message:

Customize: Ensure nav menu items lacking a label use the title from the original object.

Use original title as placeholder for label and in control title. Prevent original title from overriding empty label in initial setting values.

Fixes #38015.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/tests/phpunit/tests/customize/nav-menu-item-setting.php

    r37405 r38618  
    186186
    187187    /**
     188     * Test value method with post without nav menu item title (label).
     189     *
     190     * @see WP_Customize_Nav_Menu_Item_Setting::value()
     191     */
     192    function test_value_type_post_type_without_label() {
     193        do_action( 'customize_register', $this->wp_customize );
     194
     195        $original_title = 'Hello World';
     196        $post_id = self::factory()->post->create( array( 'post_title' => $original_title ) );
     197
     198        $menu_id = wp_create_nav_menu( 'Menu' );
     199        $item_id = wp_update_nav_menu_item( $menu_id, 0, array(
     200            'menu-item-type' => 'post_type',
     201            'menu-item-object' => 'post',
     202            'menu-item-object-id' => $post_id,
     203            'menu-item-title' => '',
     204            'menu-item-status' => 'publish',
     205        ) );
     206
     207        $setting_id = "nav_menu_item[$item_id]";
     208        $setting = new WP_Customize_Nav_Menu_Item_Setting( $this->wp_customize, $setting_id );
     209
     210        $value = $setting->value();
     211        $this->assertEquals( '', $value['title'] );
     212        $this->assertEquals( $original_title, $value['original_title'] );
     213    }
     214
     215    /**
    188216     * Test value method with taxonomy.
    189217     *
     
    805833        $this->assertEquals( 'Attempted \o/ o’o markup', $nav_menu_item->description );
    806834    }
     835
     836    /**
     837     * Test WP_Customize_Nav_Menu_Item_Setting::value_as_wp_post_nav_menu_item() where title is empty.
     838     *
     839     * @ticket 38015
     840     * @see WP_Customize_Nav_Menu_Item_Setting::value_as_wp_post_nav_menu_item()
     841     */
     842    function test_value_as_wp_post_nav_menu_item_with_empty_title() {
     843        $original_title = 'The Original Title';
     844        $post_id = self::factory()->post->create( array( 'post_title' => $original_title ) );
     845
     846        $setting = new WP_Customize_Nav_Menu_Item_Setting(
     847            $this->wp_customize,
     848            'nav_menu_item[123]'
     849        );
     850
     851        $post_value = array_merge(
     852            $setting->default,
     853            array(
     854                'object_id'        => $post_id,
     855                'object'           => 'post',
     856                'type'             => 'post_type',
     857                'status'           => 'publish',
     858                'nav_menu_term_id' => 0,
     859            )
     860        );
     861        $this->wp_customize->set_post_value( $setting->id, $post_value );
     862
     863        $setting->preview();
     864
     865        $nav_menu_item = $setting->value_as_wp_post_nav_menu_item();
     866        $this->assertEquals( $original_title, $nav_menu_item->title );
     867    }
    807868}
Note: See TracChangeset for help on using the changeset viewer.