-
Notifications
You must be signed in to change notification settings - Fork 7
Expand file tree
/
Copy pathOnlineTest.php
More file actions
49 lines (40 loc) · 1.5 KB
/
OnlineTest.php
File metadata and controls
49 lines (40 loc) · 1.5 KB
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
<?php
class OnlineTest extends PHPUnit_Framework_TestCase {
function setUp() {
$this->api = new ImageOptim\API("gnbkrbjhzb");
}
public function testFullMonty() {
$imageData = $this->api->imageFromURL('http://example.com/image.png')->resize(160,100,'crop')->dpr('2x')->getBytes();
$gdimg = imagecreatefromstring($imageData);
$this->assertEquals(160*2, imagesx($gdimg));
$this->assertEquals(100*2, imagesy($gdimg));
}
public function testUpload() {
$imageData = $this->api->imageFromPath(__dir__ . '/../ImageOptim.png')->resize(32)->getBytes();
$gdimg = imagecreatefromstring($imageData);
$this->assertEquals(32, imagesx($gdimg));
$this->assertEquals(32, imagesy($gdimg));
}
/**
* @expectedException ImageOptim\AccessDeniedException
* @expectedExceptionCode 403
*/
public function testBadKey() {
$api = new ImageOptim\API("zzzzzzzz");
$api->imageFromURL('http://example.com/image.png')->dpr('2x')->getBytes();
}
/**
* @expectedException ImageOptim\OriginServerException
* @expectedExceptionCode 403
*/
public function testGoodKeyUpstream403() {
$this->api->imageFromURL('https://im2.io/.htdeny')->dpr('2x')->getBytes();
}
/**
* @expectedException ImageOptim\NotFoundException
* @expectedExceptionCode 404
*/
public function testUpstreamError() {
$this->api->imageFromURL('http://fail.example.com/nope')->getBytes();
}
}