Make WordPress Core


Ignore:
Timestamp:
10/03/2015 05:14:12 PM (9 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/link/getPostCommentsFeedLink.php

    r34479 r34802  
    44 */
    55class Tests_Link_GetPostCommentsFeedLink extends WP_UnitTestCase {
    6     private static $rewrite;
    7     private static $permalink_structure;
    8 
    9     static function setUpBeforeClass() {
    10         global $wp_rewrite;
    11 
    12         parent::setUpBeforeClass();
    13 
    14         self::$rewrite = $wp_rewrite;
    15         self::$permalink_structure = get_option( 'permalink_structure' );
    16     }
    17 
    18     public static function tearDownAfterClass() {
    19         parent::tearDownAfterClass();
    20 
    21         self::$rewrite->init();
    22         self::$rewrite->set_permalink_structure( self::$permalink_structure );
    23         self::$rewrite->flush_rules();
    24     }
    25 
    26     public function setUp() {
    27         parent::setUp();
    28         self::$rewrite->init();
    29     }
    30 
    31     private function set_permalink_structure( $structure ) {
    32         self::$rewrite->set_permalink_structure( $structure );
    33         self::$rewrite->flush_rules();
    34     }
    356
    367    public function test_post_link() {
    37         $this->set_permalink_structure( '' );
    38 
    398        $post_id = $this->factory->post->create();
    409
     
    4918
    5019    public function test_post_pretty_link() {
    51         $this->set_permalink_structure( '/%year%/%monthnum%/%day%/%postname%/' );
     20        global $wp_rewrite;
     21        $wp_rewrite->init();
     22        $wp_rewrite->set_permalink_structure( '/%year%/%monthnum%/%day%/%postname%/' );
     23        $wp_rewrite->flush_rules();
    5224
    5325        $post_id = $this->factory->post->create();
     
    6032
    6133    public function test_attachment_link() {
    62         $this->set_permalink_structure( '' );
    63 
    6434        $post_id = $this->factory->post->create();
    6535        $attachment_id = $this->factory->attachment->create_object( 'image.jpg', $post_id, array(
     
    7848
    7949    public function test_attachment_pretty_link() {
    80         $this->set_permalink_structure( '/%year%/%monthnum%/%day%/%postname%/' );
     50        global $wp_rewrite;
     51        $wp_rewrite->init();
     52        $wp_rewrite->set_permalink_structure( '/%year%/%monthnum%/%day%/%postname%/' );
     53        $wp_rewrite->flush_rules();
    8154
    8255        $post_id = $this->factory->post->create( array(
     
    9871
    9972    public function test_attachment_no_name_pretty_link() {
    100         $this->set_permalink_structure( '/%year%/%monthnum%/%day%/%postname%/' );
     73        global $wp_rewrite;
     74        $wp_rewrite->init();
     75        $wp_rewrite->set_permalink_structure( '/%year%/%monthnum%/%day%/%postname%/' );
     76        $wp_rewrite->flush_rules();
    10177
    10278        $post_id = $this->factory->post->create();
     
    11389
    11490    public function test_unattached_link() {
    115         $this->set_permalink_structure( '' );
    116 
    11791        $attachment_id = $this->factory->attachment->create_object( 'image.jpg', 0, array(
    11892            'post_mime_type' => 'image/jpeg',
     
    130104
    131105    public function test_unattached_pretty_link() {
    132         $this->set_permalink_structure( '/%year%/%monthnum%/%day%/%postname%/' );
     106        global $wp_rewrite;
     107        $wp_rewrite->init();
     108        $wp_rewrite->set_permalink_structure( '/%year%/%monthnum%/%day%/%postname%/' );
     109        $wp_rewrite->flush_rules();
    133110
    134111        $attachment_id = $this->factory->attachment->create_object( 'image.jpg', 0, array(
Note: See TracChangeset for help on using the changeset viewer.