Skip to content

Commit

Permalink
Fix unit test
Browse files Browse the repository at this point in the history
Signed-off-by: Vitor Mattos <[email protected]>
  • Loading branch information
vitormattos committed Mar 28, 2024
1 parent 63a7978 commit 322c2ae
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 33 deletions.
2 changes: 1 addition & 1 deletion composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

29 changes: 0 additions & 29 deletions lib/Handler/TCPDFLibresign.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}
23 changes: 20 additions & 3 deletions tests/Unit/Handler/Pkcs12HandlerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

Expand Down Expand Up @@ -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) {
Expand Down

0 comments on commit 322c2ae

Please sign in to comment.