This was discovered while working on
MDL-64531, where we wanted a PHPUNIT test to test the behaviour of a function with AJAX_SCRIPT true and false.
Also, it is the case that wherever we access these constants in the code, we have duplicated logic like (defined('PHPUNIT_TEST') && PHPUNIT_TEST).
I suggest we add a wrapper for this, like:
This should reduce duplicated logic, and allow these things to be overridden during unit tests.
As well as coding this new mechanism, all the existing reference to the bare constants should be updated.