Files
myep-team/tests/Service/Pdf/SanitizerTest.php
T

50 lines
1.6 KiB
PHP

<?php
namespace App\Tests\Service\Pdf;
use App\Service\Pdf\Sanitizer;
use PHPUnit\Framework\TestCase;
use Symfony\Component\Filesystem\Filesystem;
use Symfony\Component\Process\Process;
class SanitizerTest extends TestCase
{
public function testAcceptsImages(): void
{
$tempDir = realpath(__DIR__.'/../../../temp');
$sourceFilepath = $tempDir.'/upload.png';
$targetFilepath = $tempDir.'/test-image';
$sanitizer = new Sanitizer('/usr/bin/gs', '/usr/bin/convert', $tempDir);
$process = new Process(['/usr/bin/convert', '-size', '1x1', 'xc:white', $sourceFilepath]);
$process->run();
if (false === $process->isSuccessful()) {
$this->markTestSkipped('Unable to create image fixture: '.$process->getErrorOutput());
}
$sanitizedFilepath = $sanitizer->sanitizeFile($sourceFilepath, $targetFilepath, false);
$this->assertSame($targetFilepath.'.pdf', $sanitizedFilepath);
$this->assertFileExists($sanitizedFilepath);
(new Filesystem())->remove([$sourceFilepath, $sanitizedFilepath]);
}
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, false);
$this->assertFileExists($targetFilepath);
(new Filesystem())->remove($targetFilepath);
}
}