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 Jan 4, 2024
1 parent 6f09db8 commit 575e264
Showing 1 changed file with 39 additions and 5 deletions.
44 changes: 39 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,9 @@
*/
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);
parent::tearDown();
}

/**
Expand All @@ -22,9 +22,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', 'install', ['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 575e264

Please sign in to comment.