diff --git tests/phpunit/tests/rewrite/oldDateRedirect.php tests/phpunit/tests/rewrite/oldDateRedirect.php
index 9bff121044..04be57ce23 100644
|
|
|
|
| 6 | 6 | class Tests_Rewrite_OldDateRedirect extends WP_UnitTestCase { |
| 7 | 7 | protected $old_date_redirect_url; |
| 8 | 8 | |
| 9 | | protected $post_id; |
| | 9 | public static $post_id; |
| 10 | 10 | |
| 11 | | public function setUp() { |
| 12 | | parent::setUp(); |
| | 11 | public static $attachment_id; |
| 13 | 12 | |
| 14 | | $this->post_id = self::factory()->post->create( array( |
| | 13 | public static function wpSetUpBeforeClass() { |
| | 14 | self::$post_id = self::factory()->post->create( array( |
| 15 | 15 | 'post_title' => 'Foo Bar', |
| 16 | 16 | 'post_name' => 'foo-bar', |
| 17 | 17 | ) ); |
| 18 | 18 | |
| | 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 | |
| 19 | 32 | add_filter( 'old_slug_redirect_url', array( $this, 'filter_old_date_redirect_url' ), 10, 1 ); |
| 20 | 33 | |
| 21 | 34 | $this->set_permalink_structure( '/%year%/%monthnum%/%day%/%postname%/' ); |
| … |
… |
class Tests_Rewrite_OldDateRedirect extends WP_UnitTestCase { |
| 30 | 43 | parent::tearDown(); |
| 31 | 44 | |
| 32 | 45 | $this->old_date_redirect_url = null; |
| 33 | | |
| 34 | | remove_filter( 'old_slug_redirect_url', array( $this, 'filter_old_date_redirect_url' ), 10 ); |
| 35 | 46 | } |
| 36 | 47 | |
| 37 | 48 | 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 ) ); |
| 39 | 50 | |
| 40 | 51 | $time = '2004-01-03 00:00:00'; |
| 41 | 52 | wp_update_post( array( |
| 42 | | 'ID' => $this->post_id, |
| | 53 | 'ID' => self::$post_id, |
| 43 | 54 | 'post_date' => $time, |
| 44 | 55 | 'post_date_gmt' => get_gmt_from_date( $time ), |
| 45 | 56 | ) ); |
| 46 | 57 | |
| 47 | | $permalink = user_trailingslashit( get_permalink( $this->post_id ) ); |
| | 58 | $permalink = user_trailingslashit( get_permalink( self::$post_id ) ); |
| 48 | 59 | |
| 49 | 60 | $this->go_to( $old_permalink ); |
| 50 | 61 | wp_old_slug_redirect(); |
| 51 | | $this->assertEquals( $permalink, $this->old_date_redirect_url ); |
| | 62 | $this->assertSame( $permalink, $this->old_date_redirect_url ); |
| 52 | 63 | } |
| 53 | 64 | |
| 54 | 65 | 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 ) ); |
| 56 | 67 | |
| 57 | 68 | $time = '2004-01-03 00:00:00'; |
| 58 | 69 | wp_update_post( array( |
| 59 | | 'ID' => $this->post_id, |
| | 70 | 'ID' => self::$post_id, |
| 60 | 71 | 'post_date' => $time, |
| 61 | 72 | 'post_date_gmt' => get_gmt_from_date( $time ), |
| 62 | 73 | 'post_name' => 'bar-baz', |
| 63 | 74 | ) ); |
| 64 | 75 | |
| 65 | | $permalink = user_trailingslashit( get_permalink( $this->post_id ) ); |
| | 76 | $permalink = user_trailingslashit( get_permalink( self::$post_id ) ); |
| 66 | 77 | |
| 67 | 78 | $this->go_to( $old_permalink ); |
| 68 | 79 | wp_old_slug_redirect(); |
| 69 | | $this->assertEquals( $permalink, $this->old_date_redirect_url ); |
| | 80 | $this->assertSame( $permalink, $this->old_date_redirect_url ); |
| 70 | 81 | } |
| 71 | 82 | |
| 72 | 83 | 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 ); |
| 80 | 85 | |
| 81 | 86 | $time = '2004-01-03 00:00:00'; |
| 82 | 87 | wp_update_post( array( |
| 83 | | 'ID' => $this->post_id, |
| | 88 | 'ID' => self::$post_id, |
| 84 | 89 | 'post_date' => $time, |
| 85 | 90 | 'post_date_gmt' => get_gmt_from_date( $time ), |
| 86 | 91 | ) ); |
| … |
… |
class Tests_Rewrite_OldDateRedirect extends WP_UnitTestCase { |
| 90 | 95 | $this->assertNull( $this->old_date_redirect_url ); |
| 91 | 96 | $this->assertQueryTrue( 'is_attachment', 'is_singular', 'is_single' ); |
| 92 | 97 | |
| 93 | | $old_permalink = get_attachment_link( $attachment_id ); |
| | 98 | $old_permalink = get_attachment_link( self::$attachment_id ); |
| 94 | 99 | |
| 95 | 100 | wp_update_post( array( |
| 96 | | 'ID' => $attachment_id, |
| | 101 | 'ID' => self::$attachment_id, |
| 97 | 102 | 'post_name' => 'the-attachment', |
| 98 | 103 | ) ); |
| 99 | 104 | |
| 100 | | $permalink = user_trailingslashit( trailingslashit( get_permalink( $this->post_id ) ) . 'the-attachment' ); |
| | 105 | $permalink = user_trailingslashit( trailingslashit( get_permalink( self::$post_id ) ) . 'the-attachment' ); |
| 101 | 106 | |
| 102 | 107 | $this->go_to( $old_permalink ); |
| 103 | 108 | wp_old_slug_redirect(); |
| 104 | | $this->assertEquals( $permalink, $this->old_date_redirect_url ); |
| | 109 | $this->assertSame( $permalink, $this->old_date_redirect_url ); |
| 105 | 110 | } |
| 106 | 111 | |
| 107 | 112 | 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 ); |
| 115 | 114 | |
| 116 | 115 | $time = '2004-01-03 00:00:00'; |
| 117 | 116 | wp_update_post( array( |
| 118 | | 'ID' => $this->post_id, |
| | 117 | 'ID' => self::$post_id, |
| 119 | 118 | 'post_date' => $time, |
| 120 | 119 | 'post_date_gmt' => get_gmt_from_date( $time ), |
| 121 | 120 | 'post_name' => 'bar-baz', |
| … |
… |
class Tests_Rewrite_OldDateRedirect extends WP_UnitTestCase { |
| 126 | 125 | $this->assertNull( $this->old_date_redirect_url ); |
| 127 | 126 | $this->assertQueryTrue( 'is_attachment', 'is_singular', 'is_single' ); |
| 128 | 127 | |
| 129 | | $old_permalink = get_attachment_link( $attachment_id ); |
| | 128 | $old_permalink = get_attachment_link( self::$attachment_id ); |
| 130 | 129 | |
| 131 | 130 | wp_update_post( array( |
| 132 | | 'ID' => $attachment_id, |
| | 131 | 'ID' => self::$attachment_id, |
| 133 | 132 | 'post_name' => 'the-attachment', |
| 134 | 133 | ) ); |
| 135 | 134 | |
| 136 | | $permalink = user_trailingslashit( trailingslashit( get_permalink( $this->post_id ) ) . 'the-attachment' ); |
| | 135 | $permalink = user_trailingslashit( trailingslashit( get_permalink( self::$post_id ) ) . 'the-attachment' ); |
| 137 | 136 | |
| 138 | 137 | $this->go_to( $old_permalink ); |
| 139 | 138 | wp_old_slug_redirect(); |
| 140 | | $this->assertEquals( $permalink, $this->old_date_redirect_url ); |
| | 139 | $this->assertSame( $permalink, $this->old_date_redirect_url ); |
| 141 | 140 | } |
| 142 | 141 | |
| 143 | 142 | public function test_old_date_redirect_paged() { |
| 144 | 143 | wp_update_post( array( |
| 145 | | 'ID' => $this->post_id, |
| | 144 | 'ID' => self::$post_id, |
| 146 | 145 | 'post_content' => 'Test<!--nextpage-->Test', |
| 147 | 146 | ) ); |
| 148 | 147 | |
| 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' ); |
| 150 | 149 | |
| 151 | 150 | $time = '2004-01-03 00:00:00'; |
| 152 | 151 | wp_update_post( array( |
| 153 | | 'ID' => $this->post_id, |
| | 152 | 'ID' => self::$post_id, |
| 154 | 153 | 'post_date' => $time, |
| 155 | 154 | 'post_date_gmt' => get_gmt_from_date( $time ), |
| 156 | 155 | ) ); |
| 157 | 156 | |
| 158 | | $permalink = user_trailingslashit( trailingslashit( get_permalink( $this->post_id ) ) . 'page/2' ); |
| | 157 | $permalink = user_trailingslashit( trailingslashit( get_permalink( self::$post_id ) ) . 'page/2' ); |
| 159 | 158 | |
| 160 | 159 | $this->go_to( $old_permalink ); |
| 161 | 160 | wp_old_slug_redirect(); |
| 162 | | $this->assertEquals( $permalink, $this->old_date_redirect_url ); |
| | 161 | $this->assertSame( $permalink, $this->old_date_redirect_url ); |
| 163 | 162 | } |
| 164 | 163 | |
| 165 | 164 | public function test_old_date_slug_redirect_paged() { |
| 166 | 165 | wp_update_post( array( |
| 167 | | 'ID' => $this->post_id, |
| | 166 | 'ID' => self::$post_id, |
| 168 | 167 | 'post_content' => 'Test<!--nextpage-->Test', |
| 169 | 168 | ) ); |
| 170 | 169 | |
| 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' ); |
| 172 | 171 | |
| 173 | 172 | $time = '2004-01-04 12:00:00'; |
| 174 | 173 | wp_update_post( array( |
| 175 | | 'ID' => $this->post_id, |
| | 174 | 'ID' => self::$post_id, |
| 176 | 175 | 'post_date' => $time, |
| 177 | 176 | 'post_date_gmt' => get_gmt_from_date( $time ), |
| 178 | 177 | 'post_name' => 'bar-baz', |
| 179 | 178 | ) ); |
| 180 | 179 | |
| 181 | | $permalink = user_trailingslashit( trailingslashit( get_permalink( $this->post_id ) ) . 'page/2' ); |
| | 180 | $permalink = user_trailingslashit( trailingslashit( get_permalink( self::$post_id ) ) . 'page/2' ); |
| 182 | 181 | |
| 183 | 182 | $this->go_to( $old_permalink ); |
| 184 | 183 | wp_old_slug_redirect(); |
| 185 | | $this->assertEquals( $permalink, $this->old_date_redirect_url ); |
| | 184 | $this->assertSame( $permalink, $this->old_date_redirect_url ); |
| 186 | 185 | } |
| 187 | 186 | |
| 188 | 187 | 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 ) ); |
| 190 | 189 | |
| 191 | 190 | $time = '2004-01-04 12:00:00'; |
| 192 | 191 | wp_update_post( array( |
| 193 | | 'ID' => $this->post_id, |
| | 192 | 'ID' => self::$post_id, |
| 194 | 193 | 'post_date' => $time, |
| 195 | 194 | 'post_date_gmt' => get_gmt_from_date( $time ), |
| 196 | 195 | 'post_name' => 'bar-baz', |
| … |
… |
class Tests_Rewrite_OldDateRedirect extends WP_UnitTestCase { |
| 203 | 202 | |
| 204 | 203 | $permalink = user_trailingslashit( get_permalink( $new_post_id ) ); |
| 205 | 204 | |
| 206 | | $this->assertEquals( $old_permalink, $permalink ); |
| | 205 | $this->assertSame( $old_permalink, $permalink ); |
| 207 | 206 | |
| 208 | 207 | $this->go_to( $old_permalink ); |
| 209 | 208 | wp_old_slug_redirect(); |