* Check that outputting the display value for a file field with No description doesn't generate error
*/
public function testFileDisplayValueNoDescription(): void {
+ $this->useFrozenTime();
$customGroup = $this->customGroupCreate([
'extends' => 'Individual',
'title' => 'Test Contact File Custom Group',
$file = $this->callAPISuccess('File', 'create', [
'uri' => $filePath,
]);
- $individual = $this->individualCreate(['custom_' . $fileField['id'] => $file['id']]);
+ $this->individualCreate(['custom_' . $fileField['id'] => $file['id']]);
$expectedDisplayValue = CRM_Core_BAO_File::paperIconAttachment('*', $file['id'])[$file['id']];
$this->assertEquals($expectedDisplayValue, CRM_Core_BAO_CustomField::displayValue($file['id'], $fileField['id']));
}
*/
public function testContactTokens(): void {
// Freeze the time at the start of the test, so checksums don't suffer from second rollovers.
- $restoreTime = $this->useFrozenTime();
+ $this->useFrozenTime();
$this->hookClass->setHook('civicrm_tokenValues', [$this, 'hookTokenValues']);
$this->hookClass->setHook('civicrm_tokens', [$this, 'hookTokens']);
$this->assertEquals($expected_parts[0], $returned_parts[0]);
$this->assertApproxEquals($expected_parts[1], $returned_parts[1], 2);
$this->assertEquals($expected_parts[2], $returned_parts[2]);
- $restoreTime->cleanup();
}
/**
*/
public function testTokensIndividually(): void {
// Freeze the time at the start of the test, so checksums don't suffer from second rollovers.
- // This variable releases the time on destruct so needs to be assigned for the
- // duration of the test.
- /** @noinspection PhpUnusedLocalVariableInspection */
- $restoreTime = $this->useFrozenTime();
+ $this->useFrozenTime();
$this->hookClass->setHook('civicrm_tokenValues', [$this, 'hookTokenValues']);
$this->hookClass->setHook('civicrm_tokens', [$this, 'hookTokens']);
', $messageHtml);
}
- /**
- * Temporarily freeze time, as perceived through `CRM_Utils_Time`.
- *
- * @return \CRM_Utils_AutoClean
- */
- protected function useFrozenTime(): CRM_Utils_AutoClean {
- $oldTimeFunc = getenv('TIME_FUNC');
- putenv('TIME_FUNC=frozen');
- CRM_Utils_Time::setTime(date('Y-m-d H:i:s'));
- return CRM_Utils_AutoClean::with(function () use ($oldTimeFunc) {
- putenv($oldTimeFunc === NULL ? 'TIME_FUNC' : "TIME_FUNC=$oldTimeFunc");
- CRM_Utils_Time::resetTime();
- });
- }
-
/**
* @param array $tokenData
*
*/
protected $formController;
+ /**
+ * @var \CRM_Utils_AutoClean
+ */
+ private $frozenTime;
+
/**
* Constructor.
*
protected function tearDown(): void {
$this->_apiversion = 3;
$this->resetLabels();
+ $this->frozenTime = NULL;
error_reporting(E_ALL & ~E_NOTICE);
$this->resetHooks();
return $result['values'][$result['id']];
}
+ /**
+ * Temporarily freeze time, as perceived through `CRM_Utils_Time`.
+ */
+ protected function useFrozenTime(): void {
+ $oldTimeFunc = getenv('TIME_FUNC');
+ putenv('TIME_FUNC=frozen');
+ CRM_Utils_Time::setTime(date('Y-m-d H:i:s'));
+ $this->frozenTime = CRM_Utils_AutoClean::with(function () use ($oldTimeFunc) {
+ putenv($oldTimeFunc === NULL ? 'TIME_FUNC' : "TIME_FUNC=$oldTimeFunc");
+ CRM_Utils_Time::resetTime();
+ });
+ }
+
/**
* Delete Tag.
*