Make WordPress Core


Ignore:
Timestamp:
10/03/2015 05:14:12 PM (11 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/admin/includesPost.php

    r34680 r34802  
    254254                global $wp_rewrite;
    255255
    256                 $old_permalink_structure = get_option( 'permalink_structure' );
    257256                $permalink_structure = '%postname%';
    258257                $wp_rewrite->set_permalink_structure( "/$permalink_structure/" );
     
    266265
    267266                $this->assertSame( $expected, $found[0] );
    268 
    269                 $wp_rewrite->set_permalink_structure( $old_permalink_structure );
    270                 flush_rewrite_rules();
    271267        }
    272268
     
    276272         */
    277273        public function test_get_sample_permalink_html_should_use_default_permalink_for_view_post_link_when_pretty_permalinks_are_disabled() {
    278                 global $wp_rewrite;
    279                 $old_permalink_structure = get_option( 'permalink_structure' );
    280                 $wp_rewrite->set_permalink_structure( '' );
    281                 flush_rewrite_rules();
    282 
    283274                wp_set_current_user( $this->factory->user->create( array( 'role' => 'administrator' ) ) );
    284275
     
    288279                $found = get_sample_permalink_html( $p );
    289280                $this->assertContains( 'href="' . get_option( 'home' ) . '/?p=' . $p . '"', $found );
    290 
    291                 $wp_rewrite->set_permalink_structure( $old_permalink_structure );
    292                 flush_rewrite_rules();
    293281        }
    294282
     
    299287        public function test_get_sample_permalink_html_should_use_pretty_permalink_for_view_post_link_when_pretty_permalinks_are_enabled() {
    300288                global $wp_rewrite;
    301                 $old_permalink_structure = get_option( 'permalink_structure' );
    302289                $permalink_structure = '%postname%';
    303290                $wp_rewrite->set_permalink_structure( "/$permalink_structure/" );
     
    312299                $post = get_post( $p );
    313300                $this->assertContains( 'href="' . get_option( 'home' ) . "/" . $post->post_name . '/"', $found );
    314 
    315                 $wp_rewrite->set_permalink_structure( $old_permalink_structure );
    316                 flush_rewrite_rules();
    317301        }
    318302
     
    323307        public function test_get_sample_permalink_html_should_use_correct_permalink_for_view_post_link_when_changing_slug() {
    324308                global $wp_rewrite;
    325                 $old_permalink_structure = get_option( 'permalink_structure' );
    326309                $permalink_structure = '%postname%';
    327310                $wp_rewrite->set_permalink_structure( "/$permalink_structure/" );
     
    358341
    359342                $this->assertContains( 'href="' . esc_url( $preview_link ) . '"', $found, $message );
    360 
    361                 $wp_rewrite->set_permalink_structure( $old_permalink_structure );
    362                 flush_rewrite_rules();
    363343        }
    364344
     
    378358                $found = get_sample_permalink( $p );
    379359                $this->assertEquals( '2015-2', $found[1] );
    380 
    381                 $wp_rewrite->set_permalink_structure( '' );
    382                 flush_rewrite_rules();
    383360        }
    384361
     
    398375                $found = get_sample_permalink( $p );
    399376                $this->assertEquals( '2015', $found[1] );
    400 
    401                 $wp_rewrite->set_permalink_structure( '' );
    402                 flush_rewrite_rules();
    403377        }
    404378
     
    418392                $found = get_sample_permalink( $p );
    419393                $this->assertEquals( '11-2', $found[1] );
    420 
    421                 $wp_rewrite->set_permalink_structure( '' );
    422                 flush_rewrite_rules();
    423394        }
    424395
     
    438409                $found = get_sample_permalink( $p );
    439410                $this->assertEquals( '13', $found[1] );
    440 
    441                 $wp_rewrite->set_permalink_structure( '' );
    442                 flush_rewrite_rules();
    443411        }
    444412
     
    458426                $found = get_sample_permalink( $p );
    459427                $this->assertEquals( '30-2', $found[1] );
    460 
    461                 $wp_rewrite->set_permalink_structure( '' );
    462                 flush_rewrite_rules();
    463428        }
    464429
     
    482447                $found = get_sample_permalink( $p );
    483448                $this->assertEquals( '30-3', $found[1] );
    484 
    485                 $wp_rewrite->set_permalink_structure( '' );
    486                 flush_rewrite_rules();
    487449        }
    488450
     
    502464                $found = get_sample_permalink( $p );
    503465                $this->assertEquals( '32', $found[1] );
    504 
    505                 $wp_rewrite->set_permalink_structure( '' );
    506                 flush_rewrite_rules();
    507466        }
    508467
     
    522481                $found = get_sample_permalink( $p );
    523482                $this->assertEquals( '30', $found[1] );
    524 
    525                 $wp_rewrite->set_permalink_structure( '' );
    526                 flush_rewrite_rules();
    527483        }
    528484
Note: See TracChangeset for help on using the changeset viewer.