diff --git a/lib/Handler/CertificateEngine/AEngineHandler.php b/lib/Handler/CertificateEngine/AEngineHandler.php index 7ec79af234..9bd0a9a30c 100644 --- a/lib/Handler/CertificateEngine/AEngineHandler.php +++ b/lib/Handler/CertificateEngine/AEngineHandler.php @@ -199,7 +199,7 @@ public function getEngine(): string { public function populateInstance(array $rootCert): self { if (empty($rootCert)) { - $rootCert = $this->appConfig->getValueString(Application::APP_ID, 'root_cert'); + $rootCert = $this->appConfig->getValueArray(Application::APP_ID, 'root_cert'); } if (!$rootCert) { return $this; diff --git a/tests/Unit/Handler/FooterHandlerTest.php b/tests/Unit/Handler/FooterHandlerTest.php index ab65f1ed88..3571badedf 100644 --- a/tests/Unit/Handler/FooterHandlerTest.php +++ b/tests/Unit/Handler/FooterHandlerTest.php @@ -21,13 +21,13 @@ final class FooterHandlerTest extends \OCA\Libresign\Tests\Unit\TestCase { private PdfParserService&MockObject $pdfParserService; private IURLGenerator&MockObject $urlGenerator; private IL10N&MockObject $l10n; - private ITempManager&MockObject $tempManager; + private ITempManager $tempManager; private FooterHandler $footerHandler; public function setUp(): void { $this->appConfig = $this->getMockAppConfig(); $this->pdfParserService = $this->createMock(PdfParserService::class); $this->urlGenerator = $this->createMock(IURLGenerator::class); - $this->tempManager = $this->createMock(ITempManager::class); + $this->tempManager = \OCP\Server::get(ITempManager::class); $this->l10n = $this->createMock(IL10N::class); $this->l10n @@ -47,7 +47,7 @@ private function getClass(): FooterHandler { } public function testGetFooterWithoutValidationSite(): void { - $this->appConfig->setValueBool(Application::APP_ID, 'add_footer', true); + $this->appConfig->setValueBool(Application::APP_ID, 'add_footer', false); $file = $this->createMock(\OCP\Files\File::class); $libresignFile = $this->createMock(\OCA\Libresign\Db\File::class); $actual = $this->getClass()->getFooter($file, $libresignFile); @@ -66,10 +66,6 @@ public function testGetFooterWithSuccess(array $settings, array $expected): void break; } } - $this->tempManager->method('getTempBaseDir')->willReturn(sys_get_temp_dir()); - $tempName = sys_get_temp_dir() . '/' . mt_rand() . '.php'; - touch($tempName); - $this->tempManager->method('getTemporaryFile')->willReturn($tempName); $file = $this->createMock(\OCP\Files\File::class); $libresignFile = $this->createMock(\OCA\Libresign\Db\File::class); @@ -139,7 +135,7 @@ public static function dataGetFooterWithSuccess(): array { [ 'add_footer' => true, 'validation_site' => 'http://test.coop', - 'write_qrcode_on_footer' => '0', + 'write_qrcode_on_footer' => false, 'footer_link_to_site' => 'https://libresign.coop', 'footer_signed_by' => 'Digital signed by LibreSign.', 'footer_validate_in' => 'Validate in %s.', diff --git a/tests/Unit/Service/AccountServiceTest.php b/tests/Unit/Service/AccountServiceTest.php index 0990b15ae9..2d54be858c 100644 --- a/tests/Unit/Service/AccountServiceTest.php +++ b/tests/Unit/Service/AccountServiceTest.php @@ -354,7 +354,7 @@ public function testCreateToSignWithErrorInSendingEmail():void { $this->signRequestMapper->method('getByUuid')->will($this->returnValue($signRequest)); $userToSign = $this->createMock(\OCP\IUser::class); $this->userManager->method('createUser')->will($this->returnValue($userToSign)); - $this->config->method('getValueBool')->will($this->returnValue(true)); + $this->config->method('getAppValue')->will($this->returnValue('yes')); $template = $this->createMock(\OCP\Mail\IEMailTemplate::class); $this->newUserMail->method('generateTemplate')->will($this->returnValue($template)); $this->newUserMail->method('sendMail')->will($this->returnCallback(function ():void { diff --git a/tests/Unit/Service/FolderServiceTest.php b/tests/Unit/Service/FolderServiceTest.php index f12ab958f7..d9669ae06e 100644 --- a/tests/Unit/Service/FolderServiceTest.php +++ b/tests/Unit/Service/FolderServiceTest.php @@ -10,6 +10,7 @@ use Exception; use OCA\Libresign\Service\FolderService; +use OCP\AppFramework\Services\IAppConfig; use OCP\Files\AppData\IAppDataFactory; use OCP\Files\Config\IUserMountCache; use OCP\Files\Folder; @@ -17,7 +18,6 @@ use OCP\Files\IRootFolder; use OCP\Files\SimpleFS\ISimpleFile; use OCP\Files\SimpleFS\ISimpleFolder; -use OCP\IAppConfig; use OCP\IGroupManager; use OCP\IL10N; use PHPUnit\Framework\MockObject\MockObject; diff --git a/tests/Unit/Service/Install/SignSetupServiceTest.php b/tests/Unit/Service/Install/SignSetupServiceTest.php index fb355f6352..9aaa3d7fe3 100644 --- a/tests/Unit/Service/Install/SignSetupServiceTest.php +++ b/tests/Unit/Service/Install/SignSetupServiceTest.php @@ -13,7 +13,6 @@ use OC\IntegrityCheck\Helpers\FileAccessHelper; use OCA\Libresign\AppInfo\Application; use OCA\Libresign\Service\Install\SignSetupService; -use OCA\Libresign\Tests\lib\AppConfigOverwrite; use OCP\App\IAppManager; use OCP\IAppConfig; use OCP\IConfig; @@ -34,11 +33,7 @@ public function setUp(): void { $this->fileAccessHelper = new FileAccessHelper(); $this->appManager = $this->createMock(IAppManager::class); $this->config = $this->createMock(IConfig::class); - $this->appConfig = new AppConfigOverwrite( - \OCP\Server::get(\OCP\IDBConnection::class), - \OCP\Server::get(\Psr\Log\LoggerInterface::class), - \OCP\Server::get(\OCP\Security\ICrypto::class), - ); + $this->appConfig = $this->getMockAppConfig(); } /** @@ -93,14 +88,7 @@ private function writeAppSignature(string $architecture, $resource): SignSetupSe $this->environmentHelper->method('getServerRoot') ->willReturn('vfs://home'); - $this->appConfig - ->method('getValueString') - ->willReturnCallback(function ($key, $default) use ($architecture):string { - return match ($key) { - 'java_path' => 'vfs://home/data/appdata_1/libresign/' . $architecture . '/linux/java/jdk-21.0.2+13-jre/bin/java', - default => '', - }; - }); + $this->appConfig->setValueString(Application::APP_ID, 'java_path', 'vfs://home/data/appdata_1/libresign/' . $architecture . '/linux/java/jdk-21.0.2+13-jre/bin/java'); $signSetupService = $this->getInstance([ 'getAppInfoDirectory', ]); diff --git a/tests/lib/AppConfigOverwrite.php b/tests/lib/AppConfigOverwrite.php index a09c42eb48..e2bf9efa3d 100644 --- a/tests/lib/AppConfigOverwrite.php +++ b/tests/lib/AppConfigOverwrite.php @@ -74,4 +74,17 @@ public function getValueBool(string $app, string $key, bool $default = false, bo return parent::getValueBool($app, $key, $default); } + + public function getValueString(string $app, string $key, string $default = '', bool $lazy = false): string { + if (isset($this->overWrite[$app]) && isset($this->overWrite[$app][$key])) { + return $this->overWrite[$app][$key]; + } + + return parent::getValueString($app, $key, $default); + } + + public function setValueString(string $app, string $key, string $value, bool $lazy = false, bool $sensitive = false): bool { + $this->overWrite[$app][$key] = $value; + return true; + } }