WordPress.org

Make WordPress Core

Changeset 34810


Ignore:
Timestamp:
10/03/2015 08:54:11 PM (4 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.

Location:
trunk/tests/phpunit
Files:
15 edited

Legend:

Unmodified
Added
Removed
  • trunk/tests/phpunit/includes/testcase.php

    r34807 r34810  
    5151            $this->reset_taxonomies();
    5252            $this->reset_post_statuses();
    53             $this->reset_permalinks();
     53            $this->set_permalink_structure();
    5454        }
    5555
     
    654654     *
    655655     * @global WP_Rewrite $wp_rewrite
    656      */
    657     public function reset_permalinks() {
     656     *
     657     * @param string $structure Optional. Permalink structure to set. Default empty.
     658     */
     659    public function set_permalink_structure( $structure = '' ) {
    658660        global $wp_rewrite;
    659661
    660662        $wp_rewrite->init();
    661         $wp_rewrite->set_permalink_structure( '' );
     663        $wp_rewrite->set_permalink_structure( $structure );
    662664        $wp_rewrite->flush_rules();
    663665    }
  • trunk/tests/phpunit/tests/admin/includesPost.php

    r34802 r34810  
    252252     */
    253253    public function test_get_sample_permalink_should_return_pretty_permalink_for_posts_with_post_status_future() {
    254         global $wp_rewrite;
    255 
    256254        $permalink_structure = '%postname%';
    257         $wp_rewrite->set_permalink_structure( "/$permalink_structure/" );
    258         flush_rewrite_rules();
     255        $this->set_permalink_structure( "/$permalink_structure/" );
    259256
    260257        $future_date = date( 'Y-m-d H:i:s', time() + 100 );
     
    286283     */
    287284    public function test_get_sample_permalink_html_should_use_pretty_permalink_for_view_post_link_when_pretty_permalinks_are_enabled() {
    288         global $wp_rewrite;
    289         $permalink_structure = '%postname%';
    290         $wp_rewrite->set_permalink_structure( "/$permalink_structure/" );
    291         flush_rewrite_rules();
     285        $this->set_permalink_structure( '/%postname%/' );
    292286
    293287        wp_set_current_user( $this->factory->user->create( array( 'role' => 'administrator' ) ) );
     
    306300     */
    307301    public function test_get_sample_permalink_html_should_use_correct_permalink_for_view_post_link_when_changing_slug() {
    308         global $wp_rewrite;
    309         $permalink_structure = '%postname%';
    310         $wp_rewrite->set_permalink_structure( "/$permalink_structure/" );
    311         flush_rewrite_rules();
     302        $this->set_permalink_structure( '/%postname%/' );
    312303
    313304        wp_set_current_user( $this->factory->user->create( array( 'role' => 'administrator' ) ) );
     
    347338     */
    348339    public function test_get_sample_permalink_should_avoid_slugs_that_would_create_clashes_with_year_archives() {
    349         global $wp_rewrite;
    350         $wp_rewrite->init();
    351         $wp_rewrite->set_permalink_structure( '/%postname%/' );
    352         $wp_rewrite->flush_rules();
     340        $this->set_permalink_structure( '/%postname%/' );
    353341
    354342        $p = $this->factory->post->create( array(
     
    364352     */
    365353    public function test_get_sample_permalink_should_allow_yearlike_slugs_if_permastruct_does_not_cause_an_archive_conflict() {
    366         global $wp_rewrite;
    367         $wp_rewrite->init();
    368         $wp_rewrite->set_permalink_structure( '/%year%/%postname%/' );
    369         $wp_rewrite->flush_rules();
     354        $this->set_permalink_structure( '/%year%/%postname%/' );
    370355
    371356        $p = $this->factory->post->create( array(
     
    381366     */
    382367    public function test_get_sample_permalink_should_avoid_slugs_that_would_create_clashes_with_month_archives() {
    383         global $wp_rewrite;
    384         $wp_rewrite->init();
    385         $wp_rewrite->set_permalink_structure( '/%year%/%postname%/' );
    386         $wp_rewrite->flush_rules();
     368        $this->set_permalink_structure( '/%year%/%postname%/' );
    387369
    388370        $p = $this->factory->post->create( array(
     
    398380     */
    399381    public function test_get_sample_permalink_should_ignore_potential_month_conflicts_for_invalid_monthnum() {
    400         global $wp_rewrite;
    401         $wp_rewrite->init();
    402         $wp_rewrite->set_permalink_structure( '/%year%/%postname%/' );
    403         $wp_rewrite->flush_rules();
     382        $this->set_permalink_structure( '/%year%/%postname%/' );
    404383
    405384        $p = $this->factory->post->create( array(
     
    415394     */
    416395    public function test_get_sample_permalink_should_avoid_slugs_that_would_create_clashes_with_day_archives() {
    417         global $wp_rewrite;
    418         $wp_rewrite->init();
    419         $wp_rewrite->set_permalink_structure( '/%year%/%monthnum%/%postname%/' );
    420         $wp_rewrite->flush_rules();
     396        $this->set_permalink_structure( '/%year%/%monthnum%/%postname%/' );
    421397
    422398        $p = $this->factory->post->create( array(
     
    432408     */
    433409    public function test_get_sample_permalink_should_iterate_slug_suffix_when_a_date_conflict_is_found() {
    434         global $wp_rewrite;
    435         $wp_rewrite->init();
    436         $wp_rewrite->set_permalink_structure( '/%year%/%monthnum%/%postname%/' );
    437         $wp_rewrite->flush_rules();
     410        $this->set_permalink_structure( '/%year%/%monthnum%/%postname%/' );
    438411
    439412        $this->factory->post->create( array(
     
    453426     */
    454427    public function test_get_sample_permalink_should_ignore_potential_day_conflicts_for_invalid_day() {
    455         global $wp_rewrite;
    456         $wp_rewrite->init();
    457         $wp_rewrite->set_permalink_structure( '/%year%/%monthnum%/%postname%/' );
    458         $wp_rewrite->flush_rules();
     428        $this->set_permalink_structure( '/%year%/%monthnum%/%postname%/' );
    459429
    460430        $p = $this->factory->post->create( array(
     
    470440     */
    471441    public function test_get_sample_permalink_should_allow_daylike_slugs_if_permastruct_does_not_cause_an_archive_conflict() {
    472         global $wp_rewrite;
    473         $wp_rewrite->init();
    474         $wp_rewrite->set_permalink_structure( '/%year%/%month%/%day%/%postname%/' );
    475         $wp_rewrite->flush_rules();
     442        $this->set_permalink_structure( '/%year%/%month%/%day%/%postname%/' );
    476443
    477444        $p = $this->factory->post->create( array(
  • 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' ) );
  • trunk/tests/phpunit/tests/link/getPostCommentsFeedLink.php

    r34802 r34810  
    1818
    1919    public function test_post_pretty_link() {
    20         global $wp_rewrite;
    21         $wp_rewrite->init();
    22         $wp_rewrite->set_permalink_structure( '/%year%/%monthnum%/%day%/%postname%/' );
    23         $wp_rewrite->flush_rules();
     20        $this->set_permalink_structure( '/%year%/%monthnum%/%day%/%postname%/' );
    2421
    2522        $post_id = $this->factory->post->create();
     
    4845
    4946    public function test_attachment_pretty_link() {
    50         global $wp_rewrite;
    51         $wp_rewrite->init();
    52         $wp_rewrite->set_permalink_structure( '/%year%/%monthnum%/%day%/%postname%/' );
    53         $wp_rewrite->flush_rules();
     47        $this->set_permalink_structure( '/%year%/%monthnum%/%day%/%postname%/' );
    5448
    5549        $post_id = $this->factory->post->create( array(
     
    7165
    7266    public function test_attachment_no_name_pretty_link() {
    73         global $wp_rewrite;
    74         $wp_rewrite->init();
    75         $wp_rewrite->set_permalink_structure( '/%year%/%monthnum%/%day%/%postname%/' );
    76         $wp_rewrite->flush_rules();
     67        $this->set_permalink_structure( '/%year%/%monthnum%/%day%/%postname%/' );
    7768
    7869        $post_id = $this->factory->post->create();
     
    10495
    10596    public function test_unattached_pretty_link() {
    106         global $wp_rewrite;
    107         $wp_rewrite->init();
    108         $wp_rewrite->set_permalink_structure( '/%year%/%monthnum%/%day%/%postname%/' );
    109         $wp_rewrite->flush_rules();
     97        $this->set_permalink_structure( '/%year%/%monthnum%/%day%/%postname%/' );
    11098
    11199        $attachment_id = $this->factory->attachment->create_object( 'image.jpg', 0, array(
  • trunk/tests/phpunit/tests/post.php

    r34802 r34810  
    416416     */
    417417    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() {
    418         global $wp_rewrite;
    419         $wp_rewrite->init();
    420         $wp_rewrite->set_permalink_structure( '/%postname%/' );
    421         $wp_rewrite->flush_rules();
     418        $this->set_permalink_structure( '/%postname%/' );
    422419
    423420        $p = wp_insert_post( array(
     
    430427        $post = get_post( $p );
    431428
    432         $this->reset_permalinks();
     429        $this->set_permalink_structure();
    433430
    434431        $this->assertEquals( "$p-2", $post->post_name );
     
    506503        // might only fail if the post ID is greater than four characters
    507504
    508         global $wp_rewrite;
    509         $wp_rewrite->init();
    510         $wp_rewrite->set_permalink_structure('/%year%/%monthnum%/%day%/%postname%/');
    511         $wp_rewrite->flush_rules();
     505        $this->set_permalink_structure('/%year%/%monthnum%/%day%/%postname%/');
    512506
    513507        $post = array(
  • trunk/tests/phpunit/tests/post/wpUniquePostSlug.php

    r34802 r34810  
    170170     */
    171171    public function test_slugs_resulting_in_permalinks_that_resemble_year_archives_should_be_suffixed() {
    172         global $wp_rewrite;
    173         $wp_rewrite->init();
    174         $wp_rewrite->set_permalink_structure( '/%postname%/' );
    175         $wp_rewrite->flush_rules();
     172        $this->set_permalink_structure( '/%postname%/' );
    176173
    177174        $p = $this->factory->post->create( array(
     
    188185     */
    189186    public function test_slugs_resulting_in_permalinks_that_resemble_year_archives_should_not_be_suffixed_for_already_published_posts() {
    190         global $wp_rewrite;
    191         $wp_rewrite->init();
    192         $wp_rewrite->set_permalink_structure( '/%postname%/' );
    193         $wp_rewrite->flush_rules();
     187        $this->set_permalink_structure( '/%postname%/' );
    194188
    195189        $p = $this->factory->post->create( array(
     
    207201     */
    208202    public function test_yearlike_slugs_should_not_be_suffixed_if_permalink_structure_does_not_result_in_a_clash_with_year_archives() {
    209         global $wp_rewrite;
    210         $wp_rewrite->init();
    211         $wp_rewrite->set_permalink_structure( '/%year%/%postname%/' );
    212         $wp_rewrite->flush_rules();
     203        $this->set_permalink_structure( '/%year%/%postname%/' );
    213204
    214205        $p = $this->factory->post->create( array(
     
    225216     */
    226217    public function test_slugs_resulting_in_permalinks_that_resemble_month_archives_should_be_suffixed() {
    227         global $wp_rewrite;
    228         $wp_rewrite->init();
    229         $wp_rewrite->set_permalink_structure( '/%year%/%postname%/' );
    230         $wp_rewrite->flush_rules();
     218        $this->set_permalink_structure( '/%year%/%postname%/' );
    231219
    232220        $p = $this->factory->post->create( array(
     
    243231     */
    244232    public function test_monthlike_slugs_should_not_be_suffixed_if_permalink_structure_does_not_result_in_a_clash_with_month_archives() {
    245         global $wp_rewrite;
    246         $wp_rewrite->init();
    247         $wp_rewrite->set_permalink_structure( '/%year%/foo/%postname%/' );
    248         $wp_rewrite->flush_rules();
     233        $this->set_permalink_structure( '/%year%/foo/%postname%/' );
    249234
    250235        $p = $this->factory->post->create( array(
     
    261246     */
    262247    public function test_monthlike_slugs_should_not_be_suffixed_for_invalid_month_numbers() {
    263         global $wp_rewrite;
    264         $wp_rewrite->init();
    265         $wp_rewrite->set_permalink_structure( '/%year%/%postname%/' );
    266         $wp_rewrite->flush_rules();
     248        $this->set_permalink_structure( '/%year%/%postname%/' );
    267249
    268250        $p = $this->factory->post->create( array(
     
    279261     */
    280262    public function test_slugs_resulting_in_permalinks_that_resemble_day_archives_should_be_suffixed() {
    281         global $wp_rewrite;
    282         $wp_rewrite->init();
    283         $wp_rewrite->set_permalink_structure( '/%year%/%monthnum%/%postname%/' );
    284         $wp_rewrite->flush_rules();
     263        $this->set_permalink_structure( '/%year%/%monthnum%/%postname%/' );
    285264
    286265        $p = $this->factory->post->create( array(
     
    297276     */
    298277    public function test_daylike_slugs_should_not_be_suffixed_if_permalink_structure_does_not_result_in_a_clash_with_day_archives() {
    299         global $wp_rewrite;
    300         $wp_rewrite->init();
    301         $wp_rewrite->set_permalink_structure( '/%year%/%monthnum%/%day%/%postname%/' );
    302         $wp_rewrite->flush_rules();
     278        $this->set_permalink_structure( '/%year%/%monthnum%/%day%/%postname%/' );
    303279
    304280        $p = $this->factory->post->create( array(
     
    315291     */
    316292    public function test_daylike_slugs_should_not_be_suffixed_for_invalid_day_numbers() {
    317         global $wp_rewrite;
    318         $wp_rewrite->init();
    319         $wp_rewrite->set_permalink_structure( '/%year%/%monthnum%/%postname%/' );
    320         $wp_rewrite->flush_rules();
     293        $this->set_permalink_structure( '/%year%/%monthnum%/%postname%/' );
    321294
    322295        $p = $this->factory->post->create( array(
  • trunk/tests/phpunit/tests/query.php

    r34697 r34810  
    44
    55    function setUp() {
    6         global $wp_rewrite;
    76        parent::setUp();
    87
    9         $wp_rewrite->init();
    10         $wp_rewrite->set_permalink_structure( '/%year%/%monthnum%/%day%/%postname%/' );
    11 
    128        create_initial_taxonomies();
    13 
    14         $wp_rewrite->flush_rules();
     9        $this->set_permalink_structure( '/%year%/%monthnum%/%day%/%postname%/' );
    1510    }
    1611
  • trunk/tests/phpunit/tests/query/conditionals.php

    r31754 r34810  
    2323        update_option( 'posts_per_page', 5 );
    2424
    25         global $wp_rewrite;
    26 
    27         $wp_rewrite->init();
    28         $wp_rewrite->set_permalink_structure( '/%year%/%monthnum%/%day%/%postname%/' );
    29 
    3025        create_initial_taxonomies();
    3126
    32         $wp_rewrite->flush_rules();
     27        $this->set_permalink_structure( '/%year%/%monthnum%/%day%/%postname%/' );
    3328    }
    3429
  • trunk/tests/phpunit/tests/query/isTerm.php

    r31622 r34810  
    2424
    2525    function setUp() {
    26         global $wp_rewrite;
    2726        parent::setUp();
    2827
     
    3231        $GLOBALS['wp_query'] = $GLOBALS['wp_the_query'];
    3332
    34         $wp_rewrite->init();
    35         $wp_rewrite->set_permalink_structure( '/%year%/%monthnum%/%day%/%postname%/' );
     33        $this->set_permalink_structure( '/%year%/%monthnum%/%day%/%postname%/' );
    3634
    3735        create_initial_taxonomies();
    3836        register_taxonomy( 'testtax', 'post', array( 'public' => true ) );
    3937
    40         $wp_rewrite->flush_rules();
     38        flush_rewrite_rules();
    4139
    4240        $this->tag_id = $this->factory->tag->create( array( 'slug' => 'tag-slug' ) );
  • trunk/tests/phpunit/tests/query/verboseRewriteRules.php

    r33250 r34810  
    99class Tests_Query_VerbosePageRules extends Tests_Query_Conditionals {
    1010    function setUp() {
    11         global $wp_rewrite;
    12 
    1311        parent::setUp();
    14        
    15         $wp_rewrite->init();
    16         $wp_rewrite->set_permalink_structure( '/%category%/%year%/%postname%/' );
    1712
    1813        create_initial_taxonomies();
    1914
    20         $wp_rewrite->flush_rules();
     15        $this->set_permalink_structure( '/%category%/%year%/%postname%/' );
    2116    }
    2217}
  • trunk/tests/phpunit/tests/rewrite.php

    r34708 r34810  
    1010
    1111    function setUp() {
    12         global $wp_rewrite;
    1312        parent::setUp();
    1413
    15         // Need rewrite rules in place to use url_to_postid
    16         $wp_rewrite->init();
    17         $wp_rewrite->set_permalink_structure( '/%year%/%monthnum%/%day%/%postname%/' );
    18 
    1914        create_initial_taxonomies();
    2015
    21         $wp_rewrite->flush_rules();
     16        $this->set_permalink_structure( '/%year%/%monthnum%/%day%/%postname%/' );
    2217
    2318        $this->home_url = get_option( 'home' );
  • trunk/tests/phpunit/tests/rewrite/numericSlugs.php

    r34802 r34810  
    2121
    2222    public function test_go_to_year_segment_collision_without_title() {
    23         global $wp_rewrite, $wpdb;
    24         $wp_rewrite->init();
    25         $wp_rewrite->set_permalink_structure( '/%postname%/' );
    26         $wp_rewrite->flush_rules();
     23        global $wpdb;
     24        $this->set_permalink_structure( '/%postname%/' );
    2725
    2826        $id = $this->factory->post->create( array(
     
    5149
    5250    public function test_url_to_postid_year_segment_collision_without_title() {
    53         global $wp_rewrite, $wpdb;
    54         $wp_rewrite->init();
    55         $wp_rewrite->set_permalink_structure( '/%postname%/' );
    56         $wp_rewrite->flush_rules();
     51        global $wpdb;
     52        $this->set_permalink_structure( '/%postname%/' );
    5753
    5854        $id = $this->factory->post->create( array(
     
    7975
    8076    public function test_go_to_year_segment_collision_with_title() {
    81         global $wp_rewrite;
    82         $wp_rewrite->init();
    83         $wp_rewrite->set_permalink_structure( '/%postname%/' );
    84         $wp_rewrite->flush_rules();
     77        $this->set_permalink_structure( '/%postname%/' );
    8578
    8679        $id = $this->factory->post->create( array(
     
    9891
    9992    public function test_url_to_postid_year_segment_collision_with_title() {
    100         global $wp_rewrite;
    101         $wp_rewrite->init();
    102         $wp_rewrite->set_permalink_structure( '/%postname%/' );
    103         $wp_rewrite->flush_rules();
     93        $this->set_permalink_structure( '/%postname%/' );
    10494
    10595        $id = $this->factory->post->create( array(
     
    115105
    116106    public function test_go_to_month_segment_collision_without_title() {
    117         global $wp_rewrite;
    118         $wp_rewrite->init();
    119         $wp_rewrite->set_permalink_structure( '/%year%/%postname%/' );
    120         $wp_rewrite->flush_rules();
     107        $this->set_permalink_structure( '/%year%/%postname%/' );
    121108
    122109        $id = $this->factory->post->create( array(
     
    135122
    136123    public function test_url_to_postid_month_segment_collision_without_title() {
    137         global $wp_rewrite;
    138         $wp_rewrite->init();
    139         $wp_rewrite->set_permalink_structure( '/%year%/%postname%/' );
    140         $wp_rewrite->flush_rules();
     124        $this->set_permalink_structure( '/%year%/%postname%/' );
    141125
    142126        $id = $this->factory->post->create( array(
     
    153137
    154138    public function test_go_to_month_segment_collision_without_title_no_leading_zero() {
    155         global $wp_rewrite;
    156         $wp_rewrite->init();
    157         $wp_rewrite->set_permalink_structure( '/%year%/%postname%/' );
    158         $wp_rewrite->flush_rules();
     139        $this->set_permalink_structure( '/%year%/%postname%/' );
    159140
    160141        $id = $this->factory->post->create( array(
     
    173154
    174155    public function test_url_to_postid_month_segment_collision_without_title_no_leading_zero() {
    175         global $wp_rewrite;
    176         $wp_rewrite->init();
    177         $wp_rewrite->set_permalink_structure( '/%year%/%postname%/' );
    178         $wp_rewrite->flush_rules();
     156        $this->set_permalink_structure( '/%year%/%postname%/' );
    179157
    180158        $id = $this->factory->post->create( array(
     
    191169
    192170    public function test_go_to_month_segment_collision_with_title() {
    193         global $wp_rewrite;
    194         $wp_rewrite->init();
    195         $wp_rewrite->set_permalink_structure( '/%year%/%postname%/' );
    196         $wp_rewrite->flush_rules();
     171        $this->set_permalink_structure( '/%year%/%postname%/' );
    197172
    198173        $id = $this->factory->post->create( array(
     
    210185
    211186    public function test_url_to_postid_month_segment_collision_with_title() {
    212         global $wp_rewrite;
    213         $wp_rewrite->init();
    214         $wp_rewrite->set_permalink_structure( '/%year%/%postname%/' );
    215         $wp_rewrite->flush_rules();
     187        $this->set_permalink_structure( '/%year%/%postname%/' );
    216188
    217189        $id = $this->factory->post->create( array(
     
    227199
    228200    public function test_go_to_month_segment_collision_with_title_no_leading_zero() {
    229         global $wp_rewrite;
    230         $wp_rewrite->init();
    231         $wp_rewrite->set_permalink_structure( '/%year%/%postname%/' );
    232         $wp_rewrite->flush_rules();
     201        $this->set_permalink_structure( '/%year%/%postname%/' );
    233202
    234203        $id = $this->factory->post->create( array(
     
    246215
    247216    public function test_url_to_postid_month_segment_collision_with_title_no_leading_zero() {
    248         global $wp_rewrite;
    249         $wp_rewrite->init();
    250         $wp_rewrite->set_permalink_structure( '/%year%/%postname%/' );
    251         $wp_rewrite->flush_rules();
     217        $this->set_permalink_structure( '/%year%/%postname%/' );
    252218
    253219        $id = $this->factory->post->create( array(
     
    263229
    264230    public function test_go_to_day_segment_collision_without_title() {
    265         global $wp_rewrite;
    266         $wp_rewrite->init();
    267         $wp_rewrite->set_permalink_structure( '/%year%/%monthnum%/%postname%/' );
    268         $wp_rewrite->flush_rules();
     231        $this->set_permalink_structure( '/%year%/%monthnum%/%postname%/' );
    269232
    270233        $id = $this->factory->post->create( array(
     
    283246
    284247    public function test_url_to_postid_day_segment_collision_without_title() {
    285         global $wp_rewrite;
    286         $wp_rewrite->init();
    287         $wp_rewrite->set_permalink_structure( '/%year%/%monthnum%/%postname%/' );
    288         $wp_rewrite->flush_rules();
     248        $this->set_permalink_structure( '/%year%/%monthnum%/%postname%/' );
    289249
    290250        $id = $this->factory->post->create( array(
     
    301261
    302262    public function test_go_to_day_segment_collision_with_title() {
    303         global $wp_rewrite;
    304         $wp_rewrite->init();
    305         $wp_rewrite->set_permalink_structure( '/%year%/%monthnum%/%postname%/' );
    306         $wp_rewrite->flush_rules();
     263        $this->set_permalink_structure( '/%year%/%monthnum%/%postname%/' );
    307264
    308265        $id = $this->factory->post->create( array(
     
    320277
    321278    public function test_url_to_postid_day_segment_collision_with_title() {
    322         global $wp_rewrite;
    323         $wp_rewrite->init();
    324         $wp_rewrite->set_permalink_structure( '/%year%/%monthnum%/%postname%/' );
    325         $wp_rewrite->flush_rules();
     279        $this->set_permalink_structure( '/%year%/%monthnum%/%postname%/' );
    326280
    327281        $id = $this->factory->post->create( array(
     
    337291
    338292    public function test_numeric_slug_permalink_conflicts_should_only_be_resolved_for_the_main_query() {
    339         global $wp_rewrite;
    340         $wp_rewrite->init();
    341         $wp_rewrite->set_permalink_structure( '/%year%/%monthnum%/%postname%/' );
    342         $wp_rewrite->flush_rules();
     293        $this->set_permalink_structure( '/%year%/%monthnum%/%postname%/' );
    343294
    344295        $id = $this->factory->post->create( array(
     
    361312
    362313    public function test_month_slug_collision_should_resolve_to_date_archive_when_year_does_not_match_post_year() {
    363         global $wp_rewrite;
    364         $wp_rewrite->init();
    365         $wp_rewrite->set_permalink_structure( '/%year%/%postname%/' );
    366         $wp_rewrite->flush_rules();
     314        $this->set_permalink_structure( '/%year%/%postname%/' );
    367315
    368316        // Make sure a post is published in 2013/02, to avoid 404s.
     
    392340
    393341    public function test_day_slug_collision_should_resolve_to_date_archive_when_monthnum_does_not_match_post_month() {
    394         global $wp_rewrite;
    395         $wp_rewrite->init();
    396         $wp_rewrite->set_permalink_structure( '/%year%/%monthnum%/%postname%/' );
    397         $wp_rewrite->flush_rules();
     342        $this->set_permalink_structure( '/%year%/%monthnum%/%postname%/' );
    398343
    399344        // Make sure a post is published on 2015/01/01, to avoid 404s.
     
    423368
    424369    public function test_date_slug_collision_should_distinguish_valid_pagination_from_date() {
    425         global $wp_rewrite;
    426         $wp_rewrite->init();
    427         $wp_rewrite->set_permalink_structure( '/%year%/%postname%/' );
    428         $wp_rewrite->flush_rules();
     370        $this->set_permalink_structure( '/%year%/%postname%/' );
    429371
    430372        $id = $this->factory->post->create( array(
     
    442384
    443385    public function test_date_slug_collision_should_distinguish_too_high_pagination_from_date() {
    444         global $wp_rewrite;
    445         $wp_rewrite->init();
    446         $wp_rewrite->set_permalink_structure( '/%year%/%postname%/' );
    447         $wp_rewrite->flush_rules();
     386        $this->set_permalink_structure( '/%year%/%postname%/' );
    448387
    449388        $id = $this->factory->post->create( array(
     
    461400
    462401    public function test_date_slug_collision_should_not_require_pagination_query_var() {
    463         global $wp_rewrite;
    464         $wp_rewrite->init();
    465         $wp_rewrite->set_permalink_structure( '/%year%/%postname%/' );
    466         $wp_rewrite->flush_rules();
     402        $this->set_permalink_structure( '/%year%/%postname%/' );
    467403
    468404        $id = $this->factory->post->create( array(
     
    481417
    482418    public function test_date_slug_collision_should_be_ignored_when_pagination_var_is_present_but_post_does_not_have_multiple_pages() {
    483         global $wp_rewrite;
    484         $wp_rewrite->init();
    485         $wp_rewrite->set_permalink_structure( '/%year%/%postname%/' );
    486         $wp_rewrite->flush_rules();
     419        $this->set_permalink_structure( '/%year%/%postname%/' );
    487420
    488421        $id = $this->factory->post->create( array(
  • trunk/tests/phpunit/tests/rewrite/oldSlugRedirect.php

    r34802 r34810  
    2020        add_filter( 'old_slug_redirect_url', array( $this, 'filter_old_slug_redirect_url' ), 10, 1 );
    2121
    22         global $wp_rewrite;
     22        $this->set_permalink_structure( '/%postname%/' );
    2323
    24         $wp_rewrite->init();
    25         $wp_rewrite->set_permalink_structure( '/%postname%/' );
    2624        add_rewrite_endpoint( 'custom-endpoint', EP_PERMALINK );
    2725        add_rewrite_endpoint( 'second-endpoint', EP_PERMALINK, 'custom' );
    28         $wp_rewrite->flush_rules();
     26
     27        flush_rewrite_rules();
    2928    }
    3029
  • trunk/tests/phpunit/tests/term/getTermLink.php

    r34802 r34810  
    8686
    8787    public function test_taxonomy_permastruct_with_hierarchical_rewrite_should_put_term_ancestors_in_link() {
    88         global $wp_rewrite;
    89         $wp_rewrite->init();
    90         $wp_rewrite->set_permalink_structure( '/%year%/%monthnum%/%day%/%postname%/' );
    91         $wp_rewrite->flush_rules();
     88        $this->set_permalink_structure( '/%year%/%monthnum%/%day%/%postname%/' );
    9289
    9390        register_taxonomy( 'wptests_tax2', 'post', array(
     
    9895            ),
    9996        ) );
     97
     98        flush_rewrite_rules();
    10099
    101100        $t1 = $this->factory->term->create( array(
     
    116115
    117116    public function test_taxonomy_permastruct_with_nonhierarchical_rewrite_should_not_put_term_ancestors_in_link() {
    118         global $wp_rewrite;
    119         $permalink_structure = get_option( 'permalink_structure' );
    120         $wp_rewrite->set_permalink_structure( '/%year%/%monthnum%/%day%/%postname%/' );
    121         $wp_rewrite->flush_rules();
     117        $this->set_permalink_structure( '/%year%/%monthnum%/%day%/%postname%/' );
    122118
    123119        register_taxonomy( 'wptests_tax2', 'post', array(
     
    128124            ),
    129125        ) );
     126
     127        flush_rewrite_rules();
    130128
    131129        $t1 = $this->factory->term->create( array(
  • trunk/tests/phpunit/tests/user/author.php

    r34802 r34810  
    128128     */
    129129    public function test_get_the_author_posts_link_with_permalinks() {
    130         global $wp_rewrite;
    131         $wp_rewrite->init();
    132         $wp_rewrite->set_permalink_structure( '/%postname%/' );
    133         $wp_rewrite->flush_rules();
     130        $this->set_permalink_structure( '/%postname%/' );
    134131
    135132        $author = $this->factory->user->create_and_get( array(
Note: See TracChangeset for help on using the changeset viewer.