1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Kunstmaan\MediaBundle\Tests\Helper\File; |
4
|
|
|
|
5
|
|
|
use Kunstmaan\MediaBundle\Entity\Media; |
6
|
|
|
use Kunstmaan\MediaBundle\Helper\File\PdfHandler; |
7
|
|
|
use Kunstmaan\MediaBundle\Helper\Transformer\PreviewTransformerInterface; |
8
|
|
|
use PHPUnit\Framework\TestCase; |
9
|
|
|
use Symfony\Component\Filesystem\Filesystem; |
10
|
|
|
use Symfony\Component\HttpFoundation\File\File; |
11
|
|
|
use Symfony\Component\Mime\MimeTypes; |
12
|
|
|
|
13
|
|
|
class PdfHandlerTest extends TestCase |
14
|
|
|
{ |
15
|
|
|
/** @var PdfHandler */ |
16
|
|
|
protected $object; |
17
|
|
|
|
18
|
|
|
/** @var PreviewTransformerInterface */ |
19
|
|
|
protected $pdfTransformer; |
20
|
|
|
|
21
|
|
|
/** @var string */ |
22
|
|
|
protected $filesDir; |
23
|
|
|
|
24
|
|
|
/** |
25
|
|
|
* Sets up the fixture, for example, opens a network connection. |
26
|
|
|
* This method is called before a test is executed. |
27
|
|
|
*/ |
28
|
|
|
protected function setUp(): void |
29
|
|
|
{ |
30
|
|
|
$this->pdfTransformer = $this->createMock('Kunstmaan\MediaBundle\Helper\Transformer\PreviewTransformerInterface'); |
31
|
|
|
$this->filesDir = realpath(__DIR__ . '/../../Files'); |
32
|
|
|
|
33
|
|
|
$this->object = new PdfHandler(1, new MimeTypes()); |
34
|
|
|
$this->object->setPdfTransformer($this->pdfTransformer); |
35
|
|
|
} |
36
|
|
|
|
37
|
|
|
public function testGetType() |
38
|
|
|
{ |
39
|
|
|
$this->assertEquals(PdfHandler::TYPE, $this->object->getType()); |
40
|
|
|
} |
41
|
|
|
|
42
|
|
|
public function testCanHandlePdfFiles() |
43
|
|
|
{ |
44
|
|
|
$media = new Media(); |
45
|
|
|
$media->setContent(new File($this->filesDir . '/sample.pdf')); |
46
|
|
|
$media->setContentType('application/pdf'); |
47
|
|
|
|
48
|
|
|
$this->assertTrue($this->object->canHandle($media)); |
49
|
|
|
} |
50
|
|
|
|
51
|
|
|
public function testCannotHandleNonPdfFiles() |
52
|
|
|
{ |
53
|
|
|
$media = new Media(); |
54
|
|
|
$media->setContentType('image/jpg'); |
55
|
|
|
|
56
|
|
|
$this->assertFalse($this->object->canHandle($media)); |
57
|
|
|
$this->assertFalse($this->object->canHandle(new \stdClass())); |
58
|
|
|
} |
59
|
|
|
|
60
|
|
|
public function testGetImageUrl() |
61
|
|
|
{ |
62
|
|
|
$this->pdfTransformer |
|
|
|
|
63
|
|
|
->expects($this->any()) |
64
|
|
|
->method('getPreviewFilename') |
65
|
|
|
->willReturn('/media.pdf.jpg'); |
66
|
|
|
|
67
|
|
|
$media = new Media(); |
68
|
|
|
$media->setUrl('/path/to/media.pdf'); |
69
|
|
|
$this->assertNull($this->object->getImageUrl($media, '/basepath')); |
70
|
|
|
|
71
|
|
|
$previewFilename = sys_get_temp_dir() . '/media.pdf.jpg'; |
72
|
|
|
$fileSystem = new Filesystem(); |
73
|
|
|
$fileSystem->touch($previewFilename); |
74
|
|
|
$media->setUrl('/media.pdf'); |
75
|
|
|
$this->object->setWebPath(sys_get_temp_dir()); |
76
|
|
|
$this->assertEquals('/media.pdf.jpg', $this->object->getImageUrl($media, '')); |
77
|
|
|
$fileSystem->remove($previewFilename); |
78
|
|
|
} |
79
|
|
|
} |
80
|
|
|
|
This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.
This is most likely a typographical error or the method has been renamed.