41 lines
1.1 KiB
PHP
41 lines
1.1 KiB
PHP
<?php
|
|
|
|
namespace App\Tests\Service\Pdf;
|
|
|
|
use App\Service\Pdf\Sanitizer;
|
|
use PHPUnit\Framework\TestCase;
|
|
use Symfony\Component\Filesystem\Filesystem;
|
|
|
|
class SanitizerTest extends TestCase
|
|
{
|
|
public function testAcceptsImages(): void
|
|
{
|
|
$tempDir = realpath(__DIR__.'/../../../temp');
|
|
$sourceFilepath = realpath(__DIR__.'/../../Resources/upload.jpg');
|
|
$targetFilepath = $tempDir.'/test.pdf';
|
|
|
|
$sanitizer = new Sanitizer('/usr/bin/gs', '/usr/bin/convert', $tempDir);
|
|
|
|
$sanitizer->sanitizeFile($sourceFilepath, $targetFilepath);
|
|
|
|
$this->assertFileExists($targetFilepath);
|
|
|
|
(new Filesystem())->remove($targetFilepath);
|
|
}
|
|
|
|
public function testAcceptsPdfs(): void
|
|
{
|
|
$tempDir = realpath(__DIR__.'/../../../temp');
|
|
$sourceFilepath = realpath(__DIR__.'/../../Resources/upload.pdf');
|
|
$targetFilepath = $tempDir.'/test.pdf';
|
|
|
|
$sanitizer = new Sanitizer('/usr/bin/gs', '/usr/bin/convert', $tempDir);
|
|
|
|
$sanitizer->sanitizeFile($sourceFilepath, $targetFilepath);
|
|
|
|
$this->assertFileExists($targetFilepath);
|
|
|
|
(new Filesystem())->remove($targetFilepath);
|
|
}
|
|
}
|