Commit Graph

199 Commits

Author SHA1 Message Date
Boone Gorges d63ceb08a3 Share fixtures across 'canonical' automated tests.
Sharing these fixtures results in a speed improvement of almost one minute per
run of the test suite.

My hope is that future WordPress developers will spend this extra minute with
their loved ones, for life on this earth is short, my friends, and the moments
you spend watching WP generate test data can never again be reclaimed from the
grizzled clutches of Time, and none of us are really getting younger, I mean,
geez, have you looked in the mirror lately, Gandalf?

See #30017.

git-svn-id: https://develop.svn.wordpress.org/trunk@30277 602fd350-edb4-49c9-b593-d223f7449a82
2014-11-08 19:28:12 +00:00
Boone Gorges fe726039bd Share fixtures across a number of query-related test classes.
This shaves 10-20 seconds off the running time for the suite.

See #30017.

git-svn-id: https://develop.svn.wordpress.org/trunk@30276 602fd350-edb4-49c9-b593-d223f7449a82
2014-11-08 15:29:31 +00:00
Boone Gorges f12b0f9aad Correct variable name in `WP_UnitTestCase::temp_filename()`.
git-svn-id: https://develop.svn.wordpress.org/trunk@30268 602fd350-edb4-49c9-b593-d223f7449a82
2014-11-07 01:36:05 +00:00
Boone Gorges 73eee04d38 Unset the default permalink structure after installing Multisite for automated tests.
Most of our unit tests that involve permalinks expect non-pretty permalinks;
this is the default setting for WP. However, when the test suite installs
multisite, `populate_network()` is run before WP recogizes itself as multisite,
which leads to pretty permalinks being set. This breaks a number of unit
tests in ways that are difficult to trace.

git-svn-id: https://develop.svn.wordpress.org/trunk@30267 602fd350-edb4-49c9-b593-d223f7449a82
2014-11-07 01:24:19 +00:00
Boone Gorges 1fc0287164 Set current user to 0 after each unit test.
This prevents $current_user, $userdata, and other user-related globals from
being polluted if a previous test does not properly reset the current user.

Props nacin, mnelson4.
Fixes #29712.

git-svn-id: https://develop.svn.wordpress.org/trunk@30001 602fd350-edb4-49c9-b593-d223f7449a82
2014-10-24 00:58:35 +00:00
Boone Gorges f7dbf962d7 Only reset taxonomies and post types between tests when running core tests.
A growing number of plugins and other WP-based projects use the core test
tools, such as WP_UnitTestCase, as the basis of their own tests and continuous
integration setups. At the same time, many of these third-party plugins use
custom post types and taxonomies, which are generally registered a single time
during a run of the tests: at 'init', before the testcases have run. Wiping out
these globals between tests will mess with these third-party builds.

Best practice for plugin developers is probably to clean up their own post types
and taxonomies and then reinitialize before each test. But, in the interest of
not breaking everyone's builds, the core test suite will not enforce this.

Fixes #29827.

git-svn-id: https://develop.svn.wordpress.org/trunk@29869 602fd350-edb4-49c9-b593-d223f7449a82
2014-10-10 20:25:39 +00:00
Boone Gorges 5e7be10860 Reset post types and taxonomies before each unit test.
Registering a post type or taxonomy during a unit test causes modifications to
global variables. If the test fails to clean up these globals - either by
neglecting to call _unregister_post_type()/_unregister_taxonomy() at all or by
failing before getting a chance to do so - tests that run later in the suite
can fail, leading to much gnashing of teeth. Wiping all taxonomies and
restoring to the defaults before each test ensures that we always start with a
clean slate.

Fixes #29827.

git-svn-id: https://develop.svn.wordpress.org/trunk@29860 602fd350-edb4-49c9-b593-d223f7449a82
2014-10-09 00:57:26 +00:00
Mark Jaquith be8a0c6f89 Use HTTPS URLs for trac.wordpress.org (and use core.trac.wordpress.org)
see #27115

git-svn-id: https://develop.svn.wordpress.org/trunk@29789 602fd350-edb4-49c9-b593-d223f7449a82
2014-09-29 13:36:38 +00:00
Sergey Biryukov 262929004d Avoid undefined index notices in WP_UnitTestCase::_restore_hooks().
props kevinlangleyjr.
fixes #29123.

git-svn-id: https://develop.svn.wordpress.org/trunk@29503 602fd350-edb4-49c9-b593-d223f7449a82
2014-08-15 15:40:48 +00:00
Helen Hou-Sandi c72d29e63e Revert [29267], as it causes unit test breakage and appears unnecessary. see #28986.
git-svn-id: https://develop.svn.wordpress.org/trunk@29274 602fd350-edb4-49c9-b593-d223f7449a82
2014-07-23 02:22:57 +00:00
Scott Taylor 7f9edd3e69 After [29251], set the array keys in `WP_UnitTestCase::$hooks_saved` to prevent notices in 3rd party use cases.
Props danielbachhuber.
Fixes #28986.



git-svn-id: https://develop.svn.wordpress.org/trunk@29267 602fd350-edb4-49c9-b593-d223f7449a82
2014-07-22 17:21:40 +00:00
Scott Taylor 36e455d018 Backup filter globals ( `$merged_filters, $wp_actions, $wp_current_filter, $wp_filter` ) statically when running unit tests, restore on `tearDown()`. This ensures that all tests initially use the same filters/actions.
Props mnelson4, wonderboymusic.
Fixes #28535.


git-svn-id: https://develop.svn.wordpress.org/trunk@29251 602fd350-edb4-49c9-b593-d223f7449a82
2014-07-19 23:58:07 +00:00
Scott Taylor d97b10eecf Wouldn't it be incredible if you could run Unit Tests without all of your uploads being indiscriminately blown away and your upload folder permissions being destroyed?
The Future Is Now.

Fixes #28847.


git-svn-id: https://develop.svn.wordpress.org/trunk@29120 602fd350-edb4-49c9-b593-d223f7449a82
2014-07-12 07:08:15 +00:00
Scott Taylor 3708cdc7c2 Bring back `define( 'WP_INSTALLING', true );` in `phpunit/includes/install.php`, which was removed in [28965]. tl;dr = wp-cli. Unit tests still pass in multisite because of the skips I added.
Fixes #28738, #28706.


git-svn-id: https://develop.svn.wordpress.org/trunk@28988 602fd350-edb4-49c9-b593-d223f7449a82
2014-07-04 01:38:43 +00:00
Scott Taylor 73bde8a278 Transient timeouts are untestable when `WP_INSTALLING` is defined and set to ANY value. Transient timeouts cannot be tested during multisite runs because `wpmu_create_blog()` sets `WP_INSTALLING`. I have zero idea how these tests ever passed.
See #28706.


git-svn-id: https://develop.svn.wordpress.org/trunk@28965 602fd350-edb4-49c9-b593-d223f7449a82
2014-07-03 01:16:33 +00:00
Scott Taylor 9ab7f4b144 Avoid polluted `$table_prefix` and `$_wp_switched_stack` in multisite unit tests.
Add `WP_TESTS_TABLE_PREFIX` in `bootstrap.php` to ensure the original value for `$table_prefix` is always available. 

Props jeremyfelt.
Fixes #28692.


git-svn-id: https://develop.svn.wordpress.org/trunk@28943 602fd350-edb4-49c9-b593-d223f7449a82
2014-07-01 18:51:46 +00:00
Andrew Nacin 9e24832a0e Add initial unit tests for multisite's bootstrap.
props jeremyfelt.
fixes #27884.


git-svn-id: https://develop.svn.wordpress.org/trunk@28910 602fd350-edb4-49c9-b593-d223f7449a82
2014-06-29 22:50:44 +00:00
Scott Taylor 5c48c4f8a8 Allow `wp_die()` to die in plain text when running the test suite.
Props jorbin.
Fixes #27749.


git-svn-id: https://develop.svn.wordpress.org/trunk@28797 602fd350-edb4-49c9-b593-d223f7449a82
2014-06-21 19:59:28 +00:00
Scott Taylor bf54ad6054 Add missing access modifiers to methods in `WP_Query`. Add magic methods for `__get()`, `__set()`, `__isset()`, `__unset()`, and `__call()`.
Add unit test for magic methods.

See #27881, #22234.


git-svn-id: https://develop.svn.wordpress.org/trunk@28523 602fd350-edb4-49c9-b593-d223f7449a82
2014-05-19 06:48:56 +00:00
Scott Taylor d6a3c2a0de Add access modifiers to methods and members of list table classes:
* `WP_List_Table` is the base class that implements `__get()` and `__call()` for BC
* Adds unit tests to confirm that subclasses properly inherit magic methods
* Add modifiers to subclasses: `WP_Links_List_Table`, `WP_Media_List_Table`, `WP_MS_Sites_List_Table`, `WP_MS_Themes_List_Table`, `WP_MS_Users_List_Table`, `WP_Plugin_Install_List_Table`, `WP_Plugins_List_Table`, `WP_Posts_List_Table`, `WP_Terms_List_Table`, `WP_Theme_Install_List_Table`, `WP_Themes_List_Table`

See #27881, #22234.


git-svn-id: https://develop.svn.wordpress.org/trunk@28493 602fd350-edb4-49c9-b593-d223f7449a82
2014-05-19 01:16:16 +00:00
Scott Taylor 85ac5c214d Add a unit test that demonstrates a magic getter.
See #27881.



git-svn-id: https://develop.svn.wordpress.org/trunk@28480 602fd350-edb4-49c9-b593-d223f7449a82
2014-05-18 21:14:13 +00:00
Scott Taylor 17e4da2bd8 Remove `html5` theme support on `tearDown()` so theme settings don't leak into other tests.
git-svn-id: https://develop.svn.wordpress.org/trunk@27795 602fd350-edb4-49c9-b593-d223f7449a82
2014-03-27 20:54:08 +00:00
Andrew Nacin eef62a9d0d Update PHPMailer to 5.2.7 from 5.2.4.
Includes two trivial modifications for WordPress:
 * Doesn't use the autoloader, so the check to enforce the autoloader from the constructor is removed.
 * Requires class-smtp.php for backwards compatibility with direct (non-wp_mail()) uses of PHPMailer, as the autoloader isn't used.

props bpetty.
fixes #25560.


git-svn-id: https://develop.svn.wordpress.org/trunk@27385 602fd350-edb4-49c9-b593-d223f7449a82
2014-03-03 20:24:31 +00:00
Scott Taylor a31a167359 Reset `$wp_query` and `$post` during `WP_UnitTestCase::tearDown()` to avoid spillage of globals between tests.
See #26321.



git-svn-id: https://develop.svn.wordpress.org/trunk@27183 602fd350-edb4-49c9-b593-d223f7449a82
2014-02-17 21:03:43 +00:00
Andrew Nacin 31d3af406c Multisite: Add get_network_by_path() and wp_get_network() to begin cleanup of multisite load.
Tries to get network detection under control by simplifying wpmu_current_site(). It now also pops off each subdomain to find a more general match. Adds unit tests for get_network_by_path() and a new network factory for unit tests.

Much of this is likely to change in 3.9 as more of ms-load.php and ms-settings.php gets hacked to bits.

props jeremyfelt.
see #27003.


git-svn-id: https://develop.svn.wordpress.org/trunk@27178 602fd350-edb4-49c9-b593-d223f7449a82
2014-02-13 23:06:12 +00:00
Andrew Nacin 36fe6c1c27 Don't use HTTPS in unit tests if OpenSSL isn't loaded.
props bpetty.
fixes #27114.


git-svn-id: https://develop.svn.wordpress.org/trunk@27168 602fd350-edb4-49c9-b593-d223f7449a82
2014-02-12 20:39:21 +00:00
Andrew Nacin e07424147c Test suite: Trim queries before deciding whether to create temporary tables.
props jdgrimes.
fixes #24800.


git-svn-id: https://develop.svn.wordpress.org/trunk@27086 602fd350-edb4-49c9-b593-d223f7449a82
2014-02-03 22:39:47 +00:00
Andrew Nacin c759a54b2c Test framework: Parse CREATE TABLE queries the same way we do DROP TABLE queries.
props soulseekah.
fixes #24800.


git-svn-id: https://develop.svn.wordpress.org/trunk@27041 602fd350-edb4-49c9-b593-d223f7449a82
2014-01-27 03:09:13 +00:00
Andrew Ozz 9aba880b53 Autosave: refactor autosave.js, use heartbeat for transport and move all "Add/Edit Post" related functionality to post.js. See #25272.
git-svn-id: https://develop.svn.wordpress.org/trunk@26995 602fd350-edb4-49c9-b593-d223f7449a82
2014-01-22 04:55:37 +00:00
Andrew Nacin b807bea28c Test framework: Override PHPMailer during installation.
props bpetty.
fixes #26836.


git-svn-id: https://develop.svn.wordpress.org/trunk@26944 602fd350-edb4-49c9-b593-d223f7449a82
2014-01-14 21:55:41 +00:00
Andrew Nacin 007e4ef160 Tracs are now forced SSL.
git-svn-id: https://develop.svn.wordpress.org/trunk@26909 602fd350-edb4-49c9-b593-d223f7449a82
2014-01-06 18:09:12 +00:00
Andrew Nacin 2105b8683d Test runner: Extend WP_PHPUnit_Util_Getopt instead of PHPUnit_TextUI_Command to parse incoming options.
props wawco.
fixes #26725.


git-svn-id: https://develop.svn.wordpress.org/trunk@26871 602fd350-edb4-49c9-b593-d223f7449a82
2013-12-27 15:07:07 +00:00
Scott Taylor ff4f1bb170 For unit tests that call `wpmu_create_blog()`, Blog factory, or installation code that attempts to clear transients: suppress database errors on `setUp` and restore on `tearDown`.
There are a few places in core that were preventing this from working by explicity setting `$wpdb->suppress_errors` to `false`. Instead, they should inherit the value that existed before errors were suppressed.

This allows Multisite unit tests to run without explosive database errors, and allows `$wpdb->suppress_errors` to be overridden all the way down the chain.

Fixes #26102.


git-svn-id: https://develop.svn.wordpress.org/trunk@26252 602fd350-edb4-49c9-b593-d223f7449a82
2013-11-18 20:44:34 +00:00
Sergey Biryukov cbad0abaae Normalize slashes in WP_Filesystem_MockFS::mkdir() and WP_Filesystem_MockFS::locate_parent_node() to avoid an infinite loop on Windows.
fixes #26091.

git-svn-id: https://develop.svn.wordpress.org/trunk@26246 602fd350-edb4-49c9-b593-d223f7449a82
2013-11-18 15:32:47 +00:00
Scott Taylor 5de39fc2f1 Remove the Featured Content term filters when running Unit Tests. Set the return value of `wp_get_object_terms()` to a var before passing to `array_shift()` in `test_get_object_terms_types()`, which expects a var to be passed by reference.
See #25282.



git-svn-id: https://develop.svn.wordpress.org/trunk@26187 602fd350-edb4-49c9-b593-d223f7449a82
2013-11-15 02:32:16 +00:00
Scott Taylor 6603f4802a Always clean install in PHPUnit Tests.
Props bpetty.
Fixes #25871.



git-svn-id: https://develop.svn.wordpress.org/trunk@26095 602fd350-edb4-49c9-b593-d223f7449a82
2013-11-11 22:14:24 +00:00
Scott Taylor 5321bc4957 `WP_UnitTestCase::go_to()` tried its best to clean up global space, but ultimately fell short. Because it was blowing away `WP` every time it was called, it was dropping all the query vars that were registered for custom taxonomies and custom post types (ouch).
Introduces `_cleanup_query_vars()`. This is a prerequisite for the unit tests on #20767. All unit tests pass with this change.

See #20767.
Fixes #25818.



git-svn-id: https://develop.svn.wordpress.org/trunk@26006 602fd350-edb4-49c9-b593-d223f7449a82
2013-11-04 22:46:44 +00:00
Scott Taylor 2f38d2efc6 Move `Tests_Query_Conditionals::assertQueryTrue()` to `WP_UnitTestCase`. It should be available to all unit test classes. The conditionals class is huge, other classes are necessary for better coverage.
git-svn-id: https://develop.svn.wordpress.org/trunk@26005 602fd350-edb4-49c9-b593-d223f7449a82
2013-11-04 21:55:12 +00:00
Andrew Nacin 5ceab9b1e3 Test runner: Add @expectedIncorrectUsage to trap _doing_it_wrong() calls.
see #24813, #25282.


git-svn-id: https://develop.svn.wordpress.org/trunk@25785 602fd350-edb4-49c9-b593-d223f7449a82
2013-10-15 14:30:02 +00:00
Scott Taylor f3488744ce Add a default value to `WP_UnitTest_Factory_For_Comment::default_generation_definitions['comment_content']` to avoid a tornado of database errors in PHP 5.5/MySQL 5.6, even when `WP_DEBUG` is turned off.
See #25282.



git-svn-id: https://develop.svn.wordpress.org/trunk@25660 602fd350-edb4-49c9-b593-d223f7449a82
2013-10-02 19:46:58 +00:00
Scott Taylor 535ae26afd Fix several esoteric errors related to AJAX unit tests for comments:
* `wp_ajax_get_comments()` relies on the `$post_id` global - even though `$_POST['p']` is passed to every action in the test methods. If `$post_id` is still lingering in between tests and doesn't match `p` in the request, the cap check might pass while the queries for comments will blow up. I added `unset( $GLOBALS['post_id'] )` to `Tests_Ajax_GetComments::setUp()`.
* If the global `$post_id` is empty, but `$_REQUEST['p']` is not, `$post_id` is now set to `absint( $_REQUEST['p'] )` and sanity-checked in `wp_ajax_get_comments()`.
* `map_meta_cap()` always assumes that `get_comment()` succeeds when checking for the `edit_comment` cap. It doesn't. I added sanity checks in a few places where it will break early if `get_post()` or `get_comment()` are empty.
* `wp_update_comment()` always assumes `get_comment()` succeeds. It doesn't. I added a check for empty.

All AJAX unit tests run and pass in debug mode. All general unit tests pass against these changes.

Fixes #25282.



git-svn-id: https://develop.svn.wordpress.org/trunk@25438 602fd350-edb4-49c9-b593-d223f7449a82
2013-09-14 18:35:43 +00:00
Scott Taylor d85e040859 Remove the unnecessary call to `ob_end_clean()` directly after `ob_get_clean()` in `WP_Ajax_UnitTestCase::dieHandler()`. This fixes a large number of AJAX errors in debug mode.
See #25282.



git-svn-id: https://develop.svn.wordpress.org/trunk@25432 602fd350-edb4-49c9-b593-d223f7449a82
2013-09-13 21:32:54 +00:00
Andrew Nacin 9d9a28b3e0 Test framework: Update path to multisite.xml.
props jeremyfelt.
fixes #25242.


git-svn-id: https://develop.svn.wordpress.org/trunk@25415 602fd350-edb4-49c9-b593-d223f7449a82
2013-09-12 21:04:16 +00:00
Andrew Nacin d5d476974e Test framework: Introduce the annotation @expectedDeprecated, modeled after PHPUnit's @expectedException.
It works for both functions and arguments (using the value of the first argument passed to _deprecated_function() or _deprecated_argument(), which is typically the function name). It asserts both ways:
 * If specified, those deprecated notices must be caught, or the test fails.
 * If not specified, any other deprecated notices cause the test to fail.

Works regardless of WP_DEBUG.
see #25282.


git-svn-id: https://develop.svn.wordpress.org/trunk@25408 602fd350-edb4-49c9-b593-d223f7449a82
2013-09-12 18:37:00 +00:00
Scott Taylor 654d07ebf9 There was way too much duplicated code in my notice cleanup, it built up over time, and there's definitely a need to standardize.
* Remove duplicated code for deprecated function notice suppression
* Add support in `WP_UnitTestCase` setUp/tearDown methods for `$deprecated_functions` fixture if the extending class has added it
* Add a `$deprecated_functions` fixture to each extending class that needs it

To use this fixture, add something to your Test Case class like so:
`protected $deprecated_functions = array( 'get_theme', 'get_themes', 'get_theme_data', 'get_current_theme' );`

See #25282.



git-svn-id: https://develop.svn.wordpress.org/trunk@25402 602fd350-edb4-49c9-b593-d223f7449a82
2013-09-12 14:47:58 +00:00
Scott Taylor a76e6cef7d * Avoid notice by making `WP_Image_Editor_Mock::test()` compatible with `WP_Image_Editor::test()`.
* Suppress deprecated function notice for `wp_load_image()`.
* Add assertion for `wp_get_image_editor()`.

See #25282.




git-svn-id: https://develop.svn.wordpress.org/trunk@25380 602fd350-edb4-49c9-b593-d223f7449a82
2013-09-12 04:40:13 +00:00
Scott Taylor 93cfccac2d Add unit test for `tax_query` against attachments.
See #22556.



git-svn-id: https://develop.svn.wordpress.org/trunk@25278 602fd350-edb4-49c9-b593-d223f7449a82
2013-09-06 14:43:49 +00:00
Scott Taylor 16ef2c2e36 Remove lingering instances of call time pass-by-reference, limited to instances of `callable` - use `$this` instead of `&$this`.
Props jdgrimes.
See #25160.



git-svn-id: https://develop.svn.wordpress.org/trunk@25254 602fd350-edb4-49c9-b593-d223f7449a82
2013-09-05 16:33:50 +00:00
Andrew Nacin 8045afd81b Move PHPUnit tests into a tests/phpunit directory.
wp-tests-config.php can/should reside in the root of a develop checkout. `phpunit` should be run from the root.

see #25088.


git-svn-id: https://develop.svn.wordpress.org/trunk@25165 602fd350-edb4-49c9-b593-d223f7449a82
2013-08-29 18:39:34 +00:00