Opened 3 years ago
Closed 3 years ago
#41561 closed enhancement (fixed)
Remove usage of DOING_AJAX in the test suite
Reported by: | johnbillion | Owned by: | johnbillion |
---|---|---|---|
Milestone: | 4.9 | Priority: | normal |
Severity: | normal | Version: | |
Component: | Build/Test Tools | Keywords: | needs-unit-tests |
Focuses: | Cc: |
Description
In the test suite, several tests define DOING_AJAX
to true. This effectively pollutes the tests which follow them, and prevent any other tests from operating in a non-Ajax state when they need to (for example, Tests_WP_Customize_Manager::test_not_doing_ajax()
).
Instances of DOING_AJAX should be replaced by use of a filter, for example add_filter( 'wp_doing_ajax', '__return_true' )
.
Attachments (3)
Change History (14)
#2
@
3 years ago
- Keywords has-patch dev-feedback added; needs-patch removed
I was looking on simple tickets to start with unit tests so this was perfect.
I checked and with this changes there was no problems with the tests :-)
This ticket was mentioned in Slack in #core by mte90. View the logs.
3 years ago
#4
@
3 years ago
- Keywords dev-feedback removed
- Milestone changed from Awaiting Review to 4.9
@Mte90 Looks good!
- The
test_not_doing_ajax()
test can useadd_filter( 'wp_doing_ajax', '__return_false' )
to force a non-Ajax request, and then remove themarkTestSkipped
call. - Does this cover all instances of
DOING_AJAX
in the test suite?
#5
@
3 years ago
- I will do a new patch for that asap
- I searched in all the code about the use of the constant and replace with the function :-)
#8
@
3 years ago
I am not sure the current implementation resolves the issue properly. Adding a filter in the static setUpBeforeClass
method will still exist in test cases that are run later. I advise putting the hook into the setUp
method like the wp_die_ajax_handler
hook.
I think this would also be more in line with the WP_UnitTestCase
class as it backs up all hooks in the setUp
method.
#9
@
3 years ago
- Keywords needs-unit-tests added; has-patch removed
- Resolution fixed deleted
- Status changed from closed to reopened
Re-opening as per comment above.
#10
@
3 years ago
41561.3.diff moves the filter from setUpBeforeClass()
to setUp()
in WP_Ajax_UnitTestCase
. All other occurrences are in the correct location.
Previously: #25669