From 807c0e24cd7372204b4854bd4dbda3a0a09daa41 Mon Sep 17 00:00:00 2001 From: eileen Date: Thu, 4 Jan 2024 17:04:51 +1300 Subject: [PATCH] Add test for logging report status check --- .../CRM/Utils/Check/Component/EnvTest.php | 45 ++++++++++++++++--- 1 file changed, 40 insertions(+), 5 deletions(-) diff --git a/tests/phpunit/CRM/Utils/Check/Component/EnvTest.php b/tests/phpunit/CRM/Utils/Check/Component/EnvTest.php index ff32ff323a67..573e4a81d838 100644 --- a/tests/phpunit/CRM/Utils/Check/Component/EnvTest.php +++ b/tests/phpunit/CRM/Utils/Check/Component/EnvTest.php @@ -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(); } /** @@ -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; } }