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/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(
Note: See TracChangeset for help on using the changeset viewer.