Skip to content

Commit

Permalink
Add test for logging report status check
Browse files Browse the repository at this point in the history
  • Loading branch information
eileenmcnaughton committed Jun 24, 2024
1 parent 8d6e28e commit 807c0e2
Showing 1 changed file with 40 additions and 5 deletions.
45 changes: 40 additions & 5 deletions tests/phpunit/CRM/Utils/Check/Component/EnvTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,10 @@
*/
class CRM_Utils_Check_Component_EnvTest extends CiviUnitTestCase {

public function setUp(): void {
parent::setUp();
$this->useTransaction();
public function tearDown(): void {
Civi::settings()->set('logging', FALSE);
$this->callAPISuccess('Extension', 'enable', ['key' => 'civi_report']);
parent::tearDown();
}

/**
Expand All @@ -22,9 +23,43 @@ public function testResourceUrlCheck(): void {
$failRequest = $check->fileExists('https://civicrm.org', 0.001);
$successRequest = $check->fileExists('https://civicrm.org', 0);

$this->assertEquals(FALSE, $failRequest, 'Request should fail for minimum timeout.');
$this->assertEquals(TRUE, $successRequest, 'Request should not fail for infinite timeout.');
$this->assertFalse($failRequest, 'Request should fail for minimum timeout.');
$this->assertTrue($successRequest, 'Request should not fail for infinite timeout.');
}

/**
* Test the check that warns users if they have enabled logging but not Civi-report.
*
* The check should not be triggered if logging is not enabled or it
* is enabled and civi-report is enabled.
*
* @return void
*/
public function testLoggingWithReport(): void {
$this->callAPISuccess('Extension', 'disable', ['key' => 'civi_report']);
$this->assertFalse($this->checkChecks('checkLoggingHasCiviReport'));

Civi::settings()->set('logging', 1);
$check = $this->checkChecks('checkLoggingHasCiviReport');
$this->assertEquals('CiviReport required to display detailed logging.', $check['title']);

$this->callAPISuccess('Extension', 'enable', ['key' => 'civi_report']);
$this->assertFalse($this->checkChecks('checkLoggingHasCiviReport'));
}

/**
* Check the checks are checking for the checky thing.
*
* @return bool|array
*/
public function checkChecks($checkName) {
$checks = $this->callAPISuccess('System', 'check');
foreach ($checks['values'] as $check) {
if ($check['name'] === $checkName) {
return $check;
}
}
return FALSE;
}

}

0 comments on commit 807c0e2

Please sign in to comment.