Make WordPress Core

Ticket #15397: 15397-tests.patch

File 15397-tests.patch, 9.0 KB (added by Frank Klein, 7 years ago)
  • tests/phpunit/tests/rewrite/oldDateRedirect.php

    diff --git tests/phpunit/tests/rewrite/oldDateRedirect.php tests/phpunit/tests/rewrite/oldDateRedirect.php
    index 9bff121044..04be57ce23 100644
     
    66class Tests_Rewrite_OldDateRedirect extends WP_UnitTestCase {
    77        protected $old_date_redirect_url;
    88
    9         protected $post_id;
     9        public static $post_id;
    1010
    11         public function setUp() {
    12                 parent::setUp();
     11        public static $attachment_id;
    1312
    14                 $this->post_id = self::factory()->post->create( array(
     13        public static function wpSetUpBeforeClass() {
     14                self::$post_id = self::factory()->post->create( array(
    1515                        'post_title' => 'Foo Bar',
    1616                        'post_name'  => 'foo-bar',
    1717                ) );
    1818
     19                self::$attachment_id = self::factory()->attachment->create_object(
     20                        array(
     21                                'file'           => DIR_TESTDATA . '/images/canola.jpg',
     22                                'post_mime_type' => 'image/jpeg',
     23                                'post_name'      => 'my-attachment',
     24                                'post_parent'    => self::$post_id,
     25                        )
     26                );
     27        }
     28
     29        public function setUp() {
     30                parent::setUp();
     31
    1932                add_filter( 'old_slug_redirect_url', array( $this, 'filter_old_date_redirect_url' ), 10, 1 );
    2033
    2134                $this->set_permalink_structure( '/%year%/%monthnum%/%day%/%postname%/' );
    class Tests_Rewrite_OldDateRedirect extends WP_UnitTestCase { 
    3043                parent::tearDown();
    3144
    3245                $this->old_date_redirect_url = null;
    33 
    34                 remove_filter( 'old_slug_redirect_url', array( $this, 'filter_old_date_redirect_url' ), 10 );
    3546        }
    3647
    3748        public function test_old_date_redirect() {
    38                 $old_permalink = user_trailingslashit( get_permalink( $this->post_id ) );
     49                $old_permalink = user_trailingslashit( get_permalink( self::$post_id ) );
    3950
    4051                $time = '2004-01-03 00:00:00';
    4152                wp_update_post( array(
    42                         'ID'            => $this->post_id,
     53                        'ID'            => self::$post_id,
    4354                        'post_date'     => $time,
    4455                        'post_date_gmt' => get_gmt_from_date( $time ),
    4556                ) );
    4657
    47                 $permalink = user_trailingslashit( get_permalink( $this->post_id ) );
     58                $permalink = user_trailingslashit( get_permalink( self::$post_id ) );
    4859
    4960                $this->go_to( $old_permalink );
    5061                wp_old_slug_redirect();
    51                 $this->assertEquals( $permalink, $this->old_date_redirect_url );
     62                $this->assertSame( $permalink, $this->old_date_redirect_url );
    5263        }
    5364
    5465        public function test_old_date_slug_redirect() {
    55                 $old_permalink = user_trailingslashit( get_permalink( $this->post_id ) );
     66                $old_permalink = user_trailingslashit( get_permalink( self::$post_id ) );
    5667
    5768                $time = '2004-01-03 00:00:00';
    5869                wp_update_post( array(
    59                         'ID'            => $this->post_id,
     70                        'ID'            => self::$post_id,
    6071                        'post_date'     => $time,
    6172                        'post_date_gmt' => get_gmt_from_date( $time ),
    6273                        'post_name'     => 'bar-baz',
    6374                ) );
    6475
    65                 $permalink = user_trailingslashit( get_permalink( $this->post_id ) );
     76                $permalink = user_trailingslashit( get_permalink( self::$post_id ) );
    6677
    6778                $this->go_to( $old_permalink );
    6879                wp_old_slug_redirect();
    69                 $this->assertEquals( $permalink, $this->old_date_redirect_url );
     80                $this->assertSame( $permalink, $this->old_date_redirect_url );
    7081        }
    7182
    7283        public function test_old_date_redirect_attachment() {
    73                 $file          = DIR_TESTDATA . '/images/canola.jpg';
    74                 $attachment_id = self::factory()->attachment->create_object( $file, $this->post_id, array(
    75                         'post_mime_type' => 'image/jpeg',
    76                         'post_name'      => 'my-attachment',
    77                 ) );
    78 
    79                 $old_permalink = get_attachment_link( $attachment_id );
     84                $old_permalink = get_attachment_link( self::$attachment_id );
    8085
    8186                $time = '2004-01-03 00:00:00';
    8287                wp_update_post( array(
    83                         'ID'            => $this->post_id,
     88                        'ID'            => self::$post_id,
    8489                        'post_date'     => $time,
    8590                        'post_date_gmt' => get_gmt_from_date( $time ),
    8691                ) );
    class Tests_Rewrite_OldDateRedirect extends WP_UnitTestCase { 
    9095                $this->assertNull( $this->old_date_redirect_url );
    9196                $this->assertQueryTrue( 'is_attachment', 'is_singular', 'is_single' );
    9297
    93                 $old_permalink = get_attachment_link( $attachment_id );
     98                $old_permalink = get_attachment_link( self::$attachment_id );
    9499
    95100                wp_update_post( array(
    96                         'ID'        => $attachment_id,
     101                        'ID'        => self::$attachment_id,
    97102                        'post_name' => 'the-attachment',
    98103                ) );
    99104
    100                 $permalink = user_trailingslashit( trailingslashit( get_permalink( $this->post_id ) ) . 'the-attachment' );
     105                $permalink = user_trailingslashit( trailingslashit( get_permalink( self::$post_id ) ) . 'the-attachment' );
    101106
    102107                $this->go_to( $old_permalink );
    103108                wp_old_slug_redirect();
    104                 $this->assertEquals( $permalink, $this->old_date_redirect_url );
     109                $this->assertSame( $permalink, $this->old_date_redirect_url );
    105110        }
    106111
    107112        public function test_old_date_slug_redirect_attachment() {
    108                 $file          = DIR_TESTDATA . '/images/canola.jpg';
    109                 $attachment_id = self::factory()->attachment->create_object( $file, $this->post_id, array(
    110                         'post_mime_type' => 'image/jpeg',
    111                         'post_name'      => 'my-attachment',
    112                 ) );
    113 
    114                 $old_permalink = get_attachment_link( $attachment_id );
     113                $old_permalink = get_attachment_link( self::$attachment_id );
    115114
    116115                $time = '2004-01-03 00:00:00';
    117116                wp_update_post( array(
    118                         'ID'            => $this->post_id,
     117                        'ID'            => self::$post_id,
    119118                        'post_date'     => $time,
    120119                        'post_date_gmt' => get_gmt_from_date( $time ),
    121120                        'post_name'     => 'bar-baz',
    class Tests_Rewrite_OldDateRedirect extends WP_UnitTestCase { 
    126125                $this->assertNull( $this->old_date_redirect_url );
    127126                $this->assertQueryTrue( 'is_attachment', 'is_singular', 'is_single' );
    128127
    129                 $old_permalink = get_attachment_link( $attachment_id );
     128                $old_permalink = get_attachment_link( self::$attachment_id );
    130129
    131130                wp_update_post( array(
    132                         'ID'        => $attachment_id,
     131                        'ID'        => self::$attachment_id,
    133132                        'post_name' => 'the-attachment',
    134133                ) );
    135134
    136                 $permalink = user_trailingslashit( trailingslashit( get_permalink( $this->post_id ) ) . 'the-attachment' );
     135                $permalink = user_trailingslashit( trailingslashit( get_permalink( self::$post_id ) ) . 'the-attachment' );
    137136
    138137                $this->go_to( $old_permalink );
    139138                wp_old_slug_redirect();
    140                 $this->assertEquals( $permalink, $this->old_date_redirect_url );
     139                $this->assertSame( $permalink, $this->old_date_redirect_url );
    141140        }
    142141
    143142        public function test_old_date_redirect_paged() {
    144143                wp_update_post( array(
    145                         'ID'           => $this->post_id,
     144                        'ID'           => self::$post_id,
    146145                        'post_content' => 'Test<!--nextpage-->Test',
    147146                ) );
    148147
    149                 $old_permalink = user_trailingslashit( trailingslashit( get_permalink( $this->post_id ) ) . 'page/2' );
     148                $old_permalink = user_trailingslashit( trailingslashit( get_permalink( self::$post_id ) ) . 'page/2' );
    150149
    151150                $time = '2004-01-03 00:00:00';
    152151                wp_update_post( array(
    153                         'ID'            => $this->post_id,
     152                        'ID'            => self::$post_id,
    154153                        'post_date'     => $time,
    155154                        'post_date_gmt' => get_gmt_from_date( $time ),
    156155                ) );
    157156
    158                 $permalink = user_trailingslashit( trailingslashit( get_permalink( $this->post_id ) ) . 'page/2' );
     157                $permalink = user_trailingslashit( trailingslashit( get_permalink( self::$post_id ) ) . 'page/2' );
    159158
    160159                $this->go_to( $old_permalink );
    161160                wp_old_slug_redirect();
    162                 $this->assertEquals( $permalink, $this->old_date_redirect_url );
     161                $this->assertSame( $permalink, $this->old_date_redirect_url );
    163162        }
    164163
    165164        public function test_old_date_slug_redirect_paged() {
    166165                wp_update_post( array(
    167                         'ID'           => $this->post_id,
     166                        'ID'           => self::$post_id,
    168167                        'post_content' => 'Test<!--nextpage-->Test',
    169168                ) );
    170169
    171                 $old_permalink = user_trailingslashit( trailingslashit( get_permalink( $this->post_id ) ) . 'page/2' );
     170                $old_permalink = user_trailingslashit( trailingslashit( get_permalink( self::$post_id ) ) . 'page/2' );
    172171
    173172                $time = '2004-01-04 12:00:00';
    174173                wp_update_post( array(
    175                         'ID'            => $this->post_id,
     174                        'ID'            => self::$post_id,
    176175                        'post_date'     => $time,
    177176                        'post_date_gmt' => get_gmt_from_date( $time ),
    178177                        'post_name'     => 'bar-baz',
    179178                ) );
    180179
    181                 $permalink = user_trailingslashit( trailingslashit( get_permalink( $this->post_id ) ) . 'page/2' );
     180                $permalink = user_trailingslashit( trailingslashit( get_permalink( self::$post_id ) ) . 'page/2' );
    182181
    183182                $this->go_to( $old_permalink );
    184183                wp_old_slug_redirect();
    185                 $this->assertEquals( $permalink, $this->old_date_redirect_url );
     184                $this->assertSame( $permalink, $this->old_date_redirect_url );
    186185        }
    187186
    188187        public function test_old_date_slug_doesnt_redirect_when_reused() {
    189                 $old_permalink = user_trailingslashit( get_permalink( $this->post_id ) );
     188                $old_permalink = user_trailingslashit( get_permalink( self::$post_id ) );
    190189
    191190                $time = '2004-01-04 12:00:00';
    192191                wp_update_post( array(
    193                         'ID'            => $this->post_id,
     192                        'ID'            => self::$post_id,
    194193                        'post_date'     => $time,
    195194                        'post_date_gmt' => get_gmt_from_date( $time ),
    196195                        'post_name'     => 'bar-baz',
    class Tests_Rewrite_OldDateRedirect extends WP_UnitTestCase { 
    203202
    204203                $permalink = user_trailingslashit( get_permalink( $new_post_id ) );
    205204
    206                 $this->assertEquals( $old_permalink, $permalink );
     205                $this->assertSame( $old_permalink, $permalink );
    207206
    208207                $this->go_to( $old_permalink );
    209208                wp_old_slug_redirect();