WordPress.org

Make WordPress Core

Opened 6 years ago

Closed 6 years ago

Last modified 6 years ago

#21993 closed enhancement (wontfix)

Add WP_DOING_TESTS constant, check for it in WP_Ajax_Response

Reported by: alexkingorg Owned by:
Milestone: Priority: normal
Severity: normal Version: 3.5
Component: Unit Tests Keywords: has-patch
Focuses: Cc:

Description

I'm writing unit tests for #21767 that need to call functions such as wp_ajax_add_tag(). These functions instantiate a WP_Ajax_Response object and send(), which sends HTTP headers and causes the unit tests to fail.

So far I can't find a way to keep the headers from being sent (anyone know how to do this?) so I'm opening this ticket as an alternate solution: introduce a WP_DOING_TESTS constant (defined in the bootstrap.php of the unit testing framework) and return out of the send() function if that constant is set to true.

Again, happy to be told there is a better way to do this, but definitely want to be able to get testing coverage of these "controller" functions.

Attachments (1)

ajax-send-unit-test-compat.diff (641 bytes) - added by alexkingorg 6 years ago.
Don't send headers if running unit tests

Download all attachments as: .zip

Change History (8)

@alexkingorg
6 years ago

Don't send headers if running unit tests

#1 @alexkingorg
6 years ago

Matching ticket in Unit Tests trac instance:

http://unit-tests.trac.wordpress.org/ticket/133

#2 @bpetty
6 years ago

Have you looked at the WP_Ajax_UnitTestCase provided in the core unit tests framework? We have a number of AJAX methods (that use wp-admin/admin-ajax.php) under core tests already that use this.

#3 @alexkingorg
6 years ago

I hadn't - thanks for the pointer. Will see if I can avoid needing this with those tools. Thanks!

#4 @scribu
6 years ago

  • Cc scribu added

#5 @alexkingorg
6 years ago

  • Resolution set to wontfix
  • Status changed from new to closed

Looks like I can use those successfully, thanks! Closing this ticket.

#6 @SergeyBiryukov
6 years ago

  • Milestone Awaiting Review deleted

#7 @sirzooro
6 years ago

  • Cc sirzooro added

Some time ago I proposed another solution for this: #21282. Unfortunately it is still not implemented in core.

Note: See TracTickets for help on using tickets.