1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace ByTIC\DocumentGenerator\Tests\PdfLetters; |
4
|
|
|
|
5
|
|
|
use ByTIC\DocumentGenerator\Tests\AbstractTest; |
6
|
|
|
use ByTIC\DocumentGenerator\Tests\Fixtures\Models\PdfLetters\PdfLetter; |
7
|
|
|
use ByTIC\DocumentGenerator\Tests\Fixtures\Models\Recipients\Recipient; |
8
|
|
|
use ByTIC\MediaLibrary\Media\Media; |
9
|
|
|
use Symfony\Component\HttpFoundation\File\UploadedFile; |
10
|
|
|
|
11
|
|
|
/** |
12
|
|
|
* Class PdfLetterTraitTest |
13
|
|
|
* @package ByTIC\DocumentGenerator\Tests\PdfLetters |
14
|
|
|
*/ |
15
|
|
|
class PdfLetterTraitTest extends AbstractTest |
16
|
|
|
{ |
17
|
|
|
/** |
18
|
|
|
* |
19
|
|
|
*/ |
20
|
|
View Code Duplication |
public function testUploadFromRequestValid() |
|
|
|
|
21
|
|
|
{ |
22
|
|
|
$letter = new PdfLetter(); |
23
|
|
|
$letter->id = 10; |
24
|
|
|
|
25
|
|
|
$uploadedFile = new UploadedFile( |
26
|
|
|
TEST_FIXTURE_PATH . '/files/file.pdf', |
27
|
|
|
'test original name.pdf', |
28
|
|
|
'application/pdf', |
29
|
|
|
null, |
30
|
|
|
null, |
31
|
|
|
true |
32
|
|
|
); |
33
|
|
|
|
34
|
|
|
$response = $letter->uploadFromRequest($uploadedFile); |
35
|
|
|
parent::assertInstanceOf(Media::class, $response); |
|
|
|
|
36
|
|
|
self::assertFileExists(TEST_FIXTURE_PATH . '/files/pdf_letters/10/file.pdf'); |
37
|
|
|
} |
38
|
|
|
|
39
|
|
View Code Duplication |
public function testUploadFromRequestWithInvalidFileType() |
|
|
|
|
40
|
|
|
{ |
41
|
|
|
$letter = new PdfLetter(); |
42
|
|
|
$letter->id = 10; |
43
|
|
|
|
44
|
|
|
$uploadedFile = new UploadedFile( |
45
|
|
|
TEST_FIXTURE_PATH . '/files/file.pdf', |
46
|
|
|
'test original name.doc', |
47
|
|
|
null, |
48
|
|
|
null, |
49
|
|
|
null, |
50
|
|
|
true |
51
|
|
|
); |
52
|
|
|
|
53
|
|
|
$response = $letter->uploadFromRequest($uploadedFile); |
54
|
|
|
parent::assertSame('INVALID_MIME_TYPE_ERROR', $response); |
|
|
|
|
55
|
|
|
} |
56
|
|
|
|
57
|
|
|
public function testGenerateFile() |
58
|
|
|
{ |
59
|
|
|
$letter = new PdfLetter(); |
60
|
|
|
$letter->id = 99; |
61
|
|
|
|
62
|
|
|
$pdf = $letter->generateNewPdfObj(); |
63
|
|
|
$output = $pdf->Output('output.pdf', 'S'); |
64
|
|
|
|
65
|
|
|
parent::assertStringStartsWith('%PDF-1.7', $output); |
|
|
|
|
66
|
|
|
parent::assertStringContainsString('%%EOF', $output); |
|
|
|
|
67
|
|
|
} |
68
|
|
|
} |
69
|
|
|
|
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.
You can also find more detailed suggestions in the “Code” section of your repository.