4335 Commits

Author SHA1 Message Date
Sergey Biryukov
90b6ae9943 Tests: Update the Services_JSON test for PHPUnit 9.5.10/8.5.21+.
Since PHPUnit 9.5.10 and 8.5.21, PHP deprecations are no longer converted to exceptions by default (`convertDeprecationsToExceptions="true"` can be configured to enable this).

Reference: [fac02620f6 Do not convert PHP deprecations to exceptions by default]; [https://github.com/sebastianbergmann/phpunit/blob/9.5.10/ChangeLog-9.5.md#9510---2021-09-25 PHPUnit 9.5.10 changelog].

With this change, the test for the `Services_JSON` compat class started failing:
{{{
There was 1 failure:

1) Tests_Compat_jsonEncodeDecode::test_json_encode_decode
Failed asserting that exception of type "PHPUnit\Framework\Error\Deprecated" is thrown.
}}}

This converts the native PHPUnit `::expectDeprecation()` method call in the test to a set of individual WP-specific `::setExpectedDeprecated()` method calls in order to not depend on PHPUnit behavior that is no longer the default.

Additionally, this commit includes support for catching deprecation notices from `_deprecated_file()` function calls to the `WP_UnitTestCase_Base::expectDeprecated()` method.

Follow-up to [46205], [46625], [48996], [51563], [51852], [51871].

Props jrf, netweb, SergeyBiryukov.
See #54183, #54029, #53363.

git-svn-id: https://develop.svn.wordpress.org/trunk@51872 602fd350-edb4-49c9-b593-d223f7449a82
2021-09-26 03:27:10 +00:00
Sergey Biryukov
7c2b54e027 Build/Test Tools: Update PHPUnit configuration for PHPUnit 9.5.10/8.5.21+.
Since PHPUnit 9.5.10 and 8.5.21, PHP deprecations are no longer converted to exceptions by default (`convertDeprecationsToExceptions="true"` can be configured to enable this).

Reference: [fac02620f6 Do not convert PHP deprecations to exceptions by default]; [https://github.com/sebastianbergmann/phpunit/blob/9.5.10/ChangeLog-9.5.md#9510---2021-09-25 PHPUnit 9.5.10 changelog].

Let's unpack this:

Previously (PHPUnit < 9.5.10/8.5.21), if PHPUnit would encounter a PHP native deprecation notice, it would:
1. Show a test which causes a deprecation notice to be thrown as **"errored"**,
2. Show the **first** deprecation notice it encountered and
3. PHPUnit would exit with a **non-0 exit code** (2), which will fail a CI build.

As of PHPUnit 9.5.10/8.5.21, if PHPUnit encounters a PHP native deprecation notice, it will no longer do so. Instead PHPUnit will:
1. Show a test which causes a PHP deprecation notice to be thrown as **"risky"**,
2. Show the **all** deprecation notices it encountered and
3. PHPUnit will exit with a **0 exit code**, which will show a CI build as passing.

This commit reverts PHPUnit to the previous behaviour by adding `convertDeprecationsToExceptions="true"` to the PHPUnit configuration. It also adds the other related directives for consistency.

Props jrf, netweb, costdev, SergeyBiryukov.
See #54183.

git-svn-id: https://develop.svn.wordpress.org/trunk@51871 602fd350-edb4-49c9-b593-d223f7449a82
2021-09-26 03:11:18 +00:00
Sergey Biryukov
e0359da2c1 Tests: Don't skip some Ajax tests on multisite, add them to the ms-excluded group instead.
Follow-up to [46693], [49835].

See #53363.

git-svn-id: https://develop.svn.wordpress.org/trunk@51870 602fd350-edb4-49c9-b593-d223f7449a82
2021-09-26 00:12:56 +00:00
Sergey Biryukov
364dfec369 Tests: Remove unnecessary setUp() and tearDown() methods in multisite tests.
These were originally added in [26252] to suppress database errors on `setUp()` and restore on `tearDown()` for tests that call `wpmu_create_blog()`, blog factory, or installation code that attempts to clear transients.

As the multisite test coverage expanded, these methods ended up being unnecessarily copied into other test classes, where database error suppression is not required.

Follow-up to [26252], [29916], [30286], [33184], [34898], [34899], [34901], [37234], [37477], [37894], [49212], [49616], [51859].

See #53363.

git-svn-id: https://develop.svn.wordpress.org/trunk@51869 602fd350-edb4-49c9-b593-d223f7449a82
2021-09-25 01:27:47 +00:00
Sergey Biryukov
3546c694e9 Tests: Rename classes in phpunit/tests/multisite/ per the naming conventions.
https://make.wordpress.org/core/handbook/testing/automated-testing/writing-phpunit-tests/#naming-and-organization

Follow-up to [47780], [48911], [49327], [50291], [50292], [50342], [50452], [50453], [50456], [50967], [50968], [50969], [51491], [51492], [51493], [51623], [51639], [51646], [51650], [51651].

See #53363.

git-svn-id: https://develop.svn.wordpress.org/trunk@51860 602fd350-edb4-49c9-b593-d223f7449a82
2021-09-24 00:45:43 +00:00
Sergey Biryukov
80a345f5b2 Tests: Further improve the tests for avoid_blog_page_permalink_collision():
* Rename the test filename and class to match the name of the function being tested.
* Remove unnecessary `setUp()` and `tearDown()` methods.
* Replace the `only` test group with `post`.

Follow-up to [51855-51857].

See #51147.

git-svn-id: https://develop.svn.wordpress.org/trunk@51859 602fd350-edb4-49c9-b593-d223f7449a82
2021-09-24 00:29:46 +00:00
Sergey Biryukov
a12706381b Tests: Correct the @ticket reference in wp_terms_checklist() tests.
Follow-up to [48880].

See #53363, #51137.

git-svn-id: https://develop.svn.wordpress.org/trunk@51858 602fd350-edb4-49c9-b593-d223f7449a82
2021-09-24 00:12:47 +00:00
Tonya Mork
3f6ba8aeb3 Build/Test Tools: Upgrades Tests_Multisite_MS_Permalink_Collision fixture methods and strict assertion.
Improvements include:

- Upgrades the test fixture methods to the new snake_case methods.
- Reorders the fixture methods for consistency.
- Uses strict assertions of assertSame and assertNotSame.

Follow-up to [51855-51856].

Props hellofromTonya.
See #51147.

git-svn-id: https://develop.svn.wordpress.org/trunk@51857 602fd350-edb4-49c9-b593-d223f7449a82
2021-09-23 21:29:07 +00:00
Jake Spurlock
bf705d99e6 Coding Standards: Fix the alignment of the array.
Unprops: whyisjake.
See [51855].


git-svn-id: https://develop.svn.wordpress.org/trunk@51856 602fd350-edb4-49c9-b593-d223f7449a82
2021-09-23 20:33:57 +00:00
Jake Spurlock
5bc2752524 Posts, Post Types: Don't add a trailing number when there is a unique post parent.
WordPress tries to avoid an issue where slugs might match an existing slug of a page/post. 
If we are in a hierarchical post type, there will be a level, and we can leave it the same.

Props stormrockwell, SergeyBiryukov, terriann, tubys, jeremyfelt, Daschmi, MaximeCulea, knutsp, whyisjake.
Fixes #51147.
See also #44112 and #45260.


git-svn-id: https://develop.svn.wordpress.org/trunk@51855 602fd350-edb4-49c9-b593-d223f7449a82
2021-09-23 20:26:28 +00:00
Tonya Mork
237efb5304 Build/Test Tools: Splits and improves compat tests.
Splits the tests in the `tests/phpunit/tests/compat.php` file up into individual test classes for each function being tested.

Improvements to individual test cases:
* Adds `@covers` tags.
* Adds visibility modifiers to all methods.
* Adds function availability test.
* Where relevant, fixes the assertion parameter order.
* Data provider:
   * Where relevant, reworks a test to use a data provider.
   * Where relevant, renames data provider methods to have a more obvious link to the test it applies to.
   * Makes the data provider more readable by adding keys within the data sets.
   * Moves the data provider below its associated tests.
   * Adds/removes data sets in data providers.
* Makes the actual test code more readable by using descriptive variables and multi-line function calls.
* Adds the `$message` parameter to all assertions when a test method contains more than one assertion.

Specifically for the `_mb_substr()` tests:
* Splits the `test_mb_substr_phpcore()` method into two test methods based on the PHP Core test files they are emulating.
* Makes the actual test code within the `test_mb_substr_phpcore_basic()` method more readable by using descriptive variables and multi-line function calls.
* Splits the data used for the second part of the `test_mb_substr_phpcore()` function, now `test_mb_substr_phpcore_input_type_handling()`, off into a separate data provider with named data sets.
* Removes duplicate data sets from the `data_mb_substr_phpcore_input_type_handling()`. 
   * Why? The PHP native tests test against upper/lowercase `false`, `true`, `null` and some other text string single quote/double quote variations. As things were, those differentiations had been undone when the coding standards were put in place, so in effect those weren't being tested anymore. And as this is userland code, there's no point in adding these differentiations back as they will be handled the same by PHP anyway (and that is safeguarded via the PHP native tests).
* Removes the "undefined variable" and "unset variable" test cases as, while those are relevant to the C code in which PHP is written, they are not relevant for testing userland code and will behave the same as the test passing `null`.

Follow-to [25002], [32364], [42228], [42343], [43034], [43036], [43220], [43571], [45607], [47122], [47198], [48937], [48996], [51415], [51563], [51594].

Props jrf, hellofromTonya.
See #39265, #53363.

git-svn-id: https://develop.svn.wordpress.org/trunk@51852 602fd350-edb4-49c9-b593-d223f7449a82
2021-09-22 23:05:59 +00:00
Tonya Mork
81ade4da65 Build/Test Tools: Fix null handling and string type casting in WP_UnitTestCase_Base::assertSameIgnoreEOL().
Basically, the whole `assertSameIgnoreEOL()` assertion was fundamentally flawed. The assertion contends that it checks that the expected and actual values are of the same type and value, but the reality was very different.

* The function uses `map_deep()` to potentially handle all sorts of inputs.
* `map_deep()` handles arrays and objects with special casing, but will call the callback on everything else without further distinction.
* The callback used passes the expected/actual value on to the `str_replace()` function to remove potential new line differences.
* And the `str_replace()` function will - with a non-array input for the `$subject` - always return a string.
* The output of these calls to `map_deep()` will therefore have "normalized" _all properties_ in objects, _all values_ in arrays and _all non-object, non-array values_ to strings.
* And a call to `assertSame()` will therefore NEVER do a proper type check as the type of all input has already, unintentionally, been "normalized" to string.

Aside from this clear flaw in the design of the assertion, PHP 8.1 now exposes a further issue as a `null` value for an object property, an array value or a plain value, will now yield a ` str_replace(): Passing null to parameter #3 ($subject) of type array|string is deprecated` notice.

To fix both these issues, the fix in this PR ensures that the call to `str_replace()` will now only be made if the input is a text string.
All other values passed to the callback are left in their original type.

This ensures that a proper value AND type comparison can be done as well as prevents the PHP 8.1 deprecation notices.

Ref:
* https://developer.wordpress.org/reference/functions/map_deep/
* https://www.php.net/manual/en/function.str-replace.php

This commit:
- Fixes type-casting of non-string values to `string` (the flawed part of this assertion) by invoking `str_replace()` when the value is of string type.
- Fixes the PHP 8.1 `str_replace(): Passing null to parameter #3 ($subject) of type array|string is deprecated` deprecation notice.
- Micro-optimization: skips `map_deep()` when actual and/or expected are `null` (no need to process).
- Adjusts the method documentation for both this method and the `assertEqualsIgnoreEOL()` alias method to document that the `$expected` and `$actual` parameters can be of any type.

Follow-up to [48937], [51135], [51478].

Props jrf, hellofromTonya.
See #53363, #53635.

git-svn-id: https://develop.svn.wordpress.org/trunk@51831 602fd350-edb4-49c9-b593-d223f7449a82
2021-09-20 19:58:09 +00:00
Tonya Mork
cece2cca5e REST API: Fix autovivification deprecation notice in WP_Test_REST_Widgets_Controller::set_up().
If the `'widget_testwidget'` option does not exist, `false` was returned from `get_option()`. The `set_up()` logic expects an `array()` and assigns values to keys without checking for an array. The automatic creation of an array (autovivification) triggers a `Deprecated: Automatic conversion of false to array is deprecated in` deprecation notice on PHP 8.1.

This commit:
- Fixes the deprecation notice by making the default value an empty array.
- Moves getting the option within the conditional where it's needed.
- Provides a micro-optimization by only getting the options when the conditions are correct for processing.
- Makes the code consistent within the `set_up()` for both `get_option()` instances.

Follow-up to [51029].

Props jrf, hellofromTonya, BinaryKitten.
See #53635.

git-svn-id: https://develop.svn.wordpress.org/trunk@51830 602fd350-edb4-49c9-b593-d223f7449a82
2021-09-20 18:48:47 +00:00
Tonya Mork
fe9f6a29ac Build/Test Tools: Improve Composer update command in bootstrap error messages.
Refines the test bootstrap error message to include the `-W` in the Composer update command.

Why?

To also update the chain of dependencies for the tests' dependencies. 

`composer update` will update the tests' direct dependencies.
 
`composer update -W` will update the dependencies including *their* dependencies, which is the recommended course of action for WP.

Follow-up to [51598], [51811], [51813].

Props jrf.
See #46149.

git-svn-id: https://develop.svn.wordpress.org/trunk@51828 602fd350-edb4-49c9-b593-d223f7449a82
2021-09-20 16:44:00 +00:00
Tonya Mork
97790af164 Options, Meta APIs: Fix "passing null to non-nullable" deprecations to (get|add|update|delete)_option().
In all four of the `get_option()`, `add_option()`, `update_option()` and `delete_option()` functions, the `$option` parameter (i.e. the option name) is passed to the PHP native `trim()` function without prior input validation.

In PHP 8.1, this could lead to a `trim(): Passing null to parameter #1 ($string) of type string is deprecated` for each of these functions.

`trim()`:

- expects a text string and is only useful when ''passed'' a text string as no other variable type can contain whitespace.
- will always return a `string`, which means that in practice for any non-string values passed, it would effectively function as a type cast to string.

This commit:
- Adds a check to verify the `$option` name is a scalar before processing it with `trim()`.
- The "type cast" behavior is maintained.
- If the given `$option` name is not a scalar, such as `null`, the fix prevents the PHP 8.1 deprecation notice.
- Tests are added for valid but undesired option names to safeguard against regressions.

This issue is already covered by:
- the existing `Tests_Option_Option::test_bad_option_names()` test group.
- the new `test_valid_but_undesired_option_names()` tests.

Follow-up to [13858], [22633], [23510], [25002], [51817].

Props jrf, hellofromTonya, pbearne.
See #53635.

git-svn-id: https://develop.svn.wordpress.org/trunk@51818 602fd350-edb4-49c9-b593-d223f7449a82
2021-09-15 22:18:36 +00:00
Tonya Mork
07a7b4262b Build/Test Tools: Reworks Tests_Option_Option::test_bad_option_names() into data provider.
The existing tests were running multiple functions through a `foreach()`. If any test failed, it would bail out and not test against the other scenarios.

This commit:

- Moves the scenarios to a data provider with named data sets, i.e. to ensure all scenarios are run and tested regardless if any fail.
- Splits each function under test into individual test methods.
- Adds a float scenario.
- Adds method visibility modifiers.

Follow-up to [25002].

Props jrf, hellofromTonya, pbearne.
See #53635.

git-svn-id: https://develop.svn.wordpress.org/trunk@51817 602fd350-edb4-49c9-b593-d223f7449a82
2021-09-15 21:21:58 +00:00
Tonya Mork
c0b328a74d Media: Fix $content parameter default value in img_caption_shortcode().
The shortcode content is expected to be a string, not `null`. `do_shortcode()` expects a string for `$content`.

The `img_caption_shortcode()` also expects a string for the `$content` parameter and is expected to return a string for the HTML content to display the caption. 

Prior to this commit:
The default value for the `$content` parameter was set to `null`. If no `$content` was passed, the function:
- could return `null` when the `$atts['width'] < 1` or there was no caption
- else, it invoked `do_shortcode( $content )` passing `null` which on PHP 8.1+ triggers a deprecation notice:
{{{
strpos(): Passing null to parameter #1 ($haystack) of type string is deprecated
}}}

This commit:

- Fixes the default `$content` value to align to the expected shortcode content of `string`, not `null`.
- Fixes the PHP 8.1 deprecation notice when `null` was being passed to `do_shortcode()`.
- Changes the assertion in a couple of tests to check for the empty string instead of `null.

Follow-up to [8196], [8925], [8239], [26915], [31530], [42704].

Props jrf, hellofromTonya, azaozz, joedolson.
See #53635.

git-svn-id: https://develop.svn.wordpress.org/trunk@51816 602fd350-edb4-49c9-b593-d223f7449a82
2021-09-15 19:05:20 +00:00
Tonya Mork
f44a995297 Build/Test Tools: Expect an absolute path in WP_TESTS_PHPUNIT_POLYFILLS_PATH constant.
This commit:
* Removes the use of `realpath()` to prevent issues with WSL and other virtualized filesystems.
* Changes the logic of the Polyfill bootstrap loading to expect an absolute path, rather than a relative path to the root directory of the PHPUnit Polyfills library.
* Adjusts the relevant inline documentation and error messages to expect an absolute path.
* Breaks up error messages into smaller line lengths for readability.

Follow-up to [51598], [51810], [51811], [51812].

Props jrf, schlessera, hellofromTonya, jeherve, lucatume.
See #46149.

git-svn-id: https://develop.svn.wordpress.org/trunk@51813 602fd350-edb4-49c9-b593-d223f7449a82
2021-09-14 18:52:57 +00:00
Tonya Mork
3062b3d803 Build/Test Tools: Improve messaging when PHPUnit Polyfills do not comply with version requirements.
Previously, two situations were taken in to account:
1. The `WP_TESTS_PHPUNIT_POLYFILLS_PATH` constant is defined => just show a message about the version mismatch.
2. The constant is not defined => show a message to run `composer update`. This message is intended for people trying to run the WP Core tests.

This could lead to an unclear situation for people trying to run plugin/theme integration tests without the new `WP_TESTS_PHPUNIT_POLYFILLS_PATH` constant being defined.

They could be shown the message to run `composer update` while if they would do so for their local install without adding the Polyfills, the message would still display the next time they would attempt to run the tests.

This commit:
1. Provides more information about the PHPUnit Polyfills version detected vs the version expected.
2. Shows a more specific message to guide users which have the `WP_TESTS_PHPUNIT_POLYFILLS_PATH` constant declared.
3. Only shows the message to run `composer update` when the `WP_RUN_CORE_TESTS` constant is declared to prevent confusing people more.

Follow-up to [51598], [51810], [51811].

Props jrf, schlessera, hellofromTonya, jeherve, lucatume.
See #46149.

git-svn-id: https://develop.svn.wordpress.org/trunk@51812 602fd350-edb4-49c9-b593-d223f7449a82
2021-09-14 18:47:46 +00:00
Tonya Mork
c3a3da800b Build/Test Tools: Improve messaging when PHPUnit Polyfills cannot be found.
Previously, two situations were taken in to account:
1. The `WP_TESTS_PHPUNIT_POLYFILLS_PATH` constant is defined => show message specific to that constant not being set correctly.
    This message would typically be shown for plugin/theme integration tests which are already aware of the changes in WP 5.9.
2. The constant is not defined => show a message to run `composer update`.
    This message is intended for people trying to run the WP Core tests.

This left two situations unaccounted for:
- Someone trying to run the WP Core tests, but not having set the `WP_RUN_CORE_TESTS` constant or not having set it to `1`.
- Someone trying to run plugin/theme integration tests without the new `WP_TESTS_PHPUNIT_POLYFILLS_PATH` constant being defined as they are not (yet) aware of the changes made in WP 5.9.

The changes made in this commit, are intended to improve the error messages displayed in those situations.

Follow-up to [51598], [51810].

Props jrf, schlessera, hellofromTonya, jeherve, lucatume.
See #46149.

git-svn-id: https://develop.svn.wordpress.org/trunk@51811 602fd350-edb4-49c9-b593-d223f7449a82
2021-09-14 18:40:30 +00:00
Tonya Mork
6f1a983d52 Build/Test Tools: Make WP_TESTS_PHPUNIT_POLYFILLS_PATH more flexible.
The constant `WP_TESTS_PHPUNIT_POLYFILLS_PATH` is intended to contain the path to the root directory of the PHPUnit Polyfills library without trailing slash.

The code already took into account that the value could potentially include a trailing slash.

Now it will also take into account if it is accidentally set to point to the autoload file instead of the path.

Follow-up to [51598].

Props jrf, schlessera, hellofromTonya, jeherve, lucatume.
See #46149.

git-svn-id: https://develop.svn.wordpress.org/trunk@51810 602fd350-edb4-49c9-b593-d223f7449a82
2021-09-14 18:32:39 +00:00
Tonya Mork
c64c2d77aa Tests: Fix "null to non-nullable" deprecation notice in Tests_Admin_IncludesPlugin::test_get_plugin_files_folder().
The `Tests_Admin_IncludesPlugin::_create_plugin()` expects the first parameter to be a text string to be written to a plugin file using `fwrite()`.

Passing null causes a `fwrite(): Passing null to parameter #2 ($data) of type string is deprecated` notice.

Ref: https://www.php.net/manual/en/function.fwrite

Follow-up to [31002]. [41806].

Props jrf, hellofromTonya.
See #53635.

git-svn-id: https://develop.svn.wordpress.org/trunk@51800 602fd350-edb4-49c9-b593-d223f7449a82
2021-09-10 17:26:42 +00:00
Tonya Mork
43de6d5cb5 Tests: Add tests for wpdb::_real_escape().
Adds a new dedicated test file.

Adds a test to check that various input types passed to `wpdb::_real_escape()` are handled correctly.

Note: This new test does not test the actual escaping or other logic in the function. Rather, it just and only tests and documents how the function handles various input types.

Props jrf, hellofromTonya.
See #53363.

git-svn-id: https://develop.svn.wordpress.org/trunk@51798 602fd350-edb4-49c9-b593-d223f7449a82
2021-09-10 16:29:24 +00:00
Tonya Mork
c556e0dbab Tests: Add more invalid IP test cases and @covers to Tests_Functions_Anonymization.
Adds a few more invalid IP test cases.

Adds extra `@covers` tag for the two functions which are testing the `wp_privacy_anonymize_ip()` function.

(At class level, the `wp_privacy_anonymize_data()` is set as covered).

Follow-up to [42971].

Props jrf, hellofromTonya.
See #53363.

git-svn-id: https://develop.svn.wordpress.org/trunk@51792 602fd350-edb4-49c9-b593-d223f7449a82
2021-09-09 22:43:49 +00:00
Tonya Mork
1d0e4441c1 Widgets: Revert [51705].
While the new name is much better, it doesn't fully tell what will happen when invoked nor does it fully solve the root problems. 

Why? The function is doing too much. And naming is hard.

Props azaozz, desrosj, andraganescu, zieladam, hellofromTonya.
See #53811.

git-svn-id: https://develop.svn.wordpress.org/trunk@51791 602fd350-edb4-49c9-b593-d223f7449a82
2021-09-09 21:39:39 +00:00
John Blackbourn
594079c5d1 Users: Introduce a meta_input argument for wp_insert_user().
This allows custom user meta values to be provided when creating or updating a user in the same way custom post meta can be provided to `wp_insert_post()` when creating or updating a post.

Also introduces the `insert_custom_user_meta` to filter these values.

Props desrosj, donmhico

Fixes #41950


git-svn-id: https://develop.svn.wordpress.org/trunk@51738 602fd350-edb4-49c9-b593-d223f7449a82
2021-09-07 21:30:07 +00:00
Tonya Mork
793bde1af7 Tests: Add missing @covers tags for Tests_Admin_wpCommunityEvents.
Adds missing and moves placement of existing @covers tags for consistency.

Follow-up to [40607], [42726], [49145].

Props pbearne, jrf, hellofromTonya.
See #39265.

git-svn-id: https://develop.svn.wordpress.org/trunk@51725 602fd350-edb4-49c9-b593-d223f7449a82
2021-09-01 22:26:33 +00:00
Tonya Mork
88cdf9f663 Tests: Add missing @covers tags for Tests_Admin_IncludesComment.
Follow-up to [34456], [34460].

Props pbearne, jrf, hellofromTonya.
See #39265.

git-svn-id: https://develop.svn.wordpress.org/trunk@51724 602fd350-edb4-49c9-b593-d223f7449a82
2021-09-01 21:58:32 +00:00
Tonya Mork
b7a495d337 Widgets: Rename and soft deprecate retrieve_widgets().
The original name `retrieve_widgets()` was unclear as it suggested it was a getter, i.e. getting the widgets. This function does more than get: finds orphaned widgets, assigns them to the inactive sidebar, and updates the database.

The new name is `sync_registered_widgets()` which better represents what happens when this function is invoked.

The original `retrieve_widgets()` function is soft deprecated to avoid unnecessary code churn downstream for developers that support more than the latest version of WordPress.

Follow-up to [18630].

Props zieladam, timothyblynjacobs, andraganescu, hellofromTonya.
See #53811.

git-svn-id: https://develop.svn.wordpress.org/trunk@51705 602fd350-edb4-49c9-b593-d223f7449a82
2021-08-31 19:57:20 +00:00
Andrew Ozz
1bbc5a4737 Media: apply the wp_editor_set_quality filter not only when loading an image in the editor but also when saving an converted image, after the mime-type of the output image has changed.
Props mikeschroder, desrosj, azaozz.
Fixes #53667.

git-svn-id: https://develop.svn.wordpress.org/trunk@51704 602fd350-edb4-49c9-b593-d223f7449a82
2021-08-31 18:57:09 +00:00
Tonya Mork
60d68fadbd Tests: Add missing @covers tags for actions' tests.
Props pbearne, hudson-atwell, jrf, hellofromTonya.
See #39265.

git-svn-id: https://develop.svn.wordpress.org/trunk@51702 602fd350-edb4-49c9-b593-d223f7449a82
2021-08-31 17:22:32 +00:00
Tonya Mork
30f9d4e136 Tests: Do whitespace replacement in assertDiscardWhitespace() only when string.
The `assertDiscardWhitespace()` method uses `assertEquals()` under the hood, meaning that in reality any type of actual/expected value should be accepted by the function. Fixed the documentation to reflect that.

At the same time, only strings can contain whitespace differences. So the whitespace replacement should only be done when string values are passed.

This change (a) prevents potential `passing null to non-nullable` errors on PHP 8.1, if either of the inputs would turn out to be `null` and (b) increases tests stability.

Follow-up to [35003], [44902].

Props jrf.
See #53363.

git-svn-id: https://develop.svn.wordpress.org/trunk@51698 602fd350-edb4-49c9-b593-d223f7449a82
2021-08-30 20:40:05 +00:00
Tonya Mork
877c39bb7f Tests: Test custom assertions parameter data type in WP_UnitTestCase_Base.
The following changes improve tests stability.

The `assertEqualFields()` method expects an object and a fields array as inputs and subsequently approaches the received parameters as such, but did not verify whether the received parameters are of the expected types.

Along the same lines, the `assertSameSets()`, `assertEqualSets()`, `assertSameSetsWithIndex()` and the `assertEqualSetsWithIndex()` methods all expect arrays for both the actual as well as the expected values and uses the array function `[k]sort()` on both, but never verified that the received inputs were actually arrays, which could lead to PHP errors on the sorting function calls.

Follow-up to [30687], [42343], [48937], [48939], [51480], [51481].

Props jrf.
See #53363.

git-svn-id: https://develop.svn.wordpress.org/trunk@51697 602fd350-edb4-49c9-b593-d223f7449a82
2021-08-30 20:18:31 +00:00
Tonya Mork
da835d6627 Code Modernization: Add input validation to _set_cron_array().
The private `_set_cron_array()` function expects a cron array as the first parameter, but will often be passed the - potentially updated - output of a call to `_get_cron_array()`.

When the `_get_cron_array()` function returns `false`, a "Deprecated: Automatic conversion of false to array is deprecated" warning will be thrown on PHP 8.1.

The input validation resolves the deprecation warning by setting the cron value to an empty array when not given an `array` data type.

Adds a full set of `_set_cron_array()` tests.

Follow-up to [4189], [50152].

Props jrf, hellofromTonya, peterwilsoncc.
See #53635.

git-svn-id: https://develop.svn.wordpress.org/trunk@51695 602fd350-edb4-49c9-b593-d223f7449a82
2021-08-30 15:19:38 +00:00
Jonathan Desrosiers
44180691e6 Editor: Ensure block attribute serialization in PHP matches the JavaScript equivalent.
The `serializeAttributes()` function in JavaScript uses `JSON.stringify`, which does not encode slashes and unicode characters by default. This resulted in the PHP serialization through `json_encode()` producing different results.

This also switches from `json_encode()` to `wp_json_encode()` to prevent failures when any non UTF-8 characters are included.

Props kevinfodness, SergeyBiryukov, timothyblynjacobs.
Fixes #53936.

git-svn-id: https://develop.svn.wordpress.org/trunk@51674 602fd350-edb4-49c9-b593-d223f7449a82
2021-08-26 19:09:16 +00:00
Tonya Mork
6201d437e8 Tests: Improve bootstrap error message for when ABSPATH folder does not exist.
The PHPUnit tests are/should generally be run on the `src` directory, so changes just made can be tested. While testing via the `build` directory is also still supported, this is not the default.

This was last changed in [50441], but that commit did not remove/update the error message thrown by the test bootstrap file.

This last change also did not take into account that that change meant that people had to update their own `wp`tests-config.php` file to match the change made in Core and would otherwise still get the outdated error message.

This commit changes the messaging in the test bootstrap file to be more in line with the current reality, while still accounting for the fact that tests can be run from both `src` as well as `build`.

Follow-up to [49569], [50441], [51581].
Props jrf, hellofromTonya.

git-svn-id: https://develop.svn.wordpress.org/trunk@51669 602fd350-edb4-49c9-b593-d223f7449a82
2021-08-26 17:55:02 +00:00
SergeyBiryukov
d616b931e0 Coding Standards: Add missing visibility keywords for wp_filter_object_list() and wp_list_pluck() tests.
Follow-up to [51663-51667].

Props pbearne.
See #53363, #53987.

git-svn-id: https://develop.svn.wordpress.org/trunk@51668 602fd350-edb4-49c9-b593-d223f7449a82
2021-08-26 16:50:02 +00:00
Sergey Biryukov
72de4966b8 Tests: Move wp_list_sort() tests to their own file.
This matches the name of the function being tested.

Follow-up to [38928], [51663-51666].

See #53363, #53987.

git-svn-id: https://develop.svn.wordpress.org/trunk@51667 602fd350-edb4-49c9-b593-d223f7449a82
2021-08-26 16:29:37 +00:00
Sergey Biryukov
cd1f879ced Tests: Move wp_list_filter() tests to their own file.
This matches the name of the function being tested.

Follow-up to [38928], [51663-51665].

See #53363, #53987.

git-svn-id: https://develop.svn.wordpress.org/trunk@51666 602fd350-edb4-49c9-b593-d223f7449a82
2021-08-26 16:20:57 +00:00
Sergey Biryukov
b683b830ab Tests: Rename the test file and class for wp_filter_object_list() tests.
This matches the name of the function being tested.

Follow-up to [410/tests], [51663], [51664].

See #53363, #53987.

git-svn-id: https://develop.svn.wordpress.org/trunk@51665 602fd350-edb4-49c9-b593-d223f7449a82
2021-08-26 16:08:48 +00:00
Sergey Biryukov
a90e7eb5ff Tests: Remove duplicate wp_list_pluck() tests.
The tests were partially duplicated in two separate files, and are now located in their own file.

Follow-up to [431/tests], [28900], [38928], [42527], [51663].

See #53363, #53987.

git-svn-id: https://develop.svn.wordpress.org/trunk@51664 602fd350-edb4-49c9-b593-d223f7449a82
2021-08-26 16:02:13 +00:00
Sergey Biryukov
927bc80b92 Tests: Move wp_list_pluck() tests to their own file.
The tests were partially duplicated in two separate files.

Follow-up to [431/tests], [28900], [38928], [42527].

See #53363, #53987.

git-svn-id: https://develop.svn.wordpress.org/trunk@51663 602fd350-edb4-49c9-b593-d223f7449a82
2021-08-26 15:54:29 +00:00
Tonya Mork
e83a341cc0 Coding Standards: Use static closures when not using $this.
When a closure does not use `$this`, it can be made `static` for improved performance.

Static closures are supported in PHP since PHP 5.4. ​

Props jrf, hellofromTonya, swissspidy, SergeyBiryukov.
See #53359.

git-svn-id: https://develop.svn.wordpress.org/trunk@51657 602fd350-edb4-49c9-b593-d223f7449a82
2021-08-26 12:57:08 +00:00
Andrew Ozz
67f8702477 Media: Fix wp_unique_filename() to check for name collisions with all alternate file names when an image may be converted after uploading. This includes possible collinions with pre-existing images whose sub-sizes/thumbnails are regenerated.
Props ianmjones, azaozz.
Fixes #53668.

git-svn-id: https://develop.svn.wordpress.org/trunk@51653 602fd350-edb4-49c9-b593-d223f7449a82
2021-08-24 20:50:21 +00:00
Sergey Biryukov
402e2e636b Tests: Rename classes in phpunit/tests/feed/ per the naming conventions.
https://make.wordpress.org/core/handbook/testing/automated-testing/writing-phpunit-tests/#naming-and-organization

Follow-up to [47780], [48911], [49327], [50291], [50292], [50342], [50452], [50453], [50456], [50967], [50968], [50969], [51491], [51492], [51493], [51623], [51639], [51646], [51650].

See #53363.

git-svn-id: https://develop.svn.wordpress.org/trunk@51651 602fd350-edb4-49c9-b593-d223f7449a82
2021-08-22 10:07:17 +00:00
Sergey Biryukov
43a8715ded Tests: Rename classes in phpunit/tests/error-protection/ per the naming conventions.
https://make.wordpress.org/core/handbook/testing/automated-testing/writing-phpunit-tests/#naming-and-organization

Follow-up to [47780], [48911], [49327], [50291], [50292], [50342], [50452], [50453], [50456], [50967], [50968], [50969], [51491], [51492], [51493], [51623], [51639], [51646].

See #53363.

git-svn-id: https://develop.svn.wordpress.org/trunk@51650 602fd350-edb4-49c9-b593-d223f7449a82
2021-08-21 15:32:53 +00:00
Andrew Ozz
fe3d953437 REST API: Remove trailing slashes when preloading requests and add unit tests for it.
Props antonvlasenko.
Fixes #51636.

git-svn-id: https://develop.svn.wordpress.org/trunk@51648 602fd350-edb4-49c9-b593-d223f7449a82
2021-08-20 23:43:21 +00:00
Sergey Biryukov
ee81f71ac6 Tests: Rename classes in phpunit/tests/editor/ per the naming conventions.
https://make.wordpress.org/core/handbook/testing/automated-testing/writing-phpunit-tests/#naming-and-organization

Follow-up to [47780], [48911], [49327], [50291], [50292], [50342], [50452], [50453], [50456], [50967], [50968], [50969], [51491], [51492], [51493], [51623], [51639].

See #53363.

git-svn-id: https://develop.svn.wordpress.org/trunk@51646 602fd350-edb4-49c9-b593-d223f7449a82
2021-08-20 16:11:04 +00:00
Sergey Biryukov
0778740cb4 Tests: Move loading the WP_Community_Events class to set_up_before_class().
This ensures that the class is loaded once before the first test of the test case class is run, and `require_once()` is not unnecessarily called for each test method individually.

Follow-up to [40607], [51628].

See #53363.

git-svn-id: https://develop.svn.wordpress.org/trunk@51641 602fd350-edb4-49c9-b593-d223f7449a82
2021-08-19 13:59:36 +00:00
Sergey Biryukov
e20beacb6e Tests: Rename classes in phpunit/tests/admin/ per the naming conventions.
https://make.wordpress.org/core/handbook/testing/automated-testing/writing-phpunit-tests/#naming-and-organization

Follow-up to [47780], [48911], [49327], [50291], [50292], [50342], [50452], [50453], [50456], [50967], [50968], [50969], [51491], [51492], [51493], [51623].

See #53363.

git-svn-id: https://develop.svn.wordpress.org/trunk@51639 602fd350-edb4-49c9-b593-d223f7449a82
2021-08-19 13:08:43 +00:00