-
-
Notifications
You must be signed in to change notification settings - Fork 57
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
24ce51d
commit 3bf8ee7
Showing
3 changed files
with
100 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,90 @@ | ||
<?php | ||
|
||
namespace OCA\Libresign\Tests\Unit\Service; | ||
|
||
use OC\SystemConfig; | ||
use OCA\Libresign\Exception\LibresignException; | ||
use OCA\Libresign\Service\InstallService; | ||
use OCA\Libresign\Service\PdfParserService; | ||
use OCP\IConfig; | ||
use PHPUnit\Framework\MockObject\MockObject; | ||
|
||
/** | ||
* @internal | ||
*/ | ||
final class PdfParseServiceTest extends \OCA\Libresign\Tests\Unit\TestCase { | ||
/** @var IConfig|MockObject */ | ||
private $config; | ||
/** @var SystemConfig|MockObject */ | ||
private $systemConfig; | ||
/** @var InstallService|MockObject */ | ||
private $installService; | ||
|
||
public function setUp(): void { | ||
$this->config = $this->createMock(IConfig::class); | ||
$this->systemConfig = $this->createMock(SystemConfig::class); | ||
$this->installService = $this->createMock(InstallService::class); | ||
} | ||
|
||
private function getService(): PdfParserService { | ||
return new PdfParserService( | ||
$this->config, | ||
$this->systemConfig, | ||
$this->installService | ||
); | ||
} | ||
|
||
public function testGetMetadataWithFail(): void { | ||
$this->expectException(LibresignException::class); | ||
$this->config | ||
->method('getAppValue') | ||
->willReturnCallback(function ($appid, $key, $default) { | ||
switch ($key) { | ||
case 'libresign_cli_path': return '/fake_path/'; | ||
} | ||
}); | ||
$this->systemConfig | ||
->method('getValue') | ||
->willReturnCallback(function ($key, $default) { | ||
switch ($key) { | ||
case 'datadirectory': return $default; | ||
} | ||
}); | ||
$path = '/fake'; | ||
$this->getService()->getMetadata($path); | ||
} | ||
|
||
/** | ||
* @dataProvider providerGetMetadataWIthSuccess | ||
*/ | ||
public function testGetMetadataWIthSuccess(string $path, array $expected): void { | ||
$this->installService = \OC::$server->get(InstallService::class); | ||
$this->systemConfig = \OC::$server->get(SystemConfig::class); | ||
$this->config = \OC::$server->get(IConfig::class); | ||
$actual = $this->getService()->getMetadata($path); | ||
$this->assertEquals($expected, $actual); | ||
} | ||
|
||
public function providerGetMetadataWIthSuccess(): array { | ||
return [ | ||
[ | ||
'/../apps/libresign/tests/fixtures/small_valid.pdf', | ||
[ | ||
'p' => 1, | ||
'd' => [ | ||
['w' => 595.276, 'h' => 841.89], | ||
], | ||
] | ||
], | ||
[ | ||
'/../apps/libresign/tests/fixtures/small_valid-signed.pdf', | ||
[ | ||
'p' => 1, | ||
'd' => [ | ||
['w' => 595.276, 'h' => 841.89], | ||
], | ||
] | ||
], | ||
]; | ||
} | ||
} |