Passed
Push — master ( 8e0f36...cdb6de )
by Aimeos
06:20
created

SvgTest::testConstruct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

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