Make WordPress Core


Ignore:
Timestamp:
10/03/2015 08:54:11 PM (9 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/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(
Note: See TracChangeset for help on using the changeset viewer.