Dynamic (non-explicitly declared) properties are deprecated as of PHP 8.2 and are expected to become a fatal error in PHP 9.0.
In this particular case, the test class contains a `set_up()` method that sets the `$post_type` property, which is ''used'' by the tests, but never ''changed'' by the tests.
In other words, setting this property in the `set_up()` is an unnecessary overhead and the property should be changed to a class constant.
Follow-up to [1212/tests], [52389], [53557], [53558], [53850], [53851], [53852].
Props jrf.
See #56033.
git-svn-id: https://develop.svn.wordpress.org/trunk@53853 602fd350-edb4-49c9-b593-d223f7449a82
Dynamic (non-explicitly declared) properties are deprecated as of PHP 8.2 and are expected to become a fatal error in PHP 9.0.
In this particular case, the test class contains a `set_up()` method that sets the `$img_meta` property, which is ''used'' by the tests, but never ''changed'' by the tests.
In other words, setting this property in the `set_up()` is an unnecessary overhead and the property should be changed to a class constant.
Includes renaming the test class to match the [https://make.wordpress.org/core/handbook/testing/automated-testing/writing-phpunit-tests/#naming-and-organization naming conventions].
Follow-up to [52190], [53557], [53558], [53850], [53851].
Props jrf.
See #56033.
git-svn-id: https://develop.svn.wordpress.org/trunk@53852 602fd350-edb4-49c9-b593-d223f7449a82
The dynamically created `$undefined` property appears to be a copy/paste from the `Tests_WP_Customize_Setting` class, and is not actually used in other test classes:
* `Tests_WP_Customize_Manager`
* `Tests_WP_Customize_Panel`
* `Tests_WP_Customize_Section`
Follow-up to [31329], [32658].
Props jrf.
See #56033.
git-svn-id: https://develop.svn.wordpress.org/trunk@53851 602fd350-edb4-49c9-b593-d223f7449a82
In this particular case, the test class contains a `set_up()` method which sets properties only used by select tests, while the fixture method is being run for all tests.
There were a few ways this could be fixed:
* As the values do not change across tests, use `set_up_before_class()` to set (static) properties instead.
* For those values which are set up without a function call or variable interpolation, set the values in class constants.
* Or set these values as local variables for those tests which actually use them.
The implemented solution is a combination of options 2 and 3.
Follow-up to [1106/tests], [53557], [53558].
Props jrf.
See #56033.
git-svn-id: https://develop.svn.wordpress.org/trunk@53850 602fd350-edb4-49c9-b593-d223f7449a82
Add a `wp_preload_resources` filter that developers can use to add resource preloading.
Preloading helps the browser discover and prioritize important resources earlier during the page load. This ensures that they are available earlier and are less likely to block the page's render.
Props nico23, swissspidy, igrigorik, westonruter, azaozz, furi3r, aristath, spacedmonkey, peterwilsoncc, mihai2u, gziolo.
Fixes#42438.
git-svn-id: https://develop.svn.wordpress.org/trunk@53846 602fd350-edb4-49c9-b593-d223f7449a82
This updates `wp_get_latest_revision_id_and_total_count()` and its usage to be a bit more descriptive and a bit less repetitive, e.g. `$revisions['latest_id']` instead of `$revision['revision']`.
Includes updating the `@return` tag to explain when the function returns a `WP_Error`.
Follow-up to [53759], [53769], [53778], [53779].
See #55857.
git-svn-id: https://develop.svn.wordpress.org/trunk@53841 602fd350-edb4-49c9-b593-d223f7449a82
Validate the requested sitemap is a string before attempting to use it in a provider. This prevents `WP_Sitemaps_Registry::get_provider()` from triggering a fatal error in more recent versions of PHP.
The errors can be triggered by items outside the site owner or developers control (such as a user visiting `?sitemap[foo]=bar`) so the code fails silently to avoid filling error logs with unfixable errors.
Props costdev, dd32.
Fixes#56336.
git-svn-id: https://develop.svn.wordpress.org/trunk@53838 602fd350-edb4-49c9-b593-d223f7449a82
There were two sets of tests for the function:
* One in the `link` directory, based on the `link-template.php` file name.
* One in the `term` directory, based on the component name.
To avoid confusion and make it easier to decide where new tests should go in the future, the existing tests are now combined in the former location.
Includes:
* Setting the current user in `::set_up()` instead of each individual test method.
* Changing the custom taxonomy name to `wptests_tax` for consistency with other tests.
* Moving `::register_custom_taxonomy()` and `::get_term()` helpers to the beginning of the class.
Follow-up to [32954], [36646], [52180], [52255], [53833].
See #55652.
git-svn-id: https://develop.svn.wordpress.org/trunk@53836 602fd350-edb4-49c9-b593-d223f7449a82
This makes the output when using the `--testdox` option more descriptive and is helpful when trying to debug which data set from a data provider failed the test.
Follow-up to [53818], [53821], [53822], [53834].
See #56198.
git-svn-id: https://develop.svn.wordpress.org/trunk@53835 602fd350-edb4-49c9-b593-d223f7449a82
A valid cache key for `wp_cache_*()` functions must be either an integer number or a non-empty string. To avoid potential compatibility issues or key collisions, a string that becomes empty after `trim()` should not be considered a valid cache key.
Follow-up to [53818], [53821], [53822].
Props tillkruess.
See #56198.
git-svn-id: https://develop.svn.wordpress.org/trunk@53834 602fd350-edb4-49c9-b593-d223f7449a82
* The tests use named data providers which include a flag for passing either a term ID or term object to the test, but the values for the flag were the opposite of what the array key says.
* Some array keys were duplicated, which means the earlier test case with the same name did not actually run.
Follow-up to [52180], [52255], [52258], [52305].
See #55652.
git-svn-id: https://develop.svn.wordpress.org/trunk@53833 602fd350-edb4-49c9-b593-d223f7449a82
The comment mentioned creating two cache objects with a shared cache directory, which was no longer the case.
Follow-up to [5/tests] [170/tests].
See #55646, #55652.
git-svn-id: https://develop.svn.wordpress.org/trunk@53831 602fd350-edb4-49c9-b593-d223f7449a82
This matches the location of other `wp_cache_*()` tests following the respective `WP_Object_Cache` method tests.
Follow-up to [1275/tests].
See #55652.
git-svn-id: https://develop.svn.wordpress.org/trunk@53830 602fd350-edb4-49c9-b593-d223f7449a82
This list was not up to date, and does not appear to be required, as `WP_UnitTestCase_Base::flush_cache()` adds the correct list of groups, which is up to date.
Follow-up to [1332/tests], [8068], [37613], [40561], [52976], [53826], [53828].
See #55652.
git-svn-id: https://develop.svn.wordpress.org/trunk@53829 602fd350-edb4-49c9-b593-d223f7449a82
This brings the list of persistent groups when running the test suite in line with core.
Follow-up to [1332/tests], [37613], [52976].
See #55652.
git-svn-id: https://develop.svn.wordpress.org/trunk@53828 602fd350-edb4-49c9-b593-d223f7449a82
This list was not up to date, and does not appear to be required, as `WP_UnitTestCase_Base::flush_cache()` adds the correct list of groups, which is up to date.
Follow-up to [1332/tests], [40343], [40561], [53823], [53824].
See #55652.
git-svn-id: https://develop.svn.wordpress.org/trunk@53826 602fd350-edb4-49c9-b593-d223f7449a82
This list was not up to date due to missing `blog_meta` group, and does not appear to be required for the tests to pass, as `WP_UnitTestCase_Base::flush_cache()` adds the same list of groups, which is up to date.
Follow-up to [946/tests], [1332/tests], [40343], [42836], [53823].
See #55647.
git-svn-id: https://develop.svn.wordpress.org/trunk@53824 602fd350-edb4-49c9-b593-d223f7449a82
A valid cache key for `wp_cache_*()` functions must be either an integer number or a non-empty string. To avoid potential compatibility issues or key collisions, float values should not be considered a valid cache key.
Follow-up to [53818], [53821].
Props tillkruess, malthert, spacedmonkey.
See #56198.
git-svn-id: https://develop.svn.wordpress.org/trunk@53822 602fd350-edb4-49c9-b593-d223f7449a82
A valid cache key for `wp_cache_*()` functions must be either an integer number or a non-empty string.
Follow-up to [53818].
See #56198.
git-svn-id: https://develop.svn.wordpress.org/trunk@53821 602fd350-edb4-49c9-b593-d223f7449a82
Some plugins may call the `wp_cache_*()` functions with an empty string, `false`, or `null` as cache key, usually as a result of not checking the return value of another function that's used as the key.
Previously, this was silently failing, leading to odd behavior at best and often breakage due to key collisions.
A valid cache key must be either an integer number or a non-empty string.
This commit introduces a quick type check on the given cache keys and adds a `_doing_it_wrong()` message that should help plugin developers to notice these issues quicker.
Includes:
* A check in `update_user_caches()` and `clean_user_cache()` to make sure user email is not empty before being cached or removed from cache, as it is technically possible to create a user with empty email via `wp_insert_user()`.
* Some minor cleanup in unit tests where the email was passed to `wp_insert_user()` incorrectly or was unintentionally reset.
Props tillkruess, malthert, dd32, spacedmonkey, flixos90, peterwilsoncc, SergeyBiryukov.
Fixes#56198.
git-svn-id: https://develop.svn.wordpress.org/trunk@53818 602fd350-edb4-49c9-b593-d223f7449a82
This changeset replaces the default "Just another WordPress site" tagline with an empty string for new installations. The reasoning is:
1. Not all themes display the tagline;
2. Not everyone changes the default tagline;
3. When people don't see the tagline in their theme, they may not realize it is still visible in some places, like feeds.
The string "Just another WordPress site" and the related multisite string: "Just another {NETWORK} site" are now only used as a placeholder for the tagline admin option.
Props markjaquith, Denis-de-Bernardy, westi, RyanMurphy, kovshenin, SergeyBiryukov, chriscct7, tyxla, hyperbrand, karmatosed, lukecavanagh, melchoyce, boemedia, khag7, sabernhardt, audrasjb, peterwilsoncc, costdev, martinkrcho, rafiahmedd.
Fixes#6479.
git-svn-id: https://develop.svn.wordpress.org/trunk@53815 602fd350-edb4-49c9-b593-d223f7449a82
This fixes a behavior where a draft created with the same slug as an existing post would set the existing post to a 404.
`wp_unique_post_slug()` returns the same slug for 'draft' or 'pending' posts, so to ensure that a unique slug is generated, this changeset adds the post data with the 'publish' status to `wp_unique_post_slug()`.
Props Toro_Unit, h2ham, peterwilsoncc, costdev, antonvlasenko, azaozz, ironprogrammer, audrasjb, hellofromTonya.
Fixes#52422.
git-svn-id: https://develop.svn.wordpress.org/trunk@53813 602fd350-edb4-49c9-b593-d223f7449a82
A separate file in the `actions` directory may have seemed like a good location at the time, but this is the only test left there. For consistency, it is now moved with the other action tests.
Follow-up to [1294/tests], [53806].
See #55652.
git-svn-id: https://develop.svn.wordpress.org/trunk@53808 602fd350-edb4-49c9-b593-d223f7449a82
This was previously moved to a separate file to be excluded when running the tests on PHP 5.2.x.
Now that WordPress supports PHP 5.6.x or later, this can be moved back with the other action tests.
Follow-up to [299/tests], [301/tests], [862/tests], [866/tests], [963/tests].
See #55652.
git-svn-id: https://develop.svn.wordpress.org/trunk@53806 602fd350-edb4-49c9-b593-d223f7449a82
This replaces the "tag" wording with "hook name" where appropriate, to match the core function signatures.
Includes:
* Introducing a `::get_hook_names()` method instead of `::get_tags()`, keeping the latter as an alias.
* Adding a `hook_name` key to the `::$events` property, keeping `tag` for backward compatibility for now.
* Adding missing `@since` tags for class methods.
Follow-up to [24/tests], [62/tests], [70/tests], [50807], [53804].
See #55652.
git-svn-id: https://develop.svn.wordpress.org/trunk@53805 602fd350-edb4-49c9-b593-d223f7449a82
This replaces the `$tag` variables with `$hook_name`, to match the core function signatures.
Follow-up to [24/tests], [62/tests], [866/tests], [1294/tests], [38571], [50807].
See #55652.
git-svn-id: https://develop.svn.wordpress.org/trunk@53804 602fd350-edb4-49c9-b593-d223f7449a82
While most of the action functions are aliases for the respective filter functions, using `did_action()` to detect whether a filter has been run is not possible, as it only works specifically for actions.
This is now resolved by introducing a new function, `did_filter()`, which retrieves the number of times a filter has been applied during the current request, bringing parity with `did_action()`.
Follow-up to [4630], [6318], [27294].
Props mordauk, chriscct7, andykeith, nacin, dd32, markparnell, SergeyBiryukov.
Fixes#35357.
git-svn-id: https://develop.svn.wordpress.org/trunk@53803 602fd350-edb4-49c9-b593-d223f7449a82
The remaining assertions using `preg_match_all()` do actually pass a regex, but the third parameter `$matches` is never used.
This third parameter became optional in PHP 5.4, so we may as well remove it.
Reference: [https://www.php.net/manual/en/function.preg-match-all.php PHP Manual: preg_match_all()]
Follow-up to [711/tests], [53558], [53790].
Props jrf.
See #55652.
git-svn-id: https://develop.svn.wordpress.org/trunk@53795 602fd350-edb4-49c9-b593-d223f7449a82
Change the return type of `_get_cron_array()` to an empty array if the `cron` option is either missing or of an
unexpected type.
This change ensures the return value for no registered events is consistently an empty array. Previously the return
value could be either an empty array or `false`.
Props thakkarhardik, jrf, costdev.
Fixes#53940.
git-svn-id: https://develop.svn.wordpress.org/trunk@53791 602fd350-edb4-49c9-b593-d223f7449a82
A number of assertions are checking for the number of times a hard-coded substring existed in a larger `$haystack`.
These assertions were using `preg_match_all()` to do so, but without actually using a regex.
In these cases, it is more performant (and simpler) to use the PHP native `substr_count()` function, which will yield the same result, without the overhead of regex parsing.
Reference: [https://www.php.net/manual/en/function.substr-count.php PHP Manual: substr_count()]
Follow-up to [711/tests], [38838], [42694], [53558].
Props jrf.
See #55652.
git-svn-id: https://develop.svn.wordpress.org/trunk@53790 602fd350-edb4-49c9-b593-d223f7449a82
This aims to make the tests more specific. Setting the author appears to be redundant, as the as the authorship is out of scope for these particular tests.
Follow-up to [66/tests], [84/tests], [167/tests], [296/tests], [412/tests], [496/tests], [1026/tests], [1323/tests], [25554], [33041], [34762], [35183].
See #55652.
git-svn-id: https://develop.svn.wordpress.org/trunk@53787 602fd350-edb4-49c9-b593-d223f7449a82
This changeset is a follow-up to [53751] which ensures the additional `sources` information stored in attachment metadata are available under `media_details` for each image size in the REST API responses for attachments.
Props mukesh27, eugenemanuilov, mitogh, flixos90, aaemnnosttv.
See #55443.
git-svn-id: https://develop.svn.wordpress.org/trunk@53786 602fd350-edb4-49c9-b593-d223f7449a82
Now that there is a separate test class for `wp_insert_post()` tests, some of the pre-existing tests from the general `Tests_Post` class can be moved there.
Includes:
* Removal of unnecessarily setting the current user to Editor for all tests.
* Removal of unnecessarily setting the cron option to an empty array for all tests.
Follow-up to [496/tests], [36607], [53782], [53783].
See #55652.
git-svn-id: https://develop.svn.wordpress.org/trunk@53785 602fd350-edb4-49c9-b593-d223f7449a82
Now that there is a separate test class for `wp_publish_post()` tests, some of the pre-existing tests from the general `Tests_Post` class can be moved there.
Follow-up to [1039/tests], [1174/tests], [46969], [49000].
See #55652.
git-svn-id: https://develop.svn.wordpress.org/trunk@53783 602fd350-edb4-49c9-b593-d223f7449a82
Includes:
* Using `assertIsInt()` instead of `assertIsNumeric()` for post IDs.
* Using consistent variable names for post data and retrieved posts.
* Removing added filters before performing assertions, not after.
* Removing unused `Tests_Post::$post_ids` property.
* Correcting the order of arguments in some assertions.
* Converting some `foreach()` loops to data providers.
* Wrapping long lines for better readability.
Follow-up to [13/tests], [14/tests], [167/tests], [496/tests], [1174/tests], [1246/tests], [1287/tests], [1307/tests], [1326/tests], [30510], [33261], [33630], [34762], [46279], [50012], [51438].
See #55652.
git-svn-id: https://develop.svn.wordpress.org/trunk@53782 602fd350-edb4-49c9-b593-d223f7449a82
This changeset introduces the `ajax_term_search_results` hook which can be used to filter the term search results returned by the AJAX term query.
Props grandeljay, costdev, ironprogrammer, audrasjb, SergeyBiryukov.
Fixes#55606.
git-svn-id: https://develop.svn.wordpress.org/trunk@53781 602fd350-edb4-49c9-b593-d223f7449a82
The new name is `wp_get_latest_revision_id_and_total_count()`.
This aims to reduce ambiguity about what exactly is the "first" or "last" revision, and bring more consistency with similar wording elsewhere in core, e.g. latest posts, latest comments, etc.
Follow-up to [53759], [53769].
Props peterwilsoncc.
See #55857.
git-svn-id: https://develop.svn.wordpress.org/trunk@53778 602fd350-edb4-49c9-b593-d223f7449a82
This addresses failures in `has_custom_logo()` and `get_custom_logo()` tests when being run separately:
{{{
1) Tests_General_Template::test_has_custom_logo
Custom logo should not be set after removal.
Failed asserting that true is false.
tests/phpunit/tests/general/template.php:291
2) Tests_General_Template::test_get_custom_logo
Custom logo should not be set after removal.
Failed asserting that a string is empty.
tests/phpunit/tests/general/template.php:336
}}}
Specifically, this ensures that the `site_logo` option gets deleted in `_delete_site_logo_on_remove_theme_mods()`, which in turn prevents the `core/site-logo` block filters from affecting the custom logo tests.
Alternatively, these filters could be removed instead:
{{{
remove_filter( 'theme_mod_custom_logo', '_override_custom_logo_theme_mod' );
remove_filter( 'pre_set_theme_mod_custom_logo', '_sync_custom_logo_to_site_logo' );
}}}
Follow-up to [36905], [51091], [51421], [52042].
See #55652.
git-svn-id: https://develop.svn.wordpress.org/trunk@53774 602fd350-edb4-49c9-b593-d223f7449a82
This makes the assertions more helpful, as per the [https://make.wordpress.org/core/handbook/testing/automated-testing/writing-phpunit-tests/#using-assertions Writing PHP Tests] guidelines:
> All PHPUnit assertions, as well as all WordPress custom assertions, allow for a `$message` parameter to be passed. This message will be displayed when the assertion fails and can help immensely when debugging a test. This parameter should always be used if more than one assertion is used in a test method.
Follow-up to [33181], [36905].
See #55652.
git-svn-id: https://develop.svn.wordpress.org/trunk@53773 602fd350-edb4-49c9-b593-d223f7449a82
This avoids an `Attempt to read property "cap" on null` PHP warning when checking an unregistered post type's `publish_posts` capability to disallow contributors setting the post slug for pending posts.
Follow-up to [9055], [42380].
Props Chouby, mukesh27, rafiahmedd, SergeyBiryukov.
Fixes#55877.
git-svn-id: https://develop.svn.wordpress.org/trunk@53771 602fd350-edb4-49c9-b593-d223f7449a82
Includes:
* Renaming the function to `wp_get_last_revision_id_and_total_count()`.
* Making the default value for `$post` consistent with `wp_get_post_revisions()`.
* Making `WP_Error` codes more specific and using them in test assertions.
* Adjusting the function description per the documentation standards.
Follow-up to [53759].
Props JustinSainton, SergeyBiryukov.
See #55857.
git-svn-id: https://develop.svn.wordpress.org/trunk@53769 602fd350-edb4-49c9-b593-d223f7449a82
Includes:
* Placing `WP_Object_Cache::flush_group()` next to `::flush()`.
* Placing `wp_cache_supports_group_flush()` next to `wp_cache_flush_group()`.
* Placing the `wp_cache_flush_group()` unit test next to the `::flush()` method test.
* Removing test name from assertion messages, as it is already mentioned directly above in case of failure.
* Adjusting function descriptions per the documentation standards.
Follow-up to [52706], [53763].
See #55647, #4476.
git-svn-id: https://develop.svn.wordpress.org/trunk@53767 602fd350-edb4-49c9-b593-d223f7449a82