|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
/** |
|
4
|
|
|
* @license LGPLv3, https://opensource.org/licenses/LGPL-3.0 |
|
5
|
|
|
* @copyright Aimeos (aimeos.org), 2017-2023 |
|
6
|
|
|
*/ |
|
7
|
|
|
|
|
8
|
|
|
|
|
9
|
|
|
namespace Aimeos\MW\Media\Image; |
|
10
|
|
|
|
|
11
|
|
|
|
|
12
|
|
|
class SvgTest extends \PHPUnit\Framework\TestCase |
|
13
|
|
|
{ |
|
14
|
|
|
private $content; |
|
15
|
|
|
|
|
16
|
|
|
|
|
17
|
|
|
public static function setUpBeforeClass() : void |
|
18
|
|
|
{ |
|
19
|
|
|
$dir = dirname( dirname( dirname( __DIR__ ) ) ) . '/tmp'; |
|
20
|
|
|
|
|
21
|
|
|
if( !is_dir( $dir ) ) { |
|
22
|
|
|
mkdir( $dir, 0755, true ); |
|
23
|
|
|
} |
|
24
|
|
|
} |
|
25
|
|
|
|
|
26
|
|
|
|
|
27
|
|
|
protected function setUp() : void |
|
28
|
|
|
{ |
|
29
|
|
|
$ds = DIRECTORY_SEPARATOR; |
|
30
|
|
|
$this->content = file_get_contents( dirname( __DIR__ ) . $ds . '_testfiles' . $ds . 'image.svg' ); |
|
31
|
|
|
} |
|
32
|
|
|
|
|
33
|
|
|
|
|
34
|
|
|
public function testConstruct() |
|
35
|
|
|
{ |
|
36
|
|
|
$media = new \Aimeos\MW\Media\Image\Svg( $this->content, 'image/svg+xml' ); |
|
37
|
|
|
|
|
38
|
|
|
$this->assertEquals( 'image/svg+xml', $media->getMimetype() ); |
|
39
|
|
|
} |
|
40
|
|
|
|
|
41
|
|
|
|
|
42
|
|
|
public function testConstructException() |
|
43
|
|
|
{ |
|
44
|
|
|
$this->expectException( \Aimeos\MW\Media\Exception::class ); |
|
45
|
|
|
new \Aimeos\MW\Media\Image\Svg( 'test', 'text/plain' ); |
|
46
|
|
|
} |
|
47
|
|
|
|
|
48
|
|
|
|
|
49
|
|
|
public function testGetHeight() |
|
50
|
|
|
{ |
|
51
|
|
|
$ds = DIRECTORY_SEPARATOR; |
|
52
|
|
|
$this->content = file_get_contents( dirname( __DIR__ ) . $ds . '_testfiles' . $ds . 'image.svgz' ); |
|
53
|
|
|
|
|
54
|
|
|
$media = new \Aimeos\MW\Media\Image\Svg( $this->content, 'image/svg+xml' ); |
|
55
|
|
|
|
|
56
|
|
|
$this->assertEquals( 300, $media->getHeight() ); |
|
57
|
|
|
} |
|
58
|
|
|
|
|
59
|
|
|
|
|
60
|
|
|
public function testGetWidth() |
|
61
|
|
|
{ |
|
62
|
|
|
$ds = DIRECTORY_SEPARATOR; |
|
63
|
|
|
$this->content = file_get_contents( dirname( __DIR__ ) . $ds . '_testfiles' . $ds . 'image.svgz' ); |
|
64
|
|
|
|
|
65
|
|
|
$media = new \Aimeos\MW\Media\Image\Svg( $this->content, 'image/svg+xml' ); |
|
66
|
|
|
|
|
67
|
|
|
$this->assertEquals( 200, $media->getWidth() ); |
|
68
|
|
|
} |
|
69
|
|
|
|
|
70
|
|
|
|
|
71
|
|
|
public function testSave() |
|
72
|
|
|
{ |
|
73
|
|
|
$ds = DIRECTORY_SEPARATOR; |
|
74
|
|
|
$dest = dirname( dirname( dirname( __DIR__ ) ) ) . $ds . 'tmp' . $ds . 'media.svg'; |
|
75
|
|
|
|
|
76
|
|
|
$media = new \Aimeos\MW\Media\Image\Svg( $this->content, 'image/svg+xml' ); |
|
77
|
|
|
$media->save( $dest ); |
|
78
|
|
|
|
|
79
|
|
|
$this->assertEquals( true, file_exists( $dest ) ); |
|
80
|
|
|
unlink( $dest ); |
|
81
|
|
|
} |
|
82
|
|
|
|
|
83
|
|
|
|
|
84
|
|
|
public function testSaveContent() |
|
85
|
|
|
{ |
|
86
|
|
|
$media = new \Aimeos\MW\Media\Image\Svg( $this->content, 'image/svg+xml' ); |
|
87
|
|
|
$result = $media->save(); |
|
88
|
|
|
|
|
89
|
|
|
$this->assertStringStartsWith( '<?xml version="1.0" encoding="UTF-8" standalone="yes"?>', $result ); |
|
90
|
|
|
} |
|
91
|
|
|
|
|
92
|
|
|
|
|
93
|
|
|
public function testScale() |
|
94
|
|
|
{ |
|
95
|
|
|
$media = new \Aimeos\MW\Media\Image\Svg( $this->content, 'image/svg+xml' ); |
|
96
|
|
|
$media = $media->scale( 150, 100, 0 ); |
|
97
|
|
|
|
|
98
|
|
|
$this->assertEquals( 150, $media->getWidth() ); |
|
99
|
|
|
$this->assertEquals( 100, $media->getHeight() ); |
|
100
|
|
|
$this->assertStringContainsString( 'viewBox="34 0 133 300"', $media->save() ); |
|
101
|
|
|
} |
|
102
|
|
|
|
|
103
|
|
|
|
|
104
|
|
|
public function testScaleFit() |
|
105
|
|
|
{ |
|
106
|
|
|
$media = new \Aimeos\MW\Media\Image\Svg( $this->content, 'image/svg+xml' ); |
|
107
|
|
|
$media = $media->scale( 100, 100, 1 ); |
|
108
|
|
|
|
|
109
|
|
|
$this->assertEquals( 100, $media->getWidth() ); |
|
110
|
|
|
$this->assertEquals( 100, $media->getHeight() ); |
|
111
|
|
|
$this->assertStringContainsString( 'viewBox="34 0 133 300"', $media->save() ); |
|
112
|
|
|
} |
|
113
|
|
|
|
|
114
|
|
|
|
|
115
|
|
|
public function testScaleCrop() |
|
116
|
|
|
{ |
|
117
|
|
|
$media = new \Aimeos\MW\Media\Image\Svg( $this->content, 'image/svg+xml' ); |
|
118
|
|
|
$media = $media->scale( 200, 150, 2 ); |
|
119
|
|
|
|
|
120
|
|
|
$this->assertEquals( 200, $media->getWidth() ); |
|
121
|
|
|
$this->assertEquals( 150, $media->getHeight() ); |
|
122
|
|
|
$this->assertStringContainsString( 'viewBox="0 38 200 225"', $media->save() ); |
|
123
|
|
|
} |
|
124
|
|
|
|
|
125
|
|
|
|
|
126
|
|
|
public function testSupports() |
|
127
|
|
|
{ |
|
128
|
|
|
$this->assertGreaterThan( 0, count( \Aimeos\MW\Media\Image\Svg::supports() ) ); |
|
129
|
|
|
$this->assertEquals( 1, count( \Aimeos\MW\Media\Image\Svg::supports( 'image/svg+xml' ) ) ); |
|
130
|
|
|
} |
|
131
|
|
|
} |
|
132
|
|
|
|