Make WordPress Core


Ignore:
Timestamp:
10/03/2015 08:54:11 PM (10 years ago)
Author:
DrewAPicture
Message:

Tests: Permalink Structures Phase II: DRY up logic for setting permalink structures in test methods.

Renames reset_permalinks() to set_permalink_structure() (mimicking $wp_rewrite->set_permalink_structure()) and allows it to accept an optional permalink structure. In this way, we can double dip using it to both set and reset the permalink structure from anywhere.

Removes alot of duplicated code from tests.

See #33968.

File:
1 edited

Legend:

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

    r34802 r34810  
    2121        $old_req_uri = $_SERVER['REQUEST_URI'];
    2222
    23         global $wp_rewrite;
    24         $wp_rewrite->set_permalink_structure('/%year%/%monthnum%/%day%/%postname%/');
    25         $wp_rewrite->flush_rules();
     23        $this->set_permalink_structure( '/%year%/%monthnum%/%day%/%postname%/' );
    2624
    2725        add_filter( 'home_url', array( $this, '_get_pagenum_link_cb' ) );
     
    3634
    3735    function test_wp_get_shortlink() {
    38         global $wp_rewrite;
    39 
    4036        $post_id = $this->factory->post->create();
    4137        $post_id2 = $this->factory->post->create();
     
    6864        $this->assertEquals( '', wp_get_shortlink() );
    6965
    70         $wp_rewrite->set_permalink_structure( '/%year%/%monthnum%/%day%/%postname%/' );
    71         $wp_rewrite->flush_rules();
     66        $this->set_permalink_structure( '/%year%/%monthnum%/%day%/%postname%/' );
    7267
    7368        // With a permalink structure set, get_permalink() will no longer match.
     
    8984        $this->assertEquals( home_url( '?p=' . $post_id ), wp_get_shortlink( $post_id, 'post' ) );
    9085
    91         global $wp_rewrite;
    92         $wp_rewrite->set_permalink_structure( '/%year%/%monthnum%/%day%/%postname%/' );
    93         $wp_rewrite->flush_rules();
     86        $this->set_permalink_structure( '/%year%/%monthnum%/%day%/%postname%/' );
    9487
    9588        $this->assertEquals( home_url( '?p=' . $post_id ), wp_get_shortlink( $post_id, 'post' ) );
     
    10699        $this->assertEquals( home_url( '/' ), wp_get_shortlink( $post_id, 'post' ) );
    107100
    108         global $wp_rewrite;
    109         $wp_rewrite->permalink_structure = '';
    110         $wp_rewrite->set_permalink_structure( '/%year%/%monthnum%/%day%/%postname%/' );
    111         $wp_rewrite->flush_rules();
     101        $this->set_permalink_structure( '/%year%/%monthnum%/%day%/%postname%/' );
    112102
    113103        $this->assertEquals( home_url( '/' ), wp_get_shortlink( $post_id, 'post' ) );
     
    397387     */
    398388    public function test_unattached_attachment_has_a_pretty_permalink() {
    399         global $wp_rewrite;
    400         $wp_rewrite->set_permalink_structure('/%year%/%monthnum%/%day%/%postname%/');
    401         $wp_rewrite->flush_rules();
     389        $this->set_permalink_structure( '/%year%/%monthnum%/%day%/%postname%/' );
    402390
    403391        $attachment_id = $this->factory->attachment->create_object( 'image.jpg', 0, array(
     
    417405     */
    418406    public function test_attachment_attached_to_non_existent_post_type_has_a_pretty_permalink() {
    419         global $wp_rewrite, $wp_post_types;
    420         $wp_rewrite->set_permalink_structure('/%year%/%monthnum%/%day%/%postname%/');
     407        global $wp_post_types;
     408
     409        $this->set_permalink_structure( '/%year%/%monthnum%/%day%/%postname%/' );
    421410
    422411        register_post_type( 'not_a_post_type', array( 'public' => true ) );
    423412
    424         $wp_rewrite->flush_rules();
     413        flush_rewrite_rules();
    425414
    426415        $post_id = $this->factory->post->create( array( 'post_type' => 'not_a_post_type' ) );
Note: See TracChangeset for help on using the changeset viewer.