forked from Intervention/image
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathAbstractDecoderTest.php
160 lines (122 loc) · 5.12 KB
/
AbstractDecoderTest.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
<?php
use PHPUnit\Framework\TestCase;
class AbstractDecoderTest extends TestCase
{
public function tearDown()
{
Mockery::close();
}
public function testIsImagick()
{
$source = $this->getTestDecoder(new \Imagick);
$this->assertTrue($source->isImagick());
$source = $this->getTestDecoder(new stdClass);
$this->assertFalse($source->isImagick());
$source = $this->getTestDecoder(null);
$this->assertFalse($source->isImagick());
}
public function testIsGdResource()
{
$resource = imagecreatefromjpeg(__DIR__.'/images/test.jpg');
$source = $this->getTestDecoder($resource);
$this->assertTrue($source->isGdResource());
$source = $this->getTestDecoder(tmpfile());
$this->assertFalse($source->isGdResource());
$source = $this->getTestDecoder(null);
$this->assertFalse($source->isGdResource());
}
public function testIsFilepath()
{
$source = $this->getTestDecoder(__DIR__.'/AbstractDecoderTest.php');
$this->assertTrue($source->isFilepath());
$source = $this->getTestDecoder(null);
$this->assertFalse($source->isFilepath());
$source = $this->getTestDecoder([]);
$this->assertFalse($source->isFilepath());
$source = $this->getTestDecoder(new stdClass);
$this->assertFalse($source->isFilepath());
}
public function testIsUrl()
{
$source = $this->getTestDecoder('http://foo.bar');
$this->assertTrue($source->isUrl());
$source = $this->getTestDecoder(null);
$this->assertFalse($source->isUrl());
}
public function testIsStream()
{
$source = $this->getTestDecoder(fopen(__DIR__ . '/images/test.jpg', 'r'));
$this->assertTrue($source->isStream());
$source = $this->getTestDecoder(new \GuzzleHttp\Psr7\Stream(fopen(__DIR__ . '/images/test.jpg', 'r')));
$this->assertTrue($source->isStream());
$source = $this->getTestDecoder(null);
$this->assertFalse($source->isStream());
}
public function testIsBinary()
{
$source = $this->getTestDecoder(file_get_contents(__DIR__.'/images/test.jpg'));
$this->assertTrue($source->isBinary());
$source = $this->getTestDecoder(null);
$this->assertFalse($source->isBinary());
$source = $this->getTestDecoder(1);
$this->assertFalse($source->isBinary());
$source = $this->getTestDecoder(0);
$this->assertFalse($source->isBinary());
$source = $this->getTestDecoder([1,2,3]);
$this->assertFalse($source->isBinary());
$source = $this->getTestDecoder(new stdClass);
$this->assertFalse($source->isBinary());
}
public function testIsInterventionImage()
{
$source = $this->getTestDecoder(1);
$this->assertFalse($source->isInterventionImage());
$img = Mockery::mock('Intervention\Image\Image');
$source = $this->getTestDecoder($img);
$this->assertTrue($source->isInterventionImage());
}
public function testIsSplFileInfo()
{
$source = $this->getTestDecoder(1);
$this->assertFalse($source->isSplFileInfo());
$img = Mockery::mock('SplFileInfo');
$source = $this->getTestDecoder($img);
$this->assertTrue($source->isSplFileInfo());
$img = Mockery::mock('Symfony\Component\HttpFoundation\File\UploadedFile', 'SplFileInfo');
$this->assertTrue($source->isSplFileInfo());
}
public function testIsSymfonyUpload()
{
$source = $this->getTestDecoder(1);
$this->assertFalse($source->isSymfonyUpload());
$img = Mockery::mock('Symfony\Component\HttpFoundation\File\UploadedFile');
$source = $this->getTestDecoder($img);
$this->assertTrue($source->isSymfonyUpload());
}
public function testIsDataUrl()
{
$source = $this->getTestDecoder('data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAoAAAAKCAYAAACNMs+9AAAAGElEQVQYlWM8c+bMfwYiABMxikYVUk8hAHWzA3cRvs4UAAAAAElFTkSuQmCC');
$this->assertTrue($source->isDataUrl());
$source = $this->getTestDecoder(null);
$this->assertFalse($source->isDataUrl());
}
public function testIsBase64()
{
$decoder = $this->getTestDecoder(null);
$this->assertFalse($decoder->isBase64());
$decoder = $this->getTestDecoder('random');
$this->assertFalse($decoder->isBase64());
$base64 = "iVBORw0KGgoAAAANSUhEUgAAAAoAAAAKCAYAAACNMs+9AAAAGElEQVQYlWM8c+bMfwYiABMxikYVUk8hAHWzA3cRvs4UAAAAAElFTkSuQmCC";
$decoder = $this->getTestDecoder($base64);
$this->assertTrue($decoder->isBase64());
$base64WithNewlines = 'iVBORw0KGgoAAAANSUhEUgAAAAoAAAAKCAYAAACNMs+' . "\n" .
'9AAAAGElEQVQYlWM8c+bMfwYiABMxikYVUk8hAHWzA3' . "\n" .
'cRvs4UAAAAAElFTkSuQmCC';
$decoder = $this->getTestDecoder($base64WithNewlines);
$this->assertTrue($decoder->isBase64());
}
public function getTestDecoder($data)
{
return $this->getMockForAbstractClass('\Intervention\Image\AbstractDecoder', [$data]);
}
}