Changeset 42343 for trunk/tests/phpunit/includes/testcase-canonical.php
- Timestamp:
- 11/30/2017 11:09:33 PM (8 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/tests/phpunit/includes/testcase-canonical.php
r40518 r42343 4 4 static $old_current_user; 5 5 static $author_id; 6 static $post_ids = array();6 static $post_ids = array(); 7 7 static $comment_ids = array(); 8 static $term_ids = array();9 static $terms = array();8 static $term_ids = array(); 9 static $terms = array(); 10 10 static $old_options = array(); 11 11 … … 44 44 public static function generate_shared_fixtures( $factory ) { 45 45 self::$old_current_user = get_current_user_id(); 46 self::$author_id = $factory->user->create( array( 'user_login' => 'canonical-author' ) );46 self::$author_id = $factory->user->create( array( 'user_login' => 'canonical-author' ) ); 47 47 48 48 /* … … 55 55 // self::factory()->term->create( array( 'taxonomy' => 'category', 'name' => 'uncategorized' ) ); 56 56 57 self::$post_ids[] = $factory->post->create( array( 'import_id' => 587, 'post_title' => 'post-format-test-audio', 'post_date' => '2008-06-02 00:00:00' ) ); 58 self::$post_ids[] = $post_id = $factory->post->create( array( 'post_title' => 'post-format-test-gallery', 'post_date' => '2008-06-10 00:00:00' ) ); 59 self::$post_ids[] = $factory->post->create( array( 'import_id' => 611, 'post_type' => 'attachment', 'post_title' => 'canola2', 'post_parent' => $post_id ) ); 60 61 self::$post_ids[] = $factory->post->create( array( 62 'post_title' => 'images-test', 63 'post_date' => '2008-09-03 00:00:00', 64 'post_content' => 'Page 1 <!--nextpage--> Page 2 <!--nextpage--> Page 3' 65 ) ); 66 67 self::$post_ids[] = $post_id = $factory->post->create( array( 'import_id' => 149, 'post_title' => 'comment-test', 'post_date' => '2008-03-03 00:00:00' ) ); 57 self::$post_ids[] = $factory->post->create( 58 array( 59 'import_id' => 587, 60 'post_title' => 'post-format-test-audio', 61 'post_date' => '2008-06-02 00:00:00', 62 ) 63 ); 64 self::$post_ids[] = $post_id = $factory->post->create( 65 array( 66 'post_title' => 'post-format-test-gallery', 67 'post_date' => '2008-06-10 00:00:00', 68 ) 69 ); 70 self::$post_ids[] = $factory->post->create( 71 array( 72 'import_id' => 611, 73 'post_type' => 'attachment', 74 'post_title' => 'canola2', 75 'post_parent' => $post_id, 76 ) 77 ); 78 79 self::$post_ids[] = $factory->post->create( 80 array( 81 'post_title' => 'images-test', 82 'post_date' => '2008-09-03 00:00:00', 83 'post_content' => 'Page 1 <!--nextpage--> Page 2 <!--nextpage--> Page 3', 84 ) 85 ); 86 87 self::$post_ids[] = $post_id = $factory->post->create( 88 array( 89 'import_id' => 149, 90 'post_title' => 'comment-test', 91 'post_date' => '2008-03-03 00:00:00', 92 ) 93 ); 68 94 self::$comment_ids = $factory->comment->create_post_comments( $post_id, 15 ); 69 95 … … 74 100 self::$post_ids[] = $factory->post->create( array( 'import_id' => 358 ) ); 75 101 76 self::$post_ids[] = $factory->post->create( array( 'post_type' => 'page', 'post_title' => 'sample-page' ) ); 77 self::$post_ids[] = $factory->post->create( array( 'post_type' => 'page', 'post_title' => 'about' ) ); 78 self::$post_ids[] = $post_id = $factory->post->create( array( 'post_type' => 'page', 'post_title' => 'parent-page' ) ); 79 self::$post_ids[] = $factory->post->create( 80 array( 'import_id' => 144, 'post_type' => 'page', 'post_title' => 'child-page-1', 'post_parent' => $post_id, 81 ) ); 82 83 self::$post_ids[] = $parent_id = $factory->post->create( array( 84 'post_name' => 'parent', 85 'post_type' => 'page', 86 ) ); 87 self::$post_ids[] = $child_id_1 = $factory->post->create( array( 88 'post_name' => 'child1', 89 'post_type' => 'page', 90 'post_parent' => $parent_id, 91 ) ); 92 self::$post_ids[] = $child_id_2 = $factory->post->create( array( 93 'post_name' => 'child2', 94 'post_type' => 'page', 95 'post_parent' => $parent_id, 96 ) ); 97 self::$post_ids[] = $grandchild_id_1 = $factory->post->create( array( 98 'post_name' => 'grandchild', 99 'post_type' => 'page', 100 'post_parent' => $child_id_1, 101 ) ); 102 self::$post_ids[] = $grandchild_id_2 = $factory->post->create( array( 103 'post_name' => 'grandchild', 104 'post_type' => 'page', 105 'post_parent' => $child_id_2, 106 ) ); 107 108 $cat1 = $factory->term->create( array( 'taxonomy' => 'category', 'name' => 'parent' ) ); 102 self::$post_ids[] = $factory->post->create( 103 array( 104 'post_type' => 'page', 105 'post_title' => 'sample-page', 106 ) 107 ); 108 self::$post_ids[] = $factory->post->create( 109 array( 110 'post_type' => 'page', 111 'post_title' => 'about', 112 ) 113 ); 114 self::$post_ids[] = $post_id = $factory->post->create( 115 array( 116 'post_type' => 'page', 117 'post_title' => 'parent-page', 118 ) 119 ); 120 self::$post_ids[] = $factory->post->create( 121 array( 122 'import_id' => 144, 123 'post_type' => 'page', 124 'post_title' => 'child-page-1', 125 'post_parent' => $post_id, 126 ) 127 ); 128 129 self::$post_ids[] = $parent_id = $factory->post->create( 130 array( 131 'post_name' => 'parent', 132 'post_type' => 'page', 133 ) 134 ); 135 self::$post_ids[] = $child_id_1 = $factory->post->create( 136 array( 137 'post_name' => 'child1', 138 'post_type' => 'page', 139 'post_parent' => $parent_id, 140 ) 141 ); 142 self::$post_ids[] = $child_id_2 = $factory->post->create( 143 array( 144 'post_name' => 'child2', 145 'post_type' => 'page', 146 'post_parent' => $parent_id, 147 ) 148 ); 149 self::$post_ids[] = $grandchild_id_1 = $factory->post->create( 150 array( 151 'post_name' => 'grandchild', 152 'post_type' => 'page', 153 'post_parent' => $child_id_1, 154 ) 155 ); 156 self::$post_ids[] = $grandchild_id_2 = $factory->post->create( 157 array( 158 'post_name' => 'grandchild', 159 'post_type' => 'page', 160 'post_parent' => $child_id_2, 161 ) 162 ); 163 164 $cat1 = $factory->term->create( 165 array( 166 'taxonomy' => 'category', 167 'name' => 'parent', 168 ) 169 ); 109 170 self::$terms['/category/parent/'] = $cat1; 110 self::$term_ids[ $cat1 ] = 'category'; 111 112 $cat2 = $factory->term->create( array( 113 'taxonomy' => 'category', 'name' => 'child-1', 'parent' => self::$terms['/category/parent/'], 114 ) ); 171 self::$term_ids[ $cat1 ] = 'category'; 172 173 $cat2 = $factory->term->create( 174 array( 175 'taxonomy' => 'category', 176 'name' => 'child-1', 177 'parent' => self::$terms['/category/parent/'], 178 ) 179 ); 115 180 self::$terms['/category/parent/child-1/'] = $cat2; 116 self::$term_ids[ $cat2 ] = 'category'; 117 118 $cat3 = $factory->term->create( array( 119 'taxonomy' => 'category', 'name' => 'child-2', 'parent' => self::$terms['/category/parent/child-1/'], 120 ) ); 181 self::$term_ids[ $cat2 ] = 'category'; 182 183 $cat3 = $factory->term->create( 184 array( 185 'taxonomy' => 'category', 186 'name' => 'child-2', 187 'parent' => self::$terms['/category/parent/child-1/'], 188 ) 189 ); 121 190 self::$terms['/category/parent/child-1/child-2/'] = $cat3; 122 self::$term_ids[ $cat3 ] = 'category'; 123 124 $cat4 = $factory->term->create( array( 'taxonomy' => 'category', 'name' => 'cat-a' ) ); 191 self::$term_ids[ $cat3 ] = 'category'; 192 193 $cat4 = $factory->term->create( 194 array( 195 'taxonomy' => 'category', 196 'name' => 'cat-a', 197 ) 198 ); 125 199 self::$term_ids[ $cat4 ] = 'category'; 126 200 127 $cat5 = $factory->term->create( array( 'taxonomy' => 'category', 'name' => 'cat-b' ) ); 201 $cat5 = $factory->term->create( 202 array( 203 'taxonomy' => 'category', 204 'name' => 'cat-b', 205 ) 206 ); 128 207 self::$term_ids[ $cat5 ] = 'category'; 129 208 130 $tag1 = $factory->term->create( array( 'name' => 'post-formats' ) );209 $tag1 = $factory->term->create( array( 'name' => 'post-formats' ) ); 131 210 self::$term_ids[ $tag1 ] = 'post_tag'; 132 211 } … … 138 217 */ 139 218 public static function delete_shared_fixtures() { 140 self::$author_id = null;141 self::$post_ids = array();219 self::$author_id = null; 220 self::$post_ids = array(); 142 221 self::$comment_ids = array(); 143 self::$term_ids = array();144 self::$terms = array();222 self::$term_ids = array(); 223 self::$terms = array(); 145 224 } 146 225 … … 158 237 $this->expected_doing_it_wrong = array_merge( $this->expected_doing_it_wrong, (array) $expected_doing_it_wrong ); 159 238 160 $ticket_ref = ( $ticket > 0) ? 'Ticket #' . $ticket : null;161 162 if ( is_string( $expected) )163 $expected = array( 'url' => $expected);164 elseif ( is_array($expected) && !isset($expected['url']) && !isset($expected['qv']) )239 $ticket_ref = ( $ticket > 0 ) ? 'Ticket #' . $ticket : null; 240 241 if ( is_string( $expected ) ) { 242 $expected = array( 'url' => $expected ); 243 } elseif ( is_array( $expected ) && ! isset( $expected['url'] ) && ! isset( $expected['qv'] ) ) { 165 244 $expected = array( 'qv' => $expected ); 166 167 if ( !isset($expected['url']) && !isset($expected['qv']) ) 245 } 246 247 if ( ! isset( $expected['url'] ) && ! isset( $expected['qv'] ) ) { 168 248 $this->fail( 'No valid expected output was provided' ); 249 } 169 250 170 251 $this->go_to( home_url( $test_url ) ); 171 252 172 253 // Does the redirect match what's expected? 173 $can_url = $this->get_canonical( $test_url );174 $parsed_can_url = parse_url( $can_url);254 $can_url = $this->get_canonical( $test_url ); 255 $parsed_can_url = parse_url( $can_url ); 175 256 176 257 // Just test the Path and Query if present 177 if ( isset( $expected['url']) ) {178 $this->assertEquals( $expected['url'], $parsed_can_url['path'] . ( !empty($parsed_can_url['query']) ? '?' . $parsed_can_url['query'] : ''), $ticket_ref );258 if ( isset( $expected['url'] ) ) { 259 $this->assertEquals( $expected['url'], $parsed_can_url['path'] . ( ! empty( $parsed_can_url['query'] ) ? '?' . $parsed_can_url['query'] : '' ), $ticket_ref ); 179 260 } 180 261 181 262 // If the test data doesn't include expected query vars, then we're done here 182 if ( ! isset( $expected['qv']) )263 if ( ! isset( $expected['qv'] ) ) { 183 264 return; 265 } 184 266 185 267 // "make" that the request and check the query is correct … … 189 271 global $wp; 190 272 191 $query_vars = array_diff( $wp->query_vars, $wp->extra_query_vars);192 if ( ! empty($parsed_can_url['query']) ) {193 parse_str( $parsed_can_url['query'], $_qv);273 $query_vars = array_diff( $wp->query_vars, $wp->extra_query_vars ); 274 if ( ! empty( $parsed_can_url['query'] ) ) { 275 parse_str( $parsed_can_url['query'], $_qv ); 194 276 195 277 // $_qv should not contain any elements which are set in $query_vars already (ie. $_GET vars should not be present in the Rewrite) 196 278 $this->assertEquals( array(), array_intersect( $query_vars, $_qv ), 'Query vars are duplicated from the Rewrite into $_GET; ' . $ticket_ref ); 197 279 198 $query_vars = array_merge( $query_vars, $_qv);280 $query_vars = array_merge( $query_vars, $_qv ); 199 281 } 200 282 … … 214 296 215 297 $can_url = redirect_canonical( $test_url, false ); 216 if ( ! $can_url ) 298 if ( ! $can_url ) { 217 299 return $test_url; // No redirect will take place for this request 300 } 218 301 219 302 return $can_url;
Note: See TracChangeset
for help on using the changeset viewer.