From 322c2aeac81c73739a02107092ec0ae0ecfe0169 Mon Sep 17 00:00:00 2001 From: Vitor Mattos Date: Wed, 27 Mar 2024 18:21:44 -0300 Subject: [PATCH] Fix unit test Signed-off-by: Vitor Mattos --- composer.lock | 2 +- lib/Handler/TCPDFLibresign.php | 29 ------------------------ tests/Unit/Handler/Pkcs12HandlerTest.php | 23 ++++++++++++++++--- 3 files changed, 21 insertions(+), 33 deletions(-) diff --git a/composer.lock b/composer.lock index 1ff3666351..569c744780 100644 --- a/composer.lock +++ b/composer.lock @@ -4,7 +4,7 @@ "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies", "This file is @generated automatically" ], - "content-hash": "72977a0e93b9c15c9746c12691a768ee", + "content-hash": "3b8c5d2bdc7f7847621f5e16ffc8e7fc", "packages": [ { "name": "bacon/bacon-qr-code", diff --git a/lib/Handler/TCPDFLibresign.php b/lib/Handler/TCPDFLibresign.php index 8dd8c508d6..ff3409bb2d 100644 --- a/lib/Handler/TCPDFLibresign.php +++ b/lib/Handler/TCPDFLibresign.php @@ -46,33 +46,4 @@ protected function _textstring($s, $n = 0) { } return parent::_textstring($s, $n); } - - /** - * @psalm-return array{w?: mixed, h?: mixed} - */ - public function getPageTplDimension(int $pageNum): array { - if (!$this->tpls) { - return []; - } - return [ - 'w' => $this->tpls[$pageNum]['w'], - 'h' => $this->tpls[$pageNum]['h'] - ]; - } - - public function getPagesMetadata(): array { - $pageCount = current($this->parsers)->getPageCount(); - $data = [ - 'p' => $pageCount - ]; - for ($pageNo = 1; $pageNo <= $pageCount; $pageNo++) { - $dimensions = $this->getPageTplDimension($pageNo); - if (empty($dimensions['w'])) { - $this->importPage($pageNo); - $dimensions = $this->getPageTplDimension($pageNo); - } - $data['d'][] = $dimensions; - } - return $data; - } } diff --git a/tests/Unit/Handler/Pkcs12HandlerTest.php b/tests/Unit/Handler/Pkcs12HandlerTest.php index 5af879a0c7..561e79a91d 100644 --- a/tests/Unit/Handler/Pkcs12HandlerTest.php +++ b/tests/Unit/Handler/Pkcs12HandlerTest.php @@ -107,7 +107,8 @@ public function testGetFooterWithoutValidationSite() { $this->pdfParserService, ); $file = $this->createMock(\OCP\Files\File::class); - $actual = $this->pkcs12Handler->getFooter($file, 'uuid'); + $libresignFile = $this->createMock(\OCA\Libresign\Db\File::class); + $actual = $this->pkcs12Handler->getFooter($file, $libresignFile); $this->assertEmpty($actual); } @@ -141,8 +142,24 @@ public function testGetFooterWithSuccess() { ->willReturn('small_valid.pdf'); $file->method('getContent') ->willReturn(file_get_contents(__DIR__ . '/../../fixtures/small_valid.pdf')); - $actual = $this->pkcs12Handler->getFooter($file, 'uuid'); - $this->assertEquals(18615, strlen($actual)); + $libresignFile = $this->createMock(\OCA\Libresign\Db\File::class); + $libresignFile + ->method('__call') + ->willReturnCallback(function ($key, $default) { + switch ($key) { + case 'getMetadata': return [ + 'd' => [ + [ + 'w' => 100, + 'h' => 100, + ], + ], + ]; + case 'getUuid': return 'uuid'; + } + }); + $actual = $this->pkcs12Handler->getFooter($file, $libresignFile); + $this->assertEquals(7655, strlen($actual)); } public function cfsslHandlerCallbackToGetSetArguments($functionName, $value = null) {