|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
/* |
|
4
|
|
|
* This file is part of the Sonata Project package. |
|
5
|
|
|
* |
|
6
|
|
|
* (c) Thomas Rabaix <[email protected]> |
|
7
|
|
|
* |
|
8
|
|
|
* For the full copyright and license information, please view the LICENSE |
|
9
|
|
|
* file that was distributed with this source code. |
|
10
|
|
|
*/ |
|
11
|
|
|
|
|
12
|
|
|
namespace Sonata\MediaBundle\Tests\Provider; |
|
13
|
|
|
|
|
14
|
|
|
use Buzz\Browser; |
|
15
|
|
|
use Buzz\Message\Response; |
|
16
|
|
|
use Imagine\Image\Box; |
|
17
|
|
|
use Sonata\MediaBundle\Provider\VimeoProvider; |
|
18
|
|
|
use Sonata\MediaBundle\Tests\Entity\Media; |
|
19
|
|
|
use Sonata\MediaBundle\Thumbnail\FormatThumbnail; |
|
20
|
|
|
|
|
21
|
|
|
class VimeoProviderTest extends AbstractProviderTest |
|
22
|
|
|
{ |
|
23
|
|
|
public function getProvider(Browser $browser = null) |
|
24
|
|
|
{ |
|
25
|
|
|
if (!$browser) { |
|
26
|
|
|
$browser = $this->getMockBuilder('Buzz\Browser')->getMock(); |
|
27
|
|
|
} |
|
28
|
|
|
|
|
29
|
|
|
$resizer = $this->getMock('Sonata\MediaBundle\Resizer\ResizerInterface'); |
|
|
|
|
|
|
30
|
|
|
$resizer->expects($this->any())->method('resize')->will($this->returnValue(true)); |
|
31
|
|
|
$resizer->expects($this->any())->method('getBox')->will($this->returnValue(new Box(100, 100))); |
|
32
|
|
|
|
|
33
|
|
|
$adapter = $this->getMock('Gaufrette\Adapter'); |
|
|
|
|
|
|
34
|
|
|
|
|
35
|
|
|
$filesystem = $this->getMock('Gaufrette\Filesystem', array('get'), array($adapter)); |
|
|
|
|
|
|
36
|
|
|
$file = $this->getMock('Gaufrette\File', array(), array('foo', $filesystem)); |
|
|
|
|
|
|
37
|
|
|
$filesystem->expects($this->any())->method('get')->will($this->returnValue($file)); |
|
38
|
|
|
|
|
39
|
|
|
$cdn = new \Sonata\MediaBundle\CDN\Server('/uploads/media'); |
|
40
|
|
|
|
|
41
|
|
|
$generator = new \Sonata\MediaBundle\Generator\DefaultGenerator(); |
|
42
|
|
|
|
|
43
|
|
|
$thumbnail = new FormatThumbnail('jpg'); |
|
44
|
|
|
|
|
45
|
|
|
$metadata = $this->getMock('Sonata\MediaBundle\Metadata\MetadataBuilderInterface'); |
|
|
|
|
|
|
46
|
|
|
|
|
47
|
|
|
$provider = new VimeoProvider('file', $filesystem, $cdn, $generator, $thumbnail, $browser, $metadata); |
|
48
|
|
|
$provider->setResizer($resizer); |
|
49
|
|
|
|
|
50
|
|
|
return $provider; |
|
51
|
|
|
} |
|
52
|
|
|
|
|
53
|
|
|
public function testProvider() |
|
54
|
|
|
{ |
|
55
|
|
|
$provider = $this->getProvider(); |
|
56
|
|
|
|
|
57
|
|
|
$media = new Media(); |
|
58
|
|
|
$media->setName('Blinky™'); |
|
59
|
|
|
$media->setProviderName('vimeo'); |
|
60
|
|
|
$media->setProviderReference('21216091'); |
|
61
|
|
|
$media->setContext('default'); |
|
62
|
|
|
$media->setProviderMetadata(json_decode('{"type":"video","version":"1.0","provider_name":"Vimeo","provider_url":"http:\/\/vimeo.com\/","title":"Blinky\u2122","author_name":"Ruairi Robinson","author_url":"http:\/\/vimeo.com\/ruairirobinson","is_plus":"1","html":"<iframe src=\"http:\/\/player.vimeo.com\/video\/21216091\" width=\"1920\" height=\"1080\" frameborder=\"0\"><\/iframe>","width":"1920","height":"1080","duration":"771","description":"","thumbnail_url":"http:\/\/b.vimeocdn.com\/ts\/136\/375\/136375440_1280.jpg","thumbnail_width":1280,"thumbnail_height":720,"video_id":"21216091"}', true)); |
|
63
|
|
|
|
|
64
|
|
|
$media->setId(1023457); |
|
65
|
|
|
$this->assertSame('http://b.vimeocdn.com/ts/136/375/136375440_1280.jpg', $provider->getReferenceImage($media)); |
|
66
|
|
|
|
|
67
|
|
|
$this->assertSame('default/0011/24', $provider->generatePath($media)); |
|
68
|
|
|
$this->assertSame('/uploads/media/default/0011/24/thumb_1023457_big.jpg', $provider->generatePublicUrl($media, 'big')); |
|
69
|
|
|
} |
|
70
|
|
|
|
|
71
|
|
|
public function testThumbnail() |
|
72
|
|
|
{ |
|
73
|
|
|
$response = $this->getMock('Buzz\Message\AbstractMessage'); |
|
|
|
|
|
|
74
|
|
|
$response->expects($this->once())->method('getContent')->will($this->returnValue('content')); |
|
75
|
|
|
|
|
76
|
|
|
$browser = $this->getMockBuilder('Buzz\Browser')->getMock(); |
|
77
|
|
|
|
|
78
|
|
|
$browser->expects($this->once())->method('get')->will($this->returnValue($response)); |
|
79
|
|
|
|
|
80
|
|
|
$provider = $this->getProvider($browser); |
|
81
|
|
|
|
|
82
|
|
|
$media = new Media(); |
|
83
|
|
|
$media->setName('Blinky™'); |
|
84
|
|
|
$media->setProviderName('vimeo'); |
|
85
|
|
|
$media->setProviderReference('21216091'); |
|
86
|
|
|
$media->setContext('default'); |
|
87
|
|
|
$media->setProviderMetadata(json_decode('{"type":"video","version":"1.0","provider_name":"Vimeo","provider_url":"http:\/\/vimeo.com\/","title":"Blinky\u2122","author_name":"Ruairi Robinson","author_url":"http:\/\/vimeo.com\/ruairirobinson","is_plus":"1","html":"<iframe src=\"http:\/\/player.vimeo.com\/video\/21216091\" width=\"1920\" height=\"1080\" frameborder=\"0\"><\/iframe>","width":"1920","height":"1080","duration":"771","description":"","thumbnail_url":"http:\/\/b.vimeocdn.com\/ts\/136\/375\/136375440_1280.jpg","thumbnail_width":1280,"thumbnail_height":720,"video_id":"21216091"}', true)); |
|
88
|
|
|
|
|
89
|
|
|
$media->setId(1023457); |
|
90
|
|
|
|
|
91
|
|
|
$this->assertTrue($provider->requireThumbnails($media)); |
|
|
|
|
|
|
92
|
|
|
|
|
93
|
|
|
$provider->addFormat('big', array('width' => 200, 'height' => 100, 'constraint' => true)); |
|
94
|
|
|
|
|
95
|
|
|
$this->assertNotEmpty($provider->getFormats(), '::getFormats() return an array'); |
|
96
|
|
|
|
|
97
|
|
|
$provider->generateThumbnails($media); |
|
98
|
|
|
|
|
99
|
|
|
$this->assertSame('default/0011/24/thumb_1023457_big.jpg', $provider->generatePrivateUrl($media, 'big')); |
|
100
|
|
|
} |
|
101
|
|
|
|
|
102
|
|
|
public function testTransformWithSig() |
|
103
|
|
|
{ |
|
104
|
|
|
$response = new Response(); |
|
105
|
|
|
$response->setContent(file_get_contents(__DIR__.'/../fixtures/valid_vimeo.txt')); |
|
106
|
|
|
|
|
107
|
|
|
$browser = $this->getMockBuilder('Buzz\Browser')->getMock(); |
|
108
|
|
|
$browser->expects($this->once())->method('get')->will($this->returnValue($response)); |
|
109
|
|
|
|
|
110
|
|
|
$provider = $this->getProvider($browser); |
|
111
|
|
|
|
|
112
|
|
|
$provider->addFormat('big', array('width' => 200, 'height' => 100, 'constraint' => true)); |
|
113
|
|
|
|
|
114
|
|
|
$media = new Media(); |
|
115
|
|
|
$media->setBinaryContent('BDYAbAtaDzA'); |
|
116
|
|
|
$media->setId(1023456); |
|
117
|
|
|
|
|
118
|
|
|
// pre persist the media |
|
119
|
|
|
$provider->transform($media); |
|
120
|
|
|
$provider->prePersist($media); |
|
121
|
|
|
|
|
122
|
|
|
$this->assertSame('Blinky™', $media->getName(), '::getName() return the file name'); |
|
123
|
|
|
$this->assertSame('BDYAbAtaDzA', $media->getProviderReference(), '::getProviderReference() is set'); |
|
124
|
|
|
} |
|
125
|
|
|
|
|
126
|
|
|
/** |
|
127
|
|
|
* @dataProvider getTransformWithUrlMedia |
|
128
|
|
|
*/ |
|
129
|
|
|
public function testTransformWithUrl($media) |
|
130
|
|
|
{ |
|
131
|
|
|
$response = new Response(); |
|
132
|
|
|
$response->setContent(file_get_contents(__DIR__.'/../fixtures/valid_vimeo.txt')); |
|
133
|
|
|
|
|
134
|
|
|
$browser = $this->getMockBuilder('Buzz\Browser')->getMock(); |
|
135
|
|
|
$browser->expects($this->once())->method('get')->will($this->returnValue($response)); |
|
136
|
|
|
|
|
137
|
|
|
$provider = $this->getProvider($browser); |
|
138
|
|
|
|
|
139
|
|
|
$provider->addFormat('big', array('width' => 200, 'height' => 100, 'constraint' => true)); |
|
140
|
|
|
|
|
141
|
|
|
// pre persist the media |
|
142
|
|
|
$provider->transform($media); |
|
143
|
|
|
$provider->prePersist($media); |
|
144
|
|
|
|
|
145
|
|
|
$this->assertSame('Blinky™', $media->getName(), '::getName() return the file name'); |
|
146
|
|
|
$this->assertSame('012341231', $media->getProviderReference(), '::getProviderReference() is set'); |
|
147
|
|
|
} |
|
148
|
|
|
|
|
149
|
|
|
public function getTransformWithUrlMedia() |
|
150
|
|
|
{ |
|
151
|
|
|
$mediaWebsite = new Media(); |
|
152
|
|
|
$mediaWebsite->setBinaryContent('http://vimeo.com/012341231'); |
|
153
|
|
|
$mediaWebsite->setId(1023456); |
|
154
|
|
|
|
|
155
|
|
|
$mediaPlayer = new Media(); |
|
156
|
|
|
$mediaPlayer->setBinaryContent('http://player.vimeo.com/video/012341231'); |
|
157
|
|
|
$mediaPlayer->setId(1023456); |
|
158
|
|
|
|
|
159
|
|
|
return array( |
|
160
|
|
|
'transform with website url' => array($mediaWebsite), |
|
161
|
|
|
'transform with player url' => array($mediaPlayer), |
|
162
|
|
|
); |
|
163
|
|
|
} |
|
164
|
|
|
|
|
165
|
|
|
public function testForm() |
|
166
|
|
|
{ |
|
167
|
|
|
if (!class_exists('\Sonata\AdminBundle\Form\FormMapper')) { |
|
168
|
|
|
$this->markTestSkipped("AdminBundle doesn't seem to be installed"); |
|
169
|
|
|
} |
|
170
|
|
|
|
|
171
|
|
|
$provider = $this->getProvider(); |
|
172
|
|
|
|
|
173
|
|
|
$admin = $this->getMock('Sonata\AdminBundle\Admin\AdminInterface'); |
|
|
|
|
|
|
174
|
|
|
$admin->expects($this->any()) |
|
175
|
|
|
->method('trans') |
|
176
|
|
|
->will($this->returnValue('message')); |
|
177
|
|
|
|
|
178
|
|
|
$formMapper = $this->getMock('Sonata\AdminBundle\Form\FormMapper', array('add', 'getAdmin'), array(), '', false); |
|
|
|
|
|
|
179
|
|
|
$formMapper->expects($this->exactly(8)) |
|
180
|
|
|
->method('add') |
|
181
|
|
|
->will($this->returnValue(null)); |
|
182
|
|
|
|
|
183
|
|
|
$provider->buildCreateForm($formMapper); |
|
184
|
|
|
|
|
185
|
|
|
$provider->buildEditForm($formMapper); |
|
186
|
|
|
} |
|
187
|
|
|
|
|
188
|
|
|
public function testHelperProperies() |
|
189
|
|
|
{ |
|
190
|
|
|
$provider = $this->getProvider(); |
|
191
|
|
|
|
|
192
|
|
|
$provider->addFormat('admin', array('width' => 100)); |
|
193
|
|
|
$media = new Media(); |
|
194
|
|
|
$media->setName('Les tests'); |
|
195
|
|
|
$media->setProviderReference('ASDASDAS.png'); |
|
196
|
|
|
$media->setId(10); |
|
197
|
|
|
$media->setHeight(100); |
|
198
|
|
|
$media->setWidth(100); |
|
199
|
|
|
|
|
200
|
|
|
$properties = $provider->getHelperProperties($media, 'admin'); |
|
201
|
|
|
|
|
202
|
|
|
$this->assertInternalType('array', $properties); |
|
203
|
|
|
$this->assertSame(100, $properties['height']); |
|
204
|
|
|
$this->assertSame(100, $properties['width']); |
|
205
|
|
|
} |
|
206
|
|
|
|
|
207
|
|
|
public function testGetReferenceUrl() |
|
208
|
|
|
{ |
|
209
|
|
|
$media = new Media(); |
|
210
|
|
|
$media->setProviderReference('123456'); |
|
211
|
|
|
$this->assertEquals('http://vimeo.com/123456', $this->getProvider()->getReferenceUrl($media)); |
|
212
|
|
|
} |
|
213
|
|
|
} |
|
214
|
|
|
|
This method has been deprecated. The supplier of the class has supplied an explanatory message.
The explanatory message should give you some clue as to whether and when the method will be removed from the class and what other method or class to use instead.