Skip to content

Add mock time capability

DaveD requested to merge DaveD/cdntaxreceipts:timewarp into master

This is pulled out from !133 (merged) since it's the only part that touches the non-test code, but the idea is that when not running unit tests, this should be no change and should use $_SERVER['REQUEST_TIME'] (i.e. today) for the issue date stamped on receipts the same as before. So to test this, make a receipt and look at the issue date on it.

Then the purpose of this during unit tests is to support two things:

  1. When validating the resulting pdf against a known good pdf, if the timestamps inside the files are different then it will always fail. Mock time allows fixing the time.
  2. In general in unit tests there are many times when you want to avoid something like rollover seconds between when the test starts and when it ends which causes intermittent failures. For regular unit tests civi already provides CRM_Utils_Time, but for mink tests that won't work because throughout a given test you often visit more than one page, so it gets reset each page defeating the purpose. This implements a subset of CRM_Utils_Time using a database setting instead so it doesn't get reset.

I can't put the mock class in the shared drupal module because then it would require every non-test install to have that drupal module and be on drupal 8+ which doesn't make any sense. It could be another extension which cdntax or other extensions could <require> via info.xml, but that seems overkill right now.

Merge request reports