Make WordPress Core

Ticket #41451: 41451.patch

File 41451.patch, 91.0 KB (added by Frank Klein, 7 years ago)
  • tests/phpunit/includes/functions.php

    diff --git tests/phpunit/includes/functions.php tests/phpunit/includes/functions.php
    index 9a450ece84..3aad8fa362 100644
    function _set_default_permalink_structure_for_tests() { 
    157157        update_option( 'permalink_structure', '/%year%/%monthnum%/%day%/%postname%/' );
    158158}
    159159
     160function _set_default_multisite_permalink_structure_for_tests() {
     161        update_option( 'permalink_structure', '/blog/%year%/%monthnum%/%day%/%postname%/' );
     162}
     163
    160164/**
    161165 * Helper used with the `upload_dir` filter to remove the /year/month sub directories from the uploads path and URL.
    162166 */
  • tests/phpunit/includes/install.php

    diff --git tests/phpunit/includes/install.php tests/phpunit/includes/install.php
    index 45c0d60f83..bda505258d 100644
    foreach ( $wpdb->tables( 'ms_global' ) as $table => $prefixed_table ) { 
    6565$wpdb->query( 'SET foreign_key_checks = 1' );
    6666
    6767// Prefill a permalink structure so that WP doesn't try to determine one itself.
    68 add_action( 'populate_options', '_set_default_permalink_structure_for_tests' );
     68if ( $multisite ) {
     69        add_action( 'populate_options', '_set_default_multisite_permalink_structure_for_tests' );
     70} else {
     71        add_action( 'populate_options', '_set_default_permalink_structure_for_tests' );
     72}
    6973
    7074wp_install( WP_TESTS_TITLE, 'admin', WP_TESTS_EMAIL, true, null, 'password' );
    7175
    72 // Delete dummy permalink structure, as prefilled above.
    73 if ( ! is_multisite() ) {
    74         delete_option( 'permalink_structure' );
     76if ( $multisite ) {
     77        remove_action( 'populate_options', '_set_default_multisite_permalink_structure_for_tests' );
     78} else {
     79        remove_action( 'populate_options', '_set_default_permalink_structure_for_tests' );
    7580}
    76 remove_action( 'populate_options', '_set_default_permalink_structure_for_tests' );
    7781
    7882if ( $multisite ) {
    7983        echo 'Installing network...' . PHP_EOL;
    if ( $multisite ) { 
    8589
    8690        install_network();
    8791        populate_network( 1, WP_TESTS_DOMAIN, WP_TESTS_EMAIL, $title, '/', $subdomain_install );
    88         $wp_rewrite->set_permalink_structure( '' );
    8992}
  • tests/phpunit/includes/testcase.php

    diff --git tests/phpunit/includes/testcase.php tests/phpunit/includes/testcase.php
    index fee06e0df9..2cc40a6bf6 100644
    class WP_UnitTestCase extends PHPUnit_Framework_TestCase { 
    125125                        $this->reset_taxonomies();
    126126                        $this->reset_post_statuses();
    127127                        $this->reset__SERVER();
    128 
    129                         if ( $wp_rewrite->permalink_structure ) {
    130                                 $this->set_permalink_structure( '' );
    131                         }
    132128                }
    133129
    134130                $this->start_transaction();
    135131                $this->expectDeprecated();
    136132                add_filter( 'wp_die_handler', array( $this, 'get_wp_die_handler' ) );
     133
     134                if ( get_option( 'permalink_structure' ) !== tests_get_default_permalink_structure() ) {
     135                        $this->fail( 'Permalink structure was not correctly reset: ' . get_option( 'permalink_structure' ) );
     136                }
    137137        }
    138138
    139139        /**
  • tests/phpunit/includes/utils.php

    diff --git tests/phpunit/includes/utils.php tests/phpunit/includes/utils.php
    index 3c7b1bed34..e341140e11 100644
    function test_rest_expand_compact_links( $links ) { 
    534534        }
    535535        return $links;
    536536}
     537
     538/**
     539 * Set the permalink structure.
     540 *
     541 * This updates the `permalink_structure` option, and flushes the existing rewrite rules.
     542 *
     543 * @since 5.0.0
     544 *
     545 * @param string $structure Permalink structure.
     546 */
     547function tests_set_and_flush_permalinks( $structure ) {
     548        global $wp_rewrite;
     549
     550        $wp_rewrite->set_permalink_structure( $structure );
     551        $wp_rewrite->flush_rules();
     552}
     553
     554/**
     555 * Reset the permalink structure to the default.
     556 *
     557 * @since 5.0.0
     558 */
     559function tests_reset_and_flush_permalinks() {
     560        tests_set_and_flush_permalinks( tests_get_default_permalink_structure() );
     561}
     562
     563/**
     564 * Retrieve the default permalink structure used for unit tests.
     565 *
     566 * @since 5.0.0
     567 *
     568 * @return string Permalink structure.
     569 */
     570function tests_get_default_permalink_structure() {
     571        if ( is_multisite() ) {
     572                return '/blog/%year%/%monthnum%/%day%/%postname%/';
     573        }
     574
     575        return '/%year%/%monthnum%/%day%/%postname%/';
     576}
     577
     578/**
     579 * Add the `blog` prefix to URLs if on multisite.
     580 *
     581 * When the multisite is installed, the main site gets `blog` added to its permalink structure. This makes the
     582 * permalinks different on single site installs and on multisites.
     583 *
     584 * This helper function prefixes URLs with `blog` if on multisite.
     585 *
     586 * @since 5.0.0
     587 *
     588 * @param string $url URL to maybe prefix.
     589 *
     590 * @return string Prefixed URL on multisite, else unchanged URL.
     591 */
     592function tests_add_blog_permalink_prefix_on_multisite( $url ) {
     593        if ( ! is_multisite() || ! is_main_site() ) {
     594                return $url;
     595        }
     596
     597        if ( strpos( $url, '/' ) === 0 ) {
     598                return 'blog' . $url;
     599        }
     600
     601        return 'blog/' . $url;
     602}
  • tests/phpunit/tests/admin/includesPost.php

    diff --git tests/phpunit/tests/admin/includesPost.php tests/phpunit/tests/admin/includesPost.php
    index 5c080f2ed6..b9e42ea3ba 100644
    class Tests_Admin_Includes_Post extends WP_UnitTestCase { 
    333333                $expected = trailingslashit( home_url( $permalink_structure ) );
    334334
    335335                $this->assertSame( $expected, $found[0] );
     336
     337                tests_reset_and_flush_permalinks();
    336338        }
    337339
    338340        /**
    class Tests_Admin_Includes_Post extends WP_UnitTestCase { 
    340342         * @ticket 18306
    341343         */
    342344        public function test_get_sample_permalink_html_should_use_default_permalink_for_view_post_link_when_pretty_permalinks_are_disabled() {
     345                tests_set_and_flush_permalinks( '' );
     346
    343347                wp_set_current_user( self::$admin_id );
    344348
    345349                $future_date = date( 'Y-m-d H:i:s', time() + 100 );
    class Tests_Admin_Includes_Post extends WP_UnitTestCase { 
    354358                $found = get_sample_permalink_html( $p );
    355359                $this->assertContains( 'href="' . get_option( 'home' ) . '/?p=' . $p . '"', $found );
    356360                $this->assertContains( '>' . get_option( 'home' ) . '/?p=' . $p . '<', $found );
     361
     362                tests_reset_and_flush_permalinks();
    357363        }
    358364
    359365        /**
    class Tests_Admin_Includes_Post extends WP_UnitTestCase { 
    378384                $post  = get_post( $p );
    379385                $this->assertContains( 'href="' . get_option( 'home' ) . '/' . $post->post_name . '/"', $found );
    380386                $this->assertContains( '>' . urldecode( $post->post_name ) . '<', $found );
     387
     388                tests_reset_and_flush_permalinks();
    381389        }
    382390
    383391        /**
    class Tests_Admin_Includes_Post extends WP_UnitTestCase { 
    401409                $post  = get_post( $p );
    402410                $this->assertContains( 'href="' . get_option( 'home' ) . '/' . $post->post_name . '/"', $found );
    403411                $this->assertContains( '>' . urldecode( get_permalink( $post ) ) . '<', $found );
     412
     413                tests_reset_and_flush_permalinks();
    404414        }
    405415
    406416        /**
    class Tests_Admin_Includes_Post extends WP_UnitTestCase { 
    459469
    460470                $this->assertContains( 'href="' . esc_url( $preview_link ) . '"', $found, $message );
    461471                $this->assertContains( '>new_slug-صورة<', $found, $message );
     472
     473                tests_reset_and_flush_permalinks();
    462474        }
    463475
    464476        /**
    class Tests_Admin_Includes_Post extends WP_UnitTestCase { 
    482494                $found = get_sample_permalink_html( $p );
    483495                $post  = get_post( $p );
    484496                $this->assertContains( 'href="' . esc_url( get_preview_post_link( $post ) ), $found );
     497
     498                tests_reset_and_flush_permalinks();
    485499        }
    486500
    487501        /**
    class Tests_Admin_Includes_Post extends WP_UnitTestCase { 
    498512
    499513                $found = get_sample_permalink( $p );
    500514                $this->assertEquals( '2015-2', $found[1] );
     515
     516                tests_reset_and_flush_permalinks();
    501517        }
    502518
    503519        /**
    class Tests_Admin_Includes_Post extends WP_UnitTestCase { 
    514530
    515531                $found = get_sample_permalink( $p );
    516532                $this->assertEquals( '2015', $found[1] );
     533
     534                tests_reset_and_flush_permalinks();
    517535        }
    518536
    519537        /**
    class Tests_Admin_Includes_Post extends WP_UnitTestCase { 
    530548
    531549                $found = get_sample_permalink( $p );
    532550                $this->assertEquals( '11-2', $found[1] );
     551
     552                tests_reset_and_flush_permalinks();
    533553        }
    534554
    535555        /**
    class Tests_Admin_Includes_Post extends WP_UnitTestCase { 
    546566
    547567                $found = get_sample_permalink( $p );
    548568                $this->assertEquals( '13', $found[1] );
     569
     570                tests_reset_and_flush_permalinks();
    549571        }
    550572
    551573        /**
    class Tests_Admin_Includes_Post extends WP_UnitTestCase { 
    562584
    563585                $found = get_sample_permalink( $p );
    564586                $this->assertEquals( '30-2', $found[1] );
     587
     588                tests_reset_and_flush_permalinks();
    565589        }
    566590
    567591        /**
    class Tests_Admin_Includes_Post extends WP_UnitTestCase { 
    584608
    585609                $found = get_sample_permalink( $p );
    586610                $this->assertEquals( '30-3', $found[1] );
     611
     612                tests_reset_and_flush_permalinks();
    587613        }
    588614
    589615        /**
    class Tests_Admin_Includes_Post extends WP_UnitTestCase { 
    600626
    601627                $found = get_sample_permalink( $p );
    602628                $this->assertEquals( '32', $found[1] );
     629
     630                tests_reset_and_flush_permalinks();
    603631        }
    604632
    605633        /**
    class Tests_Admin_Includes_Post extends WP_UnitTestCase { 
    616644
    617645                $found = get_sample_permalink( $p );
    618646                $this->assertEquals( '30', $found[1] );
     647
     648                tests_reset_and_flush_permalinks();
    619649        }
    620650
    621651        /**
    class Tests_Admin_Includes_Post extends WP_UnitTestCase { 
    643673                $actual = get_sample_permalink( $child );
    644674                $this->assertSame( home_url() . '/parent-page/%pagename%/', $actual[0] );
    645675                $this->assertSame( 'child-page', $actual[1] );
     676
     677                tests_reset_and_flush_permalinks();
    646678        }
    647679
    648680        public function test_post_exists_should_match_title() {
  • tests/phpunit/tests/canonical/https.php

    diff --git tests/phpunit/tests/canonical/https.php tests/phpunit/tests/canonical/https.php
    index c6b59bdb34..183553e222 100644
    class Tests_Canonical_HTTPS extends WP_Canonical_UnitTestCase { 
    99        function setUp() {
    1010                parent::setUp();
    1111
    12                 $this->set_permalink_structure( '/%year%/%monthnum%/%day%/%postname%/' );
    1312                create_initial_taxonomies();
    1413
    1514                $this->http  = set_url_scheme( home_url( 'sample-page/' ), 'http' );
  • tests/phpunit/tests/category/getCategoryLink.php

    diff --git tests/phpunit/tests/category/getCategoryLink.php tests/phpunit/tests/category/getCategoryLink.php
    index a69b522f26..703dafead3 100644
     
    66 */
    77class Tests_Category_GetCategoryLink extends WP_UnitTestCase {
    88        public function test_success() {
     9                tests_set_and_flush_permalinks( '' );
    910                $c = self::factory()->category->create();
    1011
    1112                $found = get_category_link( $c );
    1213                $expected = home_url( '?cat=' . $c );
    1314
    1415                $this->assertSame( $expected, $found );
     16
     17                tests_reset_and_flush_permalinks();
    1518        }
    1619
    1720        /**
    1821         * @ticket 42771
    1922         */
    2023        public function test_should_return_link_for_term_from_another_taxonomy_on_primed_cache() {
     24                tests_set_and_flush_permalinks( '' );
    2125                register_taxonomy( 'wptests_tax', 'post' );
    2226
    2327                $t = self::factory()->term->create( array(
    class Tests_Category_GetCategoryLink extends WP_UnitTestCase { 
    3135                $expected = home_url( '?wptests_tax=test-term' );
    3236
    3337                $this->assertSame( $expected, $found );
     38                tests_reset_and_flush_permalinks();
    3439        }
    3540
    3641        /**
    3742         * @ticket 42771
    3843         */
    3944        public function test_should_return_link_for_term_from_another_taxonomy_on_empty_cache() {
     45                tests_set_and_flush_permalinks( '' );
    4046                register_taxonomy( 'wptests_tax', 'post' );
    4147
    4248                $t = self::factory()->term->create( array(
    class Tests_Category_GetCategoryLink extends WP_UnitTestCase { 
    5056                $expected = home_url( '?wptests_tax=test-term' );
    5157
    5258                $this->assertSame( $expected, $found );
     59                tests_reset_and_flush_permalinks();
    5360        }
    5461}
  • tests/phpunit/tests/comment/commentsTemplate.php

    diff --git tests/phpunit/tests/comment/commentsTemplate.php tests/phpunit/tests/comment/commentsTemplate.php
    index 3547a14190..2e61ee500c 100644
    class Tests_Comment_CommentsTemplate extends WP_UnitTestCase { 
    570570
    571571                // They should all be on page 2.
    572572                foreach ( $matches[1] as $m ) {
    573                         $this->assertContains( 'cpage=2', $m );
     573                        $this->assertContains( 'comment-page-2', $m );
    574574                }
    575575        }
    576576
    class Tests_Comment_CommentsTemplate extends WP_UnitTestCase { 
    641641                preg_match_all( '|href="(.*?#comment-([0-9]+))|', $found_p0, $matches );
    642642
    643643                foreach ( $matches[1] as $m ) {
    644                         $this->assertContains( 'cpage=3', $m );
     644                        $this->assertContains( 'comment-page-3', $m );
    645645                }
    646646
    647647                $link_p2 = add_query_arg(
    class Tests_Comment_CommentsTemplate extends WP_UnitTestCase { 
    660660
    661661                // They should all be on page 2.
    662662                foreach ( $matches[1] as $m ) {
    663                         $this->assertContains( 'cpage=2', $m );
     663                        $this->assertContains( 'comment-page-2', $m );
    664664                }
    665665
    666666                // p1 is the last page (neat!).
    class Tests_Comment_CommentsTemplate extends WP_UnitTestCase { 
    680680
    681681                // They should all be on page 2.
    682682                foreach ( $matches[1] as $m ) {
    683                         $this->assertContains( 'cpage=1', $m );
     683                        $this->assertContains( 'comment-page-1', $m );
    684684                }
    685685        }
    686686
  • tests/phpunit/tests/comment/getCommentLink.php

    diff --git tests/phpunit/tests/comment/getCommentLink.php tests/phpunit/tests/comment/getCommentLink.php
    index ca75da1532..efe0186060 100644
    class Tests_Comment_GetCommentLink extends WP_UnitTestCase { 
    6666
    6767                $found = get_comment_link( self::$comments[1] );
    6868
    69                 $this->assertContains( 'cpage=3', $found );
     69                $this->assertContains( 'comment-page-3', $found );
    7070        }
    7171
    7272        /**
    class Tests_Comment_GetCommentLink extends WP_UnitTestCase { 
    7979
    8080                $found = get_comment_link( self::$comments[3] );
    8181
    82                 $this->assertContains( 'cpage=2', $found );
     82                $this->assertContains( 'comment-page-2', $found );
    8383        }
    8484
    8585        /**
    class Tests_Comment_GetCommentLink extends WP_UnitTestCase { 
    9292
    9393                $found = get_comment_link( self::$comments[5] );
    9494
    95                 $this->assertContains( 'cpage=1', $found );
     95                $this->assertContains( 'comment-page-1', $found );
    9696        }
    9797
    9898        /**
    class Tests_Comment_GetCommentLink extends WP_UnitTestCase { 
    117117
    118118                $found = get_comment_link( self::$comments[3] );
    119119
    120                 $this->assertContains( 'cpage=2', $found );
     120                $this->assertContains( 'comment-page-2', $found );
    121121        }
    122122
    123123        /**
    class Tests_Comment_GetCommentLink extends WP_UnitTestCase { 
    130130
    131131                $found = get_comment_link( self::$comments[1] );
    132132
    133                 $this->assertContains( 'cpage=3', $found );
     133                $this->assertContains( 'comment-page-3', $found );
    134134        }
    135135
    136136        /**
    137137         * @ticket 34946
    138138         */
    139139        public function test_should_not_contain_comment_page_1_when_pagination_is_disabled() {
    140                 $this->set_permalink_structure( '/%postname%/' );
    141140                update_option( 'page_comments', 0 );
    142141
    143142                $found = get_comment_link( self::$comments[1] );
  • tests/phpunit/tests/feed/atom.php

    diff --git tests/phpunit/tests/feed/atom.php tests/phpunit/tests/feed/atom.php
    index 356c95faf0..446494c811 100644
    class Tests_Feeds_Atom extends WP_UnitTestCase { 
    1717         * Setup a new user and attribute some posts.
    1818         */
    1919        public static function wpSetUpBeforeClass( $factory ) {
     20                global $wpdb;
     21
    2022                // Create a user
    2123                self::$user_id = $factory->user->create(
    2224                        array(
    class Tests_Feeds_Atom extends WP_UnitTestCase { 
    5052                        wp_set_object_terms( $post, self::$category->slug, 'category' );
    5153                }
    5254
     55                // Manually update the posts `guid` to be non-pretty permalinks. Due to the way that `wp_insert_post()` works,
     56                // the `guid` fields all contain pretty permalinks.
     57                foreach( self::$posts as $post_ID ) {
     58                        $wpdb->update( $wpdb->posts, array( 'guid' => 'http://example.com/?p=' . $post_ID ), array( 'ID' => $post_ID ) );
     59                }
    5360        }
    5461
    5562        /**
  • tests/phpunit/tests/feed/rss2.php

    diff --git tests/phpunit/tests/feed/rss2.php tests/phpunit/tests/feed/rss2.php
    index f8ebf2b9b1..571c25bde8 100644
    class Tests_Feeds_RSS2 extends WP_UnitTestCase { 
    1818         * Setup a new user and attribute some posts.
    1919         */
    2020        public static function wpSetUpBeforeClass( $factory ) {
     21                global $wpdb;
     22
    2123                // Create a user
    2224                self::$user_id = $factory->user->create(
    2325                        array(
    class Tests_Feeds_RSS2 extends WP_UnitTestCase { 
    5052                        )
    5153                );
    5254
     55                // Manually update the posts `guid` to be non-pretty permalinks. Due to the way that `wp_insert_post()` works,
     56                // the `guid` fields all contain pretty permalinks.
     57                foreach( self::$posts as $post_ID ) {
     58                        $wpdb->update( $wpdb->posts, array( 'guid' => 'http://example.com/?p=' . $post_ID ), array( 'ID' => $post_ID ) );
     59                }
     60
    5361                // Assign a category to those posts
    5462                foreach ( self::$posts as $post ) {
    5563                        wp_set_object_terms( $post, self::$category->slug, 'category' );
    class Tests_Feeds_RSS2 extends WP_UnitTestCase { 
    6775                // this seems to break something
    6876                update_option( 'use_smilies', false );
    6977
    70                 $this->set_permalink_structure( '/%year%/%monthnum%/%day%/%postname%/' );
    7178                create_initial_taxonomies();
    7279        }
    7380
    class Tests_Feeds_RSS2 extends WP_UnitTestCase { 
    326333         */
    327334        function test_valid_taxonomy_feed_endpoint() {
    328335                // An example of an valid taxonomy feed endpoint.
    329                 $this->go_to( 'category/foo/feed/' );
     336                $this->go_to( '/' . tests_add_blog_permalink_prefix_on_multisite( 'category/foo/feed/' ) );
    330337
    331338                // Verify the query object is a feed.
    332339                $this->assertQueryTrue( 'is_feed', 'is_archive', 'is_category' );
    class Tests_Feeds_RSS2 extends WP_UnitTestCase { 
    387394         */
    388395        function test_valid_archive_feed_endpoint() {
    389396                // An example of an valid date archive feed endpoint.
    390                 $this->go_to( '2003/05/27/feed/' );
     397                $this->go_to( tests_add_blog_permalink_prefix_on_multisite( '2003/05/27/feed/' ) );
    391398
    392399                // Verify the query object is a feed.
    393400                $this->assertQueryTrue( 'is_feed', 'is_archive', 'is_day', 'is_date' );
  • tests/phpunit/tests/general/paginateLinks.php

    diff --git tests/phpunit/tests/general/paginateLinks.php tests/phpunit/tests/general/paginateLinks.php
    index af736cc611..808127071f 100644
    EXPECTED; 
    213213         * @ticket 29636
    214214         */
    215215        function test_paginate_links_query_args() {
     216                tests_set_and_flush_permalinks( '' );
     217
    216218                add_filter( 'get_pagenum_link', array( $this, 'add_query_arg' ) );
    217219                $links = paginate_links(
    218220                        array(
    EXPECTED; 
    245247                        $href = $tag->attributes->getNamedItem( 'href' )->value;
    246248                        $this->assertEquals( $expected_href, $href );
    247249                }
     250
     251                tests_reset_and_flush_permalinks();
    248252        }
    249253
    250254        /**
    251255         * @ticket 30831
    252256         */
    253257        function test_paginate_links_with_custom_query_args() {
     258                tests_set_and_flush_permalinks( '' );
     259
    254260                add_filter( 'get_pagenum_link', array( $this, 'add_query_arg' ) );
    255261                $links = paginate_links(
    256262                        array(
    EXPECTED; 
    285291                        $href = $tag->attributes->getNamedItem( 'href' )->value;
    286292                        $this->assertEquals( $expected_href, $href );
    287293                }
     294
     295                tests_reset_and_flush_permalinks();
    288296        }
    289297
    290298        /**
  • tests/phpunit/tests/link.php

    diff --git tests/phpunit/tests/link.php tests/phpunit/tests/link.php
    index 02412510a0..57d3d71ae4 100644
    class Tests_Link extends WP_UnitTestCase { 
    1414        function test_get_pagenum_link_case_insensitivity() {
    1515                $old_req_uri = $_SERVER['REQUEST_URI'];
    1616
    17                 $this->set_permalink_structure( '/%year%/%monthnum%/%day%/%postname%/' );
    18 
    1917                add_filter( 'home_url', array( $this, '_get_pagenum_link_cb' ) );
    2018                $_SERVER['REQUEST_URI'] = '/woohoo';
    2119                $paged                  = get_pagenum_link( 2 );
    class Tests_Link extends WP_UnitTestCase { 
    3129                $post_id2 = self::factory()->post->create();
    3230
    3331                // Basic case
    34                 $this->assertEquals( get_permalink( $post_id ), wp_get_shortlink( $post_id, 'post' ) );
     32                $this->assertEquals( home_url( '?p=' . $post_id ), wp_get_shortlink( $post_id, 'post' ) );
    3533
    3634                unset( $GLOBALS['post'] );
    3735
    class Tests_Link extends WP_UnitTestCase { 
    4341                $GLOBALS['post'] = get_post( $post_id );
    4442
    4543                // Global post is set
    46                 $this->assertEquals( get_permalink( $post_id ), wp_get_shortlink( 0, 'post' ) );
    47                 $this->assertEquals( get_permalink( $post_id ), wp_get_shortlink( 0 ) );
    48                 $this->assertEquals( get_permalink( $post_id ), wp_get_shortlink() );
     44                $this->assertEquals( home_url( '?p=' . $post_id ), wp_get_shortlink( 0, 'post' ) );
     45                $this->assertEquals( home_url( '?p=' . $post_id ), wp_get_shortlink( 0 ) );
     46                $this->assertEquals( home_url( '?p=' . $post_id ), wp_get_shortlink() );
    4947
    5048                // Not the global post
    51                 $this->assertEquals( get_permalink( $post_id2 ), wp_get_shortlink( $post_id2, 'post' ) );
     49                $this->assertEquals( home_url( '?p=' . $post_id2 ), wp_get_shortlink( $post_id2, 'post' ) );
    5250
    5351                unset( $GLOBALS['post'] );
    5452
    class Tests_Link extends WP_UnitTestCase { 
    5755                $this->assertEquals( '', wp_get_shortlink( 0 ) );
    5856                $this->assertEquals( '', wp_get_shortlink() );
    5957
    60                 $this->set_permalink_structure( '/%year%/%monthnum%/%day%/%postname%/' );
    61 
    6258                // With a permalink structure set, get_permalink() will no longer match.
    6359                $this->assertNotEquals( get_permalink( $post_id ), wp_get_shortlink( $post_id, 'post' ) );
    6460                $this->assertEquals( home_url( '?p=' . $post_id ), wp_get_shortlink( $post_id, 'post' ) );
    class Tests_Link extends WP_UnitTestCase { 
    7369        function test_wp_get_shortlink_with_page() {
    7470                $post_id = self::factory()->post->create( array( 'post_type' => 'page' ) );
    7571
    76                 // Basic case
    77                 // Don't test against get_permalink() since it uses ?page_id= for pages.
    78                 $this->assertEquals( home_url( '?p=' . $post_id ), wp_get_shortlink( $post_id, 'post' ) );
    79 
    80                 $this->set_permalink_structure( '/%year%/%monthnum%/%day%/%postname%/' );
    81 
    8272                $this->assertEquals( home_url( '?p=' . $post_id ), wp_get_shortlink( $post_id, 'post' ) );
    8373        }
    8474
    class Tests_Link extends WP_UnitTestCase { 
    9181                update_option( 'page_on_front', $post_id );
    9282
    9383                $this->assertEquals( home_url( '/' ), wp_get_shortlink( $post_id, 'post' ) );
    94 
    95                 $this->set_permalink_structure( '/%year%/%monthnum%/%day%/%postname%/' );
    96 
    97                 $this->assertEquals( home_url( '/' ), wp_get_shortlink( $post_id, 'post' ) );
    9884        }
    9985
    10086        /**
    10187         * @ticket 30910
    10288         */
    10389        public function test_get_permalink_should_not_reveal_post_name_for_post_with_post_status_future() {
    104                 update_option( 'permalink_structure', '/%year%/%monthnum%/%day%/%postname%/' );
    105 
    106                 flush_rewrite_rules();
    107 
    10890                $p = self::factory()->post->create(
    10991                        array(
    11092                                'post_status' => 'publish',
    class Tests_Link extends WP_UnitTestCase { 
    121103         * @ticket 30910
    122104         */
    123105        public function test_get_permalink_should_not_reveal_post_name_for_cpt_with_post_status_future() {
    124                 update_option( 'permalink_structure', '/%year%/%monthnum%/%day%/%postname%/' );
    125 
    126106                register_post_type( 'wptests_pt', array( 'public' => true ) );
    127107
    128108                flush_rewrite_rules();
    class Tests_Link extends WP_UnitTestCase { 
    171151        public function test_attachment_attached_to_non_existent_post_type_has_a_pretty_permalink() {
    172152                global $wp_post_types;
    173153
    174                 $this->set_permalink_structure( '/%year%/%monthnum%/%day%/%postname%/' );
    175 
    176154                register_post_type( 'not_a_post_type', array( 'public' => true ) );
    177155
    178                 flush_rewrite_rules();
    179 
    180156                $post_id = self::factory()->post->create( array( 'post_type' => 'not_a_post_type' ) );
    181157
    182158                $attachment_id = self::factory()->attachment->create_object(
  • tests/phpunit/tests/link/getAdjacentPostLink.php

    diff --git tests/phpunit/tests/link/getAdjacentPostLink.php tests/phpunit/tests/link/getAdjacentPostLink.php
    index acaec3973b..340f9b31c7 100644
     
    55 */
    66class Tests_Link_GetAdjacentPostLink extends WP_UnitTestCase {
    77
    8         protected $post_ids;
     8        protected $posts;
    99        protected $cat_id;
    1010
    1111        public function setUp() {
    1212                parent::setUp();
    1313                $this->cat_id     = self::factory()->category->create( array( 'name' => 'other' ) );
    14                 $this->post_ids   = array();
    15                 $this->post_ids[] = self::factory()->post->create(
     14                $this->posts   = array();
     15                $this->posts[] = self::factory()->post->create_and_get(
    1616                        array(
    1717                                'post_type'   => 'post',
    1818                                'post_date'   => '2014-10-26 05:32:29',
    1919                                'category_id' => 1,
    2020                        )
    2121                );
    22                 $this->post_ids[] = self::factory()->post->create(
     22                $this->posts[] = self::factory()->post->create_and_get(
    2323                        array(
    2424                                'post_type'   => 'post',
    2525                                'post_date'   => '2014-10-26 04:32:29',
    2626                                'category_id' => $this->cat_id,
    2727                        )
    2828                );
    29                 $this->post_ids[] = self::factory()->post->create(
     29                $this->posts[] = self::factory()->post->create_and_get(
    3030                        array(
    3131                                'post_type'   => 'post',
    3232                                'post_date'   => '2014-10-26 03:32:29',
    3333                                'category_id' => 1,
    3434                        )
    3535                );
    36                 $this->post_ids[] = self::factory()->post->create(
     36                $this->posts[] = self::factory()->post->create_and_get(
    3737                        array(
    3838                                'post_type'   => 'post',
    3939                                'post_date'   => '2014-10-26 02:32:29',
    4040                                'category_id' => $this->cat_id,
    4141                        )
    4242                );
    43                 $this->post_ids[] = self::factory()->post->create(
     43                $this->posts[] = self::factory()->post->create_and_get(
    4444                        array(
    4545                                'post_type'   => 'post',
    4646                                'post_date'   => '2014-10-26 01:32:29',
    class Tests_Link_GetAdjacentPostLink extends WP_UnitTestCase { 
    5050
    5151                //set current post (has 2 on each end)
    5252                global $GLOBALS;
    53                 $GLOBALS['post'] = get_post( $this->post_ids[2] );
     53                $GLOBALS['post'] = $this->posts[2];
    5454        }
    5555
    5656        public function test_get_next_post_link_default() {
    57                 $actual   = get_next_post_link();
    58                 $title    = get_post( $this->post_ids[1] )->post_title;
    59                 $expected = '<a href="' . home_url( '?p=' . $this->post_ids[1] ) . '" rel="next">' . $title . '</a> &raquo;';
    60                 $this->assertSame( $expected, $actual );
     57                $this->assertSame(
     58                        '<a href="' .  get_permalink( $this->posts[1] ) . '" rel="next">' . $this->posts[1]->post_title . '</a> &raquo;',
     59                        get_next_post_link()
     60                );
    6161        }
    6262
    6363        public function test_get_previous_post_link_default() {
    64                 $actual   = get_previous_post_link();
    65                 $title    = get_post( $this->post_ids[3] )->post_title;
    66                 $expected = '&laquo; <a href="' . home_url( '?p=' . $this->post_ids[3] ) . '" rel="prev">' . $title . '</a>';
    67                 $this->assertSame( $expected, $actual );
     64                $this->assertSame(
     65                        '&laquo; <a href="' . get_permalink( $this->posts[3] ) . '" rel="prev">' . $this->posts[3]->post_title  . '</a>',
     66                        get_previous_post_link()
     67                );
    6868        }
    6969
    7070        public function test_get_next_post_link_same_category() {
    71                 $actual   = get_next_post_link( '%link &raquo;', '%title', true );
    72                 $title    = get_post( $this->post_ids[1] )->post_title;
    73                 $expected = '<a href="' . home_url( '?p=' . $this->post_ids[1] ) . '" rel="next">' . $title . '</a> &raquo;';
    74                 $this->assertSame( $expected, $actual );
     71                $this->assertSame(
     72                        '<a href="' .  get_permalink( $this->posts[1] ) . '" rel="next">' . $this->posts[1]->post_title . '</a> &raquo;',
     73                        get_next_post_link( '%link &raquo;', '%title', true )
     74                );
    7575        }
    7676
    7777        public function test_get_previous_post_link_same_category() {
    78                 $actual   = get_previous_post_link( '&laquo; %link', '%title', true );
    79                 $title    = get_post( $this->post_ids[3] )->post_title;
    80                 $expected = '&laquo; <a href="' . home_url( '?p=' . $this->post_ids[3] ) . '" rel="prev">' . $title . '</a>';
    81                 $this->assertSame( $expected, $actual );
     78                $this->assertSame(
     79                        '&laquo; <a href="' . get_permalink( $this->posts[3] ) . '" rel="prev">' . $this->posts[3]->post_title  . '</a>',
     80                        get_previous_post_link( '&laquo; %link', '%title', true )
     81                );
    8282        }
    8383
    8484        public function test_get_next_post_link_exclude_category() {
    85                 $actual   = get_next_post_link( '%link &raquo;', '%title', false, $this->cat_id );
    86                 $title    = get_post( $this->post_ids[1] )->post_title;
    87                 $expected = '<a href="' . home_url( '?p=' . $this->post_ids[1] ) . '" rel="next">' . $title . '</a> &raquo;';
    88                 $this->assertSame( $expected, $actual );
     85                $this->assertSame(
     86                        '<a href="' .  get_permalink( $this->posts[1] ) . '" rel="next">' . $this->posts[1]->post_title . '</a> &raquo;',
     87                        get_next_post_link( '%link &raquo;', '%title', false, $this->cat_id )
     88                );
     89
    8990        }
    9091
    9192        public function test_get_previous_post_link_exclude_category() {
    92                 $actual   = get_previous_post_link( '&laquo; %link', '%title', false, $this->cat_id );
    93                 $title    = get_post( $this->post_ids[3] )->post_title;
    94                 $expected = '&laquo; <a href="' . home_url( '?p=' . $this->post_ids[3] ) . '" rel="prev">' . $title . '</a>';
    95                 $this->assertSame( $expected, $actual );
     93                $this->assertSame(
     94                        '&laquo; <a href="' . get_permalink( $this->posts[3] ) . '" rel="prev">' . $this->posts[3]->post_title  . '</a>',
     95                        get_previous_post_link( '&laquo; %link', '%title', false, $this->cat_id )
     96                );
    9697        }
    9798}
  • tests/phpunit/tests/link/getNextCommentsLink.php

    diff --git tests/phpunit/tests/link/getNextCommentsLink.php tests/phpunit/tests/link/getNextCommentsLink.php
    index 204b2057ff..1d1229ad4a 100644
    class Tests_Link_GetNextCommentsLink extends WP_UnitTestCase { 
    1616
    1717                $link = get_next_comments_link( 'Next', 5 );
    1818
    19                 $this->assertContains( 'cpage=4', $link );
     19                $this->assertContains( 'comment-page-4', $link );
    2020
    2121                set_query_var( 'cpage', $cpage );
    2222        }
    class Tests_Link_GetNextCommentsLink extends WP_UnitTestCase { 
    3333
    3434                $link = get_next_comments_link( 'Next', 5 );
    3535
    36                 $this->assertContains( 'cpage=2', $link );
     36                $this->assertContains( 'comment-page-2', $link );
    3737
    3838                set_query_var( 'cpage', $cpage );
    3939        }
  • tests/phpunit/tests/link/getPostCommentsFeedLink.php

    diff --git tests/phpunit/tests/link/getPostCommentsFeedLink.php tests/phpunit/tests/link/getPostCommentsFeedLink.php
    index 986205db12..c887b099e2 100644
     
    55class Tests_Link_GetPostCommentsFeedLink extends WP_UnitTestCase {
    66
    77        public function test_post_link() {
     8                tests_set_and_flush_permalinks( '' );
     9
    810                $post_id = self::factory()->post->create();
    911
    1012                $link     = get_post_comments_feed_link( $post_id );
    class Tests_Link_GetPostCommentsFeedLink extends WP_UnitTestCase { 
    1618                );
    1719
    1820                $this->assertEquals( $expected, $link );
     21
     22                tests_reset_and_flush_permalinks();
    1923        }
    2024
    2125        public function test_post_pretty_link() {
    22                 $this->set_permalink_structure( '/%year%/%monthnum%/%day%/%postname%/' );
    23 
    2426                $post_id = self::factory()->post->create();
    2527
    2628                $link     = get_post_comments_feed_link( $post_id );
    class Tests_Link_GetPostCommentsFeedLink extends WP_UnitTestCase { 
    3032        }
    3133
    3234        public function test_attachment_link() {
     35                tests_set_and_flush_permalinks( '' );
     36
    3337                $post_id       = self::factory()->post->create();
    3438                $attachment_id = self::factory()->attachment->create_object(
    3539                        'image.jpg', $post_id, array(
    class Tests_Link_GetPostCommentsFeedLink extends WP_UnitTestCase { 
    4751                );
    4852
    4953                $this->assertEquals( $expected, $link );
     54
     55                tests_reset_and_flush_permalinks();
    5056        }
    5157
    5258        public function test_attachment_pretty_link() {
    53                 $this->set_permalink_structure( '/%year%/%monthnum%/%day%/%postname%/' );
    54 
    5559                $post_id       = self::factory()->post->create(
    5660                        array(
    5761                                'post_status' => 'publish',
    class Tests_Link_GetPostCommentsFeedLink extends WP_UnitTestCase { 
    7478        }
    7579
    7680        public function test_attachment_no_name_pretty_link() {
    77                 $this->set_permalink_structure( '/%year%/%monthnum%/%day%/%postname%/' );
    78 
    7981                $post_id       = self::factory()->post->create();
    8082                $attachment_id = self::factory()->attachment->create_object(
    8183                        'image.jpg', $post_id, array(
    class Tests_Link_GetPostCommentsFeedLink extends WP_UnitTestCase { 
    9193        }
    9294
    9395        public function test_unattached_link() {
     96                tests_set_and_flush_permalinks( '' );
     97
    9498                $attachment_id = self::factory()->attachment->create_object(
    9599                        'image.jpg', 0, array(
    96100                                'post_mime_type' => 'image/jpeg',
    class Tests_Link_GetPostCommentsFeedLink extends WP_UnitTestCase { 
    107111                );
    108112
    109113                $this->assertEquals( $expected, $link );
     114
     115                tests_reset_and_flush_permalinks();
    110116        }
    111117
    112118        public function test_unattached_pretty_link() {
    113                 $this->set_permalink_structure( '/%year%/%monthnum%/%day%/%postname%/' );
    114 
    115119                $attachment_id = self::factory()->attachment->create_object(
    116120                        'image.jpg', 0, array(
    117121                                'post_mime_type' => 'image/jpeg',
  • tests/phpunit/tests/link/getPreviousCommentsLink.php

    diff --git tests/phpunit/tests/link/getPreviousCommentsLink.php tests/phpunit/tests/link/getPreviousCommentsLink.php
    index ff4c088dea..073eaf60a3 100644
    class Tests_Link_GetPreviousCommentsLink extends WP_UnitTestCase { 
    1616
    1717                $link = get_previous_comments_link( 'Next' );
    1818
    19                 $this->assertContains( 'cpage=2', $link );
     19                $this->assertContains( 'comment-page-2', $link );
    2020
    2121                set_query_var( 'cpage', $cpage );
    2222        }
  • tests/phpunit/tests/link/wpGetCanonicalURL.php

    diff --git tests/phpunit/tests/link/wpGetCanonicalURL.php tests/phpunit/tests/link/wpGetCanonicalURL.php
    index 5a9637a9ca..91aff0b94d 100644
    class Tests_WpGetCanonicalURL extends WP_UnitTestCase { 
    1616                );
    1717        }
    1818
     19        public static function wpTearDownAfterClass() {
     20                tests_reset_and_flush_permalinks();
     21        }
     22
    1923        /**
    2024         * Test for a non existing post.
    2125         */
    class Tests_WpGetCanonicalURL extends WP_UnitTestCase { 
    4751         * Test non permalink structure page usage.
    4852         */
    4953        public function test_paged_with_plain_permalink_structure() {
     54                tests_set_and_flush_permalinks( '' );
     55
    5056                $link = add_query_arg(
    5157                        array(
    5258                                'page' => 2,
    class Tests_WpGetCanonicalURL extends WP_UnitTestCase { 
    6369                );
    6470
    6571                $this->assertEquals( $expected, wp_get_canonical_url( self::$post_id ) );
     72
     73                tests_reset_and_flush_permalinks();
    6674        }
    6775
    6876        /**
    class Tests_WpGetCanonicalURL extends WP_UnitTestCase { 
    7078         */
    7179        public function test_paged_with_custom_permalink_structure() {
    7280                $this->set_permalink_structure( '/%postname%/' );
     81
    7382                $page = 2;
    7483
    7584                $link = add_query_arg(
    class Tests_WpGetCanonicalURL extends WP_UnitTestCase { 
    8493                $expected = trailingslashit( get_permalink( self::$post_id ) ) . user_trailingslashit( $page, 'single_paged' );
    8594
    8695                $this->assertEquals( $expected, wp_get_canonical_url( self::$post_id ) );
     96
     97                tests_reset_and_flush_permalinks();
    8798        }
    8899
    89100        /**
    90101         *  Test non permalink structure comment page usage.
    91102         */
    92103        public function test_comments_paged_with_plain_permalink_structure() {
     104                tests_set_and_flush_permalinks( '' );
     105
    93106                $cpage = 2;
    94107
    95108                $link = add_query_arg(
    class Tests_WpGetCanonicalURL extends WP_UnitTestCase { 
    108121                );
    109122
    110123                $this->assertEquals( $expected, wp_get_canonical_url( self::$post_id ) );
     124                tests_reset_and_flush_permalinks();
    111125        }
    112126
    113127        /**
    class Tests_WpGetCanonicalURL extends WP_UnitTestCase { 
    116130        public function test_comments_paged_with_pretty_permalink_structure() {
    117131                global $wp_rewrite;
    118132
    119                 $this->set_permalink_structure( '/%postname%/' );
    120133                $cpage = 2;
    121134
    122135                $link = add_query_arg(
  • tests/phpunit/tests/oembed/controller.php

    diff --git tests/phpunit/tests/oembed/controller.php tests/phpunit/tests/oembed/controller.php
    index 0d91408769..2a4d02a6d1 100644
    class Test_oEmbed_Controller extends WP_UnitTestCase { 
    446446        }
    447447
    448448        function test_get_oembed_endpoint_url() {
     449                tests_set_and_flush_permalinks( '' );
     450
    449451                $this->assertEquals( home_url() . '/index.php?rest_route=/oembed/1.0/embed', get_oembed_endpoint_url() );
    450452                $this->assertEquals( home_url() . '/index.php?rest_route=/oembed/1.0/embed', get_oembed_endpoint_url( '', 'json' ) );
    451453                $this->assertEquals( home_url() . '/index.php?rest_route=/oembed/1.0/embed', get_oembed_endpoint_url( '', 'xml' ) );
    class Test_oEmbed_Controller extends WP_UnitTestCase { 
    456458
    457459                $this->assertEquals( home_url() . '/index.php?rest_route=%2Foembed%2F1.0%2Fembed&url=' . $url_encoded, get_oembed_endpoint_url( $url ) );
    458460                $this->assertEquals( home_url() . '/index.php?rest_route=%2Foembed%2F1.0%2Fembed&url=' . $url_encoded . '&format=xml', get_oembed_endpoint_url( $url, 'xml' ) );
     461
     462                tests_reset_and_flush_permalinks();
    459463        }
    460464
    461465        function test_get_oembed_endpoint_url_pretty_permalinks() {
    462                 update_option( 'permalink_structure', '/%postname%' );
    463 
    464466                $this->assertEquals( home_url() . '/wp-json/oembed/1.0/embed', get_oembed_endpoint_url() );
    465467                $this->assertEquals( home_url() . '/wp-json/oembed/1.0/embed', get_oembed_endpoint_url( '', 'xml' ) );
    466468
    class Test_oEmbed_Controller extends WP_UnitTestCase { 
    470472
    471473                $this->assertEquals( home_url() . '/wp-json/oembed/1.0/embed?url=' . $url_encoded, get_oembed_endpoint_url( $url ) );
    472474                $this->assertEquals( home_url() . '/wp-json/oembed/1.0/embed?url=' . $url_encoded . '&format=xml', get_oembed_endpoint_url( $url, 'xml' ) );
    473 
    474                 update_option( 'permalink_structure', '' );
    475475        }
    476476
    477477        public function test_proxy_without_permission() {
  • tests/phpunit/tests/oembed/postEmbedUrl.php

    diff --git tests/phpunit/tests/oembed/postEmbedUrl.php tests/phpunit/tests/oembed/postEmbedUrl.php
    index e6c478f26f..52a9982e43 100644
    class Tests_Post_Embed_URL extends WP_UnitTestCase { 
    1010        }
    1111
    1212        function test_with_pretty_permalinks() {
    13                 $this->set_permalink_structure( '/%postname%' );
    14 
    1513                $post_id   = self::factory()->post->create();
    1614                $permalink = get_permalink( $post_id );
    1715                $embed_url = get_post_embed_url( $post_id );
    1816
    19                 $this->assertEquals( $permalink . '/embed', $embed_url );
     17                $this->assertEquals( $permalink . 'embed/', $embed_url );
    2018        }
    2119
    2220        function test_with_ugly_permalinks() {
     21                tests_set_and_flush_permalinks( '' );
     22
    2323                $post_id   = self::factory()->post->create();
    2424                $permalink = get_permalink( $post_id );
    2525                $embed_url = get_post_embed_url( $post_id );
    2626
    2727                $this->assertEquals( $permalink . '&embed=true', $embed_url );
     28
     29                tests_reset_and_flush_permalinks();
    2830        }
    2931
    3032        /**
    class Tests_Post_Embed_URL extends WP_UnitTestCase { 
    4345                $this->assertSame( user_trailingslashit( trailingslashit( home_url() ) . 'embed' ), $embed_url );
    4446
    4547                update_option( 'show_on_front', 'posts' );
     48
     49                tests_reset_and_flush_permalinks();
    4650        }
    4751
    4852        /**
    4953         * @ticket 34971
    5054         */
    5155        function test_static_front_page_with_ugly_permalinks() {
     56                tests_set_and_flush_permalinks( '' );
     57
    5258                $post_id = self::factory()->post->create( array( 'post_type' => 'page' ) );
    5359
    5460                update_option( 'show_on_front', 'page' );
    class Tests_Post_Embed_URL extends WP_UnitTestCase { 
    5965                $this->assertSame( trailingslashit( home_url() ) . '?embed=true', $embed_url );
    6066
    6167                update_option( 'show_on_front', 'posts' );
     68                tests_reset_and_flush_permalinks();
    6269        }
    6370
    6471        /**
    6572         * @ticket 34971
    6673         */
    6774        function test_page_conflicts_with_embed_slug() {
    68                 $this->set_permalink_structure( '/%postname%/' );
    69 
    7075                $parent_page = self::factory()->post->create( array( 'post_type' => 'page' ) );
    7176
    7277                add_filter( 'wp_unique_post_slug', array( $this, 'filter_unique_post_slug' ) );
    class Tests_Post_Embed_URL extends WP_UnitTestCase { 
    8792         * @ticket 34971
    8893         */
    8994        function test_static_front_page_conflicts_with_embed_slug() {
    90                 $this->set_permalink_structure( '/%postname%/' );
    91 
    9295                // Create a post with the 'embed' post_name
    9396                add_filter( 'wp_unique_post_slug', array( $this, 'filter_unique_post_slug' ) );
    9497                $post_embed_slug = self::factory()->post->create( array( 'post_name' => 'embed' ) );
    class Tests_Post_Embed_URL extends WP_UnitTestCase { 
    98101                update_option( 'show_on_front', 'page' );
    99102                update_option( 'page_on_front', $page_front );
    100103
    101                 $this->assertSame( home_url() . '/embed/embed/', get_post_embed_url( $post_embed_slug ) );
     104                $expected = home_url() . '/' . tests_add_blog_permalink_prefix_on_multisite( date( 'Y/m/d', time() ) . '/embed/embed/' );
     105
     106                $this->assertSame( $expected, get_post_embed_url( $post_embed_slug ) );
    102107                $this->assertSame( home_url() . '/?embed=true', get_post_embed_url( $page_front ) );
    103108
    104109                update_option( 'show_on_front', 'posts' );
  • tests/phpunit/tests/oembed/template.php

    diff --git tests/phpunit/tests/oembed/template.php tests/phpunit/tests/oembed/template.php
    index cfe9b1ee03..dcce5a84e5 100644
    class Tests_Embed_Template extends WP_UnitTestCase { 
    106106                $this->assertNotFalse( strpos( $actual, 'canola.jpg' ) );
    107107        }
    108108
     109        /**
     110         * This tests fails with pretty permalinks enabled, see #42733.
     111         */
    109112        function test_oembed_output_draft_post() {
     113                tests_set_and_flush_permalinks( '' );
     114
    110115                $post_id = self::factory()->post->create(
    111116                        array(
    112117                                'post_title'   => 'Hello World',
    class Tests_Embed_Template extends WP_UnitTestCase { 
    127132                $doc = new DOMDocument();
    128133                $this->assertTrue( $doc->loadHTML( $actual ) );
    129134                $this->assertNotFalse( strpos( $actual, 'That embed can&#8217;t be found.' ) );
     135
     136                tests_reset_and_flush_permalinks();
    130137        }
    131138
     139        /**
     140         * This tests fails with pretty permalinks enabled, see #42733.
     141         */
    132142        function test_oembed_output_scheduled_post() {
     143                tests_set_and_flush_permalinks( '' );
     144
    133145                $post_id = self::factory()->post->create(
    134146                        array(
    135147                                'post_title'   => 'Hello World',
    class Tests_Embed_Template extends WP_UnitTestCase { 
    151163                $doc = new DOMDocument();
    152164                $this->assertTrue( $doc->loadHTML( $actual ) );
    153165                $this->assertNotFalse( strpos( $actual, 'That embed can&#8217;t be found.' ) );
     166
     167                tests_reset_and_flush_permalinks();
    154168        }
    155169
    156170        function test_oembed_output_private_post() {
  • tests/phpunit/tests/oembed/wpOembed.php

    diff --git tests/phpunit/tests/oembed/wpOembed.php tests/phpunit/tests/oembed/wpOembed.php
    index c148dd555c..e141e06167 100644
    class Tests_WP_oEmbed extends WP_UnitTestCase { 
    159159         * @group ms-required
    160160         */
    161161        public function test_wp_filter_pre_oembed_result_multisite_sub_main() {
     162                // This test fails with pretty permalinks enabled.
     163                tests_set_and_flush_permalinks( '' );
     164
    162165                $post_id   = self::factory()->post->create();
    163166                $permalink = get_permalink( $post_id );
    164167                $user_id   = self::factory()->user->create();
    class Tests_WP_oEmbed extends WP_UnitTestCase { 
    178181
    179182                $this->assertNotNull( $this->pre_oembed_result_filtered );
    180183                $this->assertEquals( $this->pre_oembed_result_filtered, $actual );
     184
     185                tests_reset_and_flush_permalinks();
    181186        }
    182187
    183188        /**
  • tests/phpunit/tests/option/sanitize-option.php

    diff --git tests/phpunit/tests/option/sanitize-option.php tests/phpunit/tests/option/sanitize-option.php
    index be10216364..b00a8a4c28 100644
    class Tests_Sanitize_Option extends WP_UnitTestCase { 
    145145        }
    146146
    147147        public function permalink_structure_provider() {
     148                $default_permalink_structure = get_option( 'permalink_structure' );
     149
    148150                return array(
    149151                        array( '', '', true ),
    150                         array( '%postname', false, false ),
    151                         array( '%/%', false, false ),
    152                         array( '%%%', false, false ),
     152                        array( '%postname', $default_permalink_structure, false ),
     153                        array( '%/%', $default_permalink_structure, false ),
     154                        array( '%%%', $default_permalink_structure, false ),
    153155                        array( '%a%', '%a%', true ),
    154156                        array( '%postname%', '%postname%', true ),
    155157                        array( '/%postname%/', '/%postname%/', true ),
  • tests/phpunit/tests/post.php

    diff --git tests/phpunit/tests/post.php tests/phpunit/tests/post.php
    index c0b20bb2a7..1bcfe5e726 100644
    class Tests_Post extends WP_UnitTestCase { 
    434434         * @ticket 5305
    435435         */
    436436        public function test_wp_insert_post_should_not_allow_a_bare_numeric_slug_that_might_conflict_with_a_date_archive_when_generating_from_an_empty_post_title() {
     437
    437438                $this->set_permalink_structure( '/%postname%/' );
    438439
    439440                $p = wp_insert_post(
    class Tests_Post extends WP_UnitTestCase { 
    447448
    448449                $post = get_post( $p );
    449450
    450                 $this->set_permalink_structure();
    451 
    452451                $this->assertEquals( "$p-2", $post->post_name );
     452                tests_reset_and_flush_permalinks();
    453453        }
    454454
    455455        /**
    class Tests_Post extends WP_UnitTestCase { 
    469469
    470470                $post = get_post( $p );
    471471
    472                 $this->assertContains( 'wptests_pt=' . $p, $post->guid );
     472                $this->assertContains( 'wptests_pt/' . $p, $post->guid );
    473473        }
    474474
    475475        /**
    class Tests_Post extends WP_UnitTestCase { 
    526526        function test_permalink_without_title() {
    527527                // bug: permalink doesn't work if post title is empty
    528528                // might only fail if the post ID is greater than four characters
    529 
    530                 $this->set_permalink_structure( '/%year%/%monthnum%/%day%/%postname%/' );
    531 
    532529                $post = array(
    533530                        'post_author'  => self::$editor_id,
    534531                        'post_status'  => 'publish',
    class Tests_Post extends WP_UnitTestCase { 
    543540                $plink = get_permalink( $id );
    544541
    545542                // permalink should include the post ID at the end
    546                 $this->assertEquals( get_option( 'siteurl' ) . '/2007/10/31/' . $id . '/', $plink );
     543                $this->assertEquals(
     544                        get_option( 'siteurl' ) . '/' . tests_add_blog_permalink_prefix_on_multisite( '2007/10/31/' . $id . '/' ),
     545                        $plink
     546                );
    547547        }
    548548
    549549        /**
  • tests/phpunit/tests/post/nav-menu.php

    diff --git tests/phpunit/tests/post/nav-menu.php tests/phpunit/tests/post/nav-menu.php
    index 17844f461e..5268a6a4c4 100644
    class Test_Nav_Menus extends WP_UnitTestCase { 
    687687         * @ticket 39800
    688688         */
    689689        function test_parent_ancestor_for_post_archive() {
     690                // This test only works without pretty permalinks.
     691                tests_set_and_flush_permalinks( '' );
    690692
    691693                register_post_type(
    692694                        'books', array(
    class Test_Nav_Menus extends WP_UnitTestCase { 
    760762
    761763                $this->assertNotContains( 'current-menu-parent', $post_archive_menu_item->classes );
    762764                $this->assertNotContains( 'current-menu-ancestor', $post_archive_menu_item->classes );
     765
     766                tests_reset_and_flush_permalinks();
    763767        }
    764768
    765769}
  • tests/phpunit/tests/post/types.php

    diff --git tests/phpunit/tests/post/types.php tests/phpunit/tests/post/types.php
    index 393e5080b3..df17c08f5e 100644
    class Tests_Post_Types extends WP_UnitTestCase { 
    313313         * @ticket 14761
    314314         */
    315315        public function test_unregister_post_type_removes_rewrite_tags() {
    316                 $this->set_permalink_structure( '/%postname%' );
    317 
    318316                global $wp_rewrite;
    319317
    320318                register_post_type(
    class Tests_Post_Types extends WP_UnitTestCase { 
    338336         * @ticket 14761
    339337         */
    340338        public function test_unregister_post_type_removes_rewrite_rules() {
    341                 $this->set_permalink_structure( '/%postname%' );
    342 
    343339                global $wp_rewrite;
    344340
    345341                register_post_type(
  • tests/phpunit/tests/post/wpPostType.php

    diff --git tests/phpunit/tests/post/wpPostType.php tests/phpunit/tests/post/wpPostType.php
    index 0cf98902c1..77a3ff70a3 100644
    class Tests_WP_Post_Type extends WP_UnitTestCase { 
    6060        }
    6161
    6262        public function test_does_not_add_query_var_if_not_public() {
    63                 $this->set_permalink_structure( '/%postname%' );
    64 
    6563                /* @var WP $wp */
    6664                global $wp;
    6765
    class Tests_WP_Post_Type extends WP_UnitTestCase { 
    7876        }
    7977
    8078        public function test_adds_query_var_if_public() {
    81                 $this->set_permalink_structure( '/%postname%' );
    82 
    8379                /* @var WP $wp */
    8480                global $wp;
    8581
    class Tests_WP_Post_Type extends WP_UnitTestCase { 
    10399        }
    104100
    105101        public function test_adds_rewrite_rules() {
    106                 $this->set_permalink_structure( '/%postname%' );
    107 
    108102                /* @var WP_Rewrite $wp_rewrite */
    109103                global $wp_rewrite;
    110104
  • tests/phpunit/tests/post/wpUniquePostSlug.php

    diff --git tests/phpunit/tests/post/wpUniquePostSlug.php tests/phpunit/tests/post/wpUniquePostSlug.php
    index 575bec4fa4..da2576c90c 100644
    class Tests_Post_WpUniquePostSlug extends WP_UnitTestCase { 
    179179         * @ticket 5305
    180180         */
    181181        public function test_slugs_resulting_in_permalinks_that_resemble_year_archives_should_be_suffixed() {
     182
    182183                $this->set_permalink_structure( '/%postname%/' );
    183184
    184185                $p = self::factory()->post->create(
    class Tests_Post_WpUniquePostSlug extends WP_UnitTestCase { 
    190191
    191192                $found = wp_unique_post_slug( '2015', $p, 'publish', 'post', 0 );
    192193                $this->assertEquals( '2015-2', $found );
     194
     195                tests_reset_and_flush_permalinks();
    193196        }
    194197
    195198        /**
    196199         * @ticket 5305
    197200         */
    198201        public function test_slugs_resulting_in_permalinks_that_resemble_year_archives_should_not_be_suffixed_for_already_published_posts() {
     202
    199203                $this->set_permalink_structure( '/%postname%/' );
    200204
    201205                $p = self::factory()->post->create(
    class Tests_Post_WpUniquePostSlug extends WP_UnitTestCase { 
    208212
    209213                $found = wp_unique_post_slug( '2015', $p, 'publish', 'post', 0 );
    210214                $this->assertEquals( '2015-2', $found );
     215
     216                tests_reset_and_flush_permalinks();
    211217        }
    212218
    213219        /**
    214220         * @ticket 5305
    215221         */
    216222        public function test_yearlike_slugs_should_not_be_suffixed_if_permalink_structure_does_not_result_in_a_clash_with_year_archives() {
     223
    217224                $this->set_permalink_structure( '/%year%/%postname%/' );
    218225
    219226                $p = self::factory()->post->create(
    class Tests_Post_WpUniquePostSlug extends WP_UnitTestCase { 
    225232
    226233                $found = wp_unique_post_slug( '2015', $p, 'publish', 'post', 0 );
    227234                $this->assertEquals( '2015', $found );
     235
     236                tests_reset_and_flush_permalinks();
    228237        }
    229238
    230239        /**
    231240         * @ticket 5305
    232241         */
    233242        public function test_slugs_resulting_in_permalinks_that_resemble_month_archives_should_be_suffixed() {
     243
    234244                $this->set_permalink_structure( '/%year%/%postname%/' );
    235245
    236246                $p = self::factory()->post->create(
    class Tests_Post_WpUniquePostSlug extends WP_UnitTestCase { 
    242252
    243253                $found = wp_unique_post_slug( '11', $p, 'publish', 'post', 0 );
    244254                $this->assertEquals( '11-2', $found );
     255
     256                tests_reset_and_flush_permalinks();
    245257        }
    246258
    247259        /**
    248260         * @ticket 5305
    249261         */
    250262        public function test_monthlike_slugs_should_not_be_suffixed_if_permalink_structure_does_not_result_in_a_clash_with_month_archives() {
     263
    251264                $this->set_permalink_structure( '/%year%/foo/%postname%/' );
    252265
    253266                $p = self::factory()->post->create(
    class Tests_Post_WpUniquePostSlug extends WP_UnitTestCase { 
    259272
    260273                $found = wp_unique_post_slug( '11', $p, 'publish', 'post', 0 );
    261274                $this->assertEquals( '11', $found );
     275
     276                tests_reset_and_flush_permalinks();
    262277        }
    263278
    264279        /**
    265280         * @ticket 5305
    266281         */
    267282        public function test_monthlike_slugs_should_not_be_suffixed_for_invalid_month_numbers() {
     283
    268284                $this->set_permalink_structure( '/%year%/%postname%/' );
    269285
    270286                $p = self::factory()->post->create(
    class Tests_Post_WpUniquePostSlug extends WP_UnitTestCase { 
    276292
    277293                $found = wp_unique_post_slug( '13', $p, 'publish', 'post', 0 );
    278294                $this->assertEquals( '13', $found );
     295
     296                tests_reset_and_flush_permalinks();
    279297        }
    280298
    281299        /**
    282300         * @ticket 5305
    283301         */
    284302        public function test_slugs_resulting_in_permalinks_that_resemble_day_archives_should_be_suffixed() {
     303
    285304                $this->set_permalink_structure( '/%year%/%monthnum%/%postname%/' );
    286305
    287306                $p = self::factory()->post->create(
    class Tests_Post_WpUniquePostSlug extends WP_UnitTestCase { 
    293312
    294313                $found = wp_unique_post_slug( '30', $p, 'publish', 'post', 0 );
    295314                $this->assertEquals( '30-2', $found );
     315
     316                tests_reset_and_flush_permalinks();
    296317        }
    297318
    298319        /**
    299320         * @ticket 5305
    300321         */
    301322        public function test_daylike_slugs_should_not_be_suffixed_if_permalink_structure_does_not_result_in_a_clash_with_day_archives() {
     323
    302324                $this->set_permalink_structure( '/%year%/%monthnum%/%day%/%postname%/' );
    303325
    304326                $p = self::factory()->post->create(
    class Tests_Post_WpUniquePostSlug extends WP_UnitTestCase { 
    310332
    311333                $found = wp_unique_post_slug( '30', $p, 'publish', 'post', 0 );
    312334                $this->assertEquals( '30', $found );
     335
     336                tests_reset_and_flush_permalinks();
    313337        }
    314338
    315339        /**
    316340         * @ticket 5305
    317341         */
    318342        public function test_daylike_slugs_should_not_be_suffixed_for_invalid_day_numbers() {
     343
    319344                $this->set_permalink_structure( '/%year%/%monthnum%/%postname%/' );
    320345
    321346                $p = self::factory()->post->create(
    class Tests_Post_WpUniquePostSlug extends WP_UnitTestCase { 
    327352
    328353                $found = wp_unique_post_slug( '32', $p, 'publish', 'post', 0 );
    329354                $this->assertEquals( '32', $found );
     355
     356                tests_reset_and_flush_permalinks();
    330357        }
    331358
    332359        /**
    333360         * @ticket 34971
    334361         */
    335362        public function test_embed_slug_should_be_suffixed_for_posts() {
     363
    336364                $this->set_permalink_structure( '/%postname%/' );
    337365
    338366                $p = self::factory()->post->create(
    class Tests_Post_WpUniquePostSlug extends WP_UnitTestCase { 
    344372
    345373                $found = wp_unique_post_slug( 'embed', $p, 'publish', 'post', 0 );
    346374                $this->assertSame( 'embed-2', $found );
     375
     376                tests_reset_and_flush_permalinks();
    347377        }
    348378
    349379        /**
    350380         * @ticket 34971
    351381         */
    352382        public function test_embed_slug_should_be_suffixed_for_pages() {
     383
    353384                $this->set_permalink_structure( '/%postname%/' );
    354385
    355386                $p = self::factory()->post->create(
    class Tests_Post_WpUniquePostSlug extends WP_UnitTestCase { 
    361392
    362393                $found = wp_unique_post_slug( 'embed', $p, 'publish', 'paage', 0 );
    363394                $this->assertSame( 'embed-2', $found );
     395
     396                tests_reset_and_flush_permalinks();
    364397        }
    365398
    366399        /**
    367400         * @ticket 34971
    368401         */
    369402        public function test_embed_slug_should_be_suffixed_for_attachments() {
     403
    370404                $this->set_permalink_structure( '/%postname%/' );
    371405
    372406                $p = self::factory()->post->create(
    class Tests_Post_WpUniquePostSlug extends WP_UnitTestCase { 
    378412
    379413                $found = wp_unique_post_slug( 'embed', $p, 'publish', 'attachment', 0 );
    380414                $this->assertSame( 'embed-2', $found );
     415
     416                tests_reset_and_flush_permalinks();
    381417        }
    382418}
  • tests/phpunit/tests/query.php

    diff --git tests/phpunit/tests/query.php tests/phpunit/tests/query.php
    index 32f3603537..fb4a0a8ce8 100644
    class Tests_Query extends WP_UnitTestCase { 
    55        function setUp() {
    66                parent::setUp();
    77
    8                 $this->set_permalink_structure( '/%year%/%monthnum%/%day%/%postname%/' );
    98                create_initial_taxonomies();
    109        }
    1110
  • tests/phpunit/tests/query/conditionals.php

    diff --git tests/phpunit/tests/query/conditionals.php tests/phpunit/tests/query/conditionals.php
    index 081adf2962..818f9ca4a4 100644
    class Tests_Query_Conditionals extends WP_UnitTestCase { 
    2222                update_option( 'comments_per_page', 5 );
    2323                update_option( 'posts_per_page', 5 );
    2424
    25                 $this->set_permalink_structure( '/%year%/%monthnum%/%day%/%postname%/' );
    26 
    2725                create_initial_taxonomies();
    2826        }
    2927
    class Tests_Query_Conditionals extends WP_UnitTestCase { 
    490488                // check the long form
    491489                $types = array( 'feed', 'rdf', 'rss', 'rss2', 'atom' );
    492490                foreach ( $types as $type ) {
    493                         $this->go_to( "/category/cat-a/feed/{$type}" );
     491                        $this->go_to( tests_add_blog_permalink_prefix_on_multisite( "category/cat-a/feed/{$type}" ) );
    494492                        $this->assertQueryTrue( 'is_archive', 'is_feed', 'is_category' );
    495493                }
    496494
    497495                // check the short form
    498496                $types = array( 'feed', 'rdf', 'rss', 'rss2', 'atom' );
    499497                foreach ( $types as $type ) {
    500                         $this->go_to( "/category/cat-a/{$type}" );
     498                        $this->go_to( tests_add_blog_permalink_prefix_on_multisite( "category/cat-a/{$type}" ) );
    501499                        $this->assertQueryTrue( 'is_archive', 'is_feed', 'is_category' );
    502500                }
    503501        }
    class Tests_Query_Conditionals extends WP_UnitTestCase { 
    506504        function test_category_paged() {
    507505                update_option( 'posts_per_page', 2 );
    508506                self::factory()->post->create_many( 3 );
    509                 $this->go_to( '/category/uncategorized/page/2/' );
     507                $this->go_to( tests_add_blog_permalink_prefix_on_multisite( 'category/uncategorized/page/2/' ) );
    510508                $this->assertQueryTrue( 'is_archive', 'is_category', 'is_paged' );
    511509        }
    512510
    class Tests_Query_Conditionals extends WP_UnitTestCase { 
    518516                                'taxonomy' => 'category',
    519517                        )
    520518                );
    521                 $this->go_to( '/category/cat-a/' );
     519                $this->go_to( tests_add_blog_permalink_prefix_on_multisite( 'category/cat-a/' ) );
    522520                $this->assertQueryTrue( 'is_archive', 'is_category' );
    523521        }
    524522
    class Tests_Query_Conditionals extends WP_UnitTestCase { 
    534532                // check the long form
    535533                $types = array( 'feed', 'rdf', 'rss', 'rss2', 'atom' );
    536534                foreach ( $types as $type ) {
    537                                 $this->go_to( "/tag/tag-a/feed/{$type}" );
     535                                $this->go_to( tests_add_blog_permalink_prefix_on_multisite( "tag/tag-a/feed/{$type}" ) );
    538536                                $this->assertQueryTrue( 'is_archive', 'is_feed', 'is_tag' );
    539537                }
    540538
    541539                // check the short form
    542540                $types = array( 'feed', 'rdf', 'rss', 'rss2', 'atom' );
    543541                foreach ( $types as $type ) {
    544                                 $this->go_to( "/tag/tag-a/{$type}" );
     542                                $this->go_to( tests_add_blog_permalink_prefix_on_multisite( "tag/tag-a/{$type}" ) );
    545543                                $this->assertQueryTrue( 'is_archive', 'is_feed', 'is_tag' );
    546544                }
    547545        }
    class Tests_Query_Conditionals extends WP_UnitTestCase { 
    553551                foreach ( $post_ids as $post_id ) {
    554552                        self::factory()->term->add_post_terms( $post_id, 'tag-a', 'post_tag' );
    555553                }
    556                 $this->go_to( '/tag/tag-a/page/2/' );
     554                $this->go_to( tests_add_blog_permalink_prefix_on_multisite( 'tag/tag-a/page/2/' ) );
    557555                $this->assertQueryTrue( 'is_archive', 'is_tag', 'is_paged' );
    558556        }
    559557
    class Tests_Query_Conditionals extends WP_UnitTestCase { 
    566564                                'taxonomy' => 'post_tag',
    567565                        )
    568566                );
    569                 $this->go_to( '/tag/tag-a/' );
     567                $this->go_to( tests_add_blog_permalink_prefix_on_multisite( 'tag/tag-a/' ) );
    570568                $this->assertQueryTrue( 'is_archive', 'is_tag' );
    571569
    572570                $tag = get_term( $term_id, 'post_tag' );
    class Tests_Query_Conditionals extends WP_UnitTestCase { 
    588586                // check the long form
    589587                $types = array( 'feed', 'rdf', 'rss', 'rss2', 'atom' );
    590588                foreach ( $types as $type ) {
    591                                 $this->go_to( "/author/user-a/feed/{$type}" );
     589                                $this->go_to( tests_add_blog_permalink_prefix_on_multisite( "author/user-a/feed/{$type}" ) );
    592590                                $this->assertQueryTrue( 'is_archive', 'is_feed', 'is_author' );
    593591                }
    594592
    595593                // check the short form
    596594                $types = array( 'feed', 'rdf', 'rss', 'rss2', 'atom' );
    597595                foreach ( $types as $type ) {
    598                                 $this->go_to( "/author/user-a/{$type}" );
     596                                $this->go_to( tests_add_blog_permalink_prefix_on_multisite( "author/user-a/{$type}" ) );
    599597                                $this->assertQueryTrue( 'is_archive', 'is_feed', 'is_author' );
    600598                }
    601599        }
    class Tests_Query_Conditionals extends WP_UnitTestCase { 
    605603                update_option( 'posts_per_page', 2 );
    606604                $user_id = self::factory()->user->create( array( 'user_login' => 'user-a' ) );
    607605                self::factory()->post->create_many( 3, array( 'post_author' => $user_id ) );
    608                 $this->go_to( '/author/user-a/page/2/' );
     606                $this->go_to( tests_add_blog_permalink_prefix_on_multisite( 'author/user-a/page/2/' ) );
    609607                $this->assertQueryTrue( 'is_archive', 'is_author', 'is_paged' );
    610608        }
    611609
    class Tests_Query_Conditionals extends WP_UnitTestCase { 
    613611        function test_author() {
    614612                $user_id = self::factory()->user->create( array( 'user_login' => 'user-a' ) );
    615613                self::factory()->post->create( array( 'post_author' => $user_id ) );
    616                 $this->go_to( '/author/user-a/' );
     614                $this->go_to( tests_add_blog_permalink_prefix_on_multisite( 'author/user-a/' ) );
    617615                $this->assertQueryTrue( 'is_archive', 'is_author' );
    618616        }
    619617
    620618        function test_author_with_no_posts() {
    621619                $user_id = self::factory()->user->create( array( 'user_login' => 'user-a' ) );
    622                 $this->go_to( '/author/user-a/' );
     620                $this->go_to( tests_add_blog_permalink_prefix_on_multisite( 'author/user-a/' ) );
    623621                $this->assertQueryTrue( 'is_archive', 'is_author' );
    624622        }
    625623
    class Tests_Query_Conditionals extends WP_UnitTestCase { 
    630628                // check the long form
    631629                $types = array( 'feed', 'rdf', 'rss', 'rss2', 'atom' );
    632630                foreach ( $types as $type ) {
    633                                 $this->go_to( "/2007/09/04/feed/{$type}" );
     631                                $this->go_to( tests_add_blog_permalink_prefix_on_multisite( "2007/09/04/feed/{$type}" ) );
    634632                                $this->assertQueryTrue( 'is_archive', 'is_feed', 'is_day', 'is_date' );
    635633                }
    636634
    637635                // check the short form
    638636                $types = array( 'feed', 'rdf', 'rss', 'rss2', 'atom' );
    639637                foreach ( $types as $type ) {
    640                                 $this->go_to( "/2007/09/04/{$type}" );
     638                                $this->go_to( tests_add_blog_permalink_prefix_on_multisite( "2007/09/04/{$type}" ) );
    641639                                $this->assertQueryTrue( 'is_archive', 'is_feed', 'is_day', 'is_date' );
    642640                }
    643641        }
    class Tests_Query_Conditionals extends WP_UnitTestCase { 
    646644        function test_ymd_paged() {
    647645                update_option( 'posts_per_page', 2 );
    648646                self::factory()->post->create_many( 3, array( 'post_date' => '2007-09-04 00:00:00' ) );
    649                 $this->go_to( '/2007/09/04/page/2/' );
     647                $this->go_to( tests_add_blog_permalink_prefix_on_multisite( '2007/09/04/page/2/' ) );
    650648                $this->assertQueryTrue( 'is_archive', 'is_day', 'is_date', 'is_paged' );
    651649        }
    652650
    653651        // '([0-9]{4})/([0-9]{1,2})/([0-9]{1,2})/?$' => 'index.php?year=$matches[1]&monthnum=$matches[2]&day=$matches[3]',
    654652        function test_ymd() {
    655653                self::factory()->post->create( array( 'post_date' => '2007-09-04 00:00:00' ) );
    656                 $this->go_to( '/2007/09/04/' );
     654                $this->go_to( tests_add_blog_permalink_prefix_on_multisite( '2007/09/04/' ) );
    657655                $this->assertQueryTrue( 'is_archive', 'is_day', 'is_date' );
    658656        }
    659657
    class Tests_Query_Conditionals extends WP_UnitTestCase { 
    664662                // check the long form
    665663                $types = array( 'feed', 'rdf', 'rss', 'rss2', 'atom' );
    666664                foreach ( $types as $type ) {
    667                                 $this->go_to( "/2007/09/feed/{$type}" );
     665                                $this->go_to( tests_add_blog_permalink_prefix_on_multisite( "2007/09/feed/{$type}" ) );
    668666                                $this->assertQueryTrue( 'is_archive', 'is_feed', 'is_month', 'is_date' );
    669667                }
    670668
    671669                // check the short form
    672670                $types = array( 'feed', 'rdf', 'rss', 'rss2', 'atom' );
    673671                foreach ( $types as $type ) {
    674                                 $this->go_to( "/2007/09/{$type}" );
     672                                $this->go_to( tests_add_blog_permalink_prefix_on_multisite( "2007/09/{$type}" ) );
    675673                                $this->assertQueryTrue( 'is_archive', 'is_feed', 'is_month', 'is_date' );
    676674                }
    677675        }
    class Tests_Query_Conditionals extends WP_UnitTestCase { 
    680678        function test_ym_paged() {
    681679                update_option( 'posts_per_page', 2 );
    682680                self::factory()->post->create_many( 3, array( 'post_date' => '2007-09-04 00:00:00' ) );
    683                 $this->go_to( '/2007/09/page/2/' );
     681                $this->go_to( tests_add_blog_permalink_prefix_on_multisite( '2007/09/page/2/' ) );
    684682                $this->assertQueryTrue( 'is_archive', 'is_date', 'is_month', 'is_paged' );
    685683        }
    686684
    687685        // '([0-9]{4})/([0-9]{1,2})/?$' => 'index.php?year=$matches[1]&monthnum=$matches[2]',
    688686        function test_ym() {
    689687                self::factory()->post->create( array( 'post_date' => '2007-09-04 00:00:00' ) );
    690                 $this->go_to( '/2007/09/' );
     688                $this->go_to( tests_add_blog_permalink_prefix_on_multisite( '2007/09/' ) );
    691689                $this->assertQueryTrue( 'is_archive', 'is_date', 'is_month' );
    692690        }
    693691
    class Tests_Query_Conditionals extends WP_UnitTestCase { 
    698696                // check the long form
    699697                $types = array( 'feed', 'rdf', 'rss', 'rss2', 'atom' );
    700698                foreach ( $types as $type ) {
    701                                 $this->go_to( "/2007/feed/{$type}" );
     699                                $this->go_to( tests_add_blog_permalink_prefix_on_multisite( "2007/feed/{$type}" ) );
    702700                                $this->assertQueryTrue( 'is_archive', 'is_feed', 'is_year', 'is_date' );
    703701                }
    704702
    705703                // check the short form
    706704                $types = array( 'feed', 'rdf', 'rss', 'rss2', 'atom' );
    707705                foreach ( $types as $type ) {
    708                                 $this->go_to( "/2007/{$type}" );
     706                                $this->go_to( tests_add_blog_permalink_prefix_on_multisite( "2007/{$type}" ) );
    709707                                $this->assertQueryTrue( 'is_archive', 'is_feed', 'is_year', 'is_date' );
    710708                }
    711709        }
    class Tests_Query_Conditionals extends WP_UnitTestCase { 
    714712        function test_y_paged() {
    715713                update_option( 'posts_per_page', 2 );
    716714                self::factory()->post->create_many( 3, array( 'post_date' => '2007-09-04 00:00:00' ) );
    717                 $this->go_to( '/2007/page/2/' );
     715                $this->go_to( tests_add_blog_permalink_prefix_on_multisite( '2007/page/2/' ) );
    718716                $this->assertQueryTrue( 'is_archive', 'is_date', 'is_year', 'is_paged' );
    719717        }
    720718
    721719        // '([0-9]{4})/?$' => 'index.php?year=$matches[1]',
    722720        function test_y() {
    723721                self::factory()->post->create( array( 'post_date' => '2007-09-04 00:00:00' ) );
    724                 $this->go_to( '/2007/' );
     722                $this->go_to( tests_add_blog_permalink_prefix_on_multisite( '2007/' ) );
    725723                $this->assertQueryTrue( 'is_archive', 'is_date', 'is_year' );
    726724        }
    727725
    class Tests_Query_Conditionals extends WP_UnitTestCase { 
    788786         * @expectedIncorrectUsage WP_Date_Query
    789787         */
    790788        function test_bad_dates() {
    791                 $this->go_to( '/2013/13/13/' );
     789                $this->go_to( tests_add_blog_permalink_prefix_on_multisite( '2013/13/13/' ) );
    792790                $this->assertQueryTrue( 'is_404' );
    793791
    794                 $this->go_to( '/2013/11/41/' );
     792                $this->go_to( tests_add_blog_permalink_prefix_on_multisite( '2013/11/41/' ) );
    795793                $this->assertQueryTrue( 'is_404' );
    796794        }
    797795
    class Tests_Query_Conditionals extends WP_UnitTestCase { 
    812810                $post_id = self::factory()->post->create( array( 'post_type' => $cpt_name ) );
    813811                wp_set_object_terms( $post_id, $tag_id, 'post_tag' );
    814812
    815                 $this->go_to( '/ptawtq/' );
     813                $this->go_to( tests_add_blog_permalink_prefix_on_multisite( 'ptawtq/' ) );
    816814                $this->assertQueryTrue( 'is_post_type_archive', 'is_archive' );
    817815                $this->assertEquals( get_queried_object(), get_post_type_object( $cpt_name ) );
    818816
    819817                add_action( 'pre_get_posts', array( $this, 'pre_get_posts_with_tax_query' ) );
    820818
    821                 $this->go_to( '/ptawtq/' );
     819                $this->go_to( tests_add_blog_permalink_prefix_on_multisite( 'ptawtq/' ) );
    822820                $this->assertQueryTrue( 'is_post_type_archive', 'is_archive' );
    823821                $this->assertEquals( get_queried_object(), get_post_type_object( $cpt_name ) );
    824822
    class Tests_Query_Conditionals extends WP_UnitTestCase { 
    852850                );
    853851                self::factory()->post->create( array( 'post_type' => $cpt_name ) );
    854852
    855                 $this->go_to( "/$cpt_name/" );
     853                $this->go_to( tests_add_blog_permalink_prefix_on_multisite( "$cpt_name/" ) );
    856854                $this->assertQueryTrue( 'is_post_type_archive', 'is_archive' );
    857855                $this->assertEquals( get_queried_object(), get_post_type_object( $cpt_name ) );
    858856
    859857                add_action( 'pre_get_posts', array( $this, 'pre_get_posts_with_type_array' ) );
    860858
    861                 $this->go_to( "/$cpt_name/" );
     859                $this->go_to( tests_add_blog_permalink_prefix_on_multisite( "$cpt_name/" ) );
    862860                $this->assertQueryTrue( 'is_post_type_archive', 'is_archive' );
    863861                $this->assertEquals( get_queried_object(), get_post_type_object( 'post' ) );
    864862
    class Tests_Query_Conditionals extends WP_UnitTestCase { 
    966964         * @ticket 24612
    967965         */
    968966        public function test_is_single_with_slug_that_clashes_with_attachment() {
     967
    969968                $this->set_permalink_structure( '/%postname%/' );
    970969
    971970                $attachment_id = $this->factory->post->create(
    class Tests_Query_Conditionals extends WP_UnitTestCase { 
    989988                $this->assertFalse( $q->is_attachment() );
    990989                $this->assertFalse( $q->is_404() );
    991990
    992                 $this->set_permalink_structure();
     991                tests_reset_and_flush_permalinks();
    993992        }
    994993
    995994        /**
  • tests/phpunit/tests/query/isTerm.php

    diff --git tests/phpunit/tests/query/isTerm.php tests/phpunit/tests/query/isTerm.php
    index 546217bb3c..3f49de019d 100644
    class Tests_Query_IsTerm extends WP_UnitTestCase { 
    3030                $GLOBALS['wp_the_query'] = new WP_Query();
    3131                $GLOBALS['wp_query']     = $GLOBALS['wp_the_query'];
    3232
    33                 $this->set_permalink_structure( '/%year%/%monthnum%/%day%/%postname%/' );
    34 
    3533                create_initial_taxonomies();
    3634                register_taxonomy( 'testtax', 'post', array( 'public' => true ) );
    3735
    class Tests_Query_IsTerm extends WP_UnitTestCase { 
    7876
    7977        function test_tag_action_tax() {
    8078                // tag with tax added
    81                 $this->go_to( home_url( '/tag/tag-slug/' ) );
     79                $this->go_to( home_url( tests_add_blog_permalink_prefix_on_multisite( '/tag/tag-slug/' ) ) );
    8280                $this->assertQueryTrue( 'is_tag', 'is_archive' );
    8381                $this->assertNotEmpty( get_query_var( 'tax_query' ) );
    8482                $this->assertNotEmpty( get_query_var( 'taxonomy' ) );
    class Tests_Query_IsTerm extends WP_UnitTestCase { 
    8987
    9088        function test_tag_query_cat_action_tax() {
    9189                // tag + category with tax added
    92                 $this->go_to( home_url( "/tag/tag-slug/?cat=$this->cat_id" ) );
     90                $this->go_to( home_url( tests_add_blog_permalink_prefix_on_multisite( "/tag/tag-slug/?cat=$this->cat_id" ) ) );
    9391                $this->assertQueryTrue( 'is_category', 'is_tag', 'is_archive' );
    9492                $this->assertNotEmpty( get_query_var( 'tax_query' ) );
    9593                $this->assertNotEmpty( get_query_var( 'taxonomy' ) );
    class Tests_Query_IsTerm extends WP_UnitTestCase { 
    10199
    102100        function test_tag_query_cat_query_tax_action_tax() {
    103101                // tag + category + tax with tax added
    104                 $this->go_to( home_url( "/tag/tag-slug/?cat=$this->cat_id&testtax=tax-slug2" ) );
     102                $this->go_to( home_url( tests_add_blog_permalink_prefix_on_multisite( "/tag/tag-slug/?cat=$this->cat_id&testtax=tax-slug2" ) ) );
    105103                $this->assertQueryTrue( 'is_category', 'is_tag', 'is_tax', 'is_archive' );
    106104                $this->assertNotEmpty( get_query_var( 'tax_query' ) );
    107105                $this->assertNotEmpty( get_query_var( 'taxonomy' ) );
    class Tests_Query_IsTerm extends WP_UnitTestCase { 
    114112
    115113        function test_cat_action_tax() {
    116114                // category with tax added
    117                 $this->go_to( home_url( '/category/cat-slug/' ) );
     115                $this->go_to( home_url( tests_add_blog_permalink_prefix_on_multisite( '/category/cat-slug/' ) ) );
    118116                $this->assertQueryTrue( 'is_category', 'is_archive' );
    119117                $this->assertNotEmpty( get_query_var( 'cat' ) );
    120118                $this->assertNotEmpty( get_query_var( 'tax_query' ) );
    class Tests_Query_IsTerm extends WP_UnitTestCase { 
    130128                // category with tax added
    131129                add_action( 'pre_get_posts', array( $this, '_cat_uncat_action_tax' ), 11 );
    132130
    133                 $this->go_to( home_url( '/category/uncategorized/' ) );
     131                $this->go_to( home_url( tests_add_blog_permalink_prefix_on_multisite( '/category/uncategorized/' ) ) );
    134132                $this->assertQueryTrue( 'is_category', 'is_archive' );
    135133                $this->assertNotEmpty( get_query_var( 'cat' ) );
    136134                $this->assertNotEmpty( get_query_var( 'tax_query' ) );
    class Tests_Query_IsTerm extends WP_UnitTestCase { 
    154152         */
    155153        function test_tax_action_tax() {
    156154                // tax with tax added
    157                 $this->go_to( home_url( '/testtax/tax-slug2/' ) );
     155                $this->go_to( home_url( tests_add_blog_permalink_prefix_on_multisite( '/testtax/tax-slug2/' ) ) );
    158156                $this->assertQueryTrue( 'is_tax', 'is_archive' );
    159157                $this->assertNotEmpty( get_query_var( 'tax_query' ) );
    160158                $this->assertNotEmpty( get_query_var( 'taxonomy' ) );
    class Tests_Query_IsTerm extends WP_UnitTestCase { 
    164162
    165163        function test_tax_query_tag_action_tax() {
    166164                // tax + tag with tax added
    167                 $this->go_to( home_url( "/testtax/tax-slug2/?tag_id=$this->tag_id" ) );
     165                $this->go_to( home_url( tests_add_blog_permalink_prefix_on_multisite( "/testtax/tax-slug2/?tag_id=$this->tag_id" ) ) );
    168166                $this->assertQueryTrue( 'is_tag', 'is_tax', 'is_archive' );
    169167                $this->assertNotEmpty( get_query_var( 'tax_query' ) );
    170168                $this->assertNotEmpty( get_query_var( 'taxonomy' ) );
    class Tests_Query_IsTerm extends WP_UnitTestCase { 
    175173
    176174        function test_tax_query_cat_action_tax() {
    177175                // tax + cat with tax added
    178                 $this->go_to( home_url( "/testtax/tax-slug2/?cat=$this->cat_id" ) );
     176                $this->go_to( home_url( tests_add_blog_permalink_prefix_on_multisite( "/testtax/tax-slug2/?cat=$this->cat_id" ) ) );
    179177                $this->assertQueryTrue( 'is_category', 'is_tax', 'is_archive' );
    180178                $this->assertNotEmpty( get_query_var( 'tax_query' ) );
    181179                $this->assertNotEmpty( get_query_var( 'taxonomy' ) );
  • tests/phpunit/tests/query/verboseRewriteRules.php

    diff --git tests/phpunit/tests/query/verboseRewriteRules.php tests/phpunit/tests/query/verboseRewriteRules.php
    index 5414a51a9a..7f864e2d7a 100644
    class Tests_Query_VerbosePageRules extends Tests_Query_Conditionals { 
    1313                $this->set_permalink_structure( '/%category%/%year%/%postname%/' );
    1414                create_initial_taxonomies();
    1515        }
     16
     17        public function tearDown() {
     18                parent::tearDown();
     19
     20                tests_reset_and_flush_permalinks();
     21        }
    1622}
  • tests/phpunit/tests/rest-api.php

    diff --git tests/phpunit/tests/rest-api.php tests/phpunit/tests/rest-api.php
    index a1c6a6b1eb..809cc8f13b 100644
    class Tests_REST_API extends WP_UnitTestCase { 
    486486         * whether the blog is configured with pretty permalink support or not.
    487487         */
    488488        public function test_rest_url_generation() {
     489
     490
    489491                // In pretty permalinks case, we expect a path of wp-json/ with no query.
    490                 $this->set_permalink_structure( '/%year%/%monthnum%/%day%/%postname%/' );
    491492                $this->assertEquals( 'http://' . WP_TESTS_DOMAIN . '/wp-json/', get_rest_url() );
    492493
    493494                // In index permalinks case, we expect a path of index.php/wp-json/ with no query.
    class Tests_REST_API extends WP_UnitTestCase { 
    497498                // In non-pretty case, we get a query string to invoke the rest router.
    498499                $this->set_permalink_structure( '' );
    499500                $this->assertEquals( 'http://' . WP_TESTS_DOMAIN . '/index.php?rest_route=/', get_rest_url() );
     501
     502                tests_reset_and_flush_permalinks();
    500503        }
    501504
    502505        /**
  • tests/phpunit/tests/rest-api/rest-posts-controller.php

    diff --git tests/phpunit/tests/rest-api/rest-posts-controller.php tests/phpunit/tests/rest-api/rest-posts-controller.php
    index e2c7bf7c89..9487a379cd 100644
    class WP_Test_REST_Posts_Controller extends WP_Test_REST_Post_Type_Controller_Te 
    28852885        }
    28862886
    28872887        public function test_update_post_with_categories() {
     2888                tests_set_and_flush_permalinks( '' );
    28882889
    28892890                wp_set_current_user( self::$editor_id );
    28902891                $category = wp_insert_term( 'Test Category', 'category' );
    class WP_Test_REST_Posts_Controller extends WP_Test_REST_Post_Type_Controller_Te 
    29112912                }
    29122913                $query = parse_url( $categories_path, PHP_URL_QUERY );
    29132914                parse_str( $query, $args );
     2915
    29142916                $request = new WP_REST_Request( 'GET', $args['rest_route'] );
    29152917                unset( $args['rest_route'] );
    29162918                $request->set_query_params( $args );
    class WP_Test_REST_Posts_Controller extends WP_Test_REST_Post_Type_Controller_Te 
    29182920                $data     = $response->get_data();
    29192921                $this->assertCount( 1, $data );
    29202922                $this->assertEquals( 'Test Category', $data[0]['name'] );
     2923
     2924                tests_reset_and_flush_permalinks();
    29212925        }
    29222926
    29232927        public function test_update_post_with_empty_categories() {
  • tests/phpunit/tests/rewrite.php

    diff --git tests/phpunit/tests/rewrite.php tests/phpunit/tests/rewrite.php
    index abb793eb34..825fd56f06 100644
    class Tests_Rewrite extends WP_UnitTestCase { 
    1111        function setUp() {
    1212                parent::setUp();
    1313
    14                 $this->set_permalink_structure( '/%year%/%monthnum%/%day%/%postname%/' );
    1514                create_initial_taxonomies();
    1615
    1716                $this->home_url = get_option( 'home' );
    1817        }
    1918
    2019        function tearDown() {
    21                 global $wp_rewrite;
    22                 $wp_rewrite->init();
    23 
    2420                update_option( 'home', $this->home_url );
    2521                parent::tearDown();
     22
     23                tests_reset_and_flush_permalinks();
    2624        }
    2725
    2826        /**
    class Tests_Rewrite extends WP_UnitTestCase { 
    8583        }
    8684
    8785        function test_url_to_postid() {
     86                tests_set_and_flush_permalinks( '' );
    8887
    8988                $id = self::factory()->post->create();
    9089                $this->assertEquals( $id, url_to_postid( get_permalink( $id ) ) );
    9190
    9291                $id = self::factory()->post->create( array( 'post_type' => 'page' ) );
    9392                $this->assertEquals( $id, url_to_postid( get_permalink( $id ) ) );
     93
     94                tests_reset_and_flush_permalinks();
    9495        }
    9596
    9697        function test_url_to_postid_set_url_scheme_https_to_http() {
    class Tests_Rewrite extends WP_UnitTestCase { 
    101102                $post_id   = self::factory()->post->create( array( 'post_type' => 'page' ) );
    102103                $permalink = get_permalink( $post_id );
    103104                $this->assertEquals( $post_id, url_to_postid( set_url_scheme( $permalink, 'https' ) ) );
     105
     106
    104107        }
    105108
    106109        function test_url_to_postid_set_url_scheme_http_to_https() {
     110
    107111                $_SERVER['HTTPS'] = 'on';
    108112
    109113                $post_id        = self::factory()->post->create();
    class Tests_Rewrite extends WP_UnitTestCase { 
    116120
    117121                $this->assertEquals( $post_id, $post_url_to_id );
    118122                $this->assertEquals( $page_id, $page_url_to_id );
     123
     124
    119125        }
    120126
    121127        /**
    class Tests_Rewrite extends WP_UnitTestCase { 
    398404         * @ticket 21970
    399405         */
    400406        function test_url_to_postid_with_post_slug_that_clashes_with_a_trashed_page() {
     407
    401408                $this->set_permalink_structure( '/%postname%/' );
    402409
    403410                $page_id = self::factory()->post->create(
    class Tests_Rewrite extends WP_UnitTestCase { 
    409416                $post_id = self::factory()->post->create( array( 'post_title' => get_post( $page_id )->post_title ) );
    410417
    411418                $this->assertEquals( $post_id, url_to_postid( get_permalink( $post_id ) ) );
     419
     420                tests_reset_and_flush_permalinks();
    412421        }
    413422
    414423        /**
    class Tests_Rewrite extends WP_UnitTestCase { 
    435444         * @ticket 39373
    436445         */
    437446        public function test_url_to_postid_should_bail_when_host_does_not_match() {
     447
    438448                $this->set_permalink_structure( '/%postname%/' );
    439449
    440450                $post_id   = self::factory()->post->create( array( 'post_name' => 'foo-bar-baz' ) );
    class Tests_Rewrite extends WP_UnitTestCase { 
    443453
    444454                $this->assertSame( $post_id, url_to_postid( $permalink ) );
    445455                $this->assertSame( 0, url_to_postid( $url ) );
     456
     457                tests_reset_and_flush_permalinks();
    446458        }
    447459
    448460        /**
    449461         * @ticket 21970
    450462         */
    451463        function test_parse_request_with_post_slug_that_clashes_with_a_trashed_page() {
     464
    452465                $this->set_permalink_structure( '/%postname%/' );
    453466
    454467                $page_id = self::factory()->post->create(
    class Tests_Rewrite extends WP_UnitTestCase { 
    463476
    464477                $this->assertTrue( is_single() );
    465478                $this->assertFalse( is_404() );
     479
     480                tests_reset_and_flush_permalinks();
    466481        }
    467482
    468483        /**
    469484         * @ticket 29107
    470485         */
    471486        public function test_flush_rules_does_not_delete_option() {
     487
    472488                $this->set_permalink_structure( '' );
    473489
    474490                $rewrite_rules = get_option( 'rewrite_rules' );
    475491                $this->assertSame( '', $rewrite_rules );
    476492
    477                 $this->set_permalink_structure( '/%year%/%monthnum%/%day%/%postname%/' );
     493                tests_reset_and_flush_permalinks();
    478494
    479495                $rewrite_rules = get_option( 'rewrite_rules' );
    480496                $this->assertInternalType( 'array', $rewrite_rules );
  • tests/phpunit/tests/rewrite/addRewriteRule.php

    diff --git tests/phpunit/tests/rewrite/addRewriteRule.php tests/phpunit/tests/rewrite/addRewriteRule.php
    index bcac78f6ae..6bd0e79467 100644
     
    44 * @group rewrite
    55 */
    66class Tests_Rewrite_AddRewriteRule extends WP_UnitTestCase {
    7 
    8         public function setUp() {
    9                 parent::setUp();
    10 
    11                 $this->set_permalink_structure( '/%postname%/' );
    12         }
    13 
    147        /**
    158         * @ticket 16840
    169         */
  • tests/phpunit/tests/rewrite/numericSlugs.php

    diff --git tests/phpunit/tests/rewrite/numericSlugs.php tests/phpunit/tests/rewrite/numericSlugs.php
    index 83e1443985..4f283638b1 100644
    class Tests_Rewrite_NumericSlugs extends WP_UnitTestCase { 
    4848                $this->go_to( get_permalink( '2015' ) );
    4949
    5050                $this->assertQueryTrue( 'is_single', 'is_singular' );
     51
     52                tests_reset_and_flush_permalinks();
    5153        }
    5254
    5355        public function test_url_to_postid_year_segment_collision_without_title() {
    class Tests_Rewrite_NumericSlugs extends WP_UnitTestCase { 
    7678                );
    7779
    7880                $this->assertEquals( '2015', url_to_postid( get_permalink( '2015' ) ) );
     81
     82                tests_reset_and_flush_permalinks();
    7983        }
    8084
    8185        public function test_go_to_year_segment_collision_with_title() {
    class Tests_Rewrite_NumericSlugs extends WP_UnitTestCase { 
    9498                $this->go_to( get_permalink( $id ) );
    9599
    96100                $this->assertQueryTrue( 'is_single', 'is_singular' );
     101
     102                tests_reset_and_flush_permalinks();
    97103        }
    98104
    99105        public function test_url_to_postid_year_segment_collision_with_title() {
    class Tests_Rewrite_NumericSlugs extends WP_UnitTestCase { 
    129135                $this->go_to( get_permalink( $id ) );
    130136
    131137                $this->assertQueryTrue( 'is_single', 'is_singular' );
     138
     139                tests_reset_and_flush_permalinks();
    132140        }
    133141
    134142        public function test_url_to_postid_month_segment_collision_without_title() {
    class Tests_Rewrite_NumericSlugs extends WP_UnitTestCase { 
    146154                );
    147155
    148156                $this->assertEquals( $id, url_to_postid( get_permalink( $id ) ) );
     157
     158                tests_reset_and_flush_permalinks();
    149159        }
    150160
    151161        public function test_go_to_month_segment_collision_without_title_no_leading_zero() {
    class Tests_Rewrite_NumericSlugs extends WP_UnitTestCase { 
    165175                $this->go_to( get_permalink( $id ) );
    166176
    167177                $this->assertQueryTrue( 'is_single', 'is_singular' );
     178
     179                tests_reset_and_flush_permalinks();
    168180        }
    169181
    170182        public function test_url_to_postid_month_segment_collision_without_title_no_leading_zero() {
    class Tests_Rewrite_NumericSlugs extends WP_UnitTestCase { 
    182194                );
    183195
    184196                $this->assertEquals( $id, url_to_postid( get_permalink( $id ) ) );
     197
     198                tests_reset_and_flush_permalinks();
    185199        }
    186200
    187201        public function test_go_to_month_segment_collision_with_title() {
    class Tests_Rewrite_NumericSlugs extends WP_UnitTestCase { 
    200214                $this->go_to( get_permalink( $id ) );
    201215
    202216                $this->assertQueryTrue( 'is_single', 'is_singular' );
     217
     218                tests_reset_and_flush_permalinks();
    203219        }
    204220
    205221        public function test_url_to_postid_month_segment_collision_with_title() {
    class Tests_Rewrite_NumericSlugs extends WP_UnitTestCase { 
    216232                );
    217233
    218234                $this->assertEquals( $id, url_to_postid( get_permalink( $id ) ) );
     235
     236                tests_reset_and_flush_permalinks();
    219237        }
    220238
    221239        public function test_go_to_month_segment_collision_with_title_no_leading_zero() {
    class Tests_Rewrite_NumericSlugs extends WP_UnitTestCase { 
    234252                $this->go_to( get_permalink( $id ) );
    235253
    236254                $this->assertQueryTrue( 'is_single', 'is_singular' );
     255
     256                tests_reset_and_flush_permalinks();
    237257        }
    238258
    239259        public function test_url_to_postid_month_segment_collision_with_title_no_leading_zero() {
    class Tests_Rewrite_NumericSlugs extends WP_UnitTestCase { 
    250270                );
    251271
    252272                $this->assertEquals( $id, url_to_postid( get_permalink( $id ) ) );
     273
     274                tests_reset_and_flush_permalinks();
    253275        }
    254276
    255277        public function test_go_to_day_segment_collision_without_title() {
    class Tests_Rewrite_NumericSlugs extends WP_UnitTestCase { 
    269291                $this->go_to( get_permalink( $id ) );
    270292
    271293                $this->assertQueryTrue( 'is_single', 'is_singular' );
     294
     295                tests_reset_and_flush_permalinks();
    272296        }
    273297
    274298        public function test_url_to_postid_day_segment_collision_without_title() {
    class Tests_Rewrite_NumericSlugs extends WP_UnitTestCase { 
    286310                );
    287311
    288312                $this->assertEquals( $id, url_to_postid( get_permalink( $id ) ) );
     313
     314                tests_reset_and_flush_permalinks();
    289315        }
    290316
    291317        public function test_go_to_day_segment_collision_with_title() {
    class Tests_Rewrite_NumericSlugs extends WP_UnitTestCase { 
    304330                $this->go_to( get_permalink( $id ) );
    305331
    306332                $this->assertQueryTrue( 'is_single', 'is_singular' );
     333
     334                tests_reset_and_flush_permalinks();
    307335        }
    308336
    309337        public function test_url_to_postid_day_segment_collision_with_title() {
    class Tests_Rewrite_NumericSlugs extends WP_UnitTestCase { 
    320348                );
    321349
    322350                $this->assertEquals( $id, url_to_postid( get_permalink( $id ) ) );
     351
     352                tests_reset_and_flush_permalinks();
    323353        }
    324354
    325355        public function test_numeric_slug_permalink_conflicts_should_only_be_resolved_for_the_main_query() {
    class Tests_Rewrite_NumericSlugs extends WP_UnitTestCase { 
    345375
    346376                $this->assertTrue( $q->is_day );
    347377                $this->assertFalse( $q->is_single );
     378
     379                tests_reset_and_flush_permalinks();
    348380        }
    349381
    350382        public function test_month_slug_collision_should_resolve_to_date_archive_when_year_does_not_match_post_year() {
    class Tests_Rewrite_NumericSlugs extends WP_UnitTestCase { 
    377409                $this->go_to( $permalink );
    378410
    379411                $this->assertTrue( is_month() );
     412
     413                tests_reset_and_flush_permalinks();
    380414        }
    381415
    382416        public function test_day_slug_collision_should_resolve_to_date_archive_when_monthnum_does_not_match_post_month() {
    class Tests_Rewrite_NumericSlugs extends WP_UnitTestCase { 
    409443                $this->go_to( $permalink );
    410444
    411445                $this->assertTrue( is_day() );
     446
     447                tests_reset_and_flush_permalinks();
    412448        }
    413449
    414450        public function test_date_slug_collision_should_distinguish_valid_pagination_from_date() {
    class Tests_Rewrite_NumericSlugs extends WP_UnitTestCase { 
    427463                $this->go_to( get_permalink( $id ) . '1' );
    428464
    429465                $this->assertFalse( is_day() );
     466
     467                tests_reset_and_flush_permalinks();
    430468        }
    431469
    432470        public function test_date_slug_collision_should_distinguish_too_high_pagination_from_date() {
    class Tests_Rewrite_NumericSlugs extends WP_UnitTestCase { 
    445483                $this->go_to( get_permalink( $id ) . '5' );
    446484
    447485                $this->assertTrue( is_day() );
     486
     487                tests_reset_and_flush_permalinks();
    448488        }
    449489
    450490        public function test_date_slug_collision_should_not_require_pagination_query_var() {
    class Tests_Rewrite_NumericSlugs extends WP_UnitTestCase { 
    464504
    465505                $this->assertQueryTrue( 'is_single', 'is_singular' );
    466506                $this->assertFalse( is_date() );
     507
     508                tests_reset_and_flush_permalinks();
    467509        }
    468510
    469511        public function test_date_slug_collision_should_be_ignored_when_pagination_var_is_present_but_post_does_not_have_multiple_pages() {
    class Tests_Rewrite_NumericSlugs extends WP_UnitTestCase { 
    482524                $this->go_to( get_permalink( $id ) . '5' );
    483525
    484526                $this->assertTrue( is_day() );
     527
     528                tests_reset_and_flush_permalinks();
    485529        }
    486530
    487531        public function filter_unique_post_slug( $slug, $post_id, $post_status, $post_type, $post_parent, $original_slug ) {
  • tests/phpunit/tests/rewrite/oldSlugRedirect.php

    diff --git tests/phpunit/tests/rewrite/oldSlugRedirect.php tests/phpunit/tests/rewrite/oldSlugRedirect.php
    index c8427e1dd1..d72e49c09f 100644
    class Tests_Rewrite_OldSlugRedirect extends WP_UnitTestCase { 
    2121
    2222                add_filter( 'old_slug_redirect_url', array( $this, 'filter_old_slug_redirect_url' ), 10, 1 );
    2323
    24                 $this->set_permalink_structure( '/%postname%/' );
    25 
    2624                add_rewrite_endpoint( 'custom-endpoint', EP_PERMALINK );
    2725                add_rewrite_endpoint( 'second-endpoint', EP_PERMALINK, 'custom' );
    2826
  • tests/phpunit/tests/rewrite/permastructs.php

    diff --git tests/phpunit/tests/rewrite/permastructs.php tests/phpunit/tests/rewrite/permastructs.php
    index 788e009c2d..4a0282dbb8 100644
    class Tests_Rewrite_Permastructs extends WP_UnitTestCase { 
    77
    88        public function setUp() {
    99                parent::setUp();
    10 
    11                 $this->set_permalink_structure( '/%postname%/' );
    1210        }
    1311
    1412        public function test_add_permastruct() {
  • tests/phpunit/tests/taxonomy.php

    diff --git tests/phpunit/tests/taxonomy.php tests/phpunit/tests/taxonomy.php
    index d651b121ff..2ca406e59b 100644
    class Tests_Taxonomy extends WP_UnitTestCase { 
    792792         * @ticket 35227
    793793         */
    794794        public function test_unregister_taxonomy_removes_permastruct() {
    795                 $this->set_permalink_structure( '/%postname%' );
    796 
    797795                global $wp_rewrite;
    798796
    799797                register_taxonomy(
    class Tests_Taxonomy extends WP_UnitTestCase { 
    812810         * @ticket 35227
    813811         */
    814812        public function test_unregister_taxonomy_removes_rewrite_rules() {
    815                 $this->set_permalink_structure( '/%postname%' );
    816 
    817813                global $wp_rewrite;
    818814
    819815                register_taxonomy( 'foo', 'post', array( 'query_var' => 'bar' ) );
  • tests/phpunit/tests/term/getTermLink.php

    diff --git tests/phpunit/tests/term/getTermLink.php tests/phpunit/tests/term/getTermLink.php
    index 370167cff3..cce925e641 100644
    class Tests_Term_GetTermLink extends WP_UnitTestCase { 
    1212        }
    1313
    1414        public function test_integer_should_be_interpreted_as_term_id() {
     15                tests_set_and_flush_permalinks( '' );
     16
    1517                $t1 = self::factory()->term->create(
    1618                        array(
    1719                                'taxonomy' => 'wptests_tax',
    class Tests_Term_GetTermLink extends WP_UnitTestCase { 
    2830                $term = intval( $t1 );
    2931
    3032                $actual = get_term_link( $term, 'wptests_tax' );
    31                 $this->assertContains( 'wptests_tax=foo', $actual );
     33                $this->assertContains( '?wptests_tax=foo', $actual );
     34
     35                tests_reset_and_flush_permalinks();
    3236        }
    3337
    3438        public function test_numeric_string_should_be_interpreted_as_term_slug() {
     39                tests_set_and_flush_permalinks( '' );
     40
    3541                $t1 = self::factory()->term->create(
    3642                        array(
    3743                                'taxonomy' => 'wptests_tax',
    class Tests_Term_GetTermLink extends WP_UnitTestCase { 
    4854                $term = (string) $t1;
    4955
    5056                $actual = get_term_link( $term, 'wptests_tax' );
    51                 $this->assertContains( 'wptests_tax=' . $term, $actual );
     57                $this->assertContains( '?wptests_tax=' . $term, $actual );
     58
     59                tests_reset_and_flush_permalinks();
    5260        }
    5361
    5462        public function test_invalid_term_should_return_wp_error() {
    class Tests_Term_GetTermLink extends WP_UnitTestCase { 
    5765        }
    5866
    5967        public function test_category_should_use_cat_query_var_with_term_id() {
     68                tests_set_and_flush_permalinks( '' );
     69
    6070                $c = self::factory()->category->create();
    6171
    6272                $actual = get_term_link( $c, 'category' );
    6373                $this->assertContains( 'cat=' . $c, $actual );
     74
     75                tests_reset_and_flush_permalinks();
    6476        }
    6577
    6678        public function test_taxonomy_with_query_var_should_use_that_query_var_with_term_slug() {
     79                tests_set_and_flush_permalinks( '' );
     80
    6781                register_taxonomy(
    6882                        'wptests_tax2', 'post', array(
    6983                                'query_var' => 'foo',
    class Tests_Term_GetTermLink extends WP_UnitTestCase { 
    7993
    8094                $actual = get_term_link( $t, 'wptests_tax2' );
    8195                $this->assertContains( 'foo=bar', $actual );
     96
     97                tests_reset_and_flush_permalinks();
    8298        }
    8399
    84100        public function test_taxonomy_without_query_var_should_use_taxonomy_query_var_and_term_query_var_with_term_slug() {
     101                tests_set_and_flush_permalinks( '' );
     102
    85103                register_taxonomy(
    86104                        'wptests_tax2', 'post', array(
    87105                                'query_var' => false,
    class Tests_Term_GetTermLink extends WP_UnitTestCase { 
    98116                $actual = get_term_link( $t, 'wptests_tax2' );
    99117                $this->assertContains( 'taxonomy=wptests_tax2', $actual );
    100118                $this->assertContains( 'term=bar', $actual );
     119
     120                tests_reset_and_flush_permalinks();
    101121        }
    102122
    103123        public function test_taxonomy_permastruct_with_hierarchical_rewrite_should_put_term_ancestors_in_link() {
    104                 $this->set_permalink_structure( '/%year%/%monthnum%/%day%/%postname%/' );
    105 
    106124                register_taxonomy(
    107125                        'wptests_tax2', 'post', array(
    108126                                'hierarchical' => true,
    class Tests_Term_GetTermLink extends WP_UnitTestCase { 
    136154        }
    137155
    138156        public function test_taxonomy_permastruct_with_nonhierarchical_rewrite_should_not_put_term_ancestors_in_link() {
    139                 $this->set_permalink_structure( '/%year%/%monthnum%/%day%/%postname%/' );
    140 
    141157                register_taxonomy(
    142158                        'wptests_tax2', 'post', array(
    143159                                'hierarchical' => true,
  • tests/phpunit/tests/term/wpTaxonomy.php

    diff --git tests/phpunit/tests/term/wpTaxonomy.php tests/phpunit/tests/term/wpTaxonomy.php
    index bd5f049c5c..4915b666e5 100644
    class Tests_WP_Taxonomy extends WP_UnitTestCase { 
    1313        }
    1414
    1515        public function test_does_not_add_query_var_if_not_public() {
    16                 $this->set_permalink_structure( '/%postname%' );
    17 
    1816                /* @var WP $wp */
    1917                global $wp;
    2018
    class Tests_WP_Taxonomy extends WP_UnitTestCase { 
    2624        }
    2725
    2826        public function test_adds_query_var_if_public() {
    29                 $this->set_permalink_structure( '/%postname%' );
    30 
    3127                /* @var WP $wp */
    3228                global $wp;
    3329
    class Tests_WP_Taxonomy extends WP_UnitTestCase { 
    5147        }
    5248
    5349        public function test_adds_rewrite_rules() {
    54                 $this->set_permalink_structure( '/%postname%' );
    55 
    5650                /* @var WP_Rewrite $wp_rewrite */
    5751                global $wp_rewrite;
    5852
  • tests/phpunit/tests/user/author.php

    diff --git tests/phpunit/tests/user/author.php tests/phpunit/tests/user/author.php
    index d8bdf37a39..9e4568525e 100644
    class Tests_User_Author_Template extends WP_UnitTestCase { 
    1010        protected static $author_id = 0;
    1111        protected static $post_id   = 0;
    1212
    13         private $permalink_structure;
    14 
    1513        public static function wpSetUpBeforeClass( WP_UnitTest_Factory $factory ) {
    1614                self::$author_id = $factory->user->create(
    1715                        array(
    class Tests_User_Author_Template extends WP_UnitTestCase { 
    118116
    119117                $GLOBALS['authordata'] = $author->data;
    120118
    121                 $link = get_the_author_posts_link();
    122119
    123                 $url = sprintf( 'http://%1$s/?author=%2$s', WP_TESTS_DOMAIN, $author->ID );
     120                tests_set_and_flush_permalinks( '' );
     121
     122                $link = get_the_author_posts_link();
     123                $url  = sprintf( 'http://%1$s/?author=%2$s', WP_TESTS_DOMAIN, $author->ID );
    124124
    125125                $this->assertContains( $url, $link );
    126126                $this->assertContains( 'Posts by Foo', $link );
    127127                $this->assertContains( '>Foo</a>', $link );
    128128
    129129                unset( $GLOBALS['authordata'] );
     130                tests_reset_and_flush_permalinks();
    130131        }
    131132
    132133        /**
    class Tests_User_Author_Template extends WP_UnitTestCase { 
    148149
    149150                $url = sprintf( 'http://%1$s/author/%2$s/', WP_TESTS_DOMAIN, $author->user_nicename );
    150151
    151                 $this->set_permalink_structure( '' );
    152 
    153152                $this->assertContains( $url, $link );
    154153                $this->assertContains( 'Posts by Foo', $link );
    155154                $this->assertContains( '>Foo</a>', $link );