Make WordPress Core


Ignore:
Timestamp:
09/24/2015 04:31:58 AM (9 years ago)
Author:
wonderboymusic
Message:

Unit Tests: after [34477], make Tests_Link_GetPostCommentsFeedLink more respectable.

See #33693.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/tests/phpunit/tests/link/getPostCommentsFeedLink.php

    r34477 r34479  
    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    }
     35
    636    public function test_post_link() {
    7         global $wp_rewrite;
    8         $permalink_structure = get_option( 'permalink_structure' );
    9         $wp_rewrite->init();
    10         $wp_rewrite->set_permalink_structure( '' );
    11         $wp_rewrite->flush_rules();
     37        $this->set_permalink_structure( '' );
    1238
    1339        $post_id = $this->factory->post->create();
     
    2349
    2450    public function test_post_pretty_link() {
    25         global $wp_rewrite;
    26         $permalink_structure = get_option( 'permalink_structure' );
    27         $wp_rewrite->init();
    28         $wp_rewrite->set_permalink_structure( '/%year%/%monthnum%/%day%/%postname%/' );
    29         $wp_rewrite->flush_rules();
     51        $this->set_permalink_structure( '/%year%/%monthnum%/%day%/%postname%/' );
    3052
    3153        $post_id = $this->factory->post->create();
     
    3860
    3961    public function test_attachment_link() {
    40         global $wp_rewrite;
    41         $wp_rewrite->init();
    42         $wp_rewrite->set_permalink_structure( '' );
    43         $wp_rewrite->flush_rules();
     62        $this->set_permalink_structure( '' );
    4463
    4564        $post_id = $this->factory->post->create();
     
    5978
    6079    public function test_attachment_pretty_link() {
    61         global $wp_rewrite;
    62         $wp_rewrite->init();
    63         $wp_rewrite->set_permalink_structure( '/%year%/%monthnum%/%day%/%postname%/' );
    64         $wp_rewrite->flush_rules();
     80        $this->set_permalink_structure( '/%year%/%monthnum%/%day%/%postname%/' );
    6581
    6682        $post_id = $this->factory->post->create( array(
     
    8298
    8399    public function test_attachment_no_name_pretty_link() {
    84         global $wp_rewrite;
    85         $wp_rewrite->init();
    86         $wp_rewrite->set_permalink_structure( '/%year%/%monthnum%/%day%/%postname%/' );
    87         $wp_rewrite->flush_rules();
     100        $this->set_permalink_structure( '/%year%/%monthnum%/%day%/%postname%/' );
    88101
    89102        $post_id = $this->factory->post->create();
     
    95108        $link = get_post_comments_feed_link( $attachment_id );
    96109        $expected = get_permalink( $post_id ) . 'attachment/' . $attachment_id . '/feed/';
    97        
     110
    98111        $this->assertEquals( $expected, $link );
    99112    }
    100113
    101114    public function test_unattached_link() {
    102         global $wp_rewrite;
    103         $wp_rewrite->init();
    104         $wp_rewrite->set_permalink_structure( '' );
    105         $wp_rewrite->flush_rules();
     115        $this->set_permalink_structure( '' );
    106116
    107117        $attachment_id = $this->factory->attachment->create_object( 'image.jpg', 0, array(
     
    120130
    121131    public function test_unattached_pretty_link() {
    122         global $wp_rewrite;
    123         $wp_rewrite->init();
    124         $wp_rewrite->set_permalink_structure( '/%year%/%monthnum%/%day%/%postname%/' );
    125         $wp_rewrite->flush_rules();
     132        $this->set_permalink_structure( '/%year%/%monthnum%/%day%/%postname%/' );
    126133
    127134        $attachment_id = $this->factory->attachment->create_object( 'image.jpg', 0, array(
Note: See TracChangeset for help on using the changeset viewer.