| 305 | | } |
| | 305 | |
| | 306 | /** |
| | 307 | * @ticket 13459 |
| | 308 | */ |
| | 309 | public function test_post_slugs_should_not_collide_with_page_slugs_with_the_same_permalink_structure() { |
| | 310 | $this->set_permalink_structure( '/%postname%/' ); |
| | 311 | $page_args = array( |
| | 312 | 'post_type' => 'page', |
| | 313 | 'post_name' => 'green', |
| | 314 | 'post_status' => 'publish', |
| | 315 | ); |
| | 316 | $page = $this->factory->post->create( $page_args ); |
| | 317 | $this->assertEquals( 'green', get_post( $page )->post_name ); |
| | 318 | |
| | 319 | $post_args = array( |
| | 320 | 'post_type' => 'post', |
| | 321 | 'post_name' => 'green', |
| | 322 | 'post_status' => 'publish', |
| | 323 | ); |
| | 324 | $post = $this->factory->post->create( $post_args ); |
| | 325 | |
| | 326 | $this->assertEquals( 'green-2', get_post( $post )->post_name ); |
| | 327 | } |
| | 328 | |
| | 329 | /** |
| | 330 | * @ticket 13459 |
| | 331 | */ |
| | 332 | public function test_page_slugs_should_not_collide_with_post_slugs_with_the_same_permalink_structure() { |
| | 333 | $this->set_permalink_structure( '/%postname%/' ); |
| | 334 | $post_args = array( |
| | 335 | 'post_type' => 'post', |
| | 336 | 'post_name' => 'red' |
| | 337 | ); |
| | 338 | $post = $this->factory->post->create( $post_args ); |
| | 339 | $this->assertEquals( 'red', get_post( $post )->post_name ); |
| | 340 | |
| | 341 | $page_args = array( |
| | 342 | 'post_type' => 'page', |
| | 343 | 'post_name' => 'red' |
| | 344 | ); |
| | 345 | $page = $this->factory->post->create( $page_args ); |
| | 346 | $this->assertEquals( 'red-2', get_post( $page )->post_name ); |
| | 347 | } |
| | 348 | |
| | 349 | /** |
| | 350 | * @ticket 13459 |
| | 351 | */ |
| | 352 | public function test_post_slugs_should_not_conflict_with_post_slugs_with_postname_permalink_structure() { |
| | 353 | $this->set_permalink_structure( '/%postname%/' ); |
| | 354 | $post_args = array( |
| | 355 | 'post_type' => 'post', |
| | 356 | 'post_name' => 'blue' |
| | 357 | ); |
| | 358 | $post = $this->factory->post->create( $post_args ); |
| | 359 | $this->assertEquals( 'blue', get_post( $post )->post_name ); |
| | 360 | |
| | 361 | $post_args = array( |
| | 362 | 'post_type' => 'post', |
| | 363 | 'post_name' => 'blue' |
| | 364 | ); |
| | 365 | $post = $this->factory->post->create( $post_args ); |
| | 366 | $this->assertEquals( 'blue-2', get_post( $post )->post_name ); |
| | 367 | } |
| | 368 | |
| | 369 | /** |
| | 370 | * @ticket 13459 |
| | 371 | */ |
| | 372 | public function test_page_slugs_should_not_conflict_with_page_slugs_with_postname_permalink_structure() { |
| | 373 | $this->set_permalink_structure( '/%postname%/' ); |
| | 374 | $page_args = array( |
| | 375 | 'post_type' => 'page', |
| | 376 | 'post_name' => 'orange' |
| | 377 | ); |
| | 378 | $page = $this->factory->post->create( $page_args ); |
| | 379 | $this->assertEquals( 'orange', get_post( $page )->post_name ); |
| | 380 | |
| | 381 | $page_args = array( |
| | 382 | 'post_type' => 'page', |
| | 383 | 'post_name' => 'orange' |
| | 384 | ); |
| | 385 | $page = $this->factory->post->create( $page_args ); |
| | 386 | $this->assertEquals( 'orange-2', get_post( $page )->post_name ); |
| | 387 | } |
| | 388 | |
| | 389 | /** |
| | 390 | * @ticket 13459 |
| | 391 | */ |
| | 392 | public function test_post_slugs_should_not_collide_with_attachments_when_permalink_structure_is_postname() { |
| | 393 | $this->set_permalink_structure( '/%postname%/' ); |
| | 394 | $args = array( |
| | 395 | 'post_type' => 'post', |
| | 396 | 'post_name' => 'some-slug', |
| | 397 | 'post_status' => 'publish', |
| | 398 | ); |
| | 399 | $post = self::factory()->post->create( $args ); |
| | 400 | |
| | 401 | $args = array( |
| | 402 | 'post_mime_type' => 'image/jpeg', |
| | 403 | 'post_type' => 'attachment', |
| | 404 | 'post_name' => 'some-slug' |
| | 405 | ); |
| | 406 | $attachment = self::factory()->attachment->create_object( 'image.jpg', 0, $args ); |
| | 407 | |
| | 408 | $this->assertEquals( 'some-slug', get_post( $post )->post_name ); |
| | 409 | $this->assertEquals( 'some-slug-2', get_post( $attachment )->post_name ); |
| | 410 | } |
| | 411 | |
| | 412 | /** |
| | 413 | * @ticket 13459 |
| | 414 | */ |
| | 415 | public function test_post_slugs_should_collide_with_attachments_when_their_permalink_structures_differ() { |
| | 416 | $this->set_permalink_structure( '/%year%/%monthnum%/%day%/%postname%/' ); |
| | 417 | |
| | 418 | $args = array( |
| | 419 | 'post_mime_type' => 'image/jpeg', |
| | 420 | 'post_type' => 'attachment', |
| | 421 | 'post_name' => 'some-slug' |
| | 422 | ); |
| | 423 | $attachment = self::factory()->attachment->create_object( 'image.jpg', 0, $args ); |
| | 424 | |
| | 425 | $args = array( |
| | 426 | 'post_type' => 'post', |
| | 427 | 'post_name' => 'some-slug', |
| | 428 | 'post_status' => 'publish', |
| | 429 | ); |
| | 430 | $post = self::factory()->post->create( $args ); |
| | 431 | |
| | 432 | $this->assertEquals( 'some-slug', get_post( $post )->post_name ); |
| | 433 | $this->assertEquals( 'some-slug', get_post( $attachment )->post_name ); |
| | 434 | } |
| | 435 | } |
| | 436 | No newline at end of file |