1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* This file is part of the IrishDan\ResponsiveImageBundle package. |
4
|
|
|
* |
5
|
|
|
* (c) Daniel Byrne <[email protected]> |
6
|
|
|
* |
7
|
|
|
* For the full copyright and license information, please view the LICENSE file that was distributed with this source |
8
|
|
|
* code. |
9
|
|
|
*/ |
10
|
|
|
|
11
|
|
|
namespace IrishDan\ResponsiveImageBundle\Tests\ImageProcessing; |
12
|
|
|
|
13
|
|
|
|
14
|
|
|
use IrishDan\ResponsiveImageBundle\Tests\ResponsiveImageTestCase; |
15
|
|
|
|
16
|
|
|
class ImageStylerTest extends ResponsiveImageTestCase |
17
|
|
|
{ |
18
|
|
|
private $imager; |
19
|
|
|
private $testImagePath = __DIR__ . '/../Resources/dummy.jpg'; |
20
|
|
|
private $generatedDirectory = __DIR__ . '/../Resources/generated/'; |
21
|
|
|
private $coordinates = '100, 100, 900, 900:400, 500, 700, 800'; |
22
|
|
|
|
23
|
|
|
public function setUp() |
24
|
|
|
{ |
25
|
|
|
$this->imager = $this->getService('responsive_image.image_styler'); |
26
|
|
|
$this->createDirectory($this->generatedDirectory); |
27
|
|
|
} |
28
|
|
|
|
29
|
|
|
public function tearDown() |
30
|
|
|
{ |
31
|
|
|
parent::tearDown(); |
32
|
|
|
$this->deleteDirectory($this->generatedDirectory); |
33
|
|
|
} |
34
|
|
|
|
35
|
|
|
public function testCreateImage() |
36
|
|
|
{ |
37
|
|
|
$style = [ |
38
|
|
|
'effect' => 'scale', |
39
|
|
|
'width' => 200, |
40
|
|
|
]; |
41
|
|
|
|
42
|
|
|
$destination = $this->generatedDirectory . 'dummy.jpg'; |
43
|
|
|
$this->imager->createImage($this->testImagePath, $destination, $style); |
44
|
|
|
|
45
|
|
|
$this->assertFileExists($destination); |
46
|
|
|
$this->assertEquals("image/jpeg", mime_content_type($destination)); |
47
|
|
|
} |
48
|
|
|
|
49
|
|
View Code Duplication |
public function testCreateImageWithScale() |
|
|
|
|
50
|
|
|
{ |
51
|
|
|
$style = [ |
52
|
|
|
'effect' => 'scale', |
53
|
|
|
'width' => 200, |
54
|
|
|
]; |
55
|
|
|
|
56
|
|
|
$destination = $this->generatedDirectory . 'dummy.jpg'; |
57
|
|
|
$this->imager->createImage($this->testImagePath, $destination, $style); |
58
|
|
|
|
59
|
|
|
$this->assertFileExists($destination); |
60
|
|
|
$this->assertEquals("image/jpeg", mime_content_type($destination)); |
61
|
|
|
$this->assertTrue(filesize($this->testImagePath) > filesize($destination)); |
62
|
|
|
} |
63
|
|
|
|
64
|
|
View Code Duplication |
public function testCreateImageWithCrop() |
|
|
|
|
65
|
|
|
{ |
66
|
|
|
$style = [ |
67
|
|
|
'effect' => 'crop', |
68
|
|
|
'width' => 200, |
69
|
|
|
'height' => 200, |
70
|
|
|
]; |
71
|
|
|
|
72
|
|
|
$destination = $this->generatedDirectory . 'dummy.jpg'; |
73
|
|
|
$this->imager->createImage($this->testImagePath, $destination, $style); |
74
|
|
|
|
75
|
|
|
$this->assertFileExists($destination); |
76
|
|
|
$this->assertEquals("image/jpeg", mime_content_type($destination)); |
77
|
|
|
$this->assertTrue(filesize($this->testImagePath) > filesize($destination)); |
78
|
|
|
} |
79
|
|
|
|
80
|
|
View Code Duplication |
public function testCreateImageWithCoordinates() |
|
|
|
|
81
|
|
|
{ |
82
|
|
|
$style = [ |
83
|
|
|
'effect' => 'crop', |
84
|
|
|
'width' => 200, |
85
|
|
|
'height' => 200, |
86
|
|
|
]; |
87
|
|
|
|
88
|
|
|
$destination = $this->generatedDirectory . 'dummy.jpg'; |
89
|
|
|
$this->imager->createImage($this->testImagePath, $destination, $style, $this->coordinates); |
90
|
|
|
|
91
|
|
|
$this->assertFileExists($destination); |
92
|
|
|
$this->assertEquals("image/jpeg", mime_content_type($destination)); |
93
|
|
|
$this->assertTrue(filesize($this->testImagePath) > filesize($destination)); |
94
|
|
|
} |
95
|
|
|
} |
96
|
|
|
|
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.