Make WordPress Core


Ignore:
Timestamp:
08/12/2015 02:06:21 PM (11 years ago)
Author:
boonebgorges
Message:

When splitting a shared 'nav_menu' term, ensure that nav items and theme locations are retained.

Props boonebgorges, dd32.
Fixes #33187.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/tests/phpunit/tests/term/splitSharedTerm.php

    r32208 r33611  
    196196        }
    197197
     198        /**
     199         * @ticket 33187
     200         * @group navmenus
     201         */
     202        public function test_nav_menu_locations_should_be_updated_on_split() {
     203                global $wpdb;
     204
     205                $cat_term = wp_insert_term( 'Foo Menu', 'category' );
     206                $shared_term_id = $cat_term['term_id'];
     207
     208                $nav_term_id = wp_create_nav_menu( 'Foo Menu' );
     209                $nav_term = get_term( $nav_term_id, 'nav_menu' );
     210
     211                // Manually modify because shared terms shouldn't naturally occur.
     212                $wpdb->update( $wpdb->term_taxonomy,
     213                        array( 'term_id' => $shared_term_id ),
     214                        array( 'term_taxonomy_id' => $nav_term->term_taxonomy_id )
     215                );
     216
     217                set_theme_mod( 'nav_menu_locations', array( 'foo' => $shared_term_id ) );
     218
     219                // Splitsville.
     220                $new_term_id = _split_shared_term( $shared_term_id, $nav_term->term_taxonomy_id );
     221
     222                $locations = get_nav_menu_locations();
     223                $this->assertEquals( $new_term_id, $locations['foo'] );
     224        }
     225
     226        /**
     227         * @ticket 33187
     228         * @group navmenus
     229         */
     230        public function test_nav_menu_term_should_retain_menu_items_on_split() {
     231                global $wpdb;
     232
     233                $cat_term = wp_insert_term( 'Foo Menu', 'category' );
     234                $shared_term_id = $cat_term['term_id'];
     235
     236                $nav_term_id = wp_create_nav_menu( 'Foo Menu' );
     237                $nav_term = get_term( $nav_term_id, 'nav_menu' );
     238
     239                // Manually modify because shared terms shouldn't naturally occur.
     240                $wpdb->update( $wpdb->term_taxonomy,
     241                        array( 'term_id' => $shared_term_id ),
     242                        array( 'term_taxonomy_id' => $nav_term->term_taxonomy_id )
     243                );
     244
     245                $t1 = wp_insert_term( 'Random term', 'category' );
     246                $cat_menu_item = wp_update_nav_menu_item( $shared_term_id, 0, array(
     247                        'menu-item-type' => 'taxonomy',
     248                        'menu-item-object' => 'category',
     249                        'menu-item-object-id' => $t1['term_id'],
     250                        'menu-item-status' => 'publish'
     251                ) );
     252
     253                // Updating the menu will split the shared term.
     254                $new_nav_menu_id = wp_update_nav_menu_object( $shared_term_id, array(
     255                        'description' => 'Updated Foo Menu',
     256                        'menu-name' => 'Updated Foo Menu',
     257                ) );
     258
     259                $menu = wp_get_nav_menu_object( $new_nav_menu_id );
     260                $this->assertSame( 'Updated Foo Menu', $menu->name );
     261                $this->assertSame( 'Updated Foo Menu', $menu->description );
     262
     263                $menu_items = wp_get_nav_menu_items( $new_nav_menu_id );
     264                $this->assertEquals( array( $cat_menu_item ), wp_list_pluck( $menu_items, 'ID' ) );
     265        }
     266
    198267        public function test_wp_get_split_terms() {
    199268                $found = wp_get_split_terms( $this->terms['t1']['term_id'] );
Note: See TracChangeset for help on using the changeset viewer.