Make WordPress Core


Ignore:
Timestamp:
10/03/2015 05:14:12 PM (11 years ago)
Author:
DrewAPicture
Message:

Tests: Introduce WP_UnitTestCase::reset_permalinks(), an attempt to DRY up logic for resetting and restoring default permalinks on setUp() and tearDown().

See #33968.

File:
1 edited

Legend:

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

    r33022 r34802  
    55 */
    66class Tests_Term_GetTermLink extends WP_UnitTestCase {
    7         private $permalink_structure;
    87
    98        public function setUp() {
    109                parent::setUp();
    1110
    12                 // Assume no pretty permalinks.
    13                 global $wp_rewrite;
    14                 $this->permalink_structure = get_option( 'permalink_structure' );
    15                 $wp_rewrite->set_permalink_structure( '' );
    16                 $wp_rewrite->flush_rules();
    17 
    1811                register_taxonomy( 'wptests_tax', 'post' );
    19         }
    20 
    21         public function tearDown() {
    22                 global $wp_rewrite;
    23                 $wp_rewrite->set_permalink_structure( $this->permalink_structure );
    24                 $wp_rewrite->flush_rules();
    25 
    26                 parent::tearDown();
    2712        }
    2813
     
    10287        public function test_taxonomy_permastruct_with_hierarchical_rewrite_should_put_term_ancestors_in_link() {
    10388                global $wp_rewrite;
    104                 $permalink_structure = get_option( 'permalink_structure' );
     89                $wp_rewrite->init();
    10590                $wp_rewrite->set_permalink_structure( '/%year%/%monthnum%/%day%/%postname%/' );
    10691                $wp_rewrite->flush_rules();
     
    126111
    127112                $actual = get_term_link( $t2, 'wptests_tax2' );
    128 
    129                 $wp_rewrite->set_permalink_structure( $permalink_structure );
    130                 $wp_rewrite->flush_rules();
    131113
    132114                $this->assertContains( '/foo/term1/term2/', $actual );
     
    160142                $actual = get_term_link( $t2, 'wptests_tax2' );
    161143
    162                 $wp_rewrite->set_permalink_structure( $permalink_structure );
    163                 $wp_rewrite->flush_rules();
    164 
    165144                $this->assertContains( '/foo/term2/', $actual );
    166145        }
Note: See TracChangeset for help on using the changeset viewer.