1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Devmachine\Bundle\OntheioBundle\Tests\Helper; |
4
|
|
|
|
5
|
|
|
use Devmachine\Bundle\OntheioBundle\Helper\ImageHelper; |
6
|
|
|
|
7
|
|
|
class ImageHelperTest extends \PHPUnit_Framework_TestCase |
8
|
|
|
{ |
9
|
|
|
public function testUrl() |
10
|
|
|
{ |
11
|
|
|
$signer = $this->getSigner(); |
12
|
|
|
$signer |
13
|
|
|
->expects($this->once()) |
14
|
|
|
->method('signSimple') |
15
|
|
|
->with($this->equalTo('key')) |
|
|
|
|
16
|
|
|
->willReturn('signature') |
17
|
|
|
; |
18
|
|
|
|
19
|
|
|
$helper = new ImageHelper($signer, 'http://base.url'); |
20
|
|
|
|
21
|
|
|
$this->assertEquals('http://base.url/key.signature.jpg', $helper->url('key')); |
22
|
|
|
} |
23
|
|
|
|
24
|
|
|
/** |
25
|
|
|
* @expectedException \InvalidArgumentException |
26
|
|
|
*/ |
27
|
|
|
public function testResizeUrlArgs() |
28
|
|
|
{ |
29
|
|
|
$helper = new ImageHelper($this->getSigner(), 'http://base.url'); |
30
|
|
|
$helper->resizeUrl('key'); |
31
|
|
|
} |
32
|
|
|
|
33
|
|
|
public function testResizeUrl() |
34
|
|
|
{ |
35
|
|
|
$signer = $this->getSigner(); |
36
|
|
|
$signer |
37
|
|
|
->expects($this->exactly(3)) |
38
|
|
|
->method('signSimple') |
39
|
|
|
->willReturn('signature') |
40
|
|
|
; |
41
|
|
|
|
42
|
|
|
$helper = new ImageHelper($signer, 'http://base.url'); |
43
|
|
|
|
44
|
|
|
$this->assertEquals('http://base.url/key.r200x.signature.jpg', $helper->resizeUrl('key', 200)); |
45
|
|
|
$this->assertEquals('http://base.url/key.rx200.signature.jpg', $helper->resizeUrl('key', null, 200)); |
46
|
|
|
$this->assertEquals('http://base.url/key.r200x150.signature.jpg', $helper->resizeUrl('key', 200, 150)); |
47
|
|
|
} |
48
|
|
|
|
49
|
|
|
public function testCropUrl() |
50
|
|
|
{ |
51
|
|
|
$signer = $this->getSigner(); |
52
|
|
|
$signer |
53
|
|
|
->expects($this->once()) |
54
|
|
|
->method('signSimple') |
55
|
|
|
->with($this->equalTo('key.c200x150x20x15')) |
|
|
|
|
56
|
|
|
->willReturn('signature') |
57
|
|
|
; |
58
|
|
|
|
59
|
|
|
$helper = new ImageHelper($signer, 'http://base.url'); |
60
|
|
|
|
61
|
|
|
$this->assertEquals('http://base.url/key.c200x150x20x15.signature.jpg', $helper->cropUrl('key', 200, 150, 20, 15)); |
62
|
|
|
} |
63
|
|
|
|
64
|
|
|
/** |
65
|
|
|
* @return \PHPUnit_Framework_MockObject_MockObject |
66
|
|
|
*/ |
67
|
|
|
private function getSigner() |
68
|
|
|
{ |
69
|
|
|
return $this->getMockBuilder('Devmachine\Bundle\OntheioBundle\Client\Image\Signer') |
70
|
|
|
->disableOriginalConstructor() |
71
|
|
|
->getMock() |
72
|
|
|
; |
73
|
|
|
} |
74
|
|
|
} |
75
|
|
|
|