Using more than one instance of `WP_UnitTest_Factory` causes all kinds of craziness, due to out-of-sync internal generator sequences. Since we want to use `setUpBeforeClass`, we were creating ad hoc instances. To avoid that, we were injecting one `static` instance via Dependency Injection in `wpSetUpBeforeClass`. All tests should really use the `static` instance, so we will remove the instance prop `$factory`.
Replace `$this->factory` with `self::$factory` over 2000 times.
Rewrite all of the tests that were hard-coding dynamic values.
#YOLOFriday
git-svn-id: https://develop.svn.wordpress.org/trunk@35225 602fd350-edb4-49c9-b593-d223f7449a82
They were added 3 years ago in [846/tests] because tests weren't excluded from the normal runs.
Reverts [35209] because it doesn't work with Xdebug.
`Tests_Ajax_Response::test_response_charset_in_header` is the only test which needs to run in a separate process, see [975/tests].
See #31491.
git-svn-id: https://develop.svn.wordpress.org/trunk@35211 602fd350-edb4-49c9-b593-d223f7449a82
Most of the Ajax tests are running in a separate PHP process, and thus PHPUnit attempts to preserve the global state from the parent process by serializing all globals. But this doesn't work for external object caches so we have to disable this "feature".
See #31491.
git-svn-id: https://develop.svn.wordpress.org/trunk@35209 602fd350-edb4-49c9-b593-d223f7449a82
This makes it way easier to add fixtures, and tear them down, without needing to instantiate `WP_UnitTest_Factory` in every class - removes the need to call `commit_transaction()` in each individual class.
See #30017, #33968.
git-svn-id: https://develop.svn.wordpress.org/trunk@35186 602fd350-edb4-49c9-b593-d223f7449a82
Baby API was born at 2.8KLOC on October 8th at 2:30 UTC. API has lots
of growing to do, so wish it the best of luck.
Thanks to everyone who helped along the way:
Props rmccue, rachelbaker, danielbachhuber, joehoyle, drewapicture,
adamsilverstein, netweb, tlovett1, shelob9, kadamwhite, pento,
westonruter, nikv, tobych, redsweater, alecuf, pollyplummer, hurtige,
bpetty, oso96_2000, ericlewis, wonderboymusic, joshkadis, mordauk,
jdgrimes, johnbillion, jeremyfelt, thiago-negri, jdolan, pkevan,
iseulde, thenbrent, maxcutler, kwight, markoheijnen, phh, natewr,
jjeaton, shprink, mattheu, quasel, jmusal, codebykat, hubdotcom,
tapsboy, QWp6t, pushred, jaredcobb, justinsainton, japh, matrixik,
jorbin, frozzare, codfish, michael-arestad, kellbot, ironpaperweight,
simonlampen, alisspers, eliorivero, davidbhayes, JohnDittmar, dimadin,
traversal, cmmarslender, Toddses, kokarn, welcher, and ericpedia.
Fixes#33982.
git-svn-id: https://develop.svn.wordpress.org/trunk@34928 602fd350-edb4-49c9-b593-d223f7449a82
New functions in `media.php`:
* `wp_get_attachment_image_srcset_array()` - Returns an array of image candidate string data used to build a `srcset` value for an attachment given an `$attachement_id` and `$size`.
* `wp_get_attachment_image_srcset()` - Returns the `srcset` value for an attachment given an `$attachement_id` and `$size`.
* `wp_get_attachment_image_sizes()` - Returns the `sizes` value for an attachment given an `$attachement_id` and `$size` and optional arguments used to alter its output.
* `wp_make_content_images_responsive()` - A display filter for adding `srcset` and `sizes` to images embedded in content.
* `wp_img_add_srcset_and_sizes()` - A utility function used by `wp_make_content_images_responsive()` to add `srcset` and `sizes` to a single `<img>` element.
Modifies existing core functions:
* Modify `wp_get_attachment_image()` so the HTML returned for an image includes `srcset` and `sizes`.
* Modify `get_media_embedded_in_content()` (sup, 3.6 leftover) by adding `<img>` to the list of accepted tags that can be matched in content. This is used in `wp_make_content_images_responsive()` to find all of the images embedded in content before passing them off to `wp_img_add_srcset_and_sizes()`.
Tests:
* Add a new factory method to `WP_UnitTest_Factory_For_Attachment` named `create_upload_object()`
* Adds unit tests
* Updates unit tests
Props joemcgill, tevko, jaspermdegroot, mdmcginn, barryceelen, peterwilsoncc, fsylum, wonderboymusic, chriscoyier, benjaminpick, jrfnl, #12kingkool68, janhenckens, ryanmarkel, side777, ryelle, wturrell, micahmills, mattbagwell, coliff, DrewAPicture.
See #33641.
git-svn-id: https://develop.svn.wordpress.org/trunk@34855 602fd350-edb4-49c9-b593-d223f7449a82
A number of the HTTP external tests can inconstantly fail. As the HTTP API is one that doesn't change often, this failure creates noise. With the goal of increasing the signal from the unit tests, these tests are now skipped if they timeout. A notice is added when running the external http tests so that the developer knows what skipped tests may mean here.
See #33968
git-svn-id: https://develop.svn.wordpress.org/trunk@34848 602fd350-edb4-49c9-b593-d223f7449a82
The `WP_INSTALLING` constant is a flag that WordPress sets in a number of
places, telling the system that options should be fetched directly from the
database instead of from the cache, that WP should not ping wordpress.org for
updates, that the normal "not installed" checks should be bypassed, and so on.
A constant is generally necessary for this purpose, because the flag is
typically set before the WP bootstrap, meaning that WP functions are not yet
available. However, it is possible - notably, during `wpmu_create_blog()` -
for the "installing" flag to be set after WP has already loaded. In these
cases, `WP_INSTALLING` would be set for the remainder of the process, since
there's no way to change a constant once it's defined. This, in turn, polluted
later function calls that ought to have been outside the scope of site
creation, particularly the non-caching of option data. The problem was
particularly evident in the case of the automated tests, where `WP_INSTALLING`
was set the first time a site was created, and remained set for the rest of the
suite.
The new `wp_installing()` function allows developers to fetch the current
installation status (when called without any arguments) or to set the
installation status (when called with a boolean `true` or `false`). Use of
the `WP_INSTALLING` constant is still supported; `wp_installing()` will default
to `true` if the constant is defined during the bootstrap.
Props boonebgorges, jeremyfelt.
See #31130.
git-svn-id: https://develop.svn.wordpress.org/trunk@34828 602fd350-edb4-49c9-b593-d223f7449a82
Renames `reset_permalinks()` to `set_permalink_structure()` (mimicking `$wp_rewrite->set_permalink_structure()`) and allows it to accept an optional permalink structure. In this way, we can double dip using it to both set and reset the permalink structure from anywhere.
Removes alot of duplicated code from tests.
See #33968.
git-svn-id: https://develop.svn.wordpress.org/trunk@34810 602fd350-edb4-49c9-b593-d223f7449a82
Removes the restoration logic, which leveraged a static property initialized with `get_option()`.
See #33968.
git-svn-id: https://develop.svn.wordpress.org/trunk@34807 602fd350-edb4-49c9-b593-d223f7449a82
* Add test file accidentally omitted from [34761].
* Bail properly from benchmarker when a `preg_last_error()` is found.
Props miqrogroove.
See #34121.
git-svn-id: https://develop.svn.wordpress.org/trunk@34773 602fd350-edb4-49c9-b593-d223f7449a82
In versions of PHP earlier than 5.4, the `$matches` parameter was required.
Excluding it here meant that PCRE benchmarking tests were erroring on older
versions of PHP without cleaning up the PCRE ini settings, causing various
problems on later tests.
Props miqrogroove, dd32, boonebgorges.
And to the cosmic forces that cause bugs like this. The best part of waking up
is diagnosing leakage between automated tests.
See #34121.
git-svn-id: https://develop.svn.wordpress.org/trunk@34772 602fd350-edb4-49c9-b593-d223f7449a82
* Move pattern from `wptexturize()` into a separate function.
* Move pattern from `wp_html_split()` into a separate function.
* Beautify code for `wp_html_split()`.
* Remove unnecessary instances of `/s` modifier in patterns that don't use dots.
* Add `tests/phpunit/data/formatting/whole-posts.php` for testing larger strings.
* Add function `benchmark_pcre_backtracking()`.
* Add tests for `wp_html_split()`.
* Add tests for `wptexturize()`.
* Add tests for `get_shortcode_regex()`.
Props miqrogroove.
Fixes#34121.
git-svn-id: https://develop.svn.wordpress.org/trunk@34761 602fd350-edb4-49c9-b593-d223f7449a82
Continuing with the "code is poetry" theme after [34719], we need to continue
to update the option in the database on non-multisite in this
`wp_insert_term()` test.
See #31130.
git-svn-id: https://develop.svn.wordpress.org/trunk@34720 602fd350-edb4-49c9-b593-d223f7449a82
[34718] introduced a 'db_version' check to term meta functions, to ensure that
they don't run when the term meta schema is not yet in place. This call to
`get_option()` causes a database hit during Multisite tests, due to the
presence of the `WP_INSTALLING` constant. See #31130. The extra database
queries are causing cache tests to fail.
In similar cases, we have `markTestSkipped()` when `is_multisite()`. Because
the term meta API is so extensive - term meta caches can be primed anywhere a
`WP_Query` loop is fired up - we implement a more generous workaround in this
case. To prevent `get_option( 'db_version' )` from hitting the database during
multisite unit tests, we use a 'pre_option_' filter.
Heaven help us.
See #34091.
git-svn-id: https://develop.svn.wordpress.org/trunk@34719 602fd350-edb4-49c9-b593-d223f7449a82
Previously, we'd run the sanity checks if `is_mysql` was not set to `false`. This caused problems for DB drop-ins that didn't define `is_mysql` at all. Instead, we can just check if `is_mysql` is `empty()`.
Also fix some unit tests that accidently ran correctly because of the strict `false ===` comparison.
Fixes#33501.
git-svn-id: https://develop.svn.wordpress.org/trunk@34655 602fd350-edb4-49c9-b593-d223f7449a82
In `_unregister_post_type()` (unit tests), don't add query vars of non-viewable post types to `WP::public_query_vars`.
Adds unit test.
Fixes#30018.
git-svn-id: https://develop.svn.wordpress.org/trunk@34215 602fd350-edb4-49c9-b593-d223f7449a82
Includes two modifications for WordPress:
* Removes support for NTLM in `class-smtp.php` since the required client (`extras/ntlm_sasl_client.php`) is not distributed as part of WordPress.
* Requires `class-smtp.php` for backwards compatibility with direct (non-wp_mail()) uses of PHPMailer, as the autoloader isn't used. See [27385].
This also includes a change to our `MockMailer` for unit tests. It now overrides `postSend() instead of `send()`, and `preSend()`.
`preSend()` resets `$this->Encoding` because PHPMailer doesn't clean up after itself / presets all variables. This becomes an issue when `PHPMailer::createBody()` sets `$this->Encoding = 'quoted-printable'` (away from it's default of 8bit) when it encounters a line longer than 998 characters. `Tests_Comment::test_comment_field_lengths` is such a case.
props MattyRob, dd32.
fixes#28909.
git-svn-id: https://develop.svn.wordpress.org/trunk@33124 602fd350-edb4-49c9-b593-d223f7449a82
If you are subclassing these classes in your own tests, you'll need to update your code.
Props johnbillion
See #31982
git-svn-id: https://develop.svn.wordpress.org/trunk@33123 602fd350-edb4-49c9-b593-d223f7449a82
PHP7 is deprecating PHP4 style constructors, so we need to modify our code to have _construct methods that fire before the named PHP4 style constructors. The PHP4 style constructors will call the PHP5 style constructor in case it is being called directly (usually via parent::METHOD).
This modifies external libraries to add PHP5 style constructors, but doesn't add a notice for when they are used. In WordPress core code, PHP4 style constructors are being given a call to _deprecated_constructor. To the PHP4 style constructor I say "I know that I can't take no more | It ain't no lie | I wanna see you out that door | Baby, bye, bye, bye..."
Upstream: https://wiki.php.net/rfc/remove_php4_constructors
Props jdgrimes, netweb, jorbin
See #31982
git-svn-id: https://develop.svn.wordpress.org/trunk@32990 602fd350-edb4-49c9-b593-d223f7449a82
This eliminates PHP notices when `wp_mail()` needs to determine its own From header.
See [25381] for a previous fix, which focused only on the mail-specific tests.
Fixes#32702.
git-svn-id: https://develop.svn.wordpress.org/trunk@32839 602fd350-edb4-49c9-b593-d223f7449a82
The override is necessary because the `get_term()` call, which fetches the
term object, needs the `'taxonomy'` argument passed to the factory method.
Props dlh.
Fixes#32536.
git-svn-id: https://develop.svn.wordpress.org/trunk@32659 602fd350-edb4-49c9-b593-d223f7449a82
The unit tests expect non-pretty permalinks, so there's no benefit to detecting
the ability to have pretty permalinks. Moreover, the `wp_remote_get()` call can
cause installation to hang when there are DNS issues.
Fixes#31994.
git-svn-id: https://develop.svn.wordpress.org/trunk@32139 602fd350-edb4-49c9-b593-d223f7449a82
Failure to set this variable meant that passing the home URL to `go_to()`
(without a trailing slash) resulted in a PHP notice, and failed to reset the
globals properly.
Props joostdevalk.
Fixes#31417.
git-svn-id: https://develop.svn.wordpress.org/trunk@31515 602fd350-edb4-49c9-b593-d223f7449a82
* Do the `expectedDeprecated()` check in `assertPostConditions()` instead of `tearDown()`. Previously, `fail`ing inside of `tearDown()` was causing the rest of the teardown process to be aborted, resulting in inter-test leakage.
* Collect all `expectedDeprecated` and `expectedIncorrectUsage` annotations in an entire method and display them all when `fail`ing, instead of showing only the first one.
Props jdgrimes.
Fixes#31362.
git-svn-id: https://develop.svn.wordpress.org/trunk@31469 602fd350-edb4-49c9-b593-d223f7449a82
These methods provide a procedural alternative to the `@expectedDeprecated`
and `@expectedIncorrectUsage` test annotations, and parallel PHPUnit's native
`setExpectedException()`.
Props prasoon2211, jdgrimes.
Fixes#28486.
git-svn-id: https://develop.svn.wordpress.org/trunk@31306 602fd350-edb4-49c9-b593-d223f7449a82
Examples: if you clean up directories in a test, or a test fails before the directories are cleaned, or a test fails before the `'upload_path'` option is reset, the next call to `wp_upload_dir()` will recreate the directories you just tried to delete.
These changes ensure that `src/foo` and `/tmp/wp-unit-test` directories are deleted immediately after `wp_upload_dir()` is fired in the tests.
Fixes#30513.
git-svn-id: https://develop.svn.wordpress.org/trunk@30658 602fd350-edb4-49c9-b593-d223f7449a82
It should be defined in a common library file so that all tests have access to
it, even when run in isolation.
See [30345], #21212.
git-svn-id: https://develop.svn.wordpress.org/trunk@30528 602fd350-edb4-49c9-b593-d223f7449a82
In general, skipped tests should live only in patches, which are committed at
the same time that the corresponding bug is fixed. In cases where it's
necessary to skip a test, use `markTestSkipped()` to declare this fact
explicitly.
We continue to check Trac when using `WP_UnitTestCase` to run non-core tests.
See #30284.
git-svn-id: https://develop.svn.wordpress.org/trunk@30526 602fd350-edb4-49c9-b593-d223f7449a82