mirror of
https://github.com/gosticks/wordpress-develop.git
synced 2025-10-16 12:05:38 +00:00
Dynamic (non-explicitly declared) properties are deprecated as of PHP 8.2 and are expected to become a fatal error in PHP 9.0. In each of the cases included in this commit, one or more properties are dynamically created in the `set_up()` method of the test class. This commit explicitly declares these properties. As these properties are being declared on test classes, they are marked as private. Even though the original dynamic property was public, this should not be considered a backward compatibility break as this only involves test classes. Notes: * As these properties receive assignments during test runs or a one-time assignment, but the assignment uses a function call or variable access, these properties cannot be changed to class constants, but they should be declared explicitly as properties on the class. * In `Tests_Theme_CustomHeader`, the `$customize_manager` property is given a default value of `null`, same as it was already being reset to `null` in the `tear_down()` method. * In `Tests_Privacy_wpPrivacyProcessPersonalDataExportPage` and `Tests_Privacy_wpPrivacyGeneratePersonalDataExportFile` classes, the property name had a leading `_` underscore. This is an outdated PHP 4 practice to indicate a private property. As PHP 4 is no longer supported, the property has been renamed to `$orig_error_level`. * Along the same lines, in `Tests_Menu_Walker_Nav_Menu`, the property name also had a leading `_` underscore. The property has been renamed to `$orig_wp_nav_menu_max_depth`. * In the `Tests_Shortcode` class, three properties were already being (re)set in the `set_up() `method, while three others were being set for most tests via the `shortcode_test_shortcode_tag()` method or in the tests themselves. It is ensured now that all six properties are given their initial `null` value in the `set_up()` method and are explicitly declared. Additionally: * In the `Tests_User_Session` class, the `set_up()` method is incorrect. No assertions should be executed in fixture methods, but the `set_up()` method contains two assertions. This has not been addressed yet as it is outside the scope of this commit, but should be addressed at a later point in time. Follow-up to [12/tests], [218/tests], [374/tests], [384/tests], [986/tests], [1106/tests], [1239/tests], [28704], [29221], [29347], [32648], [36519], [37953], [38832], [40142], [40825], [43584], [43768], [44786], [45141], [53557], [53558], [53850], [53851], [53852], [53853], [53854], [53856], [53916], [53935], [53936], [53937], [53938], [53942], [53945]. Props jrf. See #56033. git-svn-id: https://develop.svn.wordpress.org/trunk@53948 602fd350-edb4-49c9-b593-d223f7449a82
487 lines
13 KiB
PHP
487 lines
13 KiB
PHP
<?php
|
|
|
|
/**
|
|
* @group rewrite
|
|
* @ticket 5305
|
|
*/
|
|
class Tests_Rewrite_NumericSlugs extends WP_UnitTestCase {
|
|
private $old_current_user;
|
|
private $author_id;
|
|
|
|
public function set_up() {
|
|
parent::set_up();
|
|
$this->author_id = self::factory()->user->create( array( 'role' => 'editor' ) );
|
|
|
|
// Override the post/archive slug collision prevention in `wp_unique_post_slug()`.
|
|
add_filter( 'wp_unique_post_slug', array( $this, 'filter_unique_post_slug' ), 10, 6 );
|
|
}
|
|
|
|
public function test_go_to_year_segment_collision_without_title() {
|
|
global $wpdb;
|
|
$this->set_permalink_structure( '/%postname%/' );
|
|
|
|
$id = self::factory()->post->create(
|
|
array(
|
|
'post_author' => $this->author_id,
|
|
'post_status' => 'publish',
|
|
'post_content' => 'content',
|
|
'post_title' => '',
|
|
'post_name' => '2015',
|
|
'post_date' => '2015-02-01 01:00:00',
|
|
)
|
|
);
|
|
|
|
// Force an ID that resembles a year format.
|
|
$wpdb->update(
|
|
$wpdb->posts,
|
|
array(
|
|
'ID' => '2015',
|
|
'guid' => 'http://' . WP_TESTS_DOMAIN . '/?p=2015',
|
|
),
|
|
array( 'ID' => $id )
|
|
);
|
|
|
|
$this->go_to( get_permalink( '2015' ) );
|
|
|
|
$this->assertQueryTrue( 'is_single', 'is_singular' );
|
|
}
|
|
|
|
public function test_url_to_postid_year_segment_collision_without_title() {
|
|
global $wpdb;
|
|
$this->set_permalink_structure( '/%postname%/' );
|
|
|
|
$id = self::factory()->post->create(
|
|
array(
|
|
'post_author' => $this->author_id,
|
|
'post_status' => 'publish',
|
|
'post_content' => 'content',
|
|
'post_title' => '',
|
|
'post_name' => '2015',
|
|
'post_date' => '2015-02-01 01:00:00',
|
|
)
|
|
);
|
|
|
|
// Force an ID that resembles a year format.
|
|
$wpdb->update(
|
|
$wpdb->posts,
|
|
array(
|
|
'ID' => '2015',
|
|
'guid' => 'http://' . WP_TESTS_DOMAIN . '/?p=2015',
|
|
),
|
|
array( 'ID' => $id )
|
|
);
|
|
|
|
$this->assertSame( 2015, url_to_postid( get_permalink( '2015' ) ) );
|
|
}
|
|
|
|
public function test_go_to_year_segment_collision_with_title() {
|
|
$this->set_permalink_structure( '/%postname%/' );
|
|
|
|
$id = self::factory()->post->create(
|
|
array(
|
|
'post_author' => $this->author_id,
|
|
'post_status' => 'publish',
|
|
'post_content' => 'content',
|
|
'post_title' => '2015',
|
|
'post_date' => '2015-02-01 01:00:00',
|
|
)
|
|
);
|
|
|
|
$this->go_to( get_permalink( $id ) );
|
|
|
|
$this->assertQueryTrue( 'is_single', 'is_singular' );
|
|
}
|
|
|
|
public function test_url_to_postid_year_segment_collision_with_title() {
|
|
$this->set_permalink_structure( '/%postname%/' );
|
|
|
|
$id = self::factory()->post->create(
|
|
array(
|
|
'post_author' => $this->author_id,
|
|
'post_status' => 'publish',
|
|
'post_content' => 'content',
|
|
'post_title' => '2015',
|
|
'post_date' => '2015-02-01 01:00:00',
|
|
)
|
|
);
|
|
|
|
$this->assertSame( $id, url_to_postid( get_permalink( $id ) ) );
|
|
}
|
|
|
|
public function test_go_to_month_segment_collision_without_title() {
|
|
$this->set_permalink_structure( '/%year%/%postname%/' );
|
|
|
|
$id = self::factory()->post->create(
|
|
array(
|
|
'post_author' => $this->author_id,
|
|
'post_status' => 'publish',
|
|
'post_content' => 'content',
|
|
'post_title' => '',
|
|
'post_name' => '02',
|
|
'post_date' => '2015-02-01 01:00:00',
|
|
)
|
|
);
|
|
|
|
$this->go_to( get_permalink( $id ) );
|
|
|
|
$this->assertQueryTrue( 'is_single', 'is_singular' );
|
|
}
|
|
|
|
public function test_url_to_postid_month_segment_collision_without_title() {
|
|
$this->set_permalink_structure( '/%year%/%postname%/' );
|
|
|
|
$id = self::factory()->post->create(
|
|
array(
|
|
'post_author' => $this->author_id,
|
|
'post_status' => 'publish',
|
|
'post_content' => 'content',
|
|
'post_title' => '',
|
|
'post_name' => '02',
|
|
'post_date' => '2015-02-01 01:00:00',
|
|
)
|
|
);
|
|
|
|
$this->assertSame( $id, url_to_postid( get_permalink( $id ) ) );
|
|
}
|
|
|
|
public function test_go_to_month_segment_collision_without_title_no_leading_zero() {
|
|
$this->set_permalink_structure( '/%year%/%postname%/' );
|
|
|
|
$id = self::factory()->post->create(
|
|
array(
|
|
'post_author' => $this->author_id,
|
|
'post_status' => 'publish',
|
|
'post_content' => 'content',
|
|
'post_title' => '',
|
|
'post_name' => '2',
|
|
'post_date' => '2015-02-01 01:00:00',
|
|
)
|
|
);
|
|
|
|
$this->go_to( get_permalink( $id ) );
|
|
|
|
$this->assertQueryTrue( 'is_single', 'is_singular' );
|
|
}
|
|
|
|
public function test_url_to_postid_month_segment_collision_without_title_no_leading_zero() {
|
|
$this->set_permalink_structure( '/%year%/%postname%/' );
|
|
|
|
$id = self::factory()->post->create(
|
|
array(
|
|
'post_author' => $this->author_id,
|
|
'post_status' => 'publish',
|
|
'post_content' => 'content',
|
|
'post_title' => '',
|
|
'post_name' => '2',
|
|
'post_date' => '2015-02-01 01:00:00',
|
|
)
|
|
);
|
|
|
|
$this->assertSame( $id, url_to_postid( get_permalink( $id ) ) );
|
|
}
|
|
|
|
public function test_go_to_month_segment_collision_with_title() {
|
|
$this->set_permalink_structure( '/%year%/%postname%/' );
|
|
|
|
$id = self::factory()->post->create(
|
|
array(
|
|
'post_author' => $this->author_id,
|
|
'post_status' => 'publish',
|
|
'post_content' => 'content',
|
|
'post_title' => '02',
|
|
'post_date' => '2015-02-01 01:00:00',
|
|
)
|
|
);
|
|
|
|
$this->go_to( get_permalink( $id ) );
|
|
|
|
$this->assertQueryTrue( 'is_single', 'is_singular' );
|
|
}
|
|
|
|
public function test_url_to_postid_month_segment_collision_with_title() {
|
|
$this->set_permalink_structure( '/%year%/%postname%/' );
|
|
|
|
$id = self::factory()->post->create(
|
|
array(
|
|
'post_author' => $this->author_id,
|
|
'post_status' => 'publish',
|
|
'post_content' => 'content',
|
|
'post_title' => '02',
|
|
'post_date' => '2015-02-01 01:00:00',
|
|
)
|
|
);
|
|
|
|
$this->assertSame( $id, url_to_postid( get_permalink( $id ) ) );
|
|
}
|
|
|
|
public function test_go_to_month_segment_collision_with_title_no_leading_zero() {
|
|
$this->set_permalink_structure( '/%year%/%postname%/' );
|
|
|
|
$id = self::factory()->post->create(
|
|
array(
|
|
'post_author' => $this->author_id,
|
|
'post_status' => 'publish',
|
|
'post_content' => 'content',
|
|
'post_title' => '2',
|
|
'post_date' => '2015-02-01 01:00:00',
|
|
)
|
|
);
|
|
|
|
$this->go_to( get_permalink( $id ) );
|
|
|
|
$this->assertQueryTrue( 'is_single', 'is_singular' );
|
|
}
|
|
|
|
public function test_url_to_postid_month_segment_collision_with_title_no_leading_zero() {
|
|
$this->set_permalink_structure( '/%year%/%postname%/' );
|
|
|
|
$id = self::factory()->post->create(
|
|
array(
|
|
'post_author' => $this->author_id,
|
|
'post_status' => 'publish',
|
|
'post_content' => 'content',
|
|
'post_title' => '2',
|
|
'post_date' => '2015-02-01 01:00:00',
|
|
)
|
|
);
|
|
|
|
$this->assertSame( $id, url_to_postid( get_permalink( $id ) ) );
|
|
}
|
|
|
|
public function test_go_to_day_segment_collision_without_title() {
|
|
$this->set_permalink_structure( '/%year%/%monthnum%/%postname%/' );
|
|
|
|
$id = self::factory()->post->create(
|
|
array(
|
|
'post_author' => $this->author_id,
|
|
'post_status' => 'publish',
|
|
'post_content' => 'content',
|
|
'post_title' => '',
|
|
'post_name' => '01',
|
|
'post_date' => '2015-02-01 01:00:00',
|
|
)
|
|
);
|
|
|
|
$this->go_to( get_permalink( $id ) );
|
|
|
|
$this->assertQueryTrue( 'is_single', 'is_singular' );
|
|
}
|
|
|
|
public function test_url_to_postid_day_segment_collision_without_title() {
|
|
$this->set_permalink_structure( '/%year%/%monthnum%/%postname%/' );
|
|
|
|
$id = self::factory()->post->create(
|
|
array(
|
|
'post_author' => $this->author_id,
|
|
'post_status' => 'publish',
|
|
'post_content' => 'content',
|
|
'post_title' => '',
|
|
'post_name' => '01',
|
|
'post_date' => '2015-02-01 01:00:00',
|
|
)
|
|
);
|
|
|
|
$this->assertSame( $id, url_to_postid( get_permalink( $id ) ) );
|
|
}
|
|
|
|
public function test_go_to_day_segment_collision_with_title() {
|
|
$this->set_permalink_structure( '/%year%/%monthnum%/%postname%/' );
|
|
|
|
$id = self::factory()->post->create(
|
|
array(
|
|
'post_author' => $this->author_id,
|
|
'post_status' => 'publish',
|
|
'post_content' => 'content',
|
|
'post_title' => '01',
|
|
'post_date' => '2015-02-01 01:00:00',
|
|
)
|
|
);
|
|
|
|
$this->go_to( get_permalink( $id ) );
|
|
|
|
$this->assertQueryTrue( 'is_single', 'is_singular' );
|
|
}
|
|
|
|
public function test_url_to_postid_day_segment_collision_with_title() {
|
|
$this->set_permalink_structure( '/%year%/%monthnum%/%postname%/' );
|
|
|
|
$id = self::factory()->post->create(
|
|
array(
|
|
'post_author' => $this->author_id,
|
|
'post_status' => 'publish',
|
|
'post_content' => 'content',
|
|
'post_title' => '01',
|
|
'post_date' => '2015-02-01 01:00:00',
|
|
)
|
|
);
|
|
|
|
$this->assertSame( $id, url_to_postid( get_permalink( $id ) ) );
|
|
}
|
|
|
|
public function test_numeric_slug_permalink_conflicts_should_only_be_resolved_for_the_main_query() {
|
|
$this->set_permalink_structure( '/%year%/%monthnum%/%postname%/' );
|
|
|
|
$id = self::factory()->post->create(
|
|
array(
|
|
'post_author' => $this->author_id,
|
|
'post_status' => 'publish',
|
|
'post_content' => 'content',
|
|
'post_title' => '01',
|
|
'post_date' => '2015-02-01 01:00:00',
|
|
)
|
|
);
|
|
|
|
$q = new WP_Query(
|
|
array(
|
|
'year' => '2015',
|
|
'monthnum' => '02',
|
|
'day' => '01',
|
|
)
|
|
);
|
|
|
|
$this->assertTrue( $q->is_day );
|
|
$this->assertFalse( $q->is_single );
|
|
}
|
|
|
|
public function test_month_slug_collision_should_resolve_to_date_archive_when_year_does_not_match_post_year() {
|
|
$this->set_permalink_structure( '/%year%/%postname%/' );
|
|
|
|
// Make sure a post is published in 2013/02, to avoid 404s.
|
|
self::factory()->post->create(
|
|
array(
|
|
'post_author' => $this->author_id,
|
|
'post_status' => 'publish',
|
|
'post_content' => 'foo',
|
|
'post_title' => 'bar',
|
|
'post_date' => '2013-02-01 01:00:00',
|
|
)
|
|
);
|
|
|
|
$id = self::factory()->post->create(
|
|
array(
|
|
'post_author' => $this->author_id,
|
|
'post_status' => 'publish',
|
|
'post_content' => 'foo',
|
|
'post_title' => '02',
|
|
'post_date' => '2015-02-01 01:00:00',
|
|
)
|
|
);
|
|
|
|
$permalink = get_permalink( $id );
|
|
$permalink = str_replace( '/2015/', '/2013/', $permalink );
|
|
|
|
$this->go_to( $permalink );
|
|
|
|
$this->assertTrue( is_month() );
|
|
}
|
|
|
|
public function test_day_slug_collision_should_resolve_to_date_archive_when_monthnum_does_not_match_post_month() {
|
|
$this->set_permalink_structure( '/%year%/%monthnum%/%postname%/' );
|
|
|
|
// Make sure a post is published on 2015/01/01, to avoid 404s.
|
|
self::factory()->post->create(
|
|
array(
|
|
'post_author' => $this->author_id,
|
|
'post_status' => 'publish',
|
|
'post_content' => 'foo',
|
|
'post_title' => 'bar',
|
|
'post_date' => '2015-01-02 01:00:00',
|
|
)
|
|
);
|
|
|
|
$id = self::factory()->post->create(
|
|
array(
|
|
'post_author' => $this->author_id,
|
|
'post_status' => 'publish',
|
|
'post_content' => 'foo',
|
|
'post_title' => '02',
|
|
'post_date' => '2015-02-02 01:00:00',
|
|
)
|
|
);
|
|
|
|
$permalink = get_permalink( $id );
|
|
$permalink = str_replace( '/2015/02/', '/2015/01/', $permalink );
|
|
|
|
$this->go_to( $permalink );
|
|
|
|
$this->assertTrue( is_day() );
|
|
}
|
|
|
|
public function test_date_slug_collision_should_distinguish_valid_pagination_from_date() {
|
|
$this->set_permalink_structure( '/%year%/%postname%/' );
|
|
|
|
$id = self::factory()->post->create(
|
|
array(
|
|
'post_author' => $this->author_id,
|
|
'post_status' => 'publish',
|
|
'post_content' => 'Page 0<!--nextpage-->Page 1<!--nextpage-->Page 2<!--nextpage-->Page 3',
|
|
'post_title' => '02',
|
|
'post_date' => '2015-02-01 01:00:00',
|
|
)
|
|
);
|
|
|
|
$this->go_to( get_permalink( $id ) . '1' );
|
|
|
|
$this->assertFalse( is_day() );
|
|
}
|
|
|
|
public function test_date_slug_collision_should_distinguish_too_high_pagination_from_date() {
|
|
$this->set_permalink_structure( '/%year%/%postname%/' );
|
|
|
|
$id = self::factory()->post->create(
|
|
array(
|
|
'post_author' => $this->author_id,
|
|
'post_status' => 'publish',
|
|
'post_content' => 'Page 0<!--nextpage-->Page 1<!--nextpage-->Page 2<!--nextpage-->Page 3',
|
|
'post_title' => '02',
|
|
'post_date' => '2015-02-05 01:00:00',
|
|
)
|
|
);
|
|
|
|
$this->go_to( get_permalink( $id ) . '5' );
|
|
|
|
$this->assertTrue( is_day() );
|
|
}
|
|
|
|
public function test_date_slug_collision_should_not_require_pagination_query_var() {
|
|
$this->set_permalink_structure( '/%year%/%postname%/' );
|
|
|
|
$id = self::factory()->post->create(
|
|
array(
|
|
'post_author' => $this->author_id,
|
|
'post_status' => 'publish',
|
|
'post_content' => 'Page 0<!--nextpage-->Page 1<!--nextpage-->Page 2<!--nextpage-->Page 3',
|
|
'post_title' => '02',
|
|
'post_date' => '2015-02-05 01:00:00',
|
|
)
|
|
);
|
|
|
|
$this->go_to( get_permalink( $id ) );
|
|
|
|
$this->assertQueryTrue( 'is_single', 'is_singular' );
|
|
$this->assertFalse( is_date() );
|
|
}
|
|
|
|
public function test_date_slug_collision_should_be_ignored_when_pagination_var_is_present_but_post_does_not_have_multiple_pages() {
|
|
$this->set_permalink_structure( '/%year%/%postname%/' );
|
|
|
|
$id = self::factory()->post->create(
|
|
array(
|
|
'post_author' => $this->author_id,
|
|
'post_status' => 'publish',
|
|
'post_content' => 'This post does not have pagination.',
|
|
'post_title' => '02',
|
|
'post_date' => '2015-02-05 01:00:00',
|
|
)
|
|
);
|
|
|
|
$this->go_to( get_permalink( $id ) . '5' );
|
|
|
|
$this->assertTrue( is_day() );
|
|
}
|
|
|
|
public function filter_unique_post_slug( $slug, $post_id, $post_status, $post_type, $post_parent, $original_slug ) {
|
|
return $original_slug;
|
|
}
|
|
}
|