aboutsummaryrefslogtreecommitdiffstats
path: root/apps/settings/tests
diff options
context:
space:
mode:
authorFerdinand Thiessen <opensource@fthiessen.de>2024-06-27 15:14:26 +0200
committerFerdinand Thiessen <opensource@fthiessen.de>2024-07-03 11:37:49 +0200
commit8fc498fb820ed1459475eec98cfedb23161dd643 (patch)
tree600fec2bac33ad66d1b06eedfd8cca734ab9e070 /apps/settings/tests
parentacb95d5c0f5d0f3d5ea4a88b4adf1be62f52c29a (diff)
downloadnextcloud-server-8fc498fb820ed1459475eec98cfedb23161dd643.tar.gz
nextcloud-server-8fc498fb820ed1459475eec98cfedb23161dd643.zip
fix(IntegrityCheck): Ensure the check is run if no results are available
If there are no cached results the current implementation was also returning an empty array, but this was the same as when there was a successful run. So to distinguish this we return `null` if there are *no* results. In this case we need to rerun the integrity checker. Signed-off-by: Ferdinand Thiessen <opensource@fthiessen.de>
Diffstat (limited to 'apps/settings/tests')
-rw-r--r--apps/settings/tests/SetupChecks/CodeIntegrityTest.php135
1 files changed, 135 insertions, 0 deletions
diff --git a/apps/settings/tests/SetupChecks/CodeIntegrityTest.php b/apps/settings/tests/SetupChecks/CodeIntegrityTest.php
new file mode 100644
index 00000000000..52101aed901
--- /dev/null
+++ b/apps/settings/tests/SetupChecks/CodeIntegrityTest.php
@@ -0,0 +1,135 @@
+<?php
+
+declare(strict_types=1);
+
+/**
+ * SPDX-FileCopyrightText: 2024 Nextcloud GmbH and Nextcloud contributors
+ * SPDX-License-Identifier: AGPL-3.0-or-later
+ */
+namespace OCA\Settings\Tests;
+
+use OC\IntegrityCheck\Checker;
+use OCA\Settings\SetupChecks\CodeIntegrity;
+use OCP\IL10N;
+use OCP\IURLGenerator;
+use OCP\SetupCheck\SetupResult;
+use PHPUnit\Framework\MockObject\MockObject;
+use Test\TestCase;
+
+class CodeIntegrityTest extends TestCase {
+
+ private IL10N&MockObject $l10n;
+ private IURLGenerator&MockObject $urlGenerator;
+ private Checker&MockObject $checker;
+
+ protected function setUp(): void {
+ parent::setUp();
+
+ $this->l10n = $this->getMockBuilder(IL10N::class)
+ ->disableOriginalConstructor()->getMock();
+ $this->l10n->expects($this->any())
+ ->method('t')
+ ->willReturnCallback(function ($message, array $replace) {
+ return vsprintf($message, $replace);
+ });
+ $this->urlGenerator = $this->createMock(IURLGenerator::class);
+ $this->checker = $this->createMock(Checker::class);
+ }
+
+ public function testSkipOnDisabled(): void {
+ $this->checker->expects($this->atLeastOnce())
+ ->method('isCodeCheckEnforced')
+ ->willReturn(false);
+
+ $check = new CodeIntegrity(
+ $this->l10n,
+ $this->urlGenerator,
+ $this->checker,
+ );
+ $this->assertEquals(SetupResult::INFO, $check->run()->getSeverity());
+ }
+
+ public function testSuccessOnEmptyResults(): void {
+ $this->checker->expects($this->atLeastOnce())
+ ->method('isCodeCheckEnforced')
+ ->willReturn(true);
+ $this->checker->expects($this->atLeastOnce())
+ ->method('getResults')
+ ->willReturn([]);
+ $this->checker->expects(($this->atLeastOnce()))
+ ->method('hasPassedCheck')
+ ->willReturn(true);
+
+ $check = new CodeIntegrity(
+ $this->l10n,
+ $this->urlGenerator,
+ $this->checker,
+ );
+ $this->assertEquals(SetupResult::SUCCESS, $check->run()->getSeverity());
+ }
+
+ public function testCheckerIsReRunWithoutResults(): void {
+ $this->checker->expects($this->atLeastOnce())
+ ->method('isCodeCheckEnforced')
+ ->willReturn(true);
+ $this->checker->expects($this->atLeastOnce())
+ ->method('getResults')
+ ->willReturn(null);
+ $this->checker->expects(($this->atLeastOnce()))
+ ->method('hasPassedCheck')
+ ->willReturn(true);
+
+ // This is important and must be called
+ $this->checker->expects($this->once())
+ ->method('runInstanceVerification');
+
+ $check = new CodeIntegrity(
+ $this->l10n,
+ $this->urlGenerator,
+ $this->checker,
+ );
+ $this->assertEquals(SetupResult::SUCCESS, $check->run()->getSeverity());
+ }
+
+ public function testCheckerIsNotReReInAdvance(): void {
+ $this->checker->expects($this->atLeastOnce())
+ ->method('isCodeCheckEnforced')
+ ->willReturn(true);
+ $this->checker->expects($this->atLeastOnce())
+ ->method('getResults')
+ ->willReturn(['mocked']);
+ $this->checker->expects(($this->atLeastOnce()))
+ ->method('hasPassedCheck')
+ ->willReturn(true);
+
+ // There are results thus this must never be called
+ $this->checker->expects($this->never())
+ ->method('runInstanceVerification');
+
+ $check = new CodeIntegrity(
+ $this->l10n,
+ $this->urlGenerator,
+ $this->checker,
+ );
+ $this->assertEquals(SetupResult::SUCCESS, $check->run()->getSeverity());
+ }
+
+ public function testErrorOnMissingIntegrity(): void {
+ $this->checker->expects($this->atLeastOnce())
+ ->method('isCodeCheckEnforced')
+ ->willReturn(true);
+ $this->checker->expects($this->atLeastOnce())
+ ->method('getResults')
+ ->willReturn(['mocked']);
+ $this->checker->expects(($this->atLeastOnce()))
+ ->method('hasPassedCheck')
+ ->willReturn(false);
+
+ $check = new CodeIntegrity(
+ $this->l10n,
+ $this->urlGenerator,
+ $this->checker,
+ );
+ $this->assertEquals(SetupResult::ERROR, $check->run()->getSeverity());
+ }
+}