Skip to content

Commit

Permalink
fix: unit tests
Browse files Browse the repository at this point in the history
Signed-off-by: Vitor Mattos <[email protected]>
  • Loading branch information
vitormattos committed Jan 10, 2025
1 parent 54459cd commit d31589c
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 9 deletions.
12 changes: 4 additions & 8 deletions tests/Unit/Handler/FooterHandlerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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);
Expand All @@ -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);
Expand Down Expand Up @@ -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.',
Expand Down
2 changes: 1 addition & 1 deletion tests/Unit/Service/AccountServiceTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
13 changes: 13 additions & 0 deletions tests/lib/AppConfigOverwrite.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}

0 comments on commit d31589c

Please sign in to comment.