-
Notifications
You must be signed in to change notification settings - Fork 3.4k
Make layout supports compatible with enhanced pagination #5528
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
ec9eb66
e4f7eab
5468e17
2d3db44
b6138d4
89b3ba9
ca9731a
42035de
780486b
11f1cac
c01e7e8
1c8ab55
7a32e26
5aac204
f4f99fc
28cbcad
92d9392
5151440
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,196 @@ | ||
| <?php | ||
|
|
||
| /** | ||
| * Test cases for the `wp_unique_prefixed_id()` function. | ||
| * | ||
| * @package WordPress\UnitTests | ||
| * | ||
| * @since 6.4.0 | ||
| * | ||
| * @group functions.php | ||
| * @covers ::wp_unique_prefixed_id | ||
| */ | ||
| class Tests_Functions_WpUniquePrefixedId extends WP_UnitTestCase { | ||
|
|
||
| /** | ||
| * Tests that the expected unique prefixed IDs are created. | ||
| * | ||
| * @ticket 59681 | ||
| * | ||
| * @dataProvider data_should_create_unique_prefixed_ids | ||
| * | ||
| * @runInSeparateProcess | ||
| * @preserveGlobalState disabled | ||
| * | ||
| * @param mixed $prefix The prefix. | ||
| * @param array $expected The next two expected IDs. | ||
| */ | ||
| public function test_should_create_unique_prefixed_ids( $prefix, $expected ) { | ||
| $id1 = wp_unique_prefixed_id( $prefix ); | ||
| $id2 = wp_unique_prefixed_id( $prefix ); | ||
|
|
||
| $this->assertNotSame( $id1, $id2, 'The IDs are not unique.' ); | ||
| $this->assertSame( $expected, array( $id1, $id2 ), 'The IDs did not match the expected values.' ); | ||
| } | ||
|
|
||
| /** | ||
| * Data provider. | ||
| * | ||
| * @return array[] | ||
| */ | ||
| public function data_should_create_unique_prefixed_ids() { | ||
| return array( | ||
| 'prefix as empty string' => array( | ||
| 'prefix' => '', | ||
| 'expected' => array( '1', '2' ), | ||
| ), | ||
| 'prefix as (string) "0"' => array( | ||
| 'prefix' => '0', | ||
| 'expected' => array( '01', '02' ), | ||
| ), | ||
| 'prefix as string' => array( | ||
| 'prefix' => 'test', | ||
| 'expected' => array( 'test1', 'test2' ), | ||
| ), | ||
| 'prefix as string with spaces' => array( | ||
| 'prefix' => ' ', | ||
| 'expected' => array( ' 1', ' 2' ), | ||
| ), | ||
| 'prefix as (string) "1"' => array( | ||
| 'prefix' => '1', | ||
| 'expected' => array( '11', '12' ), | ||
| ), | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. As It's also possible that the "id" in question does not link directly to the HTML Coverage should also be added for a variety of possible "id" values, such as
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Sure that can be added, though would be part of the prefix, and not the incremented integer value.
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Thanks Tonya! If there are any other potential "gotcha" values that a potential future refactor could regress, we should consider those too. The non-string dataset looks good for "gotcha" values, though I think we should complete the scalar datasets with
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
| 'prefix as a (string) "."' => array( | ||
| 'prefix' => '.', | ||
| 'expected' => array( '.1', '.2' ), | ||
| ), | ||
| 'prefix as a block name' => array( | ||
| 'prefix' => 'core/list-item', | ||
| 'expected' => array( 'core/list-item1', 'core/list-item2' ), | ||
| ), | ||
| ); | ||
| } | ||
|
|
||
| /** | ||
| * @ticket 59681 | ||
| * | ||
| * @dataProvider data_should_raise_notice_and_use_empty_string_prefix_when_nonstring_given | ||
| * | ||
| * @runInSeparateProcess | ||
| * @preserveGlobalState disabled | ||
| * | ||
| * @param mixed $non_string_prefix Non-string prefix. | ||
| * @param int $number_of_ids_to_generate Number of IDs to generate. | ||
| * As the prefix will default to an empty string, changing the number of IDs generated within each dataset further tests ID uniqueness. | ||
| * @param string $expected_message Expected notice message. | ||
| * @param array $expected_ids Expected unique IDs. | ||
| */ | ||
| public function test_should_raise_notice_and_use_empty_string_prefix_when_nonstring_given( $non_string_prefix, $number_of_ids_to_generate, $expected_message, $expected_ids ) { | ||
| $this->expectNotice(); | ||
| $this->expectNoticeMessage( $expected_message ); | ||
|
|
||
| $ids = array(); | ||
| for ( $i = 0; $i < $number_of_ids_to_generate; $i++ ) { | ||
| $ids[] = wp_unique_prefixed_id( $non_string_prefix ); | ||
| } | ||
|
|
||
| $this->assertSameSets( $ids, array_unique( $ids ), 'IDs are not unique.' ); | ||
| $this->assertSameSets( $expected_ids, $ids, 'The IDs did not match the expected values.' ); | ||
| } | ||
|
|
||
| /** | ||
| * Data provider. | ||
| * | ||
| * @return array[] | ||
| */ | ||
| public function data_should_raise_notice_and_use_empty_string_prefix_when_nonstring_given() { | ||
| $message = 'wp_unique_prefixed_id(): The prefix must be a string. "%s" data type given.'; | ||
| return array( | ||
| 'prefix as null' => array( | ||
| 'non_string_prefix' => null, | ||
| 'number_of_ids_to_generate' => 2, | ||
| 'expected_message' => sprintf( $message, 'NULL' ), | ||
| 'expected_ids' => array( '1', '2' ), | ||
| ), | ||
| 'prefix as (int) 0' => array( | ||
| 'non_string_prefix' => 0, | ||
| 'number_of_ids_to_generate' => 3, | ||
| 'expected_message' => sprintf( $message, 'integer' ), | ||
| 'expected_ids' => array( '1', '2', '3' ), | ||
| ), | ||
| 'prefix as (int) 1' => array( | ||
| 'non_string_prefix' => 1, | ||
| 'number_of_ids_to_generate' => 4, | ||
| 'expected_data_type' => sprintf( $message, 'integer' ), | ||
| 'expected_ids' => array( '1', '2', '3', '4' ), | ||
| ), | ||
| 'prefix as (bool) false' => array( | ||
| 'non_string_prefix' => false, | ||
| 'number_of_ids_to_generate' => 5, | ||
| 'expected_data_type' => sprintf( $message, 'boolean' ), | ||
| 'expected_ids' => array( '1', '2', '3', '4', '5' ), | ||
| ), | ||
| 'prefix as (double) 98.7' => array( | ||
| 'non_string_prefix' => 98.7, | ||
| 'number_of_ids_to_generate' => 6, | ||
| 'expected_data_type' => sprintf( $message, 'double' ), | ||
| 'expected_ids' => array( '1', '2', '3', '4', '5', '6' ), | ||
| ), | ||
| ); | ||
| } | ||
|
|
||
| /** | ||
| * Prefixes that are or will become the same should generate unique IDs. | ||
| * | ||
| * This test is added to avoid future regressions if the function's prefix data type check is | ||
| * modified to type juggle or check for scalar data types. | ||
| * | ||
| * @ticket 59681 | ||
| * | ||
| * @dataProvider data_same_prefixes_should_generate_unique_ids | ||
| * | ||
| * @runInSeparateProcess | ||
| * @preserveGlobalState disabled | ||
| * | ||
| * @param array $prefixes The prefixes to check. | ||
| * @param array $expected The expected unique IDs. | ||
| */ | ||
| public function test_same_prefixes_should_generate_unique_ids( array $prefixes, array $expected ) { | ||
| // Suppress E_USER_NOTICE, which will be raised when a prefix is non-string. | ||
| $original_error_reporting = error_reporting(); | ||
| error_reporting( $original_error_reporting & ~E_USER_NOTICE ); | ||
|
|
||
| $ids = array(); | ||
| foreach ( $prefixes as $prefix ) { | ||
| $ids[] = wp_unique_prefixed_id( $prefix ); | ||
| } | ||
|
|
||
| // Reset error reporting. | ||
| error_reporting( $original_error_reporting ); | ||
|
|
||
| $this->assertSameSets( $ids, array_unique( $ids ), 'IDs are not unique.' ); | ||
| $this->assertSameSets( $expected, $ids, 'The IDs did not match the expected values.' ); | ||
| } | ||
|
|
||
| /** | ||
| * Data provider. | ||
| * | ||
| * @return array[] | ||
| */ | ||
| public function data_same_prefixes_should_generate_unique_ids() { | ||
| return array( | ||
| 'prefixes = empty string' => array( | ||
| 'prefixes' => array( null, true, '' ), | ||
| 'expected' => array( '1', '2', '3' ), | ||
| ), | ||
| 'prefixes = 0' => array( | ||
| 'prefixes' => array( '0', 0, 0.0, false ), | ||
| 'expected' => array( '01', '1', '2', '3' ), | ||
| ), | ||
| 'prefixes = 1' => array( | ||
| 'prefixes' => array( '1', 1, 1.0, true ), | ||
| 'expected' => array( '11', '1', '2', '3' ), | ||
| ), | ||
| ); | ||
| } | ||
| } | ||
Uh oh!
There was an error while loading. Please reload this page.