Commit Graph

3743 Commits

Author SHA1 Message Date
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
Sergey Biryukov
6e66f08ec9 Taxonomy: Ensure the child_of argument of get_terms() works as expected with 'fields' => 'id=>name' or 'id=>slug'.
Props Howdy_McGee, deepaklalwani, planvova.
Fixes #46768.

git-svn-id: https://develop.svn.wordpress.org/trunk@48663 602fd350-edb4-49c9-b593-d223f7449a82
2020-07-28 14:21:54 +00:00
Timothy Jacobs
b29101aca0 REST API: Remove assets field from block directory controller.
Gutenberg no longer uses the assets field to fetch the assets for the installed block so this field can be dropped from the endpoint. This allows us to reintroduce it at a later point without needing to worry about backward compatibility.

See #50732.


git-svn-id: https://develop.svn.wordpress.org/trunk@48656 602fd350-edb4-49c9-b593-d223f7449a82
2020-07-28 04:08:56 +00:00
Jake Spurlock
8c9b33c3b6 Mail: PHPMailer swap to use is_email for the default validator.
Prior to the PHPMailer update in 5.5, old version of the PHPMailer was setting the validator to 'auto' resulting in a sophisticated logic for determining what email address validation should be used. But the new version defaults to 'php', possibly leading to rejection of email addresses which were fine prior to the upgrade. Let's use the WordPress core function `is_email()` so that it can be fully pluggable.

Fixes #50720.
Props david.binda, ayeshrajans, Synchro, SergeyBiryukov, whyisjake.


git-svn-id: https://develop.svn.wordpress.org/trunk@48645 602fd350-edb4-49c9-b593-d223f7449a82
2020-07-27 20:17:36 +00:00
Timothy Jacobs
5149a7efd5 REST API: Fix warning when using set_param() on a JSON request with no body.
In [47559] the `WP_REST_Request::set_param()` method was adjusted to try and overwrite an existing parameter definition before forcing the value in the first parameter slot. If `set_param()` was called on a request with an `application/json` content type and an empty body, a PHP warning would be issued. This was due to the JSON parameter type not being set to an array when the body is empty.

This commit avoids the warning by adding an `is_array()` check before calling `array_key_exists`. Ideally, `WP_REST_Reuest::parse_json_params()` would set the JSON parameter type to an empty array in this case, but that is too large of a change at this point in the cycle.

Props manooweb.
Fixes #50786.


git-svn-id: https://develop.svn.wordpress.org/trunk@48642 602fd350-edb4-49c9-b593-d223f7449a82
2020-07-27 18:44:14 +00:00
Sergey Biryukov
fc62131e31 Tests: Add more fixtures to get_lastpostdate() and get_lastpostmodified() tests.
Follow-up to [48631].

Props munyagu.
See #47777.

git-svn-id: https://develop.svn.wordpress.org/trunk@48633 602fd350-edb4-49c9-b593-d223f7449a82
2020-07-27 11:15:04 +00:00
Sergey Biryukov
581deff371 Posts, Post Types: Pass the post type to get_lastpostdate() in get_lastpostmodified().
This ensures that the correct values are being compared when retrieving the result for custom post types.

Additionally, pass the `$post_type` parameter to `get_lastpostdate` and `get_lastpostmodified` filters.

Props mikaumoto, munyagu, donmhico, johnbillion, SergeyBiryukov.
Fixes #47777.

git-svn-id: https://develop.svn.wordpress.org/trunk@48631 602fd350-edb4-49c9-b593-d223f7449a82
2020-07-27 02:16:46 +00:00
Sergey Biryukov
40dd42c35d REST API: Use a consistent name for the textdomain schema property between plugins, themes, and block directory controllers.
Follow-up to [48242].

See #50321, #50776.

git-svn-id: https://develop.svn.wordpress.org/trunk@48627 602fd350-edb4-49c9-b593-d223f7449a82
2020-07-26 21:47:56 +00:00
Sergey Biryukov
6fa3286a1b Pings/Trackbacks: Avoid a PHP notice in do_enclose() when encountering a URL without a path in post content.
Props jbouganim, mukesh27, Otto42, SergeyBiryukov.
Fixes #49872.

git-svn-id: https://develop.svn.wordpress.org/trunk@48621 602fd350-edb4-49c9-b593-d223f7449a82
2020-07-26 14:06:03 +00:00
Sergey Biryukov
674e7a2283 Tests: Update wp_unique_filename() unit tests to account for sanitize_file_name() removing accents.
Follow-up to [48603].

See #22363.

git-svn-id: https://develop.svn.wordpress.org/trunk@48604 602fd350-edb4-49c9-b593-d223f7449a82
2020-07-24 18:17:49 +00:00
Sergey Biryukov
c7783dc49a Media: Remove accents in sanitize_file_name().
This brings some consistency with `sanitize_title()` and `sanitize_user()`.

Props tar.gz, NumidWasNotAvailable, juliobox, p_enrique, cristovaov, zodiac1978, mikeschroder, markoheijnen, chriscct7, swissspidy, DrProtocols, pento, gitlost, joemcgill, dustinbolton, programmin, Vayu, MaximeCulea, lucasbustamante, nilovelez, RavanH, audrasjb, SergeyBiryukov.
See #22363.

git-svn-id: https://develop.svn.wordpress.org/trunk@48603 602fd350-edb4-49c9-b593-d223f7449a82
2020-07-24 18:01:48 +00:00
Sergey Biryukov
3ebdc35d36 Media: Filter out a few more special characters in sanitize_file_name().
Props audrasjb.
Fixes #50231.

git-svn-id: https://develop.svn.wordpress.org/trunk@48596 602fd350-edb4-49c9-b593-d223f7449a82
2020-07-24 00:57:26 +00:00
Sergey Biryukov
f2d98192de Formatting: Filter out the bullet character in sanitize_title_with_dashes().
Props roytanck, deepaklalwani, veromary.
Fixes #49791.

git-svn-id: https://develop.svn.wordpress.org/trunk@48593 602fd350-edb4-49c9-b593-d223f7449a82
2020-07-24 00:01:32 +00:00
Sergey Biryukov
1ef40b14cd Build/Test Tools: Check if all the required constants are defined before running the test suite.
Follow-up to [47904].

Props azaozz, TimothyBlynJacobs, SergeyBiryukov.
Fixes #50251.

git-svn-id: https://develop.svn.wordpress.org/trunk@48592 602fd350-edb4-49c9-b593-d223f7449a82
2020-07-23 23:26:50 +00:00