1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Knp\Bundle\SnappyBundle\Tests; |
4
|
|
|
|
5
|
|
|
use PHPUnit\Framework\TestCase; |
6
|
|
|
use Symfony\Component\Filesystem\Filesystem; |
7
|
|
|
|
8
|
|
|
class FunctionalTest extends TestCase |
9
|
|
|
{ |
10
|
|
|
/** @var TestKernel */ |
11
|
|
|
private $kernel; |
12
|
|
|
|
13
|
|
|
/** @var Filesystem */ |
14
|
|
|
private $filesystem; |
15
|
|
|
|
16
|
|
|
public function setUp() |
17
|
|
|
{ |
18
|
|
|
$this->kernel = new TestKernel(uniqid(), false); |
19
|
|
|
|
20
|
|
|
$this->filesystem = new Filesystem(); |
21
|
|
|
$this->filesystem->mkdir($this->kernel->getCacheDir()); |
22
|
|
|
} |
23
|
|
|
|
24
|
|
|
public function tearDown() |
25
|
|
|
{ |
26
|
|
|
$this->filesystem->remove($this->kernel->getCacheDir()); |
27
|
|
|
} |
28
|
|
|
|
29
|
|
|
public function testServiceIsAvailableOutOfTheBox() |
30
|
|
|
{ |
31
|
|
|
$this->kernel->setConfigurationFilename(__DIR__ . '/fixtures/config/out_of_the_box.yml'); |
32
|
|
|
$this->kernel->boot(); |
33
|
|
|
|
34
|
|
|
$container = $this->kernel->getContainer(); |
35
|
|
|
|
36
|
|
|
$this->assertTrue($container->has('knp_snappy.pdf'), 'The pdf service is available.'); |
37
|
|
|
|
38
|
|
|
$pdf = $container->get('knp_snappy.pdf'); |
39
|
|
|
|
40
|
|
|
$this->assertInstanceof('Knp\Snappy\Pdf', $pdf); |
41
|
|
|
$this->assertEquals('wkhtmltopdf', $pdf->getBinary()); |
42
|
|
|
|
43
|
|
|
$this->assertTrue($container->has('knp_snappy.image'), 'The image service is available.'); |
44
|
|
|
|
45
|
|
|
$image = $container->get('knp_snappy.image'); |
46
|
|
|
|
47
|
|
|
$this->assertInstanceof('Knp\Snappy\Image', $image); |
48
|
|
|
$this->assertEquals('wkhtmltoimage', $image->getBinary()); |
49
|
|
|
} |
50
|
|
|
|
51
|
|
|
public function testChangeBinaries() |
52
|
|
|
{ |
53
|
|
|
$this->kernel->setConfigurationFilename(__DIR__ . '/fixtures/config/change_binaries.yml'); |
54
|
|
|
$this->kernel->boot(); |
55
|
|
|
|
56
|
|
|
$container = $this->kernel->getContainer(); |
57
|
|
|
|
58
|
|
|
$this->assertTrue($container->has('knp_snappy.pdf')); |
59
|
|
|
|
60
|
|
|
$pdf = $container->get('knp_snappy.pdf'); |
61
|
|
|
|
62
|
|
|
$this->assertEquals('/custom/binary/for/wkhtmltopdf', $pdf->getBinary()); |
63
|
|
|
|
64
|
|
|
$this->assertTrue($container->has('knp_snappy.image')); |
65
|
|
|
|
66
|
|
|
$image = $container->get('knp_snappy.image'); |
67
|
|
|
|
68
|
|
|
$this->assertEquals('/custom/binary/for/wkhtmltoimage', $image->getBinary()); |
69
|
|
|
} |
70
|
|
|
|
71
|
|
|
public function testChangeTemporaryFolder() |
72
|
|
|
{ |
73
|
|
|
$this->kernel->setConfigurationFilename(__DIR__ . '/fixtures/config/change_temporary_folder.yml'); |
74
|
|
|
$this->kernel->boot(); |
75
|
|
|
|
76
|
|
|
$container = $this->kernel->getContainer(); |
77
|
|
|
|
78
|
|
|
$pdf = $container->get('knp_snappy.pdf'); |
79
|
|
|
$this->assertEquals('/path/to/the/tmp', $pdf->getTemporaryFolder()); |
80
|
|
|
|
81
|
|
|
$image = $container->get('knp_snappy.image'); |
82
|
|
|
$this->assertEquals('/path/to/the/tmp', $image->getTemporaryFolder()); |
83
|
|
|
} |
84
|
|
|
|
85
|
|
|
public function testDisablePdf() |
86
|
|
|
{ |
87
|
|
|
$this->kernel->setConfigurationFilename(__DIR__ . '/fixtures/config/disable_pdf.yml'); |
88
|
|
|
$this->kernel->boot(); |
89
|
|
|
|
90
|
|
|
$container = $this->kernel->getContainer(); |
91
|
|
|
|
92
|
|
|
$this->assertFalse($container->has('knp_snappy.pdf'), 'The pdf service is NOT available.'); |
93
|
|
|
$this->assertTrue($container->has('knp_snappy.image'), 'The image service is available.'); |
94
|
|
|
} |
95
|
|
|
|
96
|
|
|
public function testDisableImage() |
97
|
|
|
{ |
98
|
|
|
$this->kernel->setConfigurationFilename(__DIR__ . '/fixtures/config/disable_image.yml'); |
99
|
|
|
$this->kernel->boot(); |
100
|
|
|
|
101
|
|
|
$container = $this->kernel->getContainer(); |
102
|
|
|
|
103
|
|
|
$this->assertTrue($container->has('knp_snappy.pdf'), 'The pdf service is available.'); |
104
|
|
|
$this->assertFalse($container->has('knp_snappy.image'), 'The image service is NOT available.'); |
105
|
|
|
} |
106
|
|
|
} |
107
|
|
|
|