Commit Graph

3856 Commits

Author SHA1 Message Date
Sergey Biryukov
79703088c4 General: Replace older-style PHP type conversion functions with type casts.
This improves performance, readability, and consistency throughout core.

* `intval()` → `(int)`
* `strval()` → `(string)`
* `floatval()` → `(float)`

Props ayeshrajans.
Fixes #42918.

git-svn-id: https://develop.svn.wordpress.org/trunk@49108 602fd350-edb4-49c9-b593-d223f7449a82
2020-10-08 21:13:57 +00:00
Sergey Biryukov
eeae797340 Build/Test Tools: Add missing <ul> tag in tests/qunit/index.html.
Props ravipatel, JeffPaul.
Fixes #51473.

git-svn-id: https://develop.svn.wordpress.org/trunk@49107 602fd350-edb4-49c9-b593-d223f7449a82
2020-10-08 18:27:07 +00:00
Timothy Jacobs
5b6f5f9f6d REST API: Introduce search term handler.
This allows for clients to search the available terms via the `/wp/v2/search` endpoint by using a `type=term` query parameter.

Fixes #51458.
Props andraganescu, zieladam, noisysocks, TimothyBlynJacobs.


git-svn-id: https://develop.svn.wordpress.org/trunk@49103 602fd350-edb4-49c9-b593-d223f7449a82
2020-10-08 01:30:25 +00:00
Andrew Ozz
9c50d3dda5 Update jQuery step two:
- Add jquery-migrate.js v.3.3.1 to core and load it in debug mode when `SCRIPT_DEBUG` is true.
- Add jquery.min.js, update jquery.js to 3.5.1 non-minified. This should help when debugging.
- Rebuild jQuery UI 1.12.1 and add it to core.
- Fix/adjust tests to match the above changes.

See #50564.

git-svn-id: https://develop.svn.wordpress.org/trunk@49101 602fd350-edb4-49c9-b593-d223f7449a82
2020-10-07 16:31:53 +00:00
Sergey Biryukov
c8ed3ebb30 Privacy: Improve clarity of privacy error strings.
Primarily this adds "user privacy" to the strings for privacy requests, so they are more easily distinguished from other system actions within logs.

Props garrett-eclipse, carike, birgire.
Fixes #51351.

git-svn-id: https://develop.svn.wordpress.org/trunk@49090 602fd350-edb4-49c9-b593-d223f7449a82
2020-10-04 03:21:38 +00:00
Helen Hou-Sandi
0488373778 Tests: Fix a linting error in a test.
See #50679.


git-svn-id: https://develop.svn.wordpress.org/trunk@49085 602fd350-edb4-49c9-b593-d223f7449a82
2020-10-01 21:42:40 +00:00
Helen Hou-Sandi
150d9bd17e Media: Don't unnecessarily check for a valid attachment before getting meta.
This makes `wp_get_attachment_metadata()` run significantly faster. See ticket for benchmarking.

Props Tkama, donmhico.
Fixes #50679.


git-svn-id: https://develop.svn.wordpress.org/trunk@49084 602fd350-edb4-49c9-b593-d223f7449a82
2020-10-01 17:53:38 +00:00
Timothy Jacobs
f60aa51988 REST API: Support the patternProperties JSON Schema keyword.
Props yakimun.
Fixes #51024.


git-svn-id: https://develop.svn.wordpress.org/trunk@49082 602fd350-edb4-49c9-b593-d223f7449a82
2020-10-01 02:47:08 +00:00
Sergey Biryukov
3b75e7d0f0 Tests: Require imagejpeg() function in Ajax media editing tests.
This outputs a proper message if the requirement is not met, instead of an obscure failure further in the test.

These tests rely on multiple resized copies of a test JPEG image being generated and available.

Follow-up to [49010], [49024], [49025], [49045], [49050], [49052].

See #50639, #50640.

git-svn-id: https://develop.svn.wordpress.org/trunk@49069 602fd350-edb4-49c9-b593-d223f7449a82
2020-09-29 14:14:28 +00:00
Timothy Jacobs
dbf692583c REST API: Support the multipleOf JSON Schema keyword.
Props yakimun.
Fixes #51022.


git-svn-id: https://develop.svn.wordpress.org/trunk@49063 602fd350-edb4-49c9-b593-d223f7449a82
2020-09-27 19:01:18 +00:00
Timothy Jacobs
4ad4eeaf7d Add ircs and irc6 to the list of allowed protocols.
This adds support for the secure and ipv6 variants of the already allowed irc protocol.

Props arealnobrainer, markparnell, ctmartin.


git-svn-id: https://develop.svn.wordpress.org/trunk@49055 602fd350-edb4-49c9-b593-d223f7449a82
2020-09-26 21:00:19 +00:00
Timothy Jacobs
d5c2c86bd8 REST API: Support the minProperties and maxProperties JSON Schema keywords.
Props yakimun.
Fixes #51023.


git-svn-id: https://develop.svn.wordpress.org/trunk@49053 602fd350-edb4-49c9-b593-d223f7449a82
2020-09-26 18:18:53 +00:00
Sergey Biryukov
9aa0e0c92b Tests: Require imagejpeg() function in WP_Widget_Media_Image::render_media() test.
This outputs a proper message if the requirement is not met, instead of an obscure failure further in the test.

This test relies on multiple resized copies of a test JPEG image being generated and available.

Follow-up to [49010], [49024], [49025], [49045], [49050].

See #50639, #50640.

git-svn-id: https://develop.svn.wordpress.org/trunk@49052 602fd350-edb4-49c9-b593-d223f7449a82
2020-09-26 14:50:51 +00:00
Sergey Biryukov
e2b74bee82 Tests: Correct assertion in WP_Test_REST_Comments_Controller::check_comment_data().
`author_avatar_urls` should be present in the comment data array keys, not values.

The test only passed accidentally due to `assertContains()` not performing a strict type check.

See #38266, #50913.

git-svn-id: https://develop.svn.wordpress.org/trunk@49051 602fd350-edb4-49c9-b593-d223f7449a82
2020-09-26 03:12:21 +00:00
Sergey Biryukov
21eb2f0d98 Tests: Require imagejpeg() function in one more media test.
This outputs a proper message if the requirement is not met, instead of an obscure failure further in the test.

This test relies on multiple resized copies of a test JPEG image being generated and available.

Follow-up to [49010], [49024], [49025], [49045].

See #50639, #50640.

git-svn-id: https://develop.svn.wordpress.org/trunk@49050 602fd350-edb4-49c9-b593-d223f7449a82
2020-09-26 02:32:25 +00:00
Sergey Biryukov
5d1a29deaa Tests: Require imagejpeg() function in some REST API attachments controller tests.
This outputs a proper message if the requirement is not met, instead of an obscure failure further in the test.

These tests rely on multiple resized copies of a test JPEG image being generated and available.

Follow-up to [49010], [49024], [49025], [49045].

See #50639, #50640.

git-svn-id: https://develop.svn.wordpress.org/trunk@49047 602fd350-edb4-49c9-b593-d223f7449a82
2020-09-25 02:21:33 +00:00
Sergey Biryukov
51a7210589 Tests: Correct the check for image sizes in some REST API attachments controller tests.
If the sizes data could not be retrieved, the controller returns an empty object instead of an array.

This makes sure that the value is in fact an array before proceeding, and outputs a proper message in case of failure, instead of an obscure PHP error further in the test.

Follow-up to [49044].

See #50913, #51393.

git-svn-id: https://develop.svn.wordpress.org/trunk@49046 602fd350-edb4-49c9-b593-d223f7449a82
2020-09-25 02:09:32 +00:00
Sergey Biryukov
5730b983b8 Tests: Require imagejpeg() function in some more media tests.
This outputs a proper message if the requirement is not met, instead of an obscure PHP error further in the test.

These tests rely on multiple resized copies of a test JPEG image being generated and available.

Follow-up to [49010], [49024], [49025].

See #50639, #50640.

git-svn-id: https://develop.svn.wordpress.org/trunk@49045 602fd350-edb4-49c9-b593-d223f7449a82
2020-09-25 01:43:19 +00:00
Sergey Biryukov
3bfa4606c7 Tests: Check if image sizes were successfully retrieved in some REST API attachments controller tests.
This outputs a proper message in case of failure, instead of an obscure PHP error further in the test.

Props TimothyBlynJacobs.
See #50913, #51393.

git-svn-id: https://develop.svn.wordpress.org/trunk@49044 602fd350-edb4-49c9-b593-d223f7449a82
2020-09-25 01:29:51 +00:00
Sergey Biryukov
c31a551273 Tests: Backport two changes from PHPUnit 9.3:
* Replace the `Match` interface with `ParametersMatch`, to avoid parse errors due to `match` being a reserved keyword in PHP 8.
* Replace `ReflectionParameter::getClass()` usage, which is deprecated in PHP 8.

This allows tests relying on the `getMockForAbstractClass()` and `getMockBuilder()` methods to run again on PHP 8.

When the test suite is updated for compatibility with PHPUnit 9.x, these overrides can be removed.

Follow-up to [48972].

See #50913, #50902.

git-svn-id: https://develop.svn.wordpress.org/trunk@49037 602fd350-edb4-49c9-b593-d223f7449a82
2020-09-23 13:52:02 +00:00
Sergey Biryukov
7d15225ad0 Users: Check if the user ID passed as selected to wp_dropdown_users() corresponds to an existing user.
This avoids a few PHP notices if the `include_selected` parameter was specified and a non-existing user ID was passed.

Props campusboy1987.
Fixes #51370.

git-svn-id: https://develop.svn.wordpress.org/trunk@49036 602fd350-edb4-49c9-b593-d223f7449a82
2020-09-23 00:25:47 +00:00
Sergey Biryukov
303deffe91 Tests: Use consistent trailing punctuation in fail() messages.
See #51344.

git-svn-id: https://develop.svn.wordpress.org/trunk@49033 602fd350-edb4-49c9-b593-d223f7449a82
2020-09-22 12:32:39 +00:00
Sergey Biryukov
a9ee47c806 Tests: Check if image metadata for a particular size was successfully retrieved in some media tests.
This outputs a proper message in case of failure, instead of an obscure PHP error further in the test.

See #50913.

git-svn-id: https://develop.svn.wordpress.org/trunk@49032 602fd350-edb4-49c9-b593-d223f7449a82
2020-09-22 12:30:48 +00:00
Timothy Jacobs
c263d2e56c REST API: Regenerate test fixtures after [48982].
Props garrett-eclipse.
Fixes #50805.


git-svn-id: https://develop.svn.wordpress.org/trunk@49031 602fd350-edb4-49c9-b593-d223f7449a82
2020-09-21 22:52:29 +00:00
Sergey Biryukov
e8617468a2 Tests: Fix typo in some markTestSkipped() messages.
See #51344.

git-svn-id: https://develop.svn.wordpress.org/trunk@49030 602fd350-edb4-49c9-b593-d223f7449a82
2020-09-21 20:18:20 +00:00
Sergey Biryukov
310799a268 Tests: Use consistent trailing punctuation in markTestSkipped() messages.
See #51344.

git-svn-id: https://develop.svn.wordpress.org/trunk@49027 602fd350-edb4-49c9-b593-d223f7449a82
2020-09-21 14:05:23 +00:00
Sergey Biryukov
6242c634ee Tests: Convert a few more function_exists() and extension_loaded() checks to @requires annotations.
This better utilizes the PHPUnit native functionality.

Follow-up to [49024].

See #50639, #50640.

git-svn-id: https://develop.svn.wordpress.org/trunk@49025 602fd350-edb4-49c9-b593-d223f7449a82
2020-09-21 13:25:38 +00:00
Sergey Biryukov
b984a64c98 Tests: Convert the checks for imagejpeg() function availability to use the @requires annotation.
This better utilizes the PHPUnit native functionality.

Props ayeshrajans, jrf, johnbillion.
Fixes #50639. See #50640.

git-svn-id: https://develop.svn.wordpress.org/trunk@49024 602fd350-edb4-49c9-b593-d223f7449a82
2020-09-21 11:34:06 +00:00
Sergey Biryukov
8856579610 Tests: Correctly unset non-supported image editor engines in some image tests.
Follow-up to [49009], [49014].

See #50639, #50640.

git-svn-id: https://develop.svn.wordpress.org/trunk@49018 602fd350-edb4-49c9-b593-d223f7449a82
2020-09-20 14:13:04 +00:00
Sergey Biryukov
e92ddaa2c3 Tests: Use more specific assertions in Tests_Image_Functions::test_load_directory().
This avoids an error on PHP 8 caused by calling `get_resource_type()` on a string.

See #50913.

git-svn-id: https://develop.svn.wordpress.org/trunk@49015 602fd350-edb4-49c9-b593-d223f7449a82
2020-09-20 13:31:08 +00:00
Sergey Biryukov
68b71263f3 Tests: Optimize some image tests to avoid checking for image editor engines availability twice.
Follow-up to [49009].

See #50639, #50640.

git-svn-id: https://develop.svn.wordpress.org/trunk@49014 602fd350-edb4-49c9-b593-d223f7449a82
2020-09-20 13:25:07 +00:00
Sergey Biryukov
8493793928 Tests: Consistently require imagejpeg() function in image_make_intermediate_size() tests.
This outputs a proper message if the requirement is not met, instead of an obscure PHP error further in the test.

See #50639, #50640.

git-svn-id: https://develop.svn.wordpress.org/trunk@49010 602fd350-edb4-49c9-b593-d223f7449a82
2020-09-20 03:31:46 +00:00
Sergey Biryukov
58385f1402 Tests: Skip some image tests if neither GD nor Imagick image editor engines are supported on the system.
The explicit message brings some consistency with other image editor tests, specifically the ones using the `WP_Image_UnitTestCase` class.

Previously, the tests were marked as "risky" in that scenario, due to performing no assertions.

See #50639, #50640.

git-svn-id: https://develop.svn.wordpress.org/trunk@49009 602fd350-edb4-49c9-b593-d223f7449a82
2020-09-20 02:45:35 +00:00
Sergey Biryukov
2bfa83d882 Coding Standards: Fix WPCS issue in [49007].
See #50913.

git-svn-id: https://develop.svn.wordpress.org/trunk@49008 602fd350-edb4-49c9-b593-d223f7449a82
2020-09-20 01:16:57 +00:00
Sergey Biryukov
cdd15a8f77 Tests: Fix the failures in REST API format keyword validation tests on PHP 8.
The tests ensure that `rest_sanitize_value_from_schema()` and `rest_validate_value_from_schema()` throw an "undefined offset" notice when the required `type` schema keyword is not passed.

In PHP 8, that notice is now a warning, so the tests need to be adjusted accordingly.

Follow-up to [48300], [48993].

See #50913.

git-svn-id: https://develop.svn.wordpress.org/trunk@49007 602fd350-edb4-49c9-b593-d223f7449a82
2020-09-20 00:55:07 +00:00
Sergey Biryukov
835e9c48a4 Tests: Add missing @covers tags for files in phpunit/tests/functions/.
Props pbearne, jrf.
See #39265.

git-svn-id: https://develop.svn.wordpress.org/trunk@49006 602fd350-edb4-49c9-b593-d223f7449a82
2020-09-19 15:52:03 +00:00
Sergey Biryukov
898eb5fc51 Tests: Speed up slashed data tests by reusing some more shared fixtures.
Follow-up to [35249], [49003].

See #51344.

git-svn-id: https://develop.svn.wordpress.org/trunk@49005 602fd350-edb4-49c9-b593-d223f7449a82
2020-09-19 11:11:00 +00:00
Sergey Biryukov
4018e92c39 Coding Standards: Give the $id variable in slashed data tests a more descriptive name.
See #50767, #51344.

git-svn-id: https://develop.svn.wordpress.org/trunk@49004 602fd350-edb4-49c9-b593-d223f7449a82
2020-09-19 10:53:15 +00:00
Sergey Biryukov
ffc129395c Tests: Speed up slashed data tests by reusing shared fixtures.
Follow-up to [35249].

See #51344.

git-svn-id: https://develop.svn.wordpress.org/trunk@49003 602fd350-edb4-49c9-b593-d223f7449a82
2020-09-19 10:34:54 +00:00
Sergey Biryukov
0c5324df3b Tests: Speed up tests for wp_allow_comment() by reusing shared fixtures.
Props frank-klein.
Fixes #51216.

git-svn-id: https://develop.svn.wordpress.org/trunk@49002 602fd350-edb4-49c9-b593-d223f7449a82
2020-09-19 09:25:55 +00:00
Sergey Biryukov
1ec9dc6fa4 Tests: Simplify the logic in WP_UnitTestCase_Base::setUpBeforeClass() and ::tearDownAfterClass().
See #51344.

git-svn-id: https://develop.svn.wordpress.org/trunk@49001 602fd350-edb4-49c9-b593-d223f7449a82
2020-09-19 09:11:23 +00:00
Peter Wilson
1ffdfdaea7 Posts, Post Types: Ensure default terms are added by wp_publish_post().
Transitioning posts from `auto-draft` to `publish` via `wp_publish_post()` could result in published posts without the default category or custom taxonomy default terms.

Props frank-klein, TimothyBlynJacobs, peterwilsoncc.
Fixes #51292.



git-svn-id: https://develop.svn.wordpress.org/trunk@49000 602fd350-edb4-49c9-b593-d223f7449a82
2020-09-19 01:20:48 +00:00
Sergey Biryukov
2f491fba50 Tests: Simplify PluralFormsTest::test_exceptions().
Previously, the test had to use an older pattern for catching the generic `Exception` exceptions for compatibility with PHPUnit 3.6 on PHP 5.2.

Now that WordPress supports PHPUnit 5.4 as the minimum version, the `expectException()` method can be used directly.

Follow-up to [41725], [41730].

See #51344.

git-svn-id: https://develop.svn.wordpress.org/trunk@48999 602fd350-edb4-49c9-b593-d223f7449a82
2020-09-18 14:11:11 +00:00
Sergey Biryukov
ba20847ef5 Docs: Update the code example in WP_Ajax_UnitTestCase::dieHandler() DocBlock to use expectException().
Follow-up to [48996], [48997].

See #51344.

git-svn-id: https://develop.svn.wordpress.org/trunk@48998 602fd350-edb4-49c9-b593-d223f7449a82
2020-09-18 13:53:31 +00:00
Sergey Biryukov
5164bba5e2 Tests: Switch Ajax tests to use the expectException() method directly, instead of the WP_UnitTestCase_Base::setExpectedException() wrapper.
This brings some consistency with other tests.

Follow-up to [48996].

See #51344.

git-svn-id: https://develop.svn.wordpress.org/trunk@48997 602fd350-edb4-49c9-b593-d223f7449a82
2020-09-18 13:48:27 +00:00
Sergey Biryukov
d46af0956d Tests: Consistently use the expectException() method instead of the older @expectedException annotation.
See https://thephp.cc/news/2016/02/questioning-phpunit-best-practices

The method is available since PHPUnit 5.2, and WordPress currently supports PHPUnit 5.4 as the minimum version.

Follow-up to [48993].

See #51344.

git-svn-id: https://develop.svn.wordpress.org/trunk@48996 602fd350-edb4-49c9-b593-d223f7449a82
2020-09-18 13:22:22 +00:00
Sergey Biryukov
bc556578b3 Tests: Fix the failure in test_get_weekday_undefined_index() on PHP 8.
The test ensures that `WP_Locale::get_weekday()` throws an "undefined offset" notice when called with an incorrect `$weekday_number` parameter.

In PHP 8, that notice is now a warning, so the test needs to be adjusted accordingly.

See #50913.

git-svn-id: https://develop.svn.wordpress.org/trunk@48993 602fd350-edb4-49c9-b593-d223f7449a82
2020-09-18 10:56:27 +00:00
Sergey Biryukov
cb38bc973e Comments: Assign the array of comment data returned from the comments_pre_query filter to the comments property of the current WP_Comment_Query instance.
This avoids the performance overhead of calling `WP_Comment_Query::get_comments()` twice: first when creating the object instance, then to retrieve the filtered results.

This also makes the filter a bit more consistent with other similar filters, e.g. `posts_pre_query`, `terms_pre_query`, or `users_pre_query`.

Follow-up to [46086].

Props dinhtungdu, imath, spacedmonkey, adamsilverstein, SergeyBiryukov.
Fixes #50521.

git-svn-id: https://develop.svn.wordpress.org/trunk@48990 602fd350-edb4-49c9-b593-d223f7449a82
2020-09-17 19:53:47 +00:00
Sergey Biryukov
f5fc714cf6 Tests: Move the data_wp_site_query_meta_query() data provider next to the test it's used in.
See #50767.

git-svn-id: https://develop.svn.wordpress.org/trunk@48988 602fd350-edb4-49c9-b593-d223f7449a82
2020-09-17 11:28:05 +00:00
Sergey Biryukov
64a0a9f108 Docs: Correct comments in comments_pre_query, networks_pre_query, and sites_pre_query tests.
Follow-up to [44983], [46086].

See #50768.

git-svn-id: https://develop.svn.wordpress.org/trunk@48987 602fd350-edb4-49c9-b593-d223f7449a82
2020-09-17 11:18:39 +00:00
Sergey Biryukov
9cb0da3754 Formatting: Make sure links_add_target() adds the target attribute to the correct tag.
Previously, the attribute could unintentionally be added to a tag that starts with the same characters, e.g. `<aside>` instead of `<a>`.

Props antonlukin.
Fixes #51313.

git-svn-id: https://develop.svn.wordpress.org/trunk@48983 602fd350-edb4-49c9-b593-d223f7449a82
2020-09-17 10:12:32 +00:00
Sergey Biryukov
aadc1d70f2 Tests: Revert [48973].
These tests ensure that a `_doing_it_wrong()` notice is thrown when `wpdb::prepare()` is called incorrectly, but also that the function will still handle the provided input as correctly as possible.

Disabling these tests on PHP 8 hides a problem, i.e. the function will no longer throw a notice and handle things correctly, it will now cause a white screen of death due to a fatal error.

That is a backward compatibility break, and `wpdb::prepare()` should be updated instead to maintain the original behaviour on PHP 8.

Props jrf, ayeshrajans.
See #50913, #50639.

git-svn-id: https://develop.svn.wordpress.org/trunk@48979 602fd350-edb4-49c9-b593-d223f7449a82
2020-09-16 01:33:42 +00:00
Sergey Biryukov
b936a4131d Build/Test Tools: Restore the QUnit global in JSHint config for QUnit.
Follow-up to [47512], [48977].

See #51312, #37117.

git-svn-id: https://develop.svn.wordpress.org/trunk@48978 602fd350-edb4-49c9-b593-d223f7449a82
2020-09-15 10:07:29 +00:00
Sergey Biryukov
d9514d19f1 Build/Test Tools: Remove unused legacy globals from JSHint config for QUnit.
Follow-up to [47512].

Props TimoTijhof.
Fixes #51312. See #37117.

git-svn-id: https://develop.svn.wordpress.org/trunk@48977 602fd350-edb4-49c9-b593-d223f7449a82
2020-09-15 10:02:22 +00:00
Sergey Biryukov
91feaf04af Tests: Correct assertion in Tests_DB::test_prepare_incorrect_arg_count().
On failure, `wpdb::prepare()` returns either an empty string or `null`, not `false`.

The test only passed accidentally due to `assertEquals()` not performing a strict type check.

Follow-up to [41662].

See #38266.

git-svn-id: https://develop.svn.wordpress.org/trunk@48974 602fd350-edb4-49c9-b593-d223f7449a82
2020-09-13 15:19:40 +00:00
Sergey Biryukov
2d01fac875 Tests: Require PHP less than 8.0 for some wpdb tests.
These tests ensure that `wpdb::prepare()` throws a `_doing_it_wrong()` notice when called with an incorrect number of arguments, or with arguments of a wrong type.

PHP 8 introduces similar error messages natively, making these tests redundant on PHP 8.0 or later.

Follow-up to [41470], [41662].

See #50913.

git-svn-id: https://develop.svn.wordpress.org/trunk@48973 602fd350-edb4-49c9-b593-d223f7449a82
2020-09-13 02:47:20 +00:00
Sergey Biryukov
1a89e63838 Tests: Replace the native PHPUnit getMockForAbstractClass() and getMockBuilder() methods.
This avoids parse errors in PHPUnit internals due to `match` being a reserved keyword in PHP 8.

To run on PHP 8, the tests relying on these methods require PHPUnit 9.3 or later.

When the test suite is updated for compatibility with PHPUnit 9.x, these overrides can be removed.

See #50913, #50902.

git-svn-id: https://develop.svn.wordpress.org/trunk@48972 602fd350-edb4-49c9-b593-d223f7449a82
2020-09-13 02:36:48 +00:00
Sergey Biryukov
a85d190b00 Tests: Replace a few instances of assertNotEquals() with assertNotFalse().
See #38266.

git-svn-id: https://develop.svn.wordpress.org/trunk@48954 602fd350-edb4-49c9-b593-d223f7449a82
2020-09-07 04:11:54 +00:00
Sergey Biryukov
3a9e78c000 Tests: Remove the polyfill for assertNotFalse().
`assertNotFalse()` is available in PHPUnit since version 4.0.

The polyfill was introduced back when WordPress still supported PHP 5.2 and PHPUnit 3.6.x, and is now redundant.

Follow-up to [39919], [45058], [47880].

See #38266.

git-svn-id: https://develop.svn.wordpress.org/trunk@48953 602fd350-edb4-49c9-b593-d223f7449a82
2020-09-07 03:26:24 +00:00
Sergey Biryukov
5bad67bccf Tests: Add a polyfill for assertEqualsWithDelta() to WP_UnitTestCase and use it where appropriate.
`assertEqualsWithDelta()` was added in PHPUnit 7.5, while WordPress still supports PHPUnit 5.4.x as the minimum version.

See #38266.

git-svn-id: https://develop.svn.wordpress.org/trunk@48952 602fd350-edb4-49c9-b593-d223f7449a82
2020-09-07 03:12:17 +00:00
Timothy Jacobs
84d524e189 REST API: Extract WP_REST_Controller::get_endpoint_args_for_item_schema() to a standalone function.
This method is useful whenever a JSON Schema needs to be converted to a format suitable for argument validation with `WP_REST_Request`. Moving the logic into a standalone function allows developers to use it outside of the `WP_REST_Controller` context.

Props pentatonicfunk.
Fixes #50876. 


git-svn-id: https://develop.svn.wordpress.org/trunk@48951 602fd350-edb4-49c9-b593-d223f7449a82
2020-09-07 02:35:52 +00:00
Sergey Biryukov
83f23c4c4f Tests: Add a test case for storing false in the cache.
Follow-up to [20089], [48949].

See #38266.

git-svn-id: https://develop.svn.wordpress.org/trunk@48950 602fd350-edb4-49c9-b593-d223f7449a82
2020-09-06 04:23:46 +00:00
Sergey Biryukov
944a6845a2 Tests: Correct assertion in Tests_Cache::test_add_get_null().
It is possible to store `null` in the cache without it being converted to an empty string.

Follow-up to [20089].

Props johnbillion, SergeyBiryukov.
See #38266.

git-svn-id: https://develop.svn.wordpress.org/trunk@48949 602fd350-edb4-49c9-b593-d223f7449a82
2020-09-06 03:35:59 +00:00
Sergey Biryukov
6f07ff569b Tests: Correct assertion in Tests_Cache::test_miss().
On failure to retrieve contents, `WP_Object_Cache::get()` returns `false`, not `null`.

The test only passed accidentally due to `assertEquals()` not performing a strict type check.

Props johnbillion.
See #38266.

git-svn-id: https://develop.svn.wordpress.org/trunk@48948 602fd350-edb4-49c9-b593-d223f7449a82
2020-09-06 02:51:45 +00:00
Timothy Jacobs
d803f6bf82 REST API: Refactor WP_REST_Server::dispatch() to make internal logic reusable.
#50244 aims to introduce batch processing in the REST API. An important feature is the ability to enforce that all requests have valid data before executing the route callbacks in "pre-validate" mode.

This necessitates splitting `WP_REST_Server::dispatch()` into two methods so the batch controller can determine the request handler to perform pre-validation and then respond to the requests.

The two new methods, `match_request_to_handler` and `respond_to_request`, have a public visibility, but are marked as `@access private`. This is to allow for iteration on the batch controller to happen in the Gutenberg repository. Developers should not rely upon these methods, their visibility may change in the future.

See #50244.
Props andraganescu, zieladam, TimothyBlynJacobs.


git-svn-id: https://develop.svn.wordpress.org/trunk@48947 602fd350-edb4-49c9-b593-d223f7449a82
2020-09-05 21:50:31 +00:00
Timothy Jacobs
88ec90d6df REST API: Support a route-level validation callback.
Most request data is validated on a per-parameter basis. Often, however, additional validation is needed that operates on the entire request object. Currently, this is done in the route callback and often in the `prepare_item_for_database` method specifically.

#50244 aims to introduce batch processing in the REST API. An important feature is the ability to enforce that all requests have valid data before executing the route callbacks in "pre-validate" mode.

This patch introduces support for calling a `validate_callback` after all parameter validation has succeeded. That allows moving more validation outside of the route callback and into `WP_REST_Request` which will improve "pre-validate" support.

Props TimothyBlynJacobs, zieladam.
Fixes #51255.
See #50244.




git-svn-id: https://develop.svn.wordpress.org/trunk@48945 602fd350-edb4-49c9-b593-d223f7449a82
2020-09-05 18:07:46 +00:00
Sergey Biryukov
af437fcdc4 Tests: Replace a few more instances of assertEquals() with assertSame().
These were previously missed due to incorrect capitalization.

Follow-up to [48937], [48939], [48940].

See #38266.

git-svn-id: https://develop.svn.wordpress.org/trunk@48944 602fd350-edb4-49c9-b593-d223f7449a82
2020-09-05 16:47:50 +00:00
Sergey Biryukov
677af117a9 Comments: Rename WP_Comments_List_Table::comment_status_dropdown() to ::comment_type_dropdown().
This better reflects the purpose of the method, which doesn't have anything to do with a comment status.

Follow-up to [48521].

Props davidbaumwald, johnbillion, SergeyBiryukov.
Fixes #51248.

git-svn-id: https://develop.svn.wordpress.org/trunk@48943 602fd350-edb4-49c9-b593-d223f7449a82
2020-09-05 00:31:03 +00:00
Sergey Biryukov
3e111d9799 Tests: Replace a few more instances of assertEquals() with assertSame().
These were previously missed due to incorrect capitalization.

Follow-up to [48937], [48939].

See #38266.

git-svn-id: https://develop.svn.wordpress.org/trunk@48940 602fd350-edb4-49c9-b593-d223f7449a82
2020-09-04 07:36:33 +00:00
Sergey Biryukov
8be943d06e Tests: Introduce assertSameSets() and assertSameSetsWithIndex(), and use them where appropriate.
This ensures that not only the array values being compared are equal, but also that their type is the same.

These new methods replace most of the existing instances of `assertEqualSets()` and `assertEqualSetsWithIndex()`.

Going forward, stricter type checking by using `assertSameSets()` or `assertSameSetsWithIndex()` should generally be preferred, to make the tests more reliable.

Follow-up to [48937].

See #38266.

git-svn-id: https://develop.svn.wordpress.org/trunk@48939 602fd350-edb4-49c9-b593-d223f7449a82
2020-09-04 07:01:00 +00:00
Sergey Biryukov
164b22cf6a Tests: First pass at using assertSame() instead of assertEquals() in most of the unit tests.
This ensures that not only the return values match the expected results, but also that their type is the same.

Going forward, stricter type checking by using `assertSame()` should generally be preferred to `assertEquals()` where appropriate, to make the tests more reliable.

Props johnbillion, jrf, SergeyBiryukov.
See #38266.

git-svn-id: https://develop.svn.wordpress.org/trunk@48937 602fd350-edb4-49c9-b593-d223f7449a82
2020-09-02 00:35:36 +00:00
Sergey Biryukov
699e44cc76 Tests: Move the tests for get_the_modified_time() to a more appropriate place.
Add some new tests to better cover the functionality, for consistency with `get_the_date()` and `get_the_time()`.

Follow-up to [48911], [48912], [48918].

Props wittich.
Fixes #51184.

git-svn-id: https://develop.svn.wordpress.org/trunk@48924 602fd350-edb4-49c9-b593-d223f7449a82
2020-08-31 22:41:02 +00:00
Sergey Biryukov
3309309f6b Date/Time: Make sure get_the_date() and related functions return correct time if the format was specified as false.
Technically, the `$format` argument should always be a string, but passing `false` used to work before [47808], so this restores backward compatibility.

The list of affected functions:
* `get_the_date()`
* `get_the_time()`
* `get_comment_date()`
* `get_comment_time()`

Props wittich, Rarst, akabarikalpesh, SergeyBiryukov.
Fixes #51184.

git-svn-id: https://develop.svn.wordpress.org/trunk@48912 602fd350-edb4-49c9-b593-d223f7449a82
2020-08-31 15:56:41 +00:00
Sergey Biryukov
34dc1cc2c9 Tests: Bring some consistency to Date/Time tests:
* Move some tests from `post.php` to a more appropriate location in the `date` directory.
* Rename `date/postTime.php` to `date/getPostTime.php` to match the function name.

Props Rarst.
See #51184.

git-svn-id: https://develop.svn.wordpress.org/trunk@48911 602fd350-edb4-49c9-b593-d223f7449a82
2020-08-31 15:33:45 +00:00
Sergey Biryukov
d841231933 Tests: Reset the $wp_sitemap global after each test, so that sitemaps are re-initialized when the next test runs.
This ensures consistent results in query var tests, regardless of whether they are run in isolation or as part of a larger group of tests.

Props pbiron, peterwilsoncc.
Fixes #51154.

git-svn-id: https://develop.svn.wordpress.org/trunk@48908 602fd350-edb4-49c9-b593-d223f7449a82
2020-08-31 03:57:50 +00:00
Sergey Biryukov
73375c4b32 Tests: Move the tests for selected() and checked() to a more appropriate place.
Convert the tests to use data providers.

Props wittich.
Fixes #51166.

git-svn-id: https://develop.svn.wordpress.org/trunk@48907 602fd350-edb4-49c9-b593-d223f7449a82
2020-08-30 01:34:38 +00:00
Sergey Biryukov
0d26989e15 Tests: Update wp_add_inline_script() unit tests to account for the jquery handle being an alias for jquery-core again.
Follow-up to [48323], [48324], [48890].

Props davidbaumwald, audrasjb.
See #50919.

git-svn-id: https://develop.svn.wordpress.org/trunk@48892 602fd350-edb4-49c9-b593-d223f7449a82
2020-08-27 20:52:36 +00:00
Timothy Jacobs
6c76a13139 REST API: Fix multi-type schemas with integer fields.
In [48306] support for multi-typed schemas was improved to first detect the data type of the value before applying further validation. The `integer` data type was detected using the new `rest_is_integer` function. This function used logic, however, that assumed that the value had already passed an `is_numeric` check. This meant that if `integer` and `string` were both acceptable types, the value would always be considered an `integer` causing the later accurate type validation to fail.

This commit fixes the `rest_is_integer` logic to include an `is_numeric` check.

Props rtagliento.
Fixes #51146.


git-svn-id: https://develop.svn.wordpress.org/trunk@48881 602fd350-edb4-49c9-b593-d223f7449a82
2020-08-27 02:55:39 +00:00
Sergey Biryukov
c8b5610b91 Taxonomy: Make sure wp_terms_checklist() and Walker_Category_Checklist::start_el() properly handle an array of strings as selected_cats or popular_cats values.
Even with these values documented as an array of integers, they can technically also accept an array of strings, e.g. as form results.

Add a unit test.

Props brianhogg, TimothyBlynJacobs, SergeyBiryukov.
Fixes #51137.

git-svn-id: https://develop.svn.wordpress.org/trunk@48880 602fd350-edb4-49c9-b593-d223f7449a82
2020-08-27 02:46:22 +00:00
Sergey Biryukov
3f7add7d99 Tests: Update one more test to account for lazy-loading being disabled for custom logos by default.
Follow-up to [48870], [48874].

Props desrosj.
See #50933.

git-svn-id: https://develop.svn.wordpress.org/trunk@48878 602fd350-edb4-49c9-b593-d223f7449a82
2020-08-27 02:01:51 +00:00
Sergey Biryukov
c77798da22 Tests: Update unit tests to account for lazy-loading being disabled for custom logos by default.
Follow-up to [48870].

See #50933.

git-svn-id: https://develop.svn.wordpress.org/trunk@48874 602fd350-edb4-49c9-b593-d223f7449a82
2020-08-27 01:53:48 +00:00
Peter Wilson
bae635f1a0 Sitemaps: Prevent incorrect redirection of paged sitemap requests.
Update `redirect_canonical()` to account for custom pagination and URL format used by sitemaps in order to follow standard practices.

Introduce the function `get_sitemap_url()` to simplify getting the index and provider URLs as needed.

Props jonathanstegall, pbiron, GamerZ, salvoaranzulla, peterwilsoncc.
Fixes #50910.



git-svn-id: https://develop.svn.wordpress.org/trunk@48872 602fd350-edb4-49c9-b593-d223f7449a82
2020-08-27 01:28:24 +00:00
Sergey Biryukov
c20372e0aa Tests: Clean up some existing @covers tags.
The `()` at the end is unnecessary and disregarded by PHPUnit, so can be removed.

Props jrf.
See #39265.

git-svn-id: https://develop.svn.wordpress.org/trunk@48858 602fd350-edb4-49c9-b593-d223f7449a82
2020-08-25 00:57:17 +00:00
Sergey Biryukov
a6bb0120ac Tests: Correct a number of malformed @covers tags.
As per the documentation of the `@covers` tag, global functions being covered should be prefixed with `::`. Also, the `()` after the function name is redundant.

Follow-up to [39918].

Props jrf.
See #50267.

git-svn-id: https://develop.svn.wordpress.org/trunk@48848 602fd350-edb4-49c9-b593-d223f7449a82
2020-08-23 17:23:52 +00:00
Sergey Biryukov
631f440506 Tests: Update wp-api-generated.js to reflect the new "Reusable Blocks" post type label.
Follow-up to [48829].

See #50755.

git-svn-id: https://develop.svn.wordpress.org/trunk@48846 602fd350-edb4-49c9-b593-d223f7449a82
2020-08-23 14:38:40 +00:00
Sergey Biryukov
c90037ca47 Tests: Clear any previous term IDs from the metadata lazyloader queue in term meta lazy-loading test.
This fixes random test failures when one of the term IDs from previous tests coincides with the orphan term ID from this test that should not be lazy-loaded.

Follow-up to [34529], [36566].

Fixes #51109.

git-svn-id: https://develop.svn.wordpress.org/trunk@48844 602fd350-edb4-49c9-b593-d223f7449a82
2020-08-23 03:46:41 +00:00
Felix Arntz
0228dd6a5d Taxonomy: Allow for wp_count_terms( $args ) signature, making passing a taxonomy optional.
This brings `wp_count_terms()` in line with other taxonomy functions such as `get_terms()` which technically no longer require a taxonomy. Similar to the previously modified functions, no deprecation warning is triggered when using the legacy signature.

Fixes #36399.


git-svn-id: https://develop.svn.wordpress.org/trunk@48840 602fd350-edb4-49c9-b593-d223f7449a82
2020-08-21 22:30:06 +00:00
Sergey Biryukov
ca5c4cebef Coding Standards: Fix WPCS issue in [48830].
See #51044.

git-svn-id: https://develop.svn.wordpress.org/trunk@48831 602fd350-edb4-49c9-b593-d223f7449a82
2020-08-19 16:33:02 +00:00
Sergey Biryukov
62562f8428 Tests: Update unit tests to account for comment_agent and comment_author_IP values being passed to the preprocess_comment filter.
See #51044.

git-svn-id: https://develop.svn.wordpress.org/trunk@48830 602fd350-edb4-49c9-b593-d223f7449a82
2020-08-19 16:06:27 +00:00
Sergey Biryukov
76c599ced2 Formatting: Make the check for empty text in wp_trim_excerpt() more resilient.
This addresses a regression in [47808], which caused excerpts to be generated from post content if an empty string is passed, but not for other values considered empty, e.g. `null` or `false`.

Props riaanlom, laxman-prajapati, SergeyBiryukov.
Fixes #51042.

git-svn-id: https://develop.svn.wordpress.org/trunk@48817 602fd350-edb4-49c9-b593-d223f7449a82
2020-08-18 15:08:19 +00:00
Sergey Biryukov
cbaa88cb5a Code Modernization: Introduce is_gd_image() to check for PHP 8 GdImage object instances.
In PHP 8, the GD extension uses `GdImage` objects instead of resources for its underlying data structures.

This updates the existing `is_resource()` calls for image resources in core to accomodate for `GdImage` instances as well.

Props ayeshrajans, jrf.
Fixes #50833.

git-svn-id: https://develop.svn.wordpress.org/trunk@48798 602fd350-edb4-49c9-b593-d223f7449a82
2020-08-16 13:31:57 +00:00
Timothy Jacobs
dddddc47f4 REST API: Add uniqueItems as a permitted endpoint argument JSON Schema keyword.
Support for the `uniqueItems` keyword was added in [48357], but wasn't included in the list of permitted keywords for `WP_REST_Controller::get_endpoint_args_for_item_schema()`. This prevented the keyword from being automatically supported if specified in a controller's item schema.

Fixes #51021.


git-svn-id: https://develop.svn.wordpress.org/trunk@48796 602fd350-edb4-49c9-b593-d223f7449a82
2020-08-15 16:09:56 +00:00
Sergey Biryukov
9c220ffaf7 Code Modernization: Fix PHP 8 deprecation notices for optional function parameters declared before required parameters.
As it already was not possible to pass the required parameters without also passing the optional one anyway, removing the default value for the (not so) optional parameters should not affect backward compatibility.

This change affects three functions in core:

* `get_comment_delimited_block_content()`
* `do_enclose()`
* `_wp_delete_tax_menu_item()`

Props jrf, ayeshrajans, desrosj.
Fixes #50343.

git-svn-id: https://develop.svn.wordpress.org/trunk@48794 602fd350-edb4-49c9-b593-d223f7449a82
2020-08-15 13:38:52 +00:00
Sergey Biryukov
285d176f08 Tests: Consistently unregister custom settings after performing assertions in WP_Test_REST_Settings_Controller.
This ensures that those settings don't leak to other tests.

Props david.binda, TimothyBlynJacobs, SergeyBiryukov.
Fixes #50986.

git-svn-id: https://develop.svn.wordpress.org/trunk@48791 602fd350-edb4-49c9-b593-d223f7449a82
2020-08-14 16:33:24 +00:00
Sergey Biryukov
f0733600c9 Code Modernization: Change create_function() in phpunit/includes/plural-form-function.php to closure.
`create_function()` has been deprecated in PHP >= 7.2 and removed in PHP 8.

The only instance left in core was used in a test that was being skipped on PHP >= 7.2. This allows the test to run again.

Follow-up to [41722], [41730].

Props jrf.
Fixes #50899.

git-svn-id: https://develop.svn.wordpress.org/trunk@48790 602fd350-edb4-49c9-b593-d223f7449a82
2020-08-13 12:32:03 +00:00
Sergey Biryukov
1bf0a780b3 Code Modernization: Remove final keyword from private methods.
Declaring a `private` method as `final` is an oxymoron, as `private` methods cannot be overloaded anyway.

Using `final private function...` will generate a warning in PHP 8.

Props jrf.
Fixes #50897.

git-svn-id: https://develop.svn.wordpress.org/trunk@48788 602fd350-edb4-49c9-b593-d223f7449a82
2020-08-12 15:03:50 +00:00
Jake Spurlock
6ebff324b2 Themes: Update the test_theme_supports_custom_logo to check for the unlink-homepage-logo property.
See #37011, [48757].
Props TimothyBlynJacobs, whyisjake.


git-svn-id: https://develop.svn.wordpress.org/trunk@48758 602fd350-edb4-49c9-b593-d223f7449a82
2020-08-07 20:42:04 +00:00
Sergey Biryukov
def2425406 Comments: Update comment cache in the upgrade routine for changing the comment_type DB field value in comments table.
This ensures that comment object cache is cleared after changing the comment type to `comment` instead of an empty string.

Add a unit test for `_wp_batch_update_comment_type()`.

Follow-up to [47597], [47626], [48225], [48227].

Props imath, westonruter.
Fixes #49236.

git-svn-id: https://develop.svn.wordpress.org/trunk@48748 602fd350-edb4-49c9-b593-d223f7449a82
2020-08-07 14:27:40 +00:00
Sergey Biryukov
58f9000f3e Tests: Correct duplicate array keys in Tests_Kses::test_wp_filter_post_kses_address().
Previously, only the last `style` value was actually tested.

Props ediamin.
Fixes #50860.

git-svn-id: https://develop.svn.wordpress.org/trunk@48744 602fd350-edb4-49c9-b593-d223f7449a82
2020-08-06 13:26:06 +00:00
Sergey Biryukov
cded42aa94 Taxonomy: Rename the default_taxonomy_$taxonomy option key to default_term_$taxonomy.
This better reflects the purpose of the option.

Follow-up to [48356], [48480].

See #43517.

git-svn-id: https://develop.svn.wordpress.org/trunk@48665 602fd350-edb4-49c9-b593-d223f7449a82
2020-07-28 15:40:35 +00:00