-
diff --git tests/phpunit/includes/functions.php tests/phpunit/includes/functions.php
index 9a450ece84..3aad8fa362 100644
|
|
|
function _set_default_permalink_structure_for_tests() { |
| 157 | 157 | update_option( 'permalink_structure', '/%year%/%monthnum%/%day%/%postname%/' ); |
| 158 | 158 | } |
| 159 | 159 | |
| | 160 | function _set_default_multisite_permalink_structure_for_tests() { |
| | 161 | update_option( 'permalink_structure', '/blog/%year%/%monthnum%/%day%/%postname%/' ); |
| | 162 | } |
| | 163 | |
| 160 | 164 | /** |
| 161 | 165 | * Helper used with the `upload_dir` filter to remove the /year/month sub directories from the uploads path and URL. |
| 162 | 166 | */ |
-
diff --git tests/phpunit/includes/install.php tests/phpunit/includes/install.php
index 45c0d60f83..bda505258d 100644
|
|
|
foreach ( $wpdb->tables( 'ms_global' ) as $table => $prefixed_table ) { |
| 65 | 65 | $wpdb->query( 'SET foreign_key_checks = 1' ); |
| 66 | 66 | |
| 67 | 67 | // Prefill a permalink structure so that WP doesn't try to determine one itself. |
| 68 | | add_action( 'populate_options', '_set_default_permalink_structure_for_tests' ); |
| | 68 | if ( $multisite ) { |
| | 69 | add_action( 'populate_options', '_set_default_multisite_permalink_structure_for_tests' ); |
| | 70 | } else { |
| | 71 | add_action( 'populate_options', '_set_default_permalink_structure_for_tests' ); |
| | 72 | } |
| 69 | 73 | |
| 70 | 74 | wp_install( WP_TESTS_TITLE, 'admin', WP_TESTS_EMAIL, true, null, 'password' ); |
| 71 | 75 | |
| 72 | | // Delete dummy permalink structure, as prefilled above. |
| 73 | | if ( ! is_multisite() ) { |
| 74 | | delete_option( 'permalink_structure' ); |
| | 76 | if ( $multisite ) { |
| | 77 | remove_action( 'populate_options', '_set_default_multisite_permalink_structure_for_tests' ); |
| | 78 | } else { |
| | 79 | remove_action( 'populate_options', '_set_default_permalink_structure_for_tests' ); |
| 75 | 80 | } |
| 76 | | remove_action( 'populate_options', '_set_default_permalink_structure_for_tests' ); |
| 77 | 81 | |
| 78 | 82 | if ( $multisite ) { |
| 79 | 83 | echo 'Installing network...' . PHP_EOL; |
| … |
… |
if ( $multisite ) { |
| 85 | 89 | |
| 86 | 90 | install_network(); |
| 87 | 91 | populate_network( 1, WP_TESTS_DOMAIN, WP_TESTS_EMAIL, $title, '/', $subdomain_install ); |
| 88 | | $wp_rewrite->set_permalink_structure( '' ); |
| 89 | 92 | } |
-
diff --git tests/phpunit/includes/testcase.php tests/phpunit/includes/testcase.php
index fee06e0df9..2cc40a6bf6 100644
|
|
|
class WP_UnitTestCase extends PHPUnit_Framework_TestCase { |
| 125 | 125 | $this->reset_taxonomies(); |
| 126 | 126 | $this->reset_post_statuses(); |
| 127 | 127 | $this->reset__SERVER(); |
| 128 | | |
| 129 | | if ( $wp_rewrite->permalink_structure ) { |
| 130 | | $this->set_permalink_structure( '' ); |
| 131 | | } |
| 132 | 128 | } |
| 133 | 129 | |
| 134 | 130 | $this->start_transaction(); |
| 135 | 131 | $this->expectDeprecated(); |
| 136 | 132 | add_filter( 'wp_die_handler', array( $this, 'get_wp_die_handler' ) ); |
| | 133 | |
| | 134 | if ( get_option( 'permalink_structure' ) !== tests_get_default_permalink_structure() ) { |
| | 135 | $this->fail( 'Permalink structure was not correctly reset: ' . get_option( 'permalink_structure' ) ); |
| | 136 | } |
| 137 | 137 | } |
| 138 | 138 | |
| 139 | 139 | /** |
-
diff --git tests/phpunit/includes/utils.php tests/phpunit/includes/utils.php
index 3c7b1bed34..e341140e11 100644
|
|
|
function test_rest_expand_compact_links( $links ) { |
| 534 | 534 | } |
| 535 | 535 | return $links; |
| 536 | 536 | } |
| | 537 | |
| | 538 | /** |
| | 539 | * Set the permalink structure. |
| | 540 | * |
| | 541 | * This updates the `permalink_structure` option, and flushes the existing rewrite rules. |
| | 542 | * |
| | 543 | * @since 5.0.0 |
| | 544 | * |
| | 545 | * @param string $structure Permalink structure. |
| | 546 | */ |
| | 547 | function tests_set_and_flush_permalinks( $structure ) { |
| | 548 | global $wp_rewrite; |
| | 549 | |
| | 550 | $wp_rewrite->set_permalink_structure( $structure ); |
| | 551 | $wp_rewrite->flush_rules(); |
| | 552 | } |
| | 553 | |
| | 554 | /** |
| | 555 | * Reset the permalink structure to the default. |
| | 556 | * |
| | 557 | * @since 5.0.0 |
| | 558 | */ |
| | 559 | function tests_reset_and_flush_permalinks() { |
| | 560 | tests_set_and_flush_permalinks( tests_get_default_permalink_structure() ); |
| | 561 | } |
| | 562 | |
| | 563 | /** |
| | 564 | * Retrieve the default permalink structure used for unit tests. |
| | 565 | * |
| | 566 | * @since 5.0.0 |
| | 567 | * |
| | 568 | * @return string Permalink structure. |
| | 569 | */ |
| | 570 | function tests_get_default_permalink_structure() { |
| | 571 | if ( is_multisite() ) { |
| | 572 | return '/blog/%year%/%monthnum%/%day%/%postname%/'; |
| | 573 | } |
| | 574 | |
| | 575 | return '/%year%/%monthnum%/%day%/%postname%/'; |
| | 576 | } |
| | 577 | |
| | 578 | /** |
| | 579 | * Add the `blog` prefix to URLs if on multisite. |
| | 580 | * |
| | 581 | * When the multisite is installed, the main site gets `blog` added to its permalink structure. This makes the |
| | 582 | * permalinks different on single site installs and on multisites. |
| | 583 | * |
| | 584 | * This helper function prefixes URLs with `blog` if on multisite. |
| | 585 | * |
| | 586 | * @since 5.0.0 |
| | 587 | * |
| | 588 | * @param string $url URL to maybe prefix. |
| | 589 | * |
| | 590 | * @return string Prefixed URL on multisite, else unchanged URL. |
| | 591 | */ |
| | 592 | function tests_add_blog_permalink_prefix_on_multisite( $url ) { |
| | 593 | if ( ! is_multisite() || ! is_main_site() ) { |
| | 594 | return $url; |
| | 595 | } |
| | 596 | |
| | 597 | if ( strpos( $url, '/' ) === 0 ) { |
| | 598 | return 'blog' . $url; |
| | 599 | } |
| | 600 | |
| | 601 | return 'blog/' . $url; |
| | 602 | } |
-
diff --git tests/phpunit/tests/admin/includesPost.php tests/phpunit/tests/admin/includesPost.php
index 5c080f2ed6..b9e42ea3ba 100644
|
|
|
class Tests_Admin_Includes_Post extends WP_UnitTestCase { |
| 333 | 333 | $expected = trailingslashit( home_url( $permalink_structure ) ); |
| 334 | 334 | |
| 335 | 335 | $this->assertSame( $expected, $found[0] ); |
| | 336 | |
| | 337 | tests_reset_and_flush_permalinks(); |
| 336 | 338 | } |
| 337 | 339 | |
| 338 | 340 | /** |
| … |
… |
class Tests_Admin_Includes_Post extends WP_UnitTestCase { |
| 340 | 342 | * @ticket 18306 |
| 341 | 343 | */ |
| 342 | 344 | public function test_get_sample_permalink_html_should_use_default_permalink_for_view_post_link_when_pretty_permalinks_are_disabled() { |
| | 345 | tests_set_and_flush_permalinks( '' ); |
| | 346 | |
| 343 | 347 | wp_set_current_user( self::$admin_id ); |
| 344 | 348 | |
| 345 | 349 | $future_date = date( 'Y-m-d H:i:s', time() + 100 ); |
| … |
… |
class Tests_Admin_Includes_Post extends WP_UnitTestCase { |
| 354 | 358 | $found = get_sample_permalink_html( $p ); |
| 355 | 359 | $this->assertContains( 'href="' . get_option( 'home' ) . '/?p=' . $p . '"', $found ); |
| 356 | 360 | $this->assertContains( '>' . get_option( 'home' ) . '/?p=' . $p . '<', $found ); |
| | 361 | |
| | 362 | tests_reset_and_flush_permalinks(); |
| 357 | 363 | } |
| 358 | 364 | |
| 359 | 365 | /** |
| … |
… |
class Tests_Admin_Includes_Post extends WP_UnitTestCase { |
| 378 | 384 | $post = get_post( $p ); |
| 379 | 385 | $this->assertContains( 'href="' . get_option( 'home' ) . '/' . $post->post_name . '/"', $found ); |
| 380 | 386 | $this->assertContains( '>' . urldecode( $post->post_name ) . '<', $found ); |
| | 387 | |
| | 388 | tests_reset_and_flush_permalinks(); |
| 381 | 389 | } |
| 382 | 390 | |
| 383 | 391 | /** |
| … |
… |
class Tests_Admin_Includes_Post extends WP_UnitTestCase { |
| 401 | 409 | $post = get_post( $p ); |
| 402 | 410 | $this->assertContains( 'href="' . get_option( 'home' ) . '/' . $post->post_name . '/"', $found ); |
| 403 | 411 | $this->assertContains( '>' . urldecode( get_permalink( $post ) ) . '<', $found ); |
| | 412 | |
| | 413 | tests_reset_and_flush_permalinks(); |
| 404 | 414 | } |
| 405 | 415 | |
| 406 | 416 | /** |
| … |
… |
class Tests_Admin_Includes_Post extends WP_UnitTestCase { |
| 459 | 469 | |
| 460 | 470 | $this->assertContains( 'href="' . esc_url( $preview_link ) . '"', $found, $message ); |
| 461 | 471 | $this->assertContains( '>new_slug-صورة<', $found, $message ); |
| | 472 | |
| | 473 | tests_reset_and_flush_permalinks(); |
| 462 | 474 | } |
| 463 | 475 | |
| 464 | 476 | /** |
| … |
… |
class Tests_Admin_Includes_Post extends WP_UnitTestCase { |
| 482 | 494 | $found = get_sample_permalink_html( $p ); |
| 483 | 495 | $post = get_post( $p ); |
| 484 | 496 | $this->assertContains( 'href="' . esc_url( get_preview_post_link( $post ) ), $found ); |
| | 497 | |
| | 498 | tests_reset_and_flush_permalinks(); |
| 485 | 499 | } |
| 486 | 500 | |
| 487 | 501 | /** |
| … |
… |
class Tests_Admin_Includes_Post extends WP_UnitTestCase { |
| 498 | 512 | |
| 499 | 513 | $found = get_sample_permalink( $p ); |
| 500 | 514 | $this->assertEquals( '2015-2', $found[1] ); |
| | 515 | |
| | 516 | tests_reset_and_flush_permalinks(); |
| 501 | 517 | } |
| 502 | 518 | |
| 503 | 519 | /** |
| … |
… |
class Tests_Admin_Includes_Post extends WP_UnitTestCase { |
| 514 | 530 | |
| 515 | 531 | $found = get_sample_permalink( $p ); |
| 516 | 532 | $this->assertEquals( '2015', $found[1] ); |
| | 533 | |
| | 534 | tests_reset_and_flush_permalinks(); |
| 517 | 535 | } |
| 518 | 536 | |
| 519 | 537 | /** |
| … |
… |
class Tests_Admin_Includes_Post extends WP_UnitTestCase { |
| 530 | 548 | |
| 531 | 549 | $found = get_sample_permalink( $p ); |
| 532 | 550 | $this->assertEquals( '11-2', $found[1] ); |
| | 551 | |
| | 552 | tests_reset_and_flush_permalinks(); |
| 533 | 553 | } |
| 534 | 554 | |
| 535 | 555 | /** |
| … |
… |
class Tests_Admin_Includes_Post extends WP_UnitTestCase { |
| 546 | 566 | |
| 547 | 567 | $found = get_sample_permalink( $p ); |
| 548 | 568 | $this->assertEquals( '13', $found[1] ); |
| | 569 | |
| | 570 | tests_reset_and_flush_permalinks(); |
| 549 | 571 | } |
| 550 | 572 | |
| 551 | 573 | /** |
| … |
… |
class Tests_Admin_Includes_Post extends WP_UnitTestCase { |
| 562 | 584 | |
| 563 | 585 | $found = get_sample_permalink( $p ); |
| 564 | 586 | $this->assertEquals( '30-2', $found[1] ); |
| | 587 | |
| | 588 | tests_reset_and_flush_permalinks(); |
| 565 | 589 | } |
| 566 | 590 | |
| 567 | 591 | /** |
| … |
… |
class Tests_Admin_Includes_Post extends WP_UnitTestCase { |
| 584 | 608 | |
| 585 | 609 | $found = get_sample_permalink( $p ); |
| 586 | 610 | $this->assertEquals( '30-3', $found[1] ); |
| | 611 | |
| | 612 | tests_reset_and_flush_permalinks(); |
| 587 | 613 | } |
| 588 | 614 | |
| 589 | 615 | /** |
| … |
… |
class Tests_Admin_Includes_Post extends WP_UnitTestCase { |
| 600 | 626 | |
| 601 | 627 | $found = get_sample_permalink( $p ); |
| 602 | 628 | $this->assertEquals( '32', $found[1] ); |
| | 629 | |
| | 630 | tests_reset_and_flush_permalinks(); |
| 603 | 631 | } |
| 604 | 632 | |
| 605 | 633 | /** |
| … |
… |
class Tests_Admin_Includes_Post extends WP_UnitTestCase { |
| 616 | 644 | |
| 617 | 645 | $found = get_sample_permalink( $p ); |
| 618 | 646 | $this->assertEquals( '30', $found[1] ); |
| | 647 | |
| | 648 | tests_reset_and_flush_permalinks(); |
| 619 | 649 | } |
| 620 | 650 | |
| 621 | 651 | /** |
| … |
… |
class Tests_Admin_Includes_Post extends WP_UnitTestCase { |
| 643 | 673 | $actual = get_sample_permalink( $child ); |
| 644 | 674 | $this->assertSame( home_url() . '/parent-page/%pagename%/', $actual[0] ); |
| 645 | 675 | $this->assertSame( 'child-page', $actual[1] ); |
| | 676 | |
| | 677 | tests_reset_and_flush_permalinks(); |
| 646 | 678 | } |
| 647 | 679 | |
| 648 | 680 | public function test_post_exists_should_match_title() { |
-
diff --git tests/phpunit/tests/canonical/https.php tests/phpunit/tests/canonical/https.php
index c6b59bdb34..183553e222 100644
|
|
|
class Tests_Canonical_HTTPS extends WP_Canonical_UnitTestCase { |
| 9 | 9 | function setUp() { |
| 10 | 10 | parent::setUp(); |
| 11 | 11 | |
| 12 | | $this->set_permalink_structure( '/%year%/%monthnum%/%day%/%postname%/' ); |
| 13 | 12 | create_initial_taxonomies(); |
| 14 | 13 | |
| 15 | 14 | $this->http = set_url_scheme( home_url( 'sample-page/' ), 'http' ); |
-
diff --git tests/phpunit/tests/category/getCategoryLink.php tests/phpunit/tests/category/getCategoryLink.php
index a69b522f26..703dafead3 100644
|
|
|
|
| 6 | 6 | */ |
| 7 | 7 | class Tests_Category_GetCategoryLink extends WP_UnitTestCase { |
| 8 | 8 | public function test_success() { |
| | 9 | tests_set_and_flush_permalinks( '' ); |
| 9 | 10 | $c = self::factory()->category->create(); |
| 10 | 11 | |
| 11 | 12 | $found = get_category_link( $c ); |
| 12 | 13 | $expected = home_url( '?cat=' . $c ); |
| 13 | 14 | |
| 14 | 15 | $this->assertSame( $expected, $found ); |
| | 16 | |
| | 17 | tests_reset_and_flush_permalinks(); |
| 15 | 18 | } |
| 16 | 19 | |
| 17 | 20 | /** |
| 18 | 21 | * @ticket 42771 |
| 19 | 22 | */ |
| 20 | 23 | public function test_should_return_link_for_term_from_another_taxonomy_on_primed_cache() { |
| | 24 | tests_set_and_flush_permalinks( '' ); |
| 21 | 25 | register_taxonomy( 'wptests_tax', 'post' ); |
| 22 | 26 | |
| 23 | 27 | $t = self::factory()->term->create( array( |
| … |
… |
class Tests_Category_GetCategoryLink extends WP_UnitTestCase { |
| 31 | 35 | $expected = home_url( '?wptests_tax=test-term' ); |
| 32 | 36 | |
| 33 | 37 | $this->assertSame( $expected, $found ); |
| | 38 | tests_reset_and_flush_permalinks(); |
| 34 | 39 | } |
| 35 | 40 | |
| 36 | 41 | /** |
| 37 | 42 | * @ticket 42771 |
| 38 | 43 | */ |
| 39 | 44 | public function test_should_return_link_for_term_from_another_taxonomy_on_empty_cache() { |
| | 45 | tests_set_and_flush_permalinks( '' ); |
| 40 | 46 | register_taxonomy( 'wptests_tax', 'post' ); |
| 41 | 47 | |
| 42 | 48 | $t = self::factory()->term->create( array( |
| … |
… |
class Tests_Category_GetCategoryLink extends WP_UnitTestCase { |
| 50 | 56 | $expected = home_url( '?wptests_tax=test-term' ); |
| 51 | 57 | |
| 52 | 58 | $this->assertSame( $expected, $found ); |
| | 59 | tests_reset_and_flush_permalinks(); |
| 53 | 60 | } |
| 54 | 61 | } |
-
diff --git tests/phpunit/tests/comment/commentsTemplate.php tests/phpunit/tests/comment/commentsTemplate.php
index 3547a14190..2e61ee500c 100644
|
|
|
class Tests_Comment_CommentsTemplate extends WP_UnitTestCase { |
| 570 | 570 | |
| 571 | 571 | // They should all be on page 2. |
| 572 | 572 | foreach ( $matches[1] as $m ) { |
| 573 | | $this->assertContains( 'cpage=2', $m ); |
| | 573 | $this->assertContains( 'comment-page-2', $m ); |
| 574 | 574 | } |
| 575 | 575 | } |
| 576 | 576 | |
| … |
… |
class Tests_Comment_CommentsTemplate extends WP_UnitTestCase { |
| 641 | 641 | preg_match_all( '|href="(.*?#comment-([0-9]+))|', $found_p0, $matches ); |
| 642 | 642 | |
| 643 | 643 | foreach ( $matches[1] as $m ) { |
| 644 | | $this->assertContains( 'cpage=3', $m ); |
| | 644 | $this->assertContains( 'comment-page-3', $m ); |
| 645 | 645 | } |
| 646 | 646 | |
| 647 | 647 | $link_p2 = add_query_arg( |
| … |
… |
class Tests_Comment_CommentsTemplate extends WP_UnitTestCase { |
| 660 | 660 | |
| 661 | 661 | // They should all be on page 2. |
| 662 | 662 | foreach ( $matches[1] as $m ) { |
| 663 | | $this->assertContains( 'cpage=2', $m ); |
| | 663 | $this->assertContains( 'comment-page-2', $m ); |
| 664 | 664 | } |
| 665 | 665 | |
| 666 | 666 | // p1 is the last page (neat!). |
| … |
… |
class Tests_Comment_CommentsTemplate extends WP_UnitTestCase { |
| 680 | 680 | |
| 681 | 681 | // They should all be on page 2. |
| 682 | 682 | foreach ( $matches[1] as $m ) { |
| 683 | | $this->assertContains( 'cpage=1', $m ); |
| | 683 | $this->assertContains( 'comment-page-1', $m ); |
| 684 | 684 | } |
| 685 | 685 | } |
| 686 | 686 | |
-
diff --git tests/phpunit/tests/comment/getCommentLink.php tests/phpunit/tests/comment/getCommentLink.php
index ca75da1532..efe0186060 100644
|
|
|
class Tests_Comment_GetCommentLink extends WP_UnitTestCase { |
| 66 | 66 | |
| 67 | 67 | $found = get_comment_link( self::$comments[1] ); |
| 68 | 68 | |
| 69 | | $this->assertContains( 'cpage=3', $found ); |
| | 69 | $this->assertContains( 'comment-page-3', $found ); |
| 70 | 70 | } |
| 71 | 71 | |
| 72 | 72 | /** |
| … |
… |
class Tests_Comment_GetCommentLink extends WP_UnitTestCase { |
| 79 | 79 | |
| 80 | 80 | $found = get_comment_link( self::$comments[3] ); |
| 81 | 81 | |
| 82 | | $this->assertContains( 'cpage=2', $found ); |
| | 82 | $this->assertContains( 'comment-page-2', $found ); |
| 83 | 83 | } |
| 84 | 84 | |
| 85 | 85 | /** |
| … |
… |
class Tests_Comment_GetCommentLink extends WP_UnitTestCase { |
| 92 | 92 | |
| 93 | 93 | $found = get_comment_link( self::$comments[5] ); |
| 94 | 94 | |
| 95 | | $this->assertContains( 'cpage=1', $found ); |
| | 95 | $this->assertContains( 'comment-page-1', $found ); |
| 96 | 96 | } |
| 97 | 97 | |
| 98 | 98 | /** |
| … |
… |
class Tests_Comment_GetCommentLink extends WP_UnitTestCase { |
| 117 | 117 | |
| 118 | 118 | $found = get_comment_link( self::$comments[3] ); |
| 119 | 119 | |
| 120 | | $this->assertContains( 'cpage=2', $found ); |
| | 120 | $this->assertContains( 'comment-page-2', $found ); |
| 121 | 121 | } |
| 122 | 122 | |
| 123 | 123 | /** |
| … |
… |
class Tests_Comment_GetCommentLink extends WP_UnitTestCase { |
| 130 | 130 | |
| 131 | 131 | $found = get_comment_link( self::$comments[1] ); |
| 132 | 132 | |
| 133 | | $this->assertContains( 'cpage=3', $found ); |
| | 133 | $this->assertContains( 'comment-page-3', $found ); |
| 134 | 134 | } |
| 135 | 135 | |
| 136 | 136 | /** |
| 137 | 137 | * @ticket 34946 |
| 138 | 138 | */ |
| 139 | 139 | public function test_should_not_contain_comment_page_1_when_pagination_is_disabled() { |
| 140 | | $this->set_permalink_structure( '/%postname%/' ); |
| 141 | 140 | update_option( 'page_comments', 0 ); |
| 142 | 141 | |
| 143 | 142 | $found = get_comment_link( self::$comments[1] ); |
-
diff --git tests/phpunit/tests/feed/atom.php tests/phpunit/tests/feed/atom.php
index 356c95faf0..446494c811 100644
|
|
|
class Tests_Feeds_Atom extends WP_UnitTestCase { |
| 17 | 17 | * Setup a new user and attribute some posts. |
| 18 | 18 | */ |
| 19 | 19 | public static function wpSetUpBeforeClass( $factory ) { |
| | 20 | global $wpdb; |
| | 21 | |
| 20 | 22 | // Create a user |
| 21 | 23 | self::$user_id = $factory->user->create( |
| 22 | 24 | array( |
| … |
… |
class Tests_Feeds_Atom extends WP_UnitTestCase { |
| 50 | 52 | wp_set_object_terms( $post, self::$category->slug, 'category' ); |
| 51 | 53 | } |
| 52 | 54 | |
| | 55 | // Manually update the posts `guid` to be non-pretty permalinks. Due to the way that `wp_insert_post()` works, |
| | 56 | // the `guid` fields all contain pretty permalinks. |
| | 57 | foreach( self::$posts as $post_ID ) { |
| | 58 | $wpdb->update( $wpdb->posts, array( 'guid' => 'http://example.com/?p=' . $post_ID ), array( 'ID' => $post_ID ) ); |
| | 59 | } |
| 53 | 60 | } |
| 54 | 61 | |
| 55 | 62 | /** |
-
diff --git tests/phpunit/tests/feed/rss2.php tests/phpunit/tests/feed/rss2.php
index f8ebf2b9b1..571c25bde8 100644
|
|
|
class Tests_Feeds_RSS2 extends WP_UnitTestCase { |
| 18 | 18 | * Setup a new user and attribute some posts. |
| 19 | 19 | */ |
| 20 | 20 | public static function wpSetUpBeforeClass( $factory ) { |
| | 21 | global $wpdb; |
| | 22 | |
| 21 | 23 | // Create a user |
| 22 | 24 | self::$user_id = $factory->user->create( |
| 23 | 25 | array( |
| … |
… |
class Tests_Feeds_RSS2 extends WP_UnitTestCase { |
| 50 | 52 | ) |
| 51 | 53 | ); |
| 52 | 54 | |
| | 55 | // Manually update the posts `guid` to be non-pretty permalinks. Due to the way that `wp_insert_post()` works, |
| | 56 | // the `guid` fields all contain pretty permalinks. |
| | 57 | foreach( self::$posts as $post_ID ) { |
| | 58 | $wpdb->update( $wpdb->posts, array( 'guid' => 'http://example.com/?p=' . $post_ID ), array( 'ID' => $post_ID ) ); |
| | 59 | } |
| | 60 | |
| 53 | 61 | // Assign a category to those posts |
| 54 | 62 | foreach ( self::$posts as $post ) { |
| 55 | 63 | wp_set_object_terms( $post, self::$category->slug, 'category' ); |
| … |
… |
class Tests_Feeds_RSS2 extends WP_UnitTestCase { |
| 67 | 75 | // this seems to break something |
| 68 | 76 | update_option( 'use_smilies', false ); |
| 69 | 77 | |
| 70 | | $this->set_permalink_structure( '/%year%/%monthnum%/%day%/%postname%/' ); |
| 71 | 78 | create_initial_taxonomies(); |
| 72 | 79 | } |
| 73 | 80 | |
| … |
… |
class Tests_Feeds_RSS2 extends WP_UnitTestCase { |
| 326 | 333 | */ |
| 327 | 334 | function test_valid_taxonomy_feed_endpoint() { |
| 328 | 335 | // An example of an valid taxonomy feed endpoint. |
| 329 | | $this->go_to( 'category/foo/feed/' ); |
| | 336 | $this->go_to( '/' . tests_add_blog_permalink_prefix_on_multisite( 'category/foo/feed/' ) ); |
| 330 | 337 | |
| 331 | 338 | // Verify the query object is a feed. |
| 332 | 339 | $this->assertQueryTrue( 'is_feed', 'is_archive', 'is_category' ); |
| … |
… |
class Tests_Feeds_RSS2 extends WP_UnitTestCase { |
| 387 | 394 | */ |
| 388 | 395 | function test_valid_archive_feed_endpoint() { |
| 389 | 396 | // An example of an valid date archive feed endpoint. |
| 390 | | $this->go_to( '2003/05/27/feed/' ); |
| | 397 | $this->go_to( tests_add_blog_permalink_prefix_on_multisite( '2003/05/27/feed/' ) ); |
| 391 | 398 | |
| 392 | 399 | // Verify the query object is a feed. |
| 393 | 400 | $this->assertQueryTrue( 'is_feed', 'is_archive', 'is_day', 'is_date' ); |
-
diff --git tests/phpunit/tests/general/paginateLinks.php tests/phpunit/tests/general/paginateLinks.php
index af736cc611..808127071f 100644
|
|
|
EXPECTED; |
| 213 | 213 | * @ticket 29636 |
| 214 | 214 | */ |
| 215 | 215 | function test_paginate_links_query_args() { |
| | 216 | tests_set_and_flush_permalinks( '' ); |
| | 217 | |
| 216 | 218 | add_filter( 'get_pagenum_link', array( $this, 'add_query_arg' ) ); |
| 217 | 219 | $links = paginate_links( |
| 218 | 220 | array( |
| … |
… |
EXPECTED; |
| 245 | 247 | $href = $tag->attributes->getNamedItem( 'href' )->value; |
| 246 | 248 | $this->assertEquals( $expected_href, $href ); |
| 247 | 249 | } |
| | 250 | |
| | 251 | tests_reset_and_flush_permalinks(); |
| 248 | 252 | } |
| 249 | 253 | |
| 250 | 254 | /** |
| 251 | 255 | * @ticket 30831 |
| 252 | 256 | */ |
| 253 | 257 | function test_paginate_links_with_custom_query_args() { |
| | 258 | tests_set_and_flush_permalinks( '' ); |
| | 259 | |
| 254 | 260 | add_filter( 'get_pagenum_link', array( $this, 'add_query_arg' ) ); |
| 255 | 261 | $links = paginate_links( |
| 256 | 262 | array( |
| … |
… |
EXPECTED; |
| 285 | 291 | $href = $tag->attributes->getNamedItem( 'href' )->value; |
| 286 | 292 | $this->assertEquals( $expected_href, $href ); |
| 287 | 293 | } |
| | 294 | |
| | 295 | tests_reset_and_flush_permalinks(); |
| 288 | 296 | } |
| 289 | 297 | |
| 290 | 298 | /** |
-
diff --git tests/phpunit/tests/link.php tests/phpunit/tests/link.php
index 02412510a0..57d3d71ae4 100644
|
|
|
class Tests_Link extends WP_UnitTestCase { |
| 14 | 14 | function test_get_pagenum_link_case_insensitivity() { |
| 15 | 15 | $old_req_uri = $_SERVER['REQUEST_URI']; |
| 16 | 16 | |
| 17 | | $this->set_permalink_structure( '/%year%/%monthnum%/%day%/%postname%/' ); |
| 18 | | |
| 19 | 17 | add_filter( 'home_url', array( $this, '_get_pagenum_link_cb' ) ); |
| 20 | 18 | $_SERVER['REQUEST_URI'] = '/woohoo'; |
| 21 | 19 | $paged = get_pagenum_link( 2 ); |
| … |
… |
class Tests_Link extends WP_UnitTestCase { |
| 31 | 29 | $post_id2 = self::factory()->post->create(); |
| 32 | 30 | |
| 33 | 31 | // Basic case |
| 34 | | $this->assertEquals( get_permalink( $post_id ), wp_get_shortlink( $post_id, 'post' ) ); |
| | 32 | $this->assertEquals( home_url( '?p=' . $post_id ), wp_get_shortlink( $post_id, 'post' ) ); |
| 35 | 33 | |
| 36 | 34 | unset( $GLOBALS['post'] ); |
| 37 | 35 | |
| … |
… |
class Tests_Link extends WP_UnitTestCase { |
| 43 | 41 | $GLOBALS['post'] = get_post( $post_id ); |
| 44 | 42 | |
| 45 | 43 | // Global post is set |
| 46 | | $this->assertEquals( get_permalink( $post_id ), wp_get_shortlink( 0, 'post' ) ); |
| 47 | | $this->assertEquals( get_permalink( $post_id ), wp_get_shortlink( 0 ) ); |
| 48 | | $this->assertEquals( get_permalink( $post_id ), wp_get_shortlink() ); |
| | 44 | $this->assertEquals( home_url( '?p=' . $post_id ), wp_get_shortlink( 0, 'post' ) ); |
| | 45 | $this->assertEquals( home_url( '?p=' . $post_id ), wp_get_shortlink( 0 ) ); |
| | 46 | $this->assertEquals( home_url( '?p=' . $post_id ), wp_get_shortlink() ); |
| 49 | 47 | |
| 50 | 48 | // Not the global post |
| 51 | | $this->assertEquals( get_permalink( $post_id2 ), wp_get_shortlink( $post_id2, 'post' ) ); |
| | 49 | $this->assertEquals( home_url( '?p=' . $post_id2 ), wp_get_shortlink( $post_id2, 'post' ) ); |
| 52 | 50 | |
| 53 | 51 | unset( $GLOBALS['post'] ); |
| 54 | 52 | |
| … |
… |
class Tests_Link extends WP_UnitTestCase { |
| 57 | 55 | $this->assertEquals( '', wp_get_shortlink( 0 ) ); |
| 58 | 56 | $this->assertEquals( '', wp_get_shortlink() ); |
| 59 | 57 | |
| 60 | | $this->set_permalink_structure( '/%year%/%monthnum%/%day%/%postname%/' ); |
| 61 | | |
| 62 | 58 | // With a permalink structure set, get_permalink() will no longer match. |
| 63 | 59 | $this->assertNotEquals( get_permalink( $post_id ), wp_get_shortlink( $post_id, 'post' ) ); |
| 64 | 60 | $this->assertEquals( home_url( '?p=' . $post_id ), wp_get_shortlink( $post_id, 'post' ) ); |
| … |
… |
class Tests_Link extends WP_UnitTestCase { |
| 73 | 69 | function test_wp_get_shortlink_with_page() { |
| 74 | 70 | $post_id = self::factory()->post->create( array( 'post_type' => 'page' ) ); |
| 75 | 71 | |
| 76 | | // Basic case |
| 77 | | // Don't test against get_permalink() since it uses ?page_id= for pages. |
| 78 | | $this->assertEquals( home_url( '?p=' . $post_id ), wp_get_shortlink( $post_id, 'post' ) ); |
| 79 | | |
| 80 | | $this->set_permalink_structure( '/%year%/%monthnum%/%day%/%postname%/' ); |
| 81 | | |
| 82 | 72 | $this->assertEquals( home_url( '?p=' . $post_id ), wp_get_shortlink( $post_id, 'post' ) ); |
| 83 | 73 | } |
| 84 | 74 | |
| … |
… |
class Tests_Link extends WP_UnitTestCase { |
| 91 | 81 | update_option( 'page_on_front', $post_id ); |
| 92 | 82 | |
| 93 | 83 | $this->assertEquals( home_url( '/' ), wp_get_shortlink( $post_id, 'post' ) ); |
| 94 | | |
| 95 | | $this->set_permalink_structure( '/%year%/%monthnum%/%day%/%postname%/' ); |
| 96 | | |
| 97 | | $this->assertEquals( home_url( '/' ), wp_get_shortlink( $post_id, 'post' ) ); |
| 98 | 84 | } |
| 99 | 85 | |
| 100 | 86 | /** |
| 101 | 87 | * @ticket 30910 |
| 102 | 88 | */ |
| 103 | 89 | public function test_get_permalink_should_not_reveal_post_name_for_post_with_post_status_future() { |
| 104 | | update_option( 'permalink_structure', '/%year%/%monthnum%/%day%/%postname%/' ); |
| 105 | | |
| 106 | | flush_rewrite_rules(); |
| 107 | | |
| 108 | 90 | $p = self::factory()->post->create( |
| 109 | 91 | array( |
| 110 | 92 | 'post_status' => 'publish', |
| … |
… |
class Tests_Link extends WP_UnitTestCase { |
| 121 | 103 | * @ticket 30910 |
| 122 | 104 | */ |
| 123 | 105 | public function test_get_permalink_should_not_reveal_post_name_for_cpt_with_post_status_future() { |
| 124 | | update_option( 'permalink_structure', '/%year%/%monthnum%/%day%/%postname%/' ); |
| 125 | | |
| 126 | 106 | register_post_type( 'wptests_pt', array( 'public' => true ) ); |
| 127 | 107 | |
| 128 | 108 | flush_rewrite_rules(); |
| … |
… |
class Tests_Link extends WP_UnitTestCase { |
| 171 | 151 | public function test_attachment_attached_to_non_existent_post_type_has_a_pretty_permalink() { |
| 172 | 152 | global $wp_post_types; |
| 173 | 153 | |
| 174 | | $this->set_permalink_structure( '/%year%/%monthnum%/%day%/%postname%/' ); |
| 175 | | |
| 176 | 154 | register_post_type( 'not_a_post_type', array( 'public' => true ) ); |
| 177 | 155 | |
| 178 | | flush_rewrite_rules(); |
| 179 | | |
| 180 | 156 | $post_id = self::factory()->post->create( array( 'post_type' => 'not_a_post_type' ) ); |
| 181 | 157 | |
| 182 | 158 | $attachment_id = self::factory()->attachment->create_object( |
-
diff --git tests/phpunit/tests/link/getAdjacentPostLink.php tests/phpunit/tests/link/getAdjacentPostLink.php
index acaec3973b..340f9b31c7 100644
|
|
|
|
| 5 | 5 | */ |
| 6 | 6 | class Tests_Link_GetAdjacentPostLink extends WP_UnitTestCase { |
| 7 | 7 | |
| 8 | | protected $post_ids; |
| | 8 | protected $posts; |
| 9 | 9 | protected $cat_id; |
| 10 | 10 | |
| 11 | 11 | public function setUp() { |
| 12 | 12 | parent::setUp(); |
| 13 | 13 | $this->cat_id = self::factory()->category->create( array( 'name' => 'other' ) ); |
| 14 | | $this->post_ids = array(); |
| 15 | | $this->post_ids[] = self::factory()->post->create( |
| | 14 | $this->posts = array(); |
| | 15 | $this->posts[] = self::factory()->post->create_and_get( |
| 16 | 16 | array( |
| 17 | 17 | 'post_type' => 'post', |
| 18 | 18 | 'post_date' => '2014-10-26 05:32:29', |
| 19 | 19 | 'category_id' => 1, |
| 20 | 20 | ) |
| 21 | 21 | ); |
| 22 | | $this->post_ids[] = self::factory()->post->create( |
| | 22 | $this->posts[] = self::factory()->post->create_and_get( |
| 23 | 23 | array( |
| 24 | 24 | 'post_type' => 'post', |
| 25 | 25 | 'post_date' => '2014-10-26 04:32:29', |
| 26 | 26 | 'category_id' => $this->cat_id, |
| 27 | 27 | ) |
| 28 | 28 | ); |
| 29 | | $this->post_ids[] = self::factory()->post->create( |
| | 29 | $this->posts[] = self::factory()->post->create_and_get( |
| 30 | 30 | array( |
| 31 | 31 | 'post_type' => 'post', |
| 32 | 32 | 'post_date' => '2014-10-26 03:32:29', |
| 33 | 33 | 'category_id' => 1, |
| 34 | 34 | ) |
| 35 | 35 | ); |
| 36 | | $this->post_ids[] = self::factory()->post->create( |
| | 36 | $this->posts[] = self::factory()->post->create_and_get( |
| 37 | 37 | array( |
| 38 | 38 | 'post_type' => 'post', |
| 39 | 39 | 'post_date' => '2014-10-26 02:32:29', |
| 40 | 40 | 'category_id' => $this->cat_id, |
| 41 | 41 | ) |
| 42 | 42 | ); |
| 43 | | $this->post_ids[] = self::factory()->post->create( |
| | 43 | $this->posts[] = self::factory()->post->create_and_get( |
| 44 | 44 | array( |
| 45 | 45 | 'post_type' => 'post', |
| 46 | 46 | 'post_date' => '2014-10-26 01:32:29', |
| … |
… |
class Tests_Link_GetAdjacentPostLink extends WP_UnitTestCase { |
| 50 | 50 | |
| 51 | 51 | //set current post (has 2 on each end) |
| 52 | 52 | global $GLOBALS; |
| 53 | | $GLOBALS['post'] = get_post( $this->post_ids[2] ); |
| | 53 | $GLOBALS['post'] = $this->posts[2]; |
| 54 | 54 | } |
| 55 | 55 | |
| 56 | 56 | public function test_get_next_post_link_default() { |
| 57 | | $actual = get_next_post_link(); |
| 58 | | $title = get_post( $this->post_ids[1] )->post_title; |
| 59 | | $expected = '<a href="' . home_url( '?p=' . $this->post_ids[1] ) . '" rel="next">' . $title . '</a> »'; |
| 60 | | $this->assertSame( $expected, $actual ); |
| | 57 | $this->assertSame( |
| | 58 | '<a href="' . get_permalink( $this->posts[1] ) . '" rel="next">' . $this->posts[1]->post_title . '</a> »', |
| | 59 | get_next_post_link() |
| | 60 | ); |
| 61 | 61 | } |
| 62 | 62 | |
| 63 | 63 | public function test_get_previous_post_link_default() { |
| 64 | | $actual = get_previous_post_link(); |
| 65 | | $title = get_post( $this->post_ids[3] )->post_title; |
| 66 | | $expected = '« <a href="' . home_url( '?p=' . $this->post_ids[3] ) . '" rel="prev">' . $title . '</a>'; |
| 67 | | $this->assertSame( $expected, $actual ); |
| | 64 | $this->assertSame( |
| | 65 | '« <a href="' . get_permalink( $this->posts[3] ) . '" rel="prev">' . $this->posts[3]->post_title . '</a>', |
| | 66 | get_previous_post_link() |
| | 67 | ); |
| 68 | 68 | } |
| 69 | 69 | |
| 70 | 70 | public function test_get_next_post_link_same_category() { |
| 71 | | $actual = get_next_post_link( '%link »', '%title', true ); |
| 72 | | $title = get_post( $this->post_ids[1] )->post_title; |
| 73 | | $expected = '<a href="' . home_url( '?p=' . $this->post_ids[1] ) . '" rel="next">' . $title . '</a> »'; |
| 74 | | $this->assertSame( $expected, $actual ); |
| | 71 | $this->assertSame( |
| | 72 | '<a href="' . get_permalink( $this->posts[1] ) . '" rel="next">' . $this->posts[1]->post_title . '</a> »', |
| | 73 | get_next_post_link( '%link »', '%title', true ) |
| | 74 | ); |
| 75 | 75 | } |
| 76 | 76 | |
| 77 | 77 | public function test_get_previous_post_link_same_category() { |
| 78 | | $actual = get_previous_post_link( '« %link', '%title', true ); |
| 79 | | $title = get_post( $this->post_ids[3] )->post_title; |
| 80 | | $expected = '« <a href="' . home_url( '?p=' . $this->post_ids[3] ) . '" rel="prev">' . $title . '</a>'; |
| 81 | | $this->assertSame( $expected, $actual ); |
| | 78 | $this->assertSame( |
| | 79 | '« <a href="' . get_permalink( $this->posts[3] ) . '" rel="prev">' . $this->posts[3]->post_title . '</a>', |
| | 80 | get_previous_post_link( '« %link', '%title', true ) |
| | 81 | ); |
| 82 | 82 | } |
| 83 | 83 | |
| 84 | 84 | public function test_get_next_post_link_exclude_category() { |
| 85 | | $actual = get_next_post_link( '%link »', '%title', false, $this->cat_id ); |
| 86 | | $title = get_post( $this->post_ids[1] )->post_title; |
| 87 | | $expected = '<a href="' . home_url( '?p=' . $this->post_ids[1] ) . '" rel="next">' . $title . '</a> »'; |
| 88 | | $this->assertSame( $expected, $actual ); |
| | 85 | $this->assertSame( |
| | 86 | '<a href="' . get_permalink( $this->posts[1] ) . '" rel="next">' . $this->posts[1]->post_title . '</a> »', |
| | 87 | get_next_post_link( '%link »', '%title', false, $this->cat_id ) |
| | 88 | ); |
| | 89 | |
| 89 | 90 | } |
| 90 | 91 | |
| 91 | 92 | public function test_get_previous_post_link_exclude_category() { |
| 92 | | $actual = get_previous_post_link( '« %link', '%title', false, $this->cat_id ); |
| 93 | | $title = get_post( $this->post_ids[3] )->post_title; |
| 94 | | $expected = '« <a href="' . home_url( '?p=' . $this->post_ids[3] ) . '" rel="prev">' . $title . '</a>'; |
| 95 | | $this->assertSame( $expected, $actual ); |
| | 93 | $this->assertSame( |
| | 94 | '« <a href="' . get_permalink( $this->posts[3] ) . '" rel="prev">' . $this->posts[3]->post_title . '</a>', |
| | 95 | get_previous_post_link( '« %link', '%title', false, $this->cat_id ) |
| | 96 | ); |
| 96 | 97 | } |
| 97 | 98 | } |
-
diff --git tests/phpunit/tests/link/getNextCommentsLink.php tests/phpunit/tests/link/getNextCommentsLink.php
index 204b2057ff..1d1229ad4a 100644
|
|
|
class Tests_Link_GetNextCommentsLink extends WP_UnitTestCase { |
| 16 | 16 | |
| 17 | 17 | $link = get_next_comments_link( 'Next', 5 ); |
| 18 | 18 | |
| 19 | | $this->assertContains( 'cpage=4', $link ); |
| | 19 | $this->assertContains( 'comment-page-4', $link ); |
| 20 | 20 | |
| 21 | 21 | set_query_var( 'cpage', $cpage ); |
| 22 | 22 | } |
| … |
… |
class Tests_Link_GetNextCommentsLink extends WP_UnitTestCase { |
| 33 | 33 | |
| 34 | 34 | $link = get_next_comments_link( 'Next', 5 ); |
| 35 | 35 | |
| 36 | | $this->assertContains( 'cpage=2', $link ); |
| | 36 | $this->assertContains( 'comment-page-2', $link ); |
| 37 | 37 | |
| 38 | 38 | set_query_var( 'cpage', $cpage ); |
| 39 | 39 | } |
-
diff --git tests/phpunit/tests/link/getPostCommentsFeedLink.php tests/phpunit/tests/link/getPostCommentsFeedLink.php
index 986205db12..c887b099e2 100644
|
|
|
|
| 5 | 5 | class Tests_Link_GetPostCommentsFeedLink extends WP_UnitTestCase { |
| 6 | 6 | |
| 7 | 7 | public function test_post_link() { |
| | 8 | tests_set_and_flush_permalinks( '' ); |
| | 9 | |
| 8 | 10 | $post_id = self::factory()->post->create(); |
| 9 | 11 | |
| 10 | 12 | $link = get_post_comments_feed_link( $post_id ); |
| … |
… |
class Tests_Link_GetPostCommentsFeedLink extends WP_UnitTestCase { |
| 16 | 18 | ); |
| 17 | 19 | |
| 18 | 20 | $this->assertEquals( $expected, $link ); |
| | 21 | |
| | 22 | tests_reset_and_flush_permalinks(); |
| 19 | 23 | } |
| 20 | 24 | |
| 21 | 25 | public function test_post_pretty_link() { |
| 22 | | $this->set_permalink_structure( '/%year%/%monthnum%/%day%/%postname%/' ); |
| 23 | | |
| 24 | 26 | $post_id = self::factory()->post->create(); |
| 25 | 27 | |
| 26 | 28 | $link = get_post_comments_feed_link( $post_id ); |
| … |
… |
class Tests_Link_GetPostCommentsFeedLink extends WP_UnitTestCase { |
| 30 | 32 | } |
| 31 | 33 | |
| 32 | 34 | public function test_attachment_link() { |
| | 35 | tests_set_and_flush_permalinks( '' ); |
| | 36 | |
| 33 | 37 | $post_id = self::factory()->post->create(); |
| 34 | 38 | $attachment_id = self::factory()->attachment->create_object( |
| 35 | 39 | 'image.jpg', $post_id, array( |
| … |
… |
class Tests_Link_GetPostCommentsFeedLink extends WP_UnitTestCase { |
| 47 | 51 | ); |
| 48 | 52 | |
| 49 | 53 | $this->assertEquals( $expected, $link ); |
| | 54 | |
| | 55 | tests_reset_and_flush_permalinks(); |
| 50 | 56 | } |
| 51 | 57 | |
| 52 | 58 | public function test_attachment_pretty_link() { |
| 53 | | $this->set_permalink_structure( '/%year%/%monthnum%/%day%/%postname%/' ); |
| 54 | | |
| 55 | 59 | $post_id = self::factory()->post->create( |
| 56 | 60 | array( |
| 57 | 61 | 'post_status' => 'publish', |
| … |
… |
class Tests_Link_GetPostCommentsFeedLink extends WP_UnitTestCase { |
| 74 | 78 | } |
| 75 | 79 | |
| 76 | 80 | public function test_attachment_no_name_pretty_link() { |
| 77 | | $this->set_permalink_structure( '/%year%/%monthnum%/%day%/%postname%/' ); |
| 78 | | |
| 79 | 81 | $post_id = self::factory()->post->create(); |
| 80 | 82 | $attachment_id = self::factory()->attachment->create_object( |
| 81 | 83 | 'image.jpg', $post_id, array( |
| … |
… |
class Tests_Link_GetPostCommentsFeedLink extends WP_UnitTestCase { |
| 91 | 93 | } |
| 92 | 94 | |
| 93 | 95 | public function test_unattached_link() { |
| | 96 | tests_set_and_flush_permalinks( '' ); |
| | 97 | |
| 94 | 98 | $attachment_id = self::factory()->attachment->create_object( |
| 95 | 99 | 'image.jpg', 0, array( |
| 96 | 100 | 'post_mime_type' => 'image/jpeg', |
| … |
… |
class Tests_Link_GetPostCommentsFeedLink extends WP_UnitTestCase { |
| 107 | 111 | ); |
| 108 | 112 | |
| 109 | 113 | $this->assertEquals( $expected, $link ); |
| | 114 | |
| | 115 | tests_reset_and_flush_permalinks(); |
| 110 | 116 | } |
| 111 | 117 | |
| 112 | 118 | public function test_unattached_pretty_link() { |
| 113 | | $this->set_permalink_structure( '/%year%/%monthnum%/%day%/%postname%/' ); |
| 114 | | |
| 115 | 119 | $attachment_id = self::factory()->attachment->create_object( |
| 116 | 120 | 'image.jpg', 0, array( |
| 117 | 121 | 'post_mime_type' => 'image/jpeg', |
-
diff --git tests/phpunit/tests/link/getPreviousCommentsLink.php tests/phpunit/tests/link/getPreviousCommentsLink.php
index ff4c088dea..073eaf60a3 100644
|
|
|
class Tests_Link_GetPreviousCommentsLink extends WP_UnitTestCase { |
| 16 | 16 | |
| 17 | 17 | $link = get_previous_comments_link( 'Next' ); |
| 18 | 18 | |
| 19 | | $this->assertContains( 'cpage=2', $link ); |
| | 19 | $this->assertContains( 'comment-page-2', $link ); |
| 20 | 20 | |
| 21 | 21 | set_query_var( 'cpage', $cpage ); |
| 22 | 22 | } |
-
diff --git tests/phpunit/tests/link/wpGetCanonicalURL.php tests/phpunit/tests/link/wpGetCanonicalURL.php
index 5a9637a9ca..91aff0b94d 100644
|
|
|
class Tests_WpGetCanonicalURL extends WP_UnitTestCase { |
| 16 | 16 | ); |
| 17 | 17 | } |
| 18 | 18 | |
| | 19 | public static function wpTearDownAfterClass() { |
| | 20 | tests_reset_and_flush_permalinks(); |
| | 21 | } |
| | 22 | |
| 19 | 23 | /** |
| 20 | 24 | * Test for a non existing post. |
| 21 | 25 | */ |
| … |
… |
class Tests_WpGetCanonicalURL extends WP_UnitTestCase { |
| 47 | 51 | * Test non permalink structure page usage. |
| 48 | 52 | */ |
| 49 | 53 | public function test_paged_with_plain_permalink_structure() { |
| | 54 | tests_set_and_flush_permalinks( '' ); |
| | 55 | |
| 50 | 56 | $link = add_query_arg( |
| 51 | 57 | array( |
| 52 | 58 | 'page' => 2, |
| … |
… |
class Tests_WpGetCanonicalURL extends WP_UnitTestCase { |
| 63 | 69 | ); |
| 64 | 70 | |
| 65 | 71 | $this->assertEquals( $expected, wp_get_canonical_url( self::$post_id ) ); |
| | 72 | |
| | 73 | tests_reset_and_flush_permalinks(); |
| 66 | 74 | } |
| 67 | 75 | |
| 68 | 76 | /** |
| … |
… |
class Tests_WpGetCanonicalURL extends WP_UnitTestCase { |
| 70 | 78 | */ |
| 71 | 79 | public function test_paged_with_custom_permalink_structure() { |
| 72 | 80 | $this->set_permalink_structure( '/%postname%/' ); |
| | 81 | |
| 73 | 82 | $page = 2; |
| 74 | 83 | |
| 75 | 84 | $link = add_query_arg( |
| … |
… |
class Tests_WpGetCanonicalURL extends WP_UnitTestCase { |
| 84 | 93 | $expected = trailingslashit( get_permalink( self::$post_id ) ) . user_trailingslashit( $page, 'single_paged' ); |
| 85 | 94 | |
| 86 | 95 | $this->assertEquals( $expected, wp_get_canonical_url( self::$post_id ) ); |
| | 96 | |
| | 97 | tests_reset_and_flush_permalinks(); |
| 87 | 98 | } |
| 88 | 99 | |
| 89 | 100 | /** |
| 90 | 101 | * Test non permalink structure comment page usage. |
| 91 | 102 | */ |
| 92 | 103 | public function test_comments_paged_with_plain_permalink_structure() { |
| | 104 | tests_set_and_flush_permalinks( '' ); |
| | 105 | |
| 93 | 106 | $cpage = 2; |
| 94 | 107 | |
| 95 | 108 | $link = add_query_arg( |
| … |
… |
class Tests_WpGetCanonicalURL extends WP_UnitTestCase { |
| 108 | 121 | ); |
| 109 | 122 | |
| 110 | 123 | $this->assertEquals( $expected, wp_get_canonical_url( self::$post_id ) ); |
| | 124 | tests_reset_and_flush_permalinks(); |
| 111 | 125 | } |
| 112 | 126 | |
| 113 | 127 | /** |
| … |
… |
class Tests_WpGetCanonicalURL extends WP_UnitTestCase { |
| 116 | 130 | public function test_comments_paged_with_pretty_permalink_structure() { |
| 117 | 131 | global $wp_rewrite; |
| 118 | 132 | |
| 119 | | $this->set_permalink_structure( '/%postname%/' ); |
| 120 | 133 | $cpage = 2; |
| 121 | 134 | |
| 122 | 135 | $link = add_query_arg( |
-
diff --git tests/phpunit/tests/oembed/controller.php tests/phpunit/tests/oembed/controller.php
index 0d91408769..2a4d02a6d1 100644
|
|
|
class Test_oEmbed_Controller extends WP_UnitTestCase { |
| 446 | 446 | } |
| 447 | 447 | |
| 448 | 448 | function test_get_oembed_endpoint_url() { |
| | 449 | tests_set_and_flush_permalinks( '' ); |
| | 450 | |
| 449 | 451 | $this->assertEquals( home_url() . '/index.php?rest_route=/oembed/1.0/embed', get_oembed_endpoint_url() ); |
| 450 | 452 | $this->assertEquals( home_url() . '/index.php?rest_route=/oembed/1.0/embed', get_oembed_endpoint_url( '', 'json' ) ); |
| 451 | 453 | $this->assertEquals( home_url() . '/index.php?rest_route=/oembed/1.0/embed', get_oembed_endpoint_url( '', 'xml' ) ); |
| … |
… |
class Test_oEmbed_Controller extends WP_UnitTestCase { |
| 456 | 458 | |
| 457 | 459 | $this->assertEquals( home_url() . '/index.php?rest_route=%2Foembed%2F1.0%2Fembed&url=' . $url_encoded, get_oembed_endpoint_url( $url ) ); |
| 458 | 460 | $this->assertEquals( home_url() . '/index.php?rest_route=%2Foembed%2F1.0%2Fembed&url=' . $url_encoded . '&format=xml', get_oembed_endpoint_url( $url, 'xml' ) ); |
| | 461 | |
| | 462 | tests_reset_and_flush_permalinks(); |
| 459 | 463 | } |
| 460 | 464 | |
| 461 | 465 | function test_get_oembed_endpoint_url_pretty_permalinks() { |
| 462 | | update_option( 'permalink_structure', '/%postname%' ); |
| 463 | | |
| 464 | 466 | $this->assertEquals( home_url() . '/wp-json/oembed/1.0/embed', get_oembed_endpoint_url() ); |
| 465 | 467 | $this->assertEquals( home_url() . '/wp-json/oembed/1.0/embed', get_oembed_endpoint_url( '', 'xml' ) ); |
| 466 | 468 | |
| … |
… |
class Test_oEmbed_Controller extends WP_UnitTestCase { |
| 470 | 472 | |
| 471 | 473 | $this->assertEquals( home_url() . '/wp-json/oembed/1.0/embed?url=' . $url_encoded, get_oembed_endpoint_url( $url ) ); |
| 472 | 474 | $this->assertEquals( home_url() . '/wp-json/oembed/1.0/embed?url=' . $url_encoded . '&format=xml', get_oembed_endpoint_url( $url, 'xml' ) ); |
| 473 | | |
| 474 | | update_option( 'permalink_structure', '' ); |
| 475 | 475 | } |
| 476 | 476 | |
| 477 | 477 | public function test_proxy_without_permission() { |
-
diff --git tests/phpunit/tests/oembed/postEmbedUrl.php tests/phpunit/tests/oembed/postEmbedUrl.php
index e6c478f26f..52a9982e43 100644
|
|
|
class Tests_Post_Embed_URL extends WP_UnitTestCase { |
| 10 | 10 | } |
| 11 | 11 | |
| 12 | 12 | function test_with_pretty_permalinks() { |
| 13 | | $this->set_permalink_structure( '/%postname%' ); |
| 14 | | |
| 15 | 13 | $post_id = self::factory()->post->create(); |
| 16 | 14 | $permalink = get_permalink( $post_id ); |
| 17 | 15 | $embed_url = get_post_embed_url( $post_id ); |
| 18 | 16 | |
| 19 | | $this->assertEquals( $permalink . '/embed', $embed_url ); |
| | 17 | $this->assertEquals( $permalink . 'embed/', $embed_url ); |
| 20 | 18 | } |
| 21 | 19 | |
| 22 | 20 | function test_with_ugly_permalinks() { |
| | 21 | tests_set_and_flush_permalinks( '' ); |
| | 22 | |
| 23 | 23 | $post_id = self::factory()->post->create(); |
| 24 | 24 | $permalink = get_permalink( $post_id ); |
| 25 | 25 | $embed_url = get_post_embed_url( $post_id ); |
| 26 | 26 | |
| 27 | 27 | $this->assertEquals( $permalink . '&embed=true', $embed_url ); |
| | 28 | |
| | 29 | tests_reset_and_flush_permalinks(); |
| 28 | 30 | } |
| 29 | 31 | |
| 30 | 32 | /** |
| … |
… |
class Tests_Post_Embed_URL extends WP_UnitTestCase { |
| 43 | 45 | $this->assertSame( user_trailingslashit( trailingslashit( home_url() ) . 'embed' ), $embed_url ); |
| 44 | 46 | |
| 45 | 47 | update_option( 'show_on_front', 'posts' ); |
| | 48 | |
| | 49 | tests_reset_and_flush_permalinks(); |
| 46 | 50 | } |
| 47 | 51 | |
| 48 | 52 | /** |
| 49 | 53 | * @ticket 34971 |
| 50 | 54 | */ |
| 51 | 55 | function test_static_front_page_with_ugly_permalinks() { |
| | 56 | tests_set_and_flush_permalinks( '' ); |
| | 57 | |
| 52 | 58 | $post_id = self::factory()->post->create( array( 'post_type' => 'page' ) ); |
| 53 | 59 | |
| 54 | 60 | update_option( 'show_on_front', 'page' ); |
| … |
… |
class Tests_Post_Embed_URL extends WP_UnitTestCase { |
| 59 | 65 | $this->assertSame( trailingslashit( home_url() ) . '?embed=true', $embed_url ); |
| 60 | 66 | |
| 61 | 67 | update_option( 'show_on_front', 'posts' ); |
| | 68 | tests_reset_and_flush_permalinks(); |
| 62 | 69 | } |
| 63 | 70 | |
| 64 | 71 | /** |
| 65 | 72 | * @ticket 34971 |
| 66 | 73 | */ |
| 67 | 74 | function test_page_conflicts_with_embed_slug() { |
| 68 | | $this->set_permalink_structure( '/%postname%/' ); |
| 69 | | |
| 70 | 75 | $parent_page = self::factory()->post->create( array( 'post_type' => 'page' ) ); |
| 71 | 76 | |
| 72 | 77 | add_filter( 'wp_unique_post_slug', array( $this, 'filter_unique_post_slug' ) ); |
| … |
… |
class Tests_Post_Embed_URL extends WP_UnitTestCase { |
| 87 | 92 | * @ticket 34971 |
| 88 | 93 | */ |
| 89 | 94 | function test_static_front_page_conflicts_with_embed_slug() { |
| 90 | | $this->set_permalink_structure( '/%postname%/' ); |
| 91 | | |
| 92 | 95 | // Create a post with the 'embed' post_name |
| 93 | 96 | add_filter( 'wp_unique_post_slug', array( $this, 'filter_unique_post_slug' ) ); |
| 94 | 97 | $post_embed_slug = self::factory()->post->create( array( 'post_name' => 'embed' ) ); |
| … |
… |
class Tests_Post_Embed_URL extends WP_UnitTestCase { |
| 98 | 101 | update_option( 'show_on_front', 'page' ); |
| 99 | 102 | update_option( 'page_on_front', $page_front ); |
| 100 | 103 | |
| 101 | | $this->assertSame( home_url() . '/embed/embed/', get_post_embed_url( $post_embed_slug ) ); |
| | 104 | $expected = home_url() . '/' . tests_add_blog_permalink_prefix_on_multisite( date( 'Y/m/d', time() ) . '/embed/embed/' ); |
| | 105 | |
| | 106 | $this->assertSame( $expected, get_post_embed_url( $post_embed_slug ) ); |
| 102 | 107 | $this->assertSame( home_url() . '/?embed=true', get_post_embed_url( $page_front ) ); |
| 103 | 108 | |
| 104 | 109 | update_option( 'show_on_front', 'posts' ); |
-
diff --git tests/phpunit/tests/oembed/template.php tests/phpunit/tests/oembed/template.php
index cfe9b1ee03..dcce5a84e5 100644
|
|
|
class Tests_Embed_Template extends WP_UnitTestCase { |
| 106 | 106 | $this->assertNotFalse( strpos( $actual, 'canola.jpg' ) ); |
| 107 | 107 | } |
| 108 | 108 | |
| | 109 | /** |
| | 110 | * This tests fails with pretty permalinks enabled, see #42733. |
| | 111 | */ |
| 109 | 112 | function test_oembed_output_draft_post() { |
| | 113 | tests_set_and_flush_permalinks( '' ); |
| | 114 | |
| 110 | 115 | $post_id = self::factory()->post->create( |
| 111 | 116 | array( |
| 112 | 117 | 'post_title' => 'Hello World', |
| … |
… |
class Tests_Embed_Template extends WP_UnitTestCase { |
| 127 | 132 | $doc = new DOMDocument(); |
| 128 | 133 | $this->assertTrue( $doc->loadHTML( $actual ) ); |
| 129 | 134 | $this->assertNotFalse( strpos( $actual, 'That embed can’t be found.' ) ); |
| | 135 | |
| | 136 | tests_reset_and_flush_permalinks(); |
| 130 | 137 | } |
| 131 | 138 | |
| | 139 | /** |
| | 140 | * This tests fails with pretty permalinks enabled, see #42733. |
| | 141 | */ |
| 132 | 142 | function test_oembed_output_scheduled_post() { |
| | 143 | tests_set_and_flush_permalinks( '' ); |
| | 144 | |
| 133 | 145 | $post_id = self::factory()->post->create( |
| 134 | 146 | array( |
| 135 | 147 | 'post_title' => 'Hello World', |
| … |
… |
class Tests_Embed_Template extends WP_UnitTestCase { |
| 151 | 163 | $doc = new DOMDocument(); |
| 152 | 164 | $this->assertTrue( $doc->loadHTML( $actual ) ); |
| 153 | 165 | $this->assertNotFalse( strpos( $actual, 'That embed can’t be found.' ) ); |
| | 166 | |
| | 167 | tests_reset_and_flush_permalinks(); |
| 154 | 168 | } |
| 155 | 169 | |
| 156 | 170 | function test_oembed_output_private_post() { |
-
diff --git tests/phpunit/tests/oembed/wpOembed.php tests/phpunit/tests/oembed/wpOembed.php
index c148dd555c..e141e06167 100644
|
|
|
class Tests_WP_oEmbed extends WP_UnitTestCase { |
| 159 | 159 | * @group ms-required |
| 160 | 160 | */ |
| 161 | 161 | public function test_wp_filter_pre_oembed_result_multisite_sub_main() { |
| | 162 | // This test fails with pretty permalinks enabled. |
| | 163 | tests_set_and_flush_permalinks( '' ); |
| | 164 | |
| 162 | 165 | $post_id = self::factory()->post->create(); |
| 163 | 166 | $permalink = get_permalink( $post_id ); |
| 164 | 167 | $user_id = self::factory()->user->create(); |
| … |
… |
class Tests_WP_oEmbed extends WP_UnitTestCase { |
| 178 | 181 | |
| 179 | 182 | $this->assertNotNull( $this->pre_oembed_result_filtered ); |
| 180 | 183 | $this->assertEquals( $this->pre_oembed_result_filtered, $actual ); |
| | 184 | |
| | 185 | tests_reset_and_flush_permalinks(); |
| 181 | 186 | } |
| 182 | 187 | |
| 183 | 188 | /** |
-
diff --git tests/phpunit/tests/option/sanitize-option.php tests/phpunit/tests/option/sanitize-option.php
index be10216364..b00a8a4c28 100644
|
|
|
class Tests_Sanitize_Option extends WP_UnitTestCase { |
| 145 | 145 | } |
| 146 | 146 | |
| 147 | 147 | public function permalink_structure_provider() { |
| | 148 | $default_permalink_structure = get_option( 'permalink_structure' ); |
| | 149 | |
| 148 | 150 | return array( |
| 149 | 151 | array( '', '', true ), |
| 150 | | array( '%postname', false, false ), |
| 151 | | array( '%/%', false, false ), |
| 152 | | array( '%%%', false, false ), |
| | 152 | array( '%postname', $default_permalink_structure, false ), |
| | 153 | array( '%/%', $default_permalink_structure, false ), |
| | 154 | array( '%%%', $default_permalink_structure, false ), |
| 153 | 155 | array( '%a%', '%a%', true ), |
| 154 | 156 | array( '%postname%', '%postname%', true ), |
| 155 | 157 | array( '/%postname%/', '/%postname%/', true ), |
-
diff --git tests/phpunit/tests/post.php tests/phpunit/tests/post.php
index c0b20bb2a7..1bcfe5e726 100644
|
|
|
class Tests_Post extends WP_UnitTestCase { |
| 434 | 434 | * @ticket 5305 |
| 435 | 435 | */ |
| 436 | 436 | public function test_wp_insert_post_should_not_allow_a_bare_numeric_slug_that_might_conflict_with_a_date_archive_when_generating_from_an_empty_post_title() { |
| | 437 | |
| 437 | 438 | $this->set_permalink_structure( '/%postname%/' ); |
| 438 | 439 | |
| 439 | 440 | $p = wp_insert_post( |
| … |
… |
class Tests_Post extends WP_UnitTestCase { |
| 447 | 448 | |
| 448 | 449 | $post = get_post( $p ); |
| 449 | 450 | |
| 450 | | $this->set_permalink_structure(); |
| 451 | | |
| 452 | 451 | $this->assertEquals( "$p-2", $post->post_name ); |
| | 452 | tests_reset_and_flush_permalinks(); |
| 453 | 453 | } |
| 454 | 454 | |
| 455 | 455 | /** |
| … |
… |
class Tests_Post extends WP_UnitTestCase { |
| 469 | 469 | |
| 470 | 470 | $post = get_post( $p ); |
| 471 | 471 | |
| 472 | | $this->assertContains( 'wptests_pt=' . $p, $post->guid ); |
| | 472 | $this->assertContains( 'wptests_pt/' . $p, $post->guid ); |
| 473 | 473 | } |
| 474 | 474 | |
| 475 | 475 | /** |
| … |
… |
class Tests_Post extends WP_UnitTestCase { |
| 526 | 526 | function test_permalink_without_title() { |
| 527 | 527 | // bug: permalink doesn't work if post title is empty |
| 528 | 528 | // might only fail if the post ID is greater than four characters |
| 529 | | |
| 530 | | $this->set_permalink_structure( '/%year%/%monthnum%/%day%/%postname%/' ); |
| 531 | | |
| 532 | 529 | $post = array( |
| 533 | 530 | 'post_author' => self::$editor_id, |
| 534 | 531 | 'post_status' => 'publish', |
| … |
… |
class Tests_Post extends WP_UnitTestCase { |
| 543 | 540 | $plink = get_permalink( $id ); |
| 544 | 541 | |
| 545 | 542 | // permalink should include the post ID at the end |
| 546 | | $this->assertEquals( get_option( 'siteurl' ) . '/2007/10/31/' . $id . '/', $plink ); |
| | 543 | $this->assertEquals( |
| | 544 | get_option( 'siteurl' ) . '/' . tests_add_blog_permalink_prefix_on_multisite( '2007/10/31/' . $id . '/' ), |
| | 545 | $plink |
| | 546 | ); |
| 547 | 547 | } |
| 548 | 548 | |
| 549 | 549 | /** |
-
diff --git tests/phpunit/tests/post/nav-menu.php tests/phpunit/tests/post/nav-menu.php
index 17844f461e..5268a6a4c4 100644
|
|
|
class Test_Nav_Menus extends WP_UnitTestCase { |
| 687 | 687 | * @ticket 39800 |
| 688 | 688 | */ |
| 689 | 689 | function test_parent_ancestor_for_post_archive() { |
| | 690 | // This test only works without pretty permalinks. |
| | 691 | tests_set_and_flush_permalinks( '' ); |
| 690 | 692 | |
| 691 | 693 | register_post_type( |
| 692 | 694 | 'books', array( |
| … |
… |
class Test_Nav_Menus extends WP_UnitTestCase { |
| 760 | 762 | |
| 761 | 763 | $this->assertNotContains( 'current-menu-parent', $post_archive_menu_item->classes ); |
| 762 | 764 | $this->assertNotContains( 'current-menu-ancestor', $post_archive_menu_item->classes ); |
| | 765 | |
| | 766 | tests_reset_and_flush_permalinks(); |
| 763 | 767 | } |
| 764 | 768 | |
| 765 | 769 | } |
-
diff --git tests/phpunit/tests/post/types.php tests/phpunit/tests/post/types.php
index 393e5080b3..df17c08f5e 100644
|
|
|
class Tests_Post_Types extends WP_UnitTestCase { |
| 313 | 313 | * @ticket 14761 |
| 314 | 314 | */ |
| 315 | 315 | public function test_unregister_post_type_removes_rewrite_tags() { |
| 316 | | $this->set_permalink_structure( '/%postname%' ); |
| 317 | | |
| 318 | 316 | global $wp_rewrite; |
| 319 | 317 | |
| 320 | 318 | register_post_type( |
| … |
… |
class Tests_Post_Types extends WP_UnitTestCase { |
| 338 | 336 | * @ticket 14761 |
| 339 | 337 | */ |
| 340 | 338 | public function test_unregister_post_type_removes_rewrite_rules() { |
| 341 | | $this->set_permalink_structure( '/%postname%' ); |
| 342 | | |
| 343 | 339 | global $wp_rewrite; |
| 344 | 340 | |
| 345 | 341 | register_post_type( |
-
diff --git tests/phpunit/tests/post/wpPostType.php tests/phpunit/tests/post/wpPostType.php
index 0cf98902c1..77a3ff70a3 100644
|
|
|
class Tests_WP_Post_Type extends WP_UnitTestCase { |
| 60 | 60 | } |
| 61 | 61 | |
| 62 | 62 | public function test_does_not_add_query_var_if_not_public() { |
| 63 | | $this->set_permalink_structure( '/%postname%' ); |
| 64 | | |
| 65 | 63 | /* @var WP $wp */ |
| 66 | 64 | global $wp; |
| 67 | 65 | |
| … |
… |
class Tests_WP_Post_Type extends WP_UnitTestCase { |
| 78 | 76 | } |
| 79 | 77 | |
| 80 | 78 | public function test_adds_query_var_if_public() { |
| 81 | | $this->set_permalink_structure( '/%postname%' ); |
| 82 | | |
| 83 | 79 | /* @var WP $wp */ |
| 84 | 80 | global $wp; |
| 85 | 81 | |
| … |
… |
class Tests_WP_Post_Type extends WP_UnitTestCase { |
| 103 | 99 | } |
| 104 | 100 | |
| 105 | 101 | public function test_adds_rewrite_rules() { |
| 106 | | $this->set_permalink_structure( '/%postname%' ); |
| 107 | | |
| 108 | 102 | /* @var WP_Rewrite $wp_rewrite */ |
| 109 | 103 | global $wp_rewrite; |
| 110 | 104 | |
-
diff --git tests/phpunit/tests/post/wpUniquePostSlug.php tests/phpunit/tests/post/wpUniquePostSlug.php
index 575bec4fa4..da2576c90c 100644
|
|
|
class Tests_Post_WpUniquePostSlug extends WP_UnitTestCase { |
| 179 | 179 | * @ticket 5305 |
| 180 | 180 | */ |
| 181 | 181 | public function test_slugs_resulting_in_permalinks_that_resemble_year_archives_should_be_suffixed() { |
| | 182 | |
| 182 | 183 | $this->set_permalink_structure( '/%postname%/' ); |
| 183 | 184 | |
| 184 | 185 | $p = self::factory()->post->create( |
| … |
… |
class Tests_Post_WpUniquePostSlug extends WP_UnitTestCase { |
| 190 | 191 | |
| 191 | 192 | $found = wp_unique_post_slug( '2015', $p, 'publish', 'post', 0 ); |
| 192 | 193 | $this->assertEquals( '2015-2', $found ); |
| | 194 | |
| | 195 | tests_reset_and_flush_permalinks(); |
| 193 | 196 | } |
| 194 | 197 | |
| 195 | 198 | /** |
| 196 | 199 | * @ticket 5305 |
| 197 | 200 | */ |
| 198 | 201 | public function test_slugs_resulting_in_permalinks_that_resemble_year_archives_should_not_be_suffixed_for_already_published_posts() { |
| | 202 | |
| 199 | 203 | $this->set_permalink_structure( '/%postname%/' ); |
| 200 | 204 | |
| 201 | 205 | $p = self::factory()->post->create( |
| … |
… |
class Tests_Post_WpUniquePostSlug extends WP_UnitTestCase { |
| 208 | 212 | |
| 209 | 213 | $found = wp_unique_post_slug( '2015', $p, 'publish', 'post', 0 ); |
| 210 | 214 | $this->assertEquals( '2015-2', $found ); |
| | 215 | |
| | 216 | tests_reset_and_flush_permalinks(); |
| 211 | 217 | } |
| 212 | 218 | |
| 213 | 219 | /** |
| 214 | 220 | * @ticket 5305 |
| 215 | 221 | */ |
| 216 | 222 | public function test_yearlike_slugs_should_not_be_suffixed_if_permalink_structure_does_not_result_in_a_clash_with_year_archives() { |
| | 223 | |
| 217 | 224 | $this->set_permalink_structure( '/%year%/%postname%/' ); |
| 218 | 225 | |
| 219 | 226 | $p = self::factory()->post->create( |
| … |
… |
class Tests_Post_WpUniquePostSlug extends WP_UnitTestCase { |
| 225 | 232 | |
| 226 | 233 | $found = wp_unique_post_slug( '2015', $p, 'publish', 'post', 0 ); |
| 227 | 234 | $this->assertEquals( '2015', $found ); |
| | 235 | |
| | 236 | tests_reset_and_flush_permalinks(); |
| 228 | 237 | } |
| 229 | 238 | |
| 230 | 239 | /** |
| 231 | 240 | * @ticket 5305 |
| 232 | 241 | */ |
| 233 | 242 | public function test_slugs_resulting_in_permalinks_that_resemble_month_archives_should_be_suffixed() { |
| | 243 | |
| 234 | 244 | $this->set_permalink_structure( '/%year%/%postname%/' ); |
| 235 | 245 | |
| 236 | 246 | $p = self::factory()->post->create( |
| … |
… |
class Tests_Post_WpUniquePostSlug extends WP_UnitTestCase { |
| 242 | 252 | |
| 243 | 253 | $found = wp_unique_post_slug( '11', $p, 'publish', 'post', 0 ); |
| 244 | 254 | $this->assertEquals( '11-2', $found ); |
| | 255 | |
| | 256 | tests_reset_and_flush_permalinks(); |
| 245 | 257 | } |
| 246 | 258 | |
| 247 | 259 | /** |
| 248 | 260 | * @ticket 5305 |
| 249 | 261 | */ |
| 250 | 262 | public function test_monthlike_slugs_should_not_be_suffixed_if_permalink_structure_does_not_result_in_a_clash_with_month_archives() { |
| | 263 | |
| 251 | 264 | $this->set_permalink_structure( '/%year%/foo/%postname%/' ); |
| 252 | 265 | |
| 253 | 266 | $p = self::factory()->post->create( |
| … |
… |
class Tests_Post_WpUniquePostSlug extends WP_UnitTestCase { |
| 259 | 272 | |
| 260 | 273 | $found = wp_unique_post_slug( '11', $p, 'publish', 'post', 0 ); |
| 261 | 274 | $this->assertEquals( '11', $found ); |
| | 275 | |
| | 276 | tests_reset_and_flush_permalinks(); |
| 262 | 277 | } |
| 263 | 278 | |
| 264 | 279 | /** |
| 265 | 280 | * @ticket 5305 |
| 266 | 281 | */ |
| 267 | 282 | public function test_monthlike_slugs_should_not_be_suffixed_for_invalid_month_numbers() { |
| | 283 | |
| 268 | 284 | $this->set_permalink_structure( '/%year%/%postname%/' ); |
| 269 | 285 | |
| 270 | 286 | $p = self::factory()->post->create( |
| … |
… |
class Tests_Post_WpUniquePostSlug extends WP_UnitTestCase { |
| 276 | 292 | |
| 277 | 293 | $found = wp_unique_post_slug( '13', $p, 'publish', 'post', 0 ); |
| 278 | 294 | $this->assertEquals( '13', $found ); |
| | 295 | |
| | 296 | tests_reset_and_flush_permalinks(); |
| 279 | 297 | } |
| 280 | 298 | |
| 281 | 299 | /** |
| 282 | 300 | * @ticket 5305 |
| 283 | 301 | */ |
| 284 | 302 | public function test_slugs_resulting_in_permalinks_that_resemble_day_archives_should_be_suffixed() { |
| | 303 | |
| 285 | 304 | $this->set_permalink_structure( '/%year%/%monthnum%/%postname%/' ); |
| 286 | 305 | |
| 287 | 306 | $p = self::factory()->post->create( |
| … |
… |
class Tests_Post_WpUniquePostSlug extends WP_UnitTestCase { |
| 293 | 312 | |
| 294 | 313 | $found = wp_unique_post_slug( '30', $p, 'publish', 'post', 0 ); |
| 295 | 314 | $this->assertEquals( '30-2', $found ); |
| | 315 | |
| | 316 | tests_reset_and_flush_permalinks(); |
| 296 | 317 | } |
| 297 | 318 | |
| 298 | 319 | /** |
| 299 | 320 | * @ticket 5305 |
| 300 | 321 | */ |
| 301 | 322 | public function test_daylike_slugs_should_not_be_suffixed_if_permalink_structure_does_not_result_in_a_clash_with_day_archives() { |
| | 323 | |
| 302 | 324 | $this->set_permalink_structure( '/%year%/%monthnum%/%day%/%postname%/' ); |
| 303 | 325 | |
| 304 | 326 | $p = self::factory()->post->create( |
| … |
… |
class Tests_Post_WpUniquePostSlug extends WP_UnitTestCase { |
| 310 | 332 | |
| 311 | 333 | $found = wp_unique_post_slug( '30', $p, 'publish', 'post', 0 ); |
| 312 | 334 | $this->assertEquals( '30', $found ); |
| | 335 | |
| | 336 | tests_reset_and_flush_permalinks(); |
| 313 | 337 | } |
| 314 | 338 | |
| 315 | 339 | /** |
| 316 | 340 | * @ticket 5305 |
| 317 | 341 | */ |
| 318 | 342 | public function test_daylike_slugs_should_not_be_suffixed_for_invalid_day_numbers() { |
| | 343 | |
| 319 | 344 | $this->set_permalink_structure( '/%year%/%monthnum%/%postname%/' ); |
| 320 | 345 | |
| 321 | 346 | $p = self::factory()->post->create( |
| … |
… |
class Tests_Post_WpUniquePostSlug extends WP_UnitTestCase { |
| 327 | 352 | |
| 328 | 353 | $found = wp_unique_post_slug( '32', $p, 'publish', 'post', 0 ); |
| 329 | 354 | $this->assertEquals( '32', $found ); |
| | 355 | |
| | 356 | tests_reset_and_flush_permalinks(); |
| 330 | 357 | } |
| 331 | 358 | |
| 332 | 359 | /** |
| 333 | 360 | * @ticket 34971 |
| 334 | 361 | */ |
| 335 | 362 | public function test_embed_slug_should_be_suffixed_for_posts() { |
| | 363 | |
| 336 | 364 | $this->set_permalink_structure( '/%postname%/' ); |
| 337 | 365 | |
| 338 | 366 | $p = self::factory()->post->create( |
| … |
… |
class Tests_Post_WpUniquePostSlug extends WP_UnitTestCase { |
| 344 | 372 | |
| 345 | 373 | $found = wp_unique_post_slug( 'embed', $p, 'publish', 'post', 0 ); |
| 346 | 374 | $this->assertSame( 'embed-2', $found ); |
| | 375 | |
| | 376 | tests_reset_and_flush_permalinks(); |
| 347 | 377 | } |
| 348 | 378 | |
| 349 | 379 | /** |
| 350 | 380 | * @ticket 34971 |
| 351 | 381 | */ |
| 352 | 382 | public function test_embed_slug_should_be_suffixed_for_pages() { |
| | 383 | |
| 353 | 384 | $this->set_permalink_structure( '/%postname%/' ); |
| 354 | 385 | |
| 355 | 386 | $p = self::factory()->post->create( |
| … |
… |
class Tests_Post_WpUniquePostSlug extends WP_UnitTestCase { |
| 361 | 392 | |
| 362 | 393 | $found = wp_unique_post_slug( 'embed', $p, 'publish', 'paage', 0 ); |
| 363 | 394 | $this->assertSame( 'embed-2', $found ); |
| | 395 | |
| | 396 | tests_reset_and_flush_permalinks(); |
| 364 | 397 | } |
| 365 | 398 | |
| 366 | 399 | /** |
| 367 | 400 | * @ticket 34971 |
| 368 | 401 | */ |
| 369 | 402 | public function test_embed_slug_should_be_suffixed_for_attachments() { |
| | 403 | |
| 370 | 404 | $this->set_permalink_structure( '/%postname%/' ); |
| 371 | 405 | |
| 372 | 406 | $p = self::factory()->post->create( |
| … |
… |
class Tests_Post_WpUniquePostSlug extends WP_UnitTestCase { |
| 378 | 412 | |
| 379 | 413 | $found = wp_unique_post_slug( 'embed', $p, 'publish', 'attachment', 0 ); |
| 380 | 414 | $this->assertSame( 'embed-2', $found ); |
| | 415 | |
| | 416 | tests_reset_and_flush_permalinks(); |
| 381 | 417 | } |
| 382 | 418 | } |
-
diff --git tests/phpunit/tests/query.php tests/phpunit/tests/query.php
index 32f3603537..fb4a0a8ce8 100644
|
|
|
class Tests_Query extends WP_UnitTestCase { |
| 5 | 5 | function setUp() { |
| 6 | 6 | parent::setUp(); |
| 7 | 7 | |
| 8 | | $this->set_permalink_structure( '/%year%/%monthnum%/%day%/%postname%/' ); |
| 9 | 8 | create_initial_taxonomies(); |
| 10 | 9 | } |
| 11 | 10 | |
-
diff --git tests/phpunit/tests/query/conditionals.php tests/phpunit/tests/query/conditionals.php
index 081adf2962..818f9ca4a4 100644
|
|
|
class Tests_Query_Conditionals extends WP_UnitTestCase { |
| 22 | 22 | update_option( 'comments_per_page', 5 ); |
| 23 | 23 | update_option( 'posts_per_page', 5 ); |
| 24 | 24 | |
| 25 | | $this->set_permalink_structure( '/%year%/%monthnum%/%day%/%postname%/' ); |
| 26 | | |
| 27 | 25 | create_initial_taxonomies(); |
| 28 | 26 | } |
| 29 | 27 | |
| … |
… |
class Tests_Query_Conditionals extends WP_UnitTestCase { |
| 490 | 488 | // check the long form |
| 491 | 489 | $types = array( 'feed', 'rdf', 'rss', 'rss2', 'atom' ); |
| 492 | 490 | foreach ( $types as $type ) { |
| 493 | | $this->go_to( "/category/cat-a/feed/{$type}" ); |
| | 491 | $this->go_to( tests_add_blog_permalink_prefix_on_multisite( "category/cat-a/feed/{$type}" ) ); |
| 494 | 492 | $this->assertQueryTrue( 'is_archive', 'is_feed', 'is_category' ); |
| 495 | 493 | } |
| 496 | 494 | |
| 497 | 495 | // check the short form |
| 498 | 496 | $types = array( 'feed', 'rdf', 'rss', 'rss2', 'atom' ); |
| 499 | 497 | foreach ( $types as $type ) { |
| 500 | | $this->go_to( "/category/cat-a/{$type}" ); |
| | 498 | $this->go_to( tests_add_blog_permalink_prefix_on_multisite( "category/cat-a/{$type}" ) ); |
| 501 | 499 | $this->assertQueryTrue( 'is_archive', 'is_feed', 'is_category' ); |
| 502 | 500 | } |
| 503 | 501 | } |
| … |
… |
class Tests_Query_Conditionals extends WP_UnitTestCase { |
| 506 | 504 | function test_category_paged() { |
| 507 | 505 | update_option( 'posts_per_page', 2 ); |
| 508 | 506 | self::factory()->post->create_many( 3 ); |
| 509 | | $this->go_to( '/category/uncategorized/page/2/' ); |
| | 507 | $this->go_to( tests_add_blog_permalink_prefix_on_multisite( 'category/uncategorized/page/2/' ) ); |
| 510 | 508 | $this->assertQueryTrue( 'is_archive', 'is_category', 'is_paged' ); |
| 511 | 509 | } |
| 512 | 510 | |
| … |
… |
class Tests_Query_Conditionals extends WP_UnitTestCase { |
| 518 | 516 | 'taxonomy' => 'category', |
| 519 | 517 | ) |
| 520 | 518 | ); |
| 521 | | $this->go_to( '/category/cat-a/' ); |
| | 519 | $this->go_to( tests_add_blog_permalink_prefix_on_multisite( 'category/cat-a/' ) ); |
| 522 | 520 | $this->assertQueryTrue( 'is_archive', 'is_category' ); |
| 523 | 521 | } |
| 524 | 522 | |
| … |
… |
class Tests_Query_Conditionals extends WP_UnitTestCase { |
| 534 | 532 | // check the long form |
| 535 | 533 | $types = array( 'feed', 'rdf', 'rss', 'rss2', 'atom' ); |
| 536 | 534 | foreach ( $types as $type ) { |
| 537 | | $this->go_to( "/tag/tag-a/feed/{$type}" ); |
| | 535 | $this->go_to( tests_add_blog_permalink_prefix_on_multisite( "tag/tag-a/feed/{$type}" ) ); |
| 538 | 536 | $this->assertQueryTrue( 'is_archive', 'is_feed', 'is_tag' ); |
| 539 | 537 | } |
| 540 | 538 | |
| 541 | 539 | // check the short form |
| 542 | 540 | $types = array( 'feed', 'rdf', 'rss', 'rss2', 'atom' ); |
| 543 | 541 | foreach ( $types as $type ) { |
| 544 | | $this->go_to( "/tag/tag-a/{$type}" ); |
| | 542 | $this->go_to( tests_add_blog_permalink_prefix_on_multisite( "tag/tag-a/{$type}" ) ); |
| 545 | 543 | $this->assertQueryTrue( 'is_archive', 'is_feed', 'is_tag' ); |
| 546 | 544 | } |
| 547 | 545 | } |
| … |
… |
class Tests_Query_Conditionals extends WP_UnitTestCase { |
| 553 | 551 | foreach ( $post_ids as $post_id ) { |
| 554 | 552 | self::factory()->term->add_post_terms( $post_id, 'tag-a', 'post_tag' ); |
| 555 | 553 | } |
| 556 | | $this->go_to( '/tag/tag-a/page/2/' ); |
| | 554 | $this->go_to( tests_add_blog_permalink_prefix_on_multisite( 'tag/tag-a/page/2/' ) ); |
| 557 | 555 | $this->assertQueryTrue( 'is_archive', 'is_tag', 'is_paged' ); |
| 558 | 556 | } |
| 559 | 557 | |
| … |
… |
class Tests_Query_Conditionals extends WP_UnitTestCase { |
| 566 | 564 | 'taxonomy' => 'post_tag', |
| 567 | 565 | ) |
| 568 | 566 | ); |
| 569 | | $this->go_to( '/tag/tag-a/' ); |
| | 567 | $this->go_to( tests_add_blog_permalink_prefix_on_multisite( 'tag/tag-a/' ) ); |
| 570 | 568 | $this->assertQueryTrue( 'is_archive', 'is_tag' ); |
| 571 | 569 | |
| 572 | 570 | $tag = get_term( $term_id, 'post_tag' ); |
| … |
… |
class Tests_Query_Conditionals extends WP_UnitTestCase { |
| 588 | 586 | // check the long form |
| 589 | 587 | $types = array( 'feed', 'rdf', 'rss', 'rss2', 'atom' ); |
| 590 | 588 | foreach ( $types as $type ) { |
| 591 | | $this->go_to( "/author/user-a/feed/{$type}" ); |
| | 589 | $this->go_to( tests_add_blog_permalink_prefix_on_multisite( "author/user-a/feed/{$type}" ) ); |
| 592 | 590 | $this->assertQueryTrue( 'is_archive', 'is_feed', 'is_author' ); |
| 593 | 591 | } |
| 594 | 592 | |
| 595 | 593 | // check the short form |
| 596 | 594 | $types = array( 'feed', 'rdf', 'rss', 'rss2', 'atom' ); |
| 597 | 595 | foreach ( $types as $type ) { |
| 598 | | $this->go_to( "/author/user-a/{$type}" ); |
| | 596 | $this->go_to( tests_add_blog_permalink_prefix_on_multisite( "author/user-a/{$type}" ) ); |
| 599 | 597 | $this->assertQueryTrue( 'is_archive', 'is_feed', 'is_author' ); |
| 600 | 598 | } |
| 601 | 599 | } |
| … |
… |
class Tests_Query_Conditionals extends WP_UnitTestCase { |
| 605 | 603 | update_option( 'posts_per_page', 2 ); |
| 606 | 604 | $user_id = self::factory()->user->create( array( 'user_login' => 'user-a' ) ); |
| 607 | 605 | self::factory()->post->create_many( 3, array( 'post_author' => $user_id ) ); |
| 608 | | $this->go_to( '/author/user-a/page/2/' ); |
| | 606 | $this->go_to( tests_add_blog_permalink_prefix_on_multisite( 'author/user-a/page/2/' ) ); |
| 609 | 607 | $this->assertQueryTrue( 'is_archive', 'is_author', 'is_paged' ); |
| 610 | 608 | } |
| 611 | 609 | |
| … |
… |
class Tests_Query_Conditionals extends WP_UnitTestCase { |
| 613 | 611 | function test_author() { |
| 614 | 612 | $user_id = self::factory()->user->create( array( 'user_login' => 'user-a' ) ); |
| 615 | 613 | self::factory()->post->create( array( 'post_author' => $user_id ) ); |
| 616 | | $this->go_to( '/author/user-a/' ); |
| | 614 | $this->go_to( tests_add_blog_permalink_prefix_on_multisite( 'author/user-a/' ) ); |
| 617 | 615 | $this->assertQueryTrue( 'is_archive', 'is_author' ); |
| 618 | 616 | } |
| 619 | 617 | |
| 620 | 618 | function test_author_with_no_posts() { |
| 621 | 619 | $user_id = self::factory()->user->create( array( 'user_login' => 'user-a' ) ); |
| 622 | | $this->go_to( '/author/user-a/' ); |
| | 620 | $this->go_to( tests_add_blog_permalink_prefix_on_multisite( 'author/user-a/' ) ); |
| 623 | 621 | $this->assertQueryTrue( 'is_archive', 'is_author' ); |
| 624 | 622 | } |
| 625 | 623 | |
| … |
… |
class Tests_Query_Conditionals extends WP_UnitTestCase { |
| 630 | 628 | // check the long form |
| 631 | 629 | $types = array( 'feed', 'rdf', 'rss', 'rss2', 'atom' ); |
| 632 | 630 | foreach ( $types as $type ) { |
| 633 | | $this->go_to( "/2007/09/04/feed/{$type}" ); |
| | 631 | $this->go_to( tests_add_blog_permalink_prefix_on_multisite( "2007/09/04/feed/{$type}" ) ); |
| 634 | 632 | $this->assertQueryTrue( 'is_archive', 'is_feed', 'is_day', 'is_date' ); |
| 635 | 633 | } |
| 636 | 634 | |
| 637 | 635 | // check the short form |
| 638 | 636 | $types = array( 'feed', 'rdf', 'rss', 'rss2', 'atom' ); |
| 639 | 637 | foreach ( $types as $type ) { |
| 640 | | $this->go_to( "/2007/09/04/{$type}" ); |
| | 638 | $this->go_to( tests_add_blog_permalink_prefix_on_multisite( "2007/09/04/{$type}" ) ); |
| 641 | 639 | $this->assertQueryTrue( 'is_archive', 'is_feed', 'is_day', 'is_date' ); |
| 642 | 640 | } |
| 643 | 641 | } |
| … |
… |
class Tests_Query_Conditionals extends WP_UnitTestCase { |
| 646 | 644 | function test_ymd_paged() { |
| 647 | 645 | update_option( 'posts_per_page', 2 ); |
| 648 | 646 | self::factory()->post->create_many( 3, array( 'post_date' => '2007-09-04 00:00:00' ) ); |
| 649 | | $this->go_to( '/2007/09/04/page/2/' ); |
| | 647 | $this->go_to( tests_add_blog_permalink_prefix_on_multisite( '2007/09/04/page/2/' ) ); |
| 650 | 648 | $this->assertQueryTrue( 'is_archive', 'is_day', 'is_date', 'is_paged' ); |
| 651 | 649 | } |
| 652 | 650 | |
| 653 | 651 | // '([0-9]{4})/([0-9]{1,2})/([0-9]{1,2})/?$' => 'index.php?year=$matches[1]&monthnum=$matches[2]&day=$matches[3]', |
| 654 | 652 | function test_ymd() { |
| 655 | 653 | self::factory()->post->create( array( 'post_date' => '2007-09-04 00:00:00' ) ); |
| 656 | | $this->go_to( '/2007/09/04/' ); |
| | 654 | $this->go_to( tests_add_blog_permalink_prefix_on_multisite( '2007/09/04/' ) ); |
| 657 | 655 | $this->assertQueryTrue( 'is_archive', 'is_day', 'is_date' ); |
| 658 | 656 | } |
| 659 | 657 | |
| … |
… |
class Tests_Query_Conditionals extends WP_UnitTestCase { |
| 664 | 662 | // check the long form |
| 665 | 663 | $types = array( 'feed', 'rdf', 'rss', 'rss2', 'atom' ); |
| 666 | 664 | foreach ( $types as $type ) { |
| 667 | | $this->go_to( "/2007/09/feed/{$type}" ); |
| | 665 | $this->go_to( tests_add_blog_permalink_prefix_on_multisite( "2007/09/feed/{$type}" ) ); |
| 668 | 666 | $this->assertQueryTrue( 'is_archive', 'is_feed', 'is_month', 'is_date' ); |
| 669 | 667 | } |
| 670 | 668 | |
| 671 | 669 | // check the short form |
| 672 | 670 | $types = array( 'feed', 'rdf', 'rss', 'rss2', 'atom' ); |
| 673 | 671 | foreach ( $types as $type ) { |
| 674 | | $this->go_to( "/2007/09/{$type}" ); |
| | 672 | $this->go_to( tests_add_blog_permalink_prefix_on_multisite( "2007/09/{$type}" ) ); |
| 675 | 673 | $this->assertQueryTrue( 'is_archive', 'is_feed', 'is_month', 'is_date' ); |
| 676 | 674 | } |
| 677 | 675 | } |
| … |
… |
class Tests_Query_Conditionals extends WP_UnitTestCase { |
| 680 | 678 | function test_ym_paged() { |
| 681 | 679 | update_option( 'posts_per_page', 2 ); |
| 682 | 680 | self::factory()->post->create_many( 3, array( 'post_date' => '2007-09-04 00:00:00' ) ); |
| 683 | | $this->go_to( '/2007/09/page/2/' ); |
| | 681 | $this->go_to( tests_add_blog_permalink_prefix_on_multisite( '2007/09/page/2/' ) ); |
| 684 | 682 | $this->assertQueryTrue( 'is_archive', 'is_date', 'is_month', 'is_paged' ); |
| 685 | 683 | } |
| 686 | 684 | |
| 687 | 685 | // '([0-9]{4})/([0-9]{1,2})/?$' => 'index.php?year=$matches[1]&monthnum=$matches[2]', |
| 688 | 686 | function test_ym() { |
| 689 | 687 | self::factory()->post->create( array( 'post_date' => '2007-09-04 00:00:00' ) ); |
| 690 | | $this->go_to( '/2007/09/' ); |
| | 688 | $this->go_to( tests_add_blog_permalink_prefix_on_multisite( '2007/09/' ) ); |
| 691 | 689 | $this->assertQueryTrue( 'is_archive', 'is_date', 'is_month' ); |
| 692 | 690 | } |
| 693 | 691 | |
| … |
… |
class Tests_Query_Conditionals extends WP_UnitTestCase { |
| 698 | 696 | // check the long form |
| 699 | 697 | $types = array( 'feed', 'rdf', 'rss', 'rss2', 'atom' ); |
| 700 | 698 | foreach ( $types as $type ) { |
| 701 | | $this->go_to( "/2007/feed/{$type}" ); |
| | 699 | $this->go_to( tests_add_blog_permalink_prefix_on_multisite( "2007/feed/{$type}" ) ); |
| 702 | 700 | $this->assertQueryTrue( 'is_archive', 'is_feed', 'is_year', 'is_date' ); |
| 703 | 701 | } |
| 704 | 702 | |
| 705 | 703 | // check the short form |
| 706 | 704 | $types = array( 'feed', 'rdf', 'rss', 'rss2', 'atom' ); |
| 707 | 705 | foreach ( $types as $type ) { |
| 708 | | $this->go_to( "/2007/{$type}" ); |
| | 706 | $this->go_to( tests_add_blog_permalink_prefix_on_multisite( "2007/{$type}" ) ); |
| 709 | 707 | $this->assertQueryTrue( 'is_archive', 'is_feed', 'is_year', 'is_date' ); |
| 710 | 708 | } |
| 711 | 709 | } |
| … |
… |
class Tests_Query_Conditionals extends WP_UnitTestCase { |
| 714 | 712 | function test_y_paged() { |
| 715 | 713 | update_option( 'posts_per_page', 2 ); |
| 716 | 714 | self::factory()->post->create_many( 3, array( 'post_date' => '2007-09-04 00:00:00' ) ); |
| 717 | | $this->go_to( '/2007/page/2/' ); |
| | 715 | $this->go_to( tests_add_blog_permalink_prefix_on_multisite( '2007/page/2/' ) ); |
| 718 | 716 | $this->assertQueryTrue( 'is_archive', 'is_date', 'is_year', 'is_paged' ); |
| 719 | 717 | } |
| 720 | 718 | |
| 721 | 719 | // '([0-9]{4})/?$' => 'index.php?year=$matches[1]', |
| 722 | 720 | function test_y() { |
| 723 | 721 | self::factory()->post->create( array( 'post_date' => '2007-09-04 00:00:00' ) ); |
| 724 | | $this->go_to( '/2007/' ); |
| | 722 | $this->go_to( tests_add_blog_permalink_prefix_on_multisite( '2007/' ) ); |
| 725 | 723 | $this->assertQueryTrue( 'is_archive', 'is_date', 'is_year' ); |
| 726 | 724 | } |
| 727 | 725 | |
| … |
… |
class Tests_Query_Conditionals extends WP_UnitTestCase { |
| 788 | 786 | * @expectedIncorrectUsage WP_Date_Query |
| 789 | 787 | */ |
| 790 | 788 | function test_bad_dates() { |
| 791 | | $this->go_to( '/2013/13/13/' ); |
| | 789 | $this->go_to( tests_add_blog_permalink_prefix_on_multisite( '2013/13/13/' ) ); |
| 792 | 790 | $this->assertQueryTrue( 'is_404' ); |
| 793 | 791 | |
| 794 | | $this->go_to( '/2013/11/41/' ); |
| | 792 | $this->go_to( tests_add_blog_permalink_prefix_on_multisite( '2013/11/41/' ) ); |
| 795 | 793 | $this->assertQueryTrue( 'is_404' ); |
| 796 | 794 | } |
| 797 | 795 | |
| … |
… |
class Tests_Query_Conditionals extends WP_UnitTestCase { |
| 812 | 810 | $post_id = self::factory()->post->create( array( 'post_type' => $cpt_name ) ); |
| 813 | 811 | wp_set_object_terms( $post_id, $tag_id, 'post_tag' ); |
| 814 | 812 | |
| 815 | | $this->go_to( '/ptawtq/' ); |
| | 813 | $this->go_to( tests_add_blog_permalink_prefix_on_multisite( 'ptawtq/' ) ); |
| 816 | 814 | $this->assertQueryTrue( 'is_post_type_archive', 'is_archive' ); |
| 817 | 815 | $this->assertEquals( get_queried_object(), get_post_type_object( $cpt_name ) ); |
| 818 | 816 | |
| 819 | 817 | add_action( 'pre_get_posts', array( $this, 'pre_get_posts_with_tax_query' ) ); |
| 820 | 818 | |
| 821 | | $this->go_to( '/ptawtq/' ); |
| | 819 | $this->go_to( tests_add_blog_permalink_prefix_on_multisite( 'ptawtq/' ) ); |
| 822 | 820 | $this->assertQueryTrue( 'is_post_type_archive', 'is_archive' ); |
| 823 | 821 | $this->assertEquals( get_queried_object(), get_post_type_object( $cpt_name ) ); |
| 824 | 822 | |
| … |
… |
class Tests_Query_Conditionals extends WP_UnitTestCase { |
| 852 | 850 | ); |
| 853 | 851 | self::factory()->post->create( array( 'post_type' => $cpt_name ) ); |
| 854 | 852 | |
| 855 | | $this->go_to( "/$cpt_name/" ); |
| | 853 | $this->go_to( tests_add_blog_permalink_prefix_on_multisite( "$cpt_name/" ) ); |
| 856 | 854 | $this->assertQueryTrue( 'is_post_type_archive', 'is_archive' ); |
| 857 | 855 | $this->assertEquals( get_queried_object(), get_post_type_object( $cpt_name ) ); |
| 858 | 856 | |
| 859 | 857 | add_action( 'pre_get_posts', array( $this, 'pre_get_posts_with_type_array' ) ); |
| 860 | 858 | |
| 861 | | $this->go_to( "/$cpt_name/" ); |
| | 859 | $this->go_to( tests_add_blog_permalink_prefix_on_multisite( "$cpt_name/" ) ); |
| 862 | 860 | $this->assertQueryTrue( 'is_post_type_archive', 'is_archive' ); |
| 863 | 861 | $this->assertEquals( get_queried_object(), get_post_type_object( 'post' ) ); |
| 864 | 862 | |
| … |
… |
class Tests_Query_Conditionals extends WP_UnitTestCase { |
| 966 | 964 | * @ticket 24612 |
| 967 | 965 | */ |
| 968 | 966 | public function test_is_single_with_slug_that_clashes_with_attachment() { |
| | 967 | |
| 969 | 968 | $this->set_permalink_structure( '/%postname%/' ); |
| 970 | 969 | |
| 971 | 970 | $attachment_id = $this->factory->post->create( |
| … |
… |
class Tests_Query_Conditionals extends WP_UnitTestCase { |
| 989 | 988 | $this->assertFalse( $q->is_attachment() ); |
| 990 | 989 | $this->assertFalse( $q->is_404() ); |
| 991 | 990 | |
| 992 | | $this->set_permalink_structure(); |
| | 991 | tests_reset_and_flush_permalinks(); |
| 993 | 992 | } |
| 994 | 993 | |
| 995 | 994 | /** |
-
diff --git tests/phpunit/tests/query/isTerm.php tests/phpunit/tests/query/isTerm.php
index 546217bb3c..3f49de019d 100644
|
|
|
class Tests_Query_IsTerm extends WP_UnitTestCase { |
| 30 | 30 | $GLOBALS['wp_the_query'] = new WP_Query(); |
| 31 | 31 | $GLOBALS['wp_query'] = $GLOBALS['wp_the_query']; |
| 32 | 32 | |
| 33 | | $this->set_permalink_structure( '/%year%/%monthnum%/%day%/%postname%/' ); |
| 34 | | |
| 35 | 33 | create_initial_taxonomies(); |
| 36 | 34 | register_taxonomy( 'testtax', 'post', array( 'public' => true ) ); |
| 37 | 35 | |
| … |
… |
class Tests_Query_IsTerm extends WP_UnitTestCase { |
| 78 | 76 | |
| 79 | 77 | function test_tag_action_tax() { |
| 80 | 78 | // tag with tax added |
| 81 | | $this->go_to( home_url( '/tag/tag-slug/' ) ); |
| | 79 | $this->go_to( home_url( tests_add_blog_permalink_prefix_on_multisite( '/tag/tag-slug/' ) ) ); |
| 82 | 80 | $this->assertQueryTrue( 'is_tag', 'is_archive' ); |
| 83 | 81 | $this->assertNotEmpty( get_query_var( 'tax_query' ) ); |
| 84 | 82 | $this->assertNotEmpty( get_query_var( 'taxonomy' ) ); |
| … |
… |
class Tests_Query_IsTerm extends WP_UnitTestCase { |
| 89 | 87 | |
| 90 | 88 | function test_tag_query_cat_action_tax() { |
| 91 | 89 | // tag + category with tax added |
| 92 | | $this->go_to( home_url( "/tag/tag-slug/?cat=$this->cat_id" ) ); |
| | 90 | $this->go_to( home_url( tests_add_blog_permalink_prefix_on_multisite( "/tag/tag-slug/?cat=$this->cat_id" ) ) ); |
| 93 | 91 | $this->assertQueryTrue( 'is_category', 'is_tag', 'is_archive' ); |
| 94 | 92 | $this->assertNotEmpty( get_query_var( 'tax_query' ) ); |
| 95 | 93 | $this->assertNotEmpty( get_query_var( 'taxonomy' ) ); |
| … |
… |
class Tests_Query_IsTerm extends WP_UnitTestCase { |
| 101 | 99 | |
| 102 | 100 | function test_tag_query_cat_query_tax_action_tax() { |
| 103 | 101 | // tag + category + tax with tax added |
| 104 | | $this->go_to( home_url( "/tag/tag-slug/?cat=$this->cat_id&testtax=tax-slug2" ) ); |
| | 102 | $this->go_to( home_url( tests_add_blog_permalink_prefix_on_multisite( "/tag/tag-slug/?cat=$this->cat_id&testtax=tax-slug2" ) ) ); |
| 105 | 103 | $this->assertQueryTrue( 'is_category', 'is_tag', 'is_tax', 'is_archive' ); |
| 106 | 104 | $this->assertNotEmpty( get_query_var( 'tax_query' ) ); |
| 107 | 105 | $this->assertNotEmpty( get_query_var( 'taxonomy' ) ); |
| … |
… |
class Tests_Query_IsTerm extends WP_UnitTestCase { |
| 114 | 112 | |
| 115 | 113 | function test_cat_action_tax() { |
| 116 | 114 | // category with tax added |
| 117 | | $this->go_to( home_url( '/category/cat-slug/' ) ); |
| | 115 | $this->go_to( home_url( tests_add_blog_permalink_prefix_on_multisite( '/category/cat-slug/' ) ) ); |
| 118 | 116 | $this->assertQueryTrue( 'is_category', 'is_archive' ); |
| 119 | 117 | $this->assertNotEmpty( get_query_var( 'cat' ) ); |
| 120 | 118 | $this->assertNotEmpty( get_query_var( 'tax_query' ) ); |
| … |
… |
class Tests_Query_IsTerm extends WP_UnitTestCase { |
| 130 | 128 | // category with tax added |
| 131 | 129 | add_action( 'pre_get_posts', array( $this, '_cat_uncat_action_tax' ), 11 ); |
| 132 | 130 | |
| 133 | | $this->go_to( home_url( '/category/uncategorized/' ) ); |
| | 131 | $this->go_to( home_url( tests_add_blog_permalink_prefix_on_multisite( '/category/uncategorized/' ) ) ); |
| 134 | 132 | $this->assertQueryTrue( 'is_category', 'is_archive' ); |
| 135 | 133 | $this->assertNotEmpty( get_query_var( 'cat' ) ); |
| 136 | 134 | $this->assertNotEmpty( get_query_var( 'tax_query' ) ); |
| … |
… |
class Tests_Query_IsTerm extends WP_UnitTestCase { |
| 154 | 152 | */ |
| 155 | 153 | function test_tax_action_tax() { |
| 156 | 154 | // tax with tax added |
| 157 | | $this->go_to( home_url( '/testtax/tax-slug2/' ) ); |
| | 155 | $this->go_to( home_url( tests_add_blog_permalink_prefix_on_multisite( '/testtax/tax-slug2/' ) ) ); |
| 158 | 156 | $this->assertQueryTrue( 'is_tax', 'is_archive' ); |
| 159 | 157 | $this->assertNotEmpty( get_query_var( 'tax_query' ) ); |
| 160 | 158 | $this->assertNotEmpty( get_query_var( 'taxonomy' ) ); |
| … |
… |
class Tests_Query_IsTerm extends WP_UnitTestCase { |
| 164 | 162 | |
| 165 | 163 | function test_tax_query_tag_action_tax() { |
| 166 | 164 | // tax + tag with tax added |
| 167 | | $this->go_to( home_url( "/testtax/tax-slug2/?tag_id=$this->tag_id" ) ); |
| | 165 | $this->go_to( home_url( tests_add_blog_permalink_prefix_on_multisite( "/testtax/tax-slug2/?tag_id=$this->tag_id" ) ) ); |
| 168 | 166 | $this->assertQueryTrue( 'is_tag', 'is_tax', 'is_archive' ); |
| 169 | 167 | $this->assertNotEmpty( get_query_var( 'tax_query' ) ); |
| 170 | 168 | $this->assertNotEmpty( get_query_var( 'taxonomy' ) ); |
| … |
… |
class Tests_Query_IsTerm extends WP_UnitTestCase { |
| 175 | 173 | |
| 176 | 174 | function test_tax_query_cat_action_tax() { |
| 177 | 175 | // tax + cat with tax added |
| 178 | | $this->go_to( home_url( "/testtax/tax-slug2/?cat=$this->cat_id" ) ); |
| | 176 | $this->go_to( home_url( tests_add_blog_permalink_prefix_on_multisite( "/testtax/tax-slug2/?cat=$this->cat_id" ) ) ); |
| 179 | 177 | $this->assertQueryTrue( 'is_category', 'is_tax', 'is_archive' ); |
| 180 | 178 | $this->assertNotEmpty( get_query_var( 'tax_query' ) ); |
| 181 | 179 | $this->assertNotEmpty( get_query_var( 'taxonomy' ) ); |
-
diff --git tests/phpunit/tests/query/verboseRewriteRules.php tests/phpunit/tests/query/verboseRewriteRules.php
index 5414a51a9a..7f864e2d7a 100644
|
|
|
class Tests_Query_VerbosePageRules extends Tests_Query_Conditionals { |
| 13 | 13 | $this->set_permalink_structure( '/%category%/%year%/%postname%/' ); |
| 14 | 14 | create_initial_taxonomies(); |
| 15 | 15 | } |
| | 16 | |
| | 17 | public function tearDown() { |
| | 18 | parent::tearDown(); |
| | 19 | |
| | 20 | tests_reset_and_flush_permalinks(); |
| | 21 | } |
| 16 | 22 | } |
-
diff --git tests/phpunit/tests/rest-api.php tests/phpunit/tests/rest-api.php
index a1c6a6b1eb..809cc8f13b 100644
|
|
|
class Tests_REST_API extends WP_UnitTestCase { |
| 486 | 486 | * whether the blog is configured with pretty permalink support or not. |
| 487 | 487 | */ |
| 488 | 488 | public function test_rest_url_generation() { |
| | 489 | |
| | 490 | |
| 489 | 491 | // In pretty permalinks case, we expect a path of wp-json/ with no query. |
| 490 | | $this->set_permalink_structure( '/%year%/%monthnum%/%day%/%postname%/' ); |
| 491 | 492 | $this->assertEquals( 'http://' . WP_TESTS_DOMAIN . '/wp-json/', get_rest_url() ); |
| 492 | 493 | |
| 493 | 494 | // In index permalinks case, we expect a path of index.php/wp-json/ with no query. |
| … |
… |
class Tests_REST_API extends WP_UnitTestCase { |
| 497 | 498 | // In non-pretty case, we get a query string to invoke the rest router. |
| 498 | 499 | $this->set_permalink_structure( '' ); |
| 499 | 500 | $this->assertEquals( 'http://' . WP_TESTS_DOMAIN . '/index.php?rest_route=/', get_rest_url() ); |
| | 501 | |
| | 502 | tests_reset_and_flush_permalinks(); |
| 500 | 503 | } |
| 501 | 504 | |
| 502 | 505 | /** |
-
diff --git tests/phpunit/tests/rest-api/rest-posts-controller.php tests/phpunit/tests/rest-api/rest-posts-controller.php
index e2c7bf7c89..9487a379cd 100644
|
|
|
class WP_Test_REST_Posts_Controller extends WP_Test_REST_Post_Type_Controller_Te |
| 2885 | 2885 | } |
| 2886 | 2886 | |
| 2887 | 2887 | public function test_update_post_with_categories() { |
| | 2888 | tests_set_and_flush_permalinks( '' ); |
| 2888 | 2889 | |
| 2889 | 2890 | wp_set_current_user( self::$editor_id ); |
| 2890 | 2891 | $category = wp_insert_term( 'Test Category', 'category' ); |
| … |
… |
class WP_Test_REST_Posts_Controller extends WP_Test_REST_Post_Type_Controller_Te |
| 2911 | 2912 | } |
| 2912 | 2913 | $query = parse_url( $categories_path, PHP_URL_QUERY ); |
| 2913 | 2914 | parse_str( $query, $args ); |
| | 2915 | |
| 2914 | 2916 | $request = new WP_REST_Request( 'GET', $args['rest_route'] ); |
| 2915 | 2917 | unset( $args['rest_route'] ); |
| 2916 | 2918 | $request->set_query_params( $args ); |
| … |
… |
class WP_Test_REST_Posts_Controller extends WP_Test_REST_Post_Type_Controller_Te |
| 2918 | 2920 | $data = $response->get_data(); |
| 2919 | 2921 | $this->assertCount( 1, $data ); |
| 2920 | 2922 | $this->assertEquals( 'Test Category', $data[0]['name'] ); |
| | 2923 | |
| | 2924 | tests_reset_and_flush_permalinks(); |
| 2921 | 2925 | } |
| 2922 | 2926 | |
| 2923 | 2927 | public function test_update_post_with_empty_categories() { |
-
diff --git tests/phpunit/tests/rewrite.php tests/phpunit/tests/rewrite.php
index abb793eb34..825fd56f06 100644
|
|
|
class Tests_Rewrite extends WP_UnitTestCase { |
| 11 | 11 | function setUp() { |
| 12 | 12 | parent::setUp(); |
| 13 | 13 | |
| 14 | | $this->set_permalink_structure( '/%year%/%monthnum%/%day%/%postname%/' ); |
| 15 | 14 | create_initial_taxonomies(); |
| 16 | 15 | |
| 17 | 16 | $this->home_url = get_option( 'home' ); |
| 18 | 17 | } |
| 19 | 18 | |
| 20 | 19 | function tearDown() { |
| 21 | | global $wp_rewrite; |
| 22 | | $wp_rewrite->init(); |
| 23 | | |
| 24 | 20 | update_option( 'home', $this->home_url ); |
| 25 | 21 | parent::tearDown(); |
| | 22 | |
| | 23 | tests_reset_and_flush_permalinks(); |
| 26 | 24 | } |
| 27 | 25 | |
| 28 | 26 | /** |
| … |
… |
class Tests_Rewrite extends WP_UnitTestCase { |
| 85 | 83 | } |
| 86 | 84 | |
| 87 | 85 | function test_url_to_postid() { |
| | 86 | tests_set_and_flush_permalinks( '' ); |
| 88 | 87 | |
| 89 | 88 | $id = self::factory()->post->create(); |
| 90 | 89 | $this->assertEquals( $id, url_to_postid( get_permalink( $id ) ) ); |
| 91 | 90 | |
| 92 | 91 | $id = self::factory()->post->create( array( 'post_type' => 'page' ) ); |
| 93 | 92 | $this->assertEquals( $id, url_to_postid( get_permalink( $id ) ) ); |
| | 93 | |
| | 94 | tests_reset_and_flush_permalinks(); |
| 94 | 95 | } |
| 95 | 96 | |
| 96 | 97 | function test_url_to_postid_set_url_scheme_https_to_http() { |
| … |
… |
class Tests_Rewrite extends WP_UnitTestCase { |
| 101 | 102 | $post_id = self::factory()->post->create( array( 'post_type' => 'page' ) ); |
| 102 | 103 | $permalink = get_permalink( $post_id ); |
| 103 | 104 | $this->assertEquals( $post_id, url_to_postid( set_url_scheme( $permalink, 'https' ) ) ); |
| | 105 | |
| | 106 | |
| 104 | 107 | } |
| 105 | 108 | |
| 106 | 109 | function test_url_to_postid_set_url_scheme_http_to_https() { |
| | 110 | |
| 107 | 111 | $_SERVER['HTTPS'] = 'on'; |
| 108 | 112 | |
| 109 | 113 | $post_id = self::factory()->post->create(); |
| … |
… |
class Tests_Rewrite extends WP_UnitTestCase { |
| 116 | 120 | |
| 117 | 121 | $this->assertEquals( $post_id, $post_url_to_id ); |
| 118 | 122 | $this->assertEquals( $page_id, $page_url_to_id ); |
| | 123 | |
| | 124 | |
| 119 | 125 | } |
| 120 | 126 | |
| 121 | 127 | /** |
| … |
… |
class Tests_Rewrite extends WP_UnitTestCase { |
| 398 | 404 | * @ticket 21970 |
| 399 | 405 | */ |
| 400 | 406 | function test_url_to_postid_with_post_slug_that_clashes_with_a_trashed_page() { |
| | 407 | |
| 401 | 408 | $this->set_permalink_structure( '/%postname%/' ); |
| 402 | 409 | |
| 403 | 410 | $page_id = self::factory()->post->create( |
| … |
… |
class Tests_Rewrite extends WP_UnitTestCase { |
| 409 | 416 | $post_id = self::factory()->post->create( array( 'post_title' => get_post( $page_id )->post_title ) ); |
| 410 | 417 | |
| 411 | 418 | $this->assertEquals( $post_id, url_to_postid( get_permalink( $post_id ) ) ); |
| | 419 | |
| | 420 | tests_reset_and_flush_permalinks(); |
| 412 | 421 | } |
| 413 | 422 | |
| 414 | 423 | /** |
| … |
… |
class Tests_Rewrite extends WP_UnitTestCase { |
| 435 | 444 | * @ticket 39373 |
| 436 | 445 | */ |
| 437 | 446 | public function test_url_to_postid_should_bail_when_host_does_not_match() { |
| | 447 | |
| 438 | 448 | $this->set_permalink_structure( '/%postname%/' ); |
| 439 | 449 | |
| 440 | 450 | $post_id = self::factory()->post->create( array( 'post_name' => 'foo-bar-baz' ) ); |
| … |
… |
class Tests_Rewrite extends WP_UnitTestCase { |
| 443 | 453 | |
| 444 | 454 | $this->assertSame( $post_id, url_to_postid( $permalink ) ); |
| 445 | 455 | $this->assertSame( 0, url_to_postid( $url ) ); |
| | 456 | |
| | 457 | tests_reset_and_flush_permalinks(); |
| 446 | 458 | } |
| 447 | 459 | |
| 448 | 460 | /** |
| 449 | 461 | * @ticket 21970 |
| 450 | 462 | */ |
| 451 | 463 | function test_parse_request_with_post_slug_that_clashes_with_a_trashed_page() { |
| | 464 | |
| 452 | 465 | $this->set_permalink_structure( '/%postname%/' ); |
| 453 | 466 | |
| 454 | 467 | $page_id = self::factory()->post->create( |
| … |
… |
class Tests_Rewrite extends WP_UnitTestCase { |
| 463 | 476 | |
| 464 | 477 | $this->assertTrue( is_single() ); |
| 465 | 478 | $this->assertFalse( is_404() ); |
| | 479 | |
| | 480 | tests_reset_and_flush_permalinks(); |
| 466 | 481 | } |
| 467 | 482 | |
| 468 | 483 | /** |
| 469 | 484 | * @ticket 29107 |
| 470 | 485 | */ |
| 471 | 486 | public function test_flush_rules_does_not_delete_option() { |
| | 487 | |
| 472 | 488 | $this->set_permalink_structure( '' ); |
| 473 | 489 | |
| 474 | 490 | $rewrite_rules = get_option( 'rewrite_rules' ); |
| 475 | 491 | $this->assertSame( '', $rewrite_rules ); |
| 476 | 492 | |
| 477 | | $this->set_permalink_structure( '/%year%/%monthnum%/%day%/%postname%/' ); |
| | 493 | tests_reset_and_flush_permalinks(); |
| 478 | 494 | |
| 479 | 495 | $rewrite_rules = get_option( 'rewrite_rules' ); |
| 480 | 496 | $this->assertInternalType( 'array', $rewrite_rules ); |
-
diff --git tests/phpunit/tests/rewrite/addRewriteRule.php tests/phpunit/tests/rewrite/addRewriteRule.php
index bcac78f6ae..6bd0e79467 100644
|
|
|
|
| 4 | 4 | * @group rewrite |
| 5 | 5 | */ |
| 6 | 6 | class Tests_Rewrite_AddRewriteRule extends WP_UnitTestCase { |
| 7 | | |
| 8 | | public function setUp() { |
| 9 | | parent::setUp(); |
| 10 | | |
| 11 | | $this->set_permalink_structure( '/%postname%/' ); |
| 12 | | } |
| 13 | | |
| 14 | 7 | /** |
| 15 | 8 | * @ticket 16840 |
| 16 | 9 | */ |
-
diff --git tests/phpunit/tests/rewrite/numericSlugs.php tests/phpunit/tests/rewrite/numericSlugs.php
index 83e1443985..4f283638b1 100644
|
|
|
class Tests_Rewrite_NumericSlugs extends WP_UnitTestCase { |
| 48 | 48 | $this->go_to( get_permalink( '2015' ) ); |
| 49 | 49 | |
| 50 | 50 | $this->assertQueryTrue( 'is_single', 'is_singular' ); |
| | 51 | |
| | 52 | tests_reset_and_flush_permalinks(); |
| 51 | 53 | } |
| 52 | 54 | |
| 53 | 55 | public function test_url_to_postid_year_segment_collision_without_title() { |
| … |
… |
class Tests_Rewrite_NumericSlugs extends WP_UnitTestCase { |
| 76 | 78 | ); |
| 77 | 79 | |
| 78 | 80 | $this->assertEquals( '2015', url_to_postid( get_permalink( '2015' ) ) ); |
| | 81 | |
| | 82 | tests_reset_and_flush_permalinks(); |
| 79 | 83 | } |
| 80 | 84 | |
| 81 | 85 | public function test_go_to_year_segment_collision_with_title() { |
| … |
… |
class Tests_Rewrite_NumericSlugs extends WP_UnitTestCase { |
| 94 | 98 | $this->go_to( get_permalink( $id ) ); |
| 95 | 99 | |
| 96 | 100 | $this->assertQueryTrue( 'is_single', 'is_singular' ); |
| | 101 | |
| | 102 | tests_reset_and_flush_permalinks(); |
| 97 | 103 | } |
| 98 | 104 | |
| 99 | 105 | public function test_url_to_postid_year_segment_collision_with_title() { |
| … |
… |
class Tests_Rewrite_NumericSlugs extends WP_UnitTestCase { |
| 129 | 135 | $this->go_to( get_permalink( $id ) ); |
| 130 | 136 | |
| 131 | 137 | $this->assertQueryTrue( 'is_single', 'is_singular' ); |
| | 138 | |
| | 139 | tests_reset_and_flush_permalinks(); |
| 132 | 140 | } |
| 133 | 141 | |
| 134 | 142 | public function test_url_to_postid_month_segment_collision_without_title() { |
| … |
… |
class Tests_Rewrite_NumericSlugs extends WP_UnitTestCase { |
| 146 | 154 | ); |
| 147 | 155 | |
| 148 | 156 | $this->assertEquals( $id, url_to_postid( get_permalink( $id ) ) ); |
| | 157 | |
| | 158 | tests_reset_and_flush_permalinks(); |
| 149 | 159 | } |
| 150 | 160 | |
| 151 | 161 | public function test_go_to_month_segment_collision_without_title_no_leading_zero() { |
| … |
… |
class Tests_Rewrite_NumericSlugs extends WP_UnitTestCase { |
| 165 | 175 | $this->go_to( get_permalink( $id ) ); |
| 166 | 176 | |
| 167 | 177 | $this->assertQueryTrue( 'is_single', 'is_singular' ); |
| | 178 | |
| | 179 | tests_reset_and_flush_permalinks(); |
| 168 | 180 | } |
| 169 | 181 | |
| 170 | 182 | public function test_url_to_postid_month_segment_collision_without_title_no_leading_zero() { |
| … |
… |
class Tests_Rewrite_NumericSlugs extends WP_UnitTestCase { |
| 182 | 194 | ); |
| 183 | 195 | |
| 184 | 196 | $this->assertEquals( $id, url_to_postid( get_permalink( $id ) ) ); |
| | 197 | |
| | 198 | tests_reset_and_flush_permalinks(); |
| 185 | 199 | } |
| 186 | 200 | |
| 187 | 201 | public function test_go_to_month_segment_collision_with_title() { |
| … |
… |
class Tests_Rewrite_NumericSlugs extends WP_UnitTestCase { |
| 200 | 214 | $this->go_to( get_permalink( $id ) ); |
| 201 | 215 | |
| 202 | 216 | $this->assertQueryTrue( 'is_single', 'is_singular' ); |
| | 217 | |
| | 218 | tests_reset_and_flush_permalinks(); |
| 203 | 219 | } |
| 204 | 220 | |
| 205 | 221 | public function test_url_to_postid_month_segment_collision_with_title() { |
| … |
… |
class Tests_Rewrite_NumericSlugs extends WP_UnitTestCase { |
| 216 | 232 | ); |
| 217 | 233 | |
| 218 | 234 | $this->assertEquals( $id, url_to_postid( get_permalink( $id ) ) ); |
| | 235 | |
| | 236 | tests_reset_and_flush_permalinks(); |
| 219 | 237 | } |
| 220 | 238 | |
| 221 | 239 | public function test_go_to_month_segment_collision_with_title_no_leading_zero() { |
| … |
… |
class Tests_Rewrite_NumericSlugs extends WP_UnitTestCase { |
| 234 | 252 | $this->go_to( get_permalink( $id ) ); |
| 235 | 253 | |
| 236 | 254 | $this->assertQueryTrue( 'is_single', 'is_singular' ); |
| | 255 | |
| | 256 | tests_reset_and_flush_permalinks(); |
| 237 | 257 | } |
| 238 | 258 | |
| 239 | 259 | public function test_url_to_postid_month_segment_collision_with_title_no_leading_zero() { |
| … |
… |
class Tests_Rewrite_NumericSlugs extends WP_UnitTestCase { |
| 250 | 270 | ); |
| 251 | 271 | |
| 252 | 272 | $this->assertEquals( $id, url_to_postid( get_permalink( $id ) ) ); |
| | 273 | |
| | 274 | tests_reset_and_flush_permalinks(); |
| 253 | 275 | } |
| 254 | 276 | |
| 255 | 277 | public function test_go_to_day_segment_collision_without_title() { |
| … |
… |
class Tests_Rewrite_NumericSlugs extends WP_UnitTestCase { |
| 269 | 291 | $this->go_to( get_permalink( $id ) ); |
| 270 | 292 | |
| 271 | 293 | $this->assertQueryTrue( 'is_single', 'is_singular' ); |
| | 294 | |
| | 295 | tests_reset_and_flush_permalinks(); |
| 272 | 296 | } |
| 273 | 297 | |
| 274 | 298 | public function test_url_to_postid_day_segment_collision_without_title() { |
| … |
… |
class Tests_Rewrite_NumericSlugs extends WP_UnitTestCase { |
| 286 | 310 | ); |
| 287 | 311 | |
| 288 | 312 | $this->assertEquals( $id, url_to_postid( get_permalink( $id ) ) ); |
| | 313 | |
| | 314 | tests_reset_and_flush_permalinks(); |
| 289 | 315 | } |
| 290 | 316 | |
| 291 | 317 | public function test_go_to_day_segment_collision_with_title() { |
| … |
… |
class Tests_Rewrite_NumericSlugs extends WP_UnitTestCase { |
| 304 | 330 | $this->go_to( get_permalink( $id ) ); |
| 305 | 331 | |
| 306 | 332 | $this->assertQueryTrue( 'is_single', 'is_singular' ); |
| | 333 | |
| | 334 | tests_reset_and_flush_permalinks(); |
| 307 | 335 | } |
| 308 | 336 | |
| 309 | 337 | public function test_url_to_postid_day_segment_collision_with_title() { |
| … |
… |
class Tests_Rewrite_NumericSlugs extends WP_UnitTestCase { |
| 320 | 348 | ); |
| 321 | 349 | |
| 322 | 350 | $this->assertEquals( $id, url_to_postid( get_permalink( $id ) ) ); |
| | 351 | |
| | 352 | tests_reset_and_flush_permalinks(); |
| 323 | 353 | } |
| 324 | 354 | |
| 325 | 355 | public function test_numeric_slug_permalink_conflicts_should_only_be_resolved_for_the_main_query() { |
| … |
… |
class Tests_Rewrite_NumericSlugs extends WP_UnitTestCase { |
| 345 | 375 | |
| 346 | 376 | $this->assertTrue( $q->is_day ); |
| 347 | 377 | $this->assertFalse( $q->is_single ); |
| | 378 | |
| | 379 | tests_reset_and_flush_permalinks(); |
| 348 | 380 | } |
| 349 | 381 | |
| 350 | 382 | public function test_month_slug_collision_should_resolve_to_date_archive_when_year_does_not_match_post_year() { |
| … |
… |
class Tests_Rewrite_NumericSlugs extends WP_UnitTestCase { |
| 377 | 409 | $this->go_to( $permalink ); |
| 378 | 410 | |
| 379 | 411 | $this->assertTrue( is_month() ); |
| | 412 | |
| | 413 | tests_reset_and_flush_permalinks(); |
| 380 | 414 | } |
| 381 | 415 | |
| 382 | 416 | public function test_day_slug_collision_should_resolve_to_date_archive_when_monthnum_does_not_match_post_month() { |
| … |
… |
class Tests_Rewrite_NumericSlugs extends WP_UnitTestCase { |
| 409 | 443 | $this->go_to( $permalink ); |
| 410 | 444 | |
| 411 | 445 | $this->assertTrue( is_day() ); |
| | 446 | |
| | 447 | tests_reset_and_flush_permalinks(); |
| 412 | 448 | } |
| 413 | 449 | |
| 414 | 450 | public function test_date_slug_collision_should_distinguish_valid_pagination_from_date() { |
| … |
… |
class Tests_Rewrite_NumericSlugs extends WP_UnitTestCase { |
| 427 | 463 | $this->go_to( get_permalink( $id ) . '1' ); |
| 428 | 464 | |
| 429 | 465 | $this->assertFalse( is_day() ); |
| | 466 | |
| | 467 | tests_reset_and_flush_permalinks(); |
| 430 | 468 | } |
| 431 | 469 | |
| 432 | 470 | public function test_date_slug_collision_should_distinguish_too_high_pagination_from_date() { |
| … |
… |
class Tests_Rewrite_NumericSlugs extends WP_UnitTestCase { |
| 445 | 483 | $this->go_to( get_permalink( $id ) . '5' ); |
| 446 | 484 | |
| 447 | 485 | $this->assertTrue( is_day() ); |
| | 486 | |
| | 487 | tests_reset_and_flush_permalinks(); |
| 448 | 488 | } |
| 449 | 489 | |
| 450 | 490 | public function test_date_slug_collision_should_not_require_pagination_query_var() { |
| … |
… |
class Tests_Rewrite_NumericSlugs extends WP_UnitTestCase { |
| 464 | 504 | |
| 465 | 505 | $this->assertQueryTrue( 'is_single', 'is_singular' ); |
| 466 | 506 | $this->assertFalse( is_date() ); |
| | 507 | |
| | 508 | tests_reset_and_flush_permalinks(); |
| 467 | 509 | } |
| 468 | 510 | |
| 469 | 511 | public function test_date_slug_collision_should_be_ignored_when_pagination_var_is_present_but_post_does_not_have_multiple_pages() { |
| … |
… |
class Tests_Rewrite_NumericSlugs extends WP_UnitTestCase { |
| 482 | 524 | $this->go_to( get_permalink( $id ) . '5' ); |
| 483 | 525 | |
| 484 | 526 | $this->assertTrue( is_day() ); |
| | 527 | |
| | 528 | tests_reset_and_flush_permalinks(); |
| 485 | 529 | } |
| 486 | 530 | |
| 487 | 531 | public function filter_unique_post_slug( $slug, $post_id, $post_status, $post_type, $post_parent, $original_slug ) { |
-
diff --git tests/phpunit/tests/rewrite/oldSlugRedirect.php tests/phpunit/tests/rewrite/oldSlugRedirect.php
index c8427e1dd1..d72e49c09f 100644
|
|
|
class Tests_Rewrite_OldSlugRedirect extends WP_UnitTestCase { |
| 21 | 21 | |
| 22 | 22 | add_filter( 'old_slug_redirect_url', array( $this, 'filter_old_slug_redirect_url' ), 10, 1 ); |
| 23 | 23 | |
| 24 | | $this->set_permalink_structure( '/%postname%/' ); |
| 25 | | |
| 26 | 24 | add_rewrite_endpoint( 'custom-endpoint', EP_PERMALINK ); |
| 27 | 25 | add_rewrite_endpoint( 'second-endpoint', EP_PERMALINK, 'custom' ); |
| 28 | 26 | |
-
diff --git tests/phpunit/tests/rewrite/permastructs.php tests/phpunit/tests/rewrite/permastructs.php
index 788e009c2d..4a0282dbb8 100644
|
|
|
class Tests_Rewrite_Permastructs extends WP_UnitTestCase { |
| 7 | 7 | |
| 8 | 8 | public function setUp() { |
| 9 | 9 | parent::setUp(); |
| 10 | | |
| 11 | | $this->set_permalink_structure( '/%postname%/' ); |
| 12 | 10 | } |
| 13 | 11 | |
| 14 | 12 | public function test_add_permastruct() { |
-
diff --git tests/phpunit/tests/taxonomy.php tests/phpunit/tests/taxonomy.php
index d651b121ff..2ca406e59b 100644
|
|
|
class Tests_Taxonomy extends WP_UnitTestCase { |
| 792 | 792 | * @ticket 35227 |
| 793 | 793 | */ |
| 794 | 794 | public function test_unregister_taxonomy_removes_permastruct() { |
| 795 | | $this->set_permalink_structure( '/%postname%' ); |
| 796 | | |
| 797 | 795 | global $wp_rewrite; |
| 798 | 796 | |
| 799 | 797 | register_taxonomy( |
| … |
… |
class Tests_Taxonomy extends WP_UnitTestCase { |
| 812 | 810 | * @ticket 35227 |
| 813 | 811 | */ |
| 814 | 812 | public function test_unregister_taxonomy_removes_rewrite_rules() { |
| 815 | | $this->set_permalink_structure( '/%postname%' ); |
| 816 | | |
| 817 | 813 | global $wp_rewrite; |
| 818 | 814 | |
| 819 | 815 | register_taxonomy( 'foo', 'post', array( 'query_var' => 'bar' ) ); |
-
diff --git tests/phpunit/tests/term/getTermLink.php tests/phpunit/tests/term/getTermLink.php
index 370167cff3..cce925e641 100644
|
|
|
class Tests_Term_GetTermLink extends WP_UnitTestCase { |
| 12 | 12 | } |
| 13 | 13 | |
| 14 | 14 | public function test_integer_should_be_interpreted_as_term_id() { |
| | 15 | tests_set_and_flush_permalinks( '' ); |
| | 16 | |
| 15 | 17 | $t1 = self::factory()->term->create( |
| 16 | 18 | array( |
| 17 | 19 | 'taxonomy' => 'wptests_tax', |
| … |
… |
class Tests_Term_GetTermLink extends WP_UnitTestCase { |
| 28 | 30 | $term = intval( $t1 ); |
| 29 | 31 | |
| 30 | 32 | $actual = get_term_link( $term, 'wptests_tax' ); |
| 31 | | $this->assertContains( 'wptests_tax=foo', $actual ); |
| | 33 | $this->assertContains( '?wptests_tax=foo', $actual ); |
| | 34 | |
| | 35 | tests_reset_and_flush_permalinks(); |
| 32 | 36 | } |
| 33 | 37 | |
| 34 | 38 | public function test_numeric_string_should_be_interpreted_as_term_slug() { |
| | 39 | tests_set_and_flush_permalinks( '' ); |
| | 40 | |
| 35 | 41 | $t1 = self::factory()->term->create( |
| 36 | 42 | array( |
| 37 | 43 | 'taxonomy' => 'wptests_tax', |
| … |
… |
class Tests_Term_GetTermLink extends WP_UnitTestCase { |
| 48 | 54 | $term = (string) $t1; |
| 49 | 55 | |
| 50 | 56 | $actual = get_term_link( $term, 'wptests_tax' ); |
| 51 | | $this->assertContains( 'wptests_tax=' . $term, $actual ); |
| | 57 | $this->assertContains( '?wptests_tax=' . $term, $actual ); |
| | 58 | |
| | 59 | tests_reset_and_flush_permalinks(); |
| 52 | 60 | } |
| 53 | 61 | |
| 54 | 62 | public function test_invalid_term_should_return_wp_error() { |
| … |
… |
class Tests_Term_GetTermLink extends WP_UnitTestCase { |
| 57 | 65 | } |
| 58 | 66 | |
| 59 | 67 | public function test_category_should_use_cat_query_var_with_term_id() { |
| | 68 | tests_set_and_flush_permalinks( '' ); |
| | 69 | |
| 60 | 70 | $c = self::factory()->category->create(); |
| 61 | 71 | |
| 62 | 72 | $actual = get_term_link( $c, 'category' ); |
| 63 | 73 | $this->assertContains( 'cat=' . $c, $actual ); |
| | 74 | |
| | 75 | tests_reset_and_flush_permalinks(); |
| 64 | 76 | } |
| 65 | 77 | |
| 66 | 78 | public function test_taxonomy_with_query_var_should_use_that_query_var_with_term_slug() { |
| | 79 | tests_set_and_flush_permalinks( '' ); |
| | 80 | |
| 67 | 81 | register_taxonomy( |
| 68 | 82 | 'wptests_tax2', 'post', array( |
| 69 | 83 | 'query_var' => 'foo', |
| … |
… |
class Tests_Term_GetTermLink extends WP_UnitTestCase { |
| 79 | 93 | |
| 80 | 94 | $actual = get_term_link( $t, 'wptests_tax2' ); |
| 81 | 95 | $this->assertContains( 'foo=bar', $actual ); |
| | 96 | |
| | 97 | tests_reset_and_flush_permalinks(); |
| 82 | 98 | } |
| 83 | 99 | |
| 84 | 100 | public function test_taxonomy_without_query_var_should_use_taxonomy_query_var_and_term_query_var_with_term_slug() { |
| | 101 | tests_set_and_flush_permalinks( '' ); |
| | 102 | |
| 85 | 103 | register_taxonomy( |
| 86 | 104 | 'wptests_tax2', 'post', array( |
| 87 | 105 | 'query_var' => false, |
| … |
… |
class Tests_Term_GetTermLink extends WP_UnitTestCase { |
| 98 | 116 | $actual = get_term_link( $t, 'wptests_tax2' ); |
| 99 | 117 | $this->assertContains( 'taxonomy=wptests_tax2', $actual ); |
| 100 | 118 | $this->assertContains( 'term=bar', $actual ); |
| | 119 | |
| | 120 | tests_reset_and_flush_permalinks(); |
| 101 | 121 | } |
| 102 | 122 | |
| 103 | 123 | public function test_taxonomy_permastruct_with_hierarchical_rewrite_should_put_term_ancestors_in_link() { |
| 104 | | $this->set_permalink_structure( '/%year%/%monthnum%/%day%/%postname%/' ); |
| 105 | | |
| 106 | 124 | register_taxonomy( |
| 107 | 125 | 'wptests_tax2', 'post', array( |
| 108 | 126 | 'hierarchical' => true, |
| … |
… |
class Tests_Term_GetTermLink extends WP_UnitTestCase { |
| 136 | 154 | } |
| 137 | 155 | |
| 138 | 156 | public function test_taxonomy_permastruct_with_nonhierarchical_rewrite_should_not_put_term_ancestors_in_link() { |
| 139 | | $this->set_permalink_structure( '/%year%/%monthnum%/%day%/%postname%/' ); |
| 140 | | |
| 141 | 157 | register_taxonomy( |
| 142 | 158 | 'wptests_tax2', 'post', array( |
| 143 | 159 | 'hierarchical' => true, |
-
diff --git tests/phpunit/tests/term/wpTaxonomy.php tests/phpunit/tests/term/wpTaxonomy.php
index bd5f049c5c..4915b666e5 100644
|
|
|
class Tests_WP_Taxonomy extends WP_UnitTestCase { |
| 13 | 13 | } |
| 14 | 14 | |
| 15 | 15 | public function test_does_not_add_query_var_if_not_public() { |
| 16 | | $this->set_permalink_structure( '/%postname%' ); |
| 17 | | |
| 18 | 16 | /* @var WP $wp */ |
| 19 | 17 | global $wp; |
| 20 | 18 | |
| … |
… |
class Tests_WP_Taxonomy extends WP_UnitTestCase { |
| 26 | 24 | } |
| 27 | 25 | |
| 28 | 26 | public function test_adds_query_var_if_public() { |
| 29 | | $this->set_permalink_structure( '/%postname%' ); |
| 30 | | |
| 31 | 27 | /* @var WP $wp */ |
| 32 | 28 | global $wp; |
| 33 | 29 | |
| … |
… |
class Tests_WP_Taxonomy extends WP_UnitTestCase { |
| 51 | 47 | } |
| 52 | 48 | |
| 53 | 49 | public function test_adds_rewrite_rules() { |
| 54 | | $this->set_permalink_structure( '/%postname%' ); |
| 55 | | |
| 56 | 50 | /* @var WP_Rewrite $wp_rewrite */ |
| 57 | 51 | global $wp_rewrite; |
| 58 | 52 | |
-
diff --git tests/phpunit/tests/user/author.php tests/phpunit/tests/user/author.php
index d8bdf37a39..9e4568525e 100644
|
|
|
class Tests_User_Author_Template extends WP_UnitTestCase { |
| 10 | 10 | protected static $author_id = 0; |
| 11 | 11 | protected static $post_id = 0; |
| 12 | 12 | |
| 13 | | private $permalink_structure; |
| 14 | | |
| 15 | 13 | public static function wpSetUpBeforeClass( WP_UnitTest_Factory $factory ) { |
| 16 | 14 | self::$author_id = $factory->user->create( |
| 17 | 15 | array( |
| … |
… |
class Tests_User_Author_Template extends WP_UnitTestCase { |
| 118 | 116 | |
| 119 | 117 | $GLOBALS['authordata'] = $author->data; |
| 120 | 118 | |
| 121 | | $link = get_the_author_posts_link(); |
| 122 | 119 | |
| 123 | | $url = sprintf( 'http://%1$s/?author=%2$s', WP_TESTS_DOMAIN, $author->ID ); |
| | 120 | tests_set_and_flush_permalinks( '' ); |
| | 121 | |
| | 122 | $link = get_the_author_posts_link(); |
| | 123 | $url = sprintf( 'http://%1$s/?author=%2$s', WP_TESTS_DOMAIN, $author->ID ); |
| 124 | 124 | |
| 125 | 125 | $this->assertContains( $url, $link ); |
| 126 | 126 | $this->assertContains( 'Posts by Foo', $link ); |
| 127 | 127 | $this->assertContains( '>Foo</a>', $link ); |
| 128 | 128 | |
| 129 | 129 | unset( $GLOBALS['authordata'] ); |
| | 130 | tests_reset_and_flush_permalinks(); |
| 130 | 131 | } |
| 131 | 132 | |
| 132 | 133 | /** |
| … |
… |
class Tests_User_Author_Template extends WP_UnitTestCase { |
| 148 | 149 | |
| 149 | 150 | $url = sprintf( 'http://%1$s/author/%2$s/', WP_TESTS_DOMAIN, $author->user_nicename ); |
| 150 | 151 | |
| 151 | | $this->set_permalink_structure( '' ); |
| 152 | | |
| 153 | 152 | $this->assertContains( $url, $link ); |
| 154 | 153 | $this->assertContains( 'Posts by Foo', $link ); |
| 155 | 154 | $this->assertContains( '>Foo</a>', $link ); |