Make WordPress Core

Ticket #43401: 43401.tests.patch

File 43401.tests.patch, 1.5 KB (added by soulseekah, 7 years ago)

Initial tests

  • tests/phpunit/tests/post/nav-menu.php

    diff --git tests/phpunit/tests/post/nav-menu.php tests/phpunit/tests/post/nav-menu.php
    index e575f36..f34d656 100644
    class Test_Nav_Menus extends WP_UnitTestCase { 
    762762                $this->assertNotContains( 'current-menu-ancestor', $post_archive_menu_item->classes );
    763763        }
    764764
     765        /**
     766         * Provides IRI matching data for _wp_menu_item_classes_by_context test
     767         */
     768        function get_iri_current_menu_items() {
     769                return array(
     770                        array( site_url( '/%D0%BF%D1%80%D0%B8%D0%B2%D0%B5%D1%82/' ) ),
     771                        array( site_url( '/%D0%BF%D1%80%D0%B8%D0%B2%D0%B5%D1%82' ) ),
     772                        array( '/%D0%BF%D1%80%D0%B8%D0%B2%D0%B5%D1%82/' ),
     773                        array( '/%D0%BF%D1%80%D0%B8%D0%B2%D0%B5%D1%82' ),
     774                        array( '/привет/' ),
     775                        array( '/привет' ),
     776                );
     777        }
     778
     779        /**
     780         * @ticket 43401
     781         * @dataProvider get_iri_current_menu_items
     782         */
     783        function test_iri_current_menu_item( $custom_link, $current = true ) {
     784                wp_update_nav_menu_item(
     785                        $this->menu_id, 0, array(
     786                                'menu-item-status' => 'publish',
     787                                'menu-item-type' => 'custom',
     788                                'menu-item-url' => $custom_link,
     789                        )
     790                );
     791
     792                $this->go_to( site_url( '/%D0%BF%D1%80%D0%B8%D0%B2%D0%B5%D1%82/' ) );
     793
     794                $menu_items = wp_get_nav_menu_items( $this->menu_id );
     795                _wp_menu_item_classes_by_context( $menu_items );
     796
     797                $classes = $menu_items[0]->classes;
     798
     799                if ( $current ) {
     800                        $this->assertContains( 'current-menu-item', $classes );
     801                } else {
     802                        $this->assertNotContains( 'current-menu-item', $classes );
     803                }
     804        }
     805
    765806}