Make WordPress Core

Opened 6 years ago

Last modified 5 years ago

#45132 new enhancement

Explore better implementation of Autosaves Controller unit tests

Reported by: danielbachhuber's profile danielbachhuber Owned by:
Milestone: Future Release Priority: normal
Severity: normal Version:
Component: Build/Test Tools Keywords: needs-patch
Focuses: rest-api Cc:


In [43768], we had to introduce an edge case where tests/rest-api/rest-autosaves-controller.php is run last in the test suite because the definition of DOING_AUTOSAVE pollutes the test suite.

We can't remove DOING_AUTOSAVE, but we could potentially avoid defining it during a test suite run. Or maybe there are other ideas we can explore.

"Done" for this issue would be a solution where tests/rest-api/rest-autosaves-controller.php can be tested as a part of the standard test suite execution order, not last.

Change History (4)

#1 @danielbachhuber
6 years ago

In 43769:

REST API: Skip Autosaves controller test for multisite.

There's some PHP 5.2 (cough, cough) edge case where paths calculated differently, possibly caused by differing version of PHPUnit.

See #45132, #45131, #43316.

#2 @azaozz
6 years ago

A possible solution for this and other similar cases would be to introduce a helper function, perhaps is_testing() similar to is_admin(). We already have WP_RUN_CORE_TESTS defined when PHPUnit is running, but better to have something filterable :)

#3 @desrosj
5 years ago

In 44126:

REST API: Introduce Autosaves controller and endpoint.

  • Adds WP_REST_Autosaves_Controller which extends WP_REST_Revisions_Controller.
  • Autosaves endpoint is registered for all post types except attachment because even post types without revisions enabled are expected to autosave.
  • Because setting the DOING_AUTOSAVE constant pollutes the test suite, autosaves tests are run last. We may want to improve upon this later.

Also, use a truly impossibly high number in User Controller tests. The number 100, (or 7777 in trunk), could be valid in certain test run configurations. The REST_TESTS_IMPOSSIBLY_HIGH_NUMBER constant is impossibly high for this very reason.

Finally, Skip Autosaves controller test for multisite. There's a PHP 5.2 edge case where paths calculated differently, possibly caused by differing version of PHPUnit.

Props adamsilverstein, aduth, azaozz, danielbachhuber, rmccue, danielbachhuber.

Merges [43767], [43768], [43769] to trunk.

See #45132, #45131.
Fixes #45128, #43316.

This ticket was mentioned in Slack in #core-restapi by earnjam. View the logs.

5 years ago

Note: See TracTickets for help on using tickets.