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