|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace SilverStripe\View\Tests\Embed; |
|
4
|
|
|
|
|
5
|
|
|
use Embed\Adapters\Adapter; |
|
6
|
|
|
use Embed\Http\DispatcherInterface; |
|
7
|
|
|
use Embed\Http\Response; |
|
8
|
|
|
use Embed\Http\Url; |
|
9
|
|
|
use SilverStripe\Core\Injector\Injector; |
|
10
|
|
|
use SilverStripe\Dev\SapphireTest; |
|
11
|
|
|
use SilverStripe\View\Embed\EmbedResource; |
|
12
|
|
|
|
|
13
|
|
|
class EmbedResourceTest extends SapphireTest |
|
14
|
|
|
{ |
|
15
|
|
|
public function testGetEmbed() |
|
16
|
|
|
{ |
|
17
|
|
|
$dispatcherMock = $this->createMock(DispatcherInterface::class); |
|
18
|
|
|
$dispatcherMock->expects($this->atLeastOnce())->method('dispatch')->willReturn($this->mockResponse()); |
|
19
|
|
|
|
|
20
|
|
|
/** @var EmbedResource $embed */ |
|
21
|
|
|
$embed = Injector::inst()->create(EmbedResource::class, 'https://www.youtube.com/watch?v=iRXJXaLV0n4'); |
|
22
|
|
|
$this->assertEmpty($embed->getOptions()); |
|
23
|
|
|
$this->assertEmpty($embed->getDispatcher()); |
|
24
|
|
|
|
|
25
|
|
|
$embed->setOptions(['foo' => 'bar']); |
|
26
|
|
|
$embed->setDispatcher($dispatcherMock); |
|
27
|
|
|
|
|
28
|
|
|
$adapter = $embed->getEmbed(); |
|
29
|
|
|
$this->assertInstanceOf(Adapter::class, $adapter); |
|
30
|
|
|
$this->assertSame('Try to stay SERIOUS -The most popular CAT videos', $adapter->getTitle()); |
|
31
|
|
|
} |
|
32
|
|
|
|
|
33
|
|
|
/** |
|
34
|
|
|
* Generate a mock Response object suitable for Embed |
|
35
|
|
|
* |
|
36
|
|
|
* @return Response |
|
37
|
|
|
*/ |
|
38
|
|
|
private function mockResponse() |
|
39
|
|
|
{ |
|
40
|
|
|
$url = Url::create('https://www.youtube.com/watch?v=iRXJXaLV0n4'); |
|
41
|
|
|
return new Response( |
|
42
|
|
|
$url, |
|
43
|
|
|
$url, |
|
44
|
|
|
200, |
|
45
|
|
|
'application/json', |
|
46
|
|
|
json_encode([ |
|
47
|
|
|
'author_url' => 'https://www.youtube.com/channel/UCR2KG2dK1tAkwZZjm7rAiSg', |
|
48
|
|
|
'thumbnail_width' => 480, |
|
49
|
|
|
'title' => 'Try to stay SERIOUS -The most popular CAT videos', |
|
50
|
|
|
'width' => 480, |
|
51
|
|
|
'provider_name' => 'YouTube', |
|
52
|
|
|
'author_name' => 'Tiger Funnies', |
|
53
|
|
|
'height' => 270, |
|
54
|
|
|
'version' => '1.0', |
|
55
|
|
|
'type' => 'video', |
|
56
|
|
|
// phpcs:ignore |
|
57
|
|
|
'html' => '<iframe width="480" height="270" src="https://www.youtube.com/embed/iRXJXaLV0n4?feature=oembed" frameborder="0" allow="autoplay; encrypted-media" allowfullscreen></iframe>', |
|
58
|
|
|
'provider_url' => 'https://www.youtube.com/', |
|
59
|
|
|
'thumbnail_height' => 360, |
|
60
|
|
|
'thumbnail_url' => 'https://i.ytimg.com/vi/iRXJXaLV0n4/hqdefault.jpg', |
|
61
|
|
|
]), |
|
62
|
|
|
[] |
|
63
|
|
|
); |
|
64
|
|
|
} |
|
65
|
|
|
} |
|
66
|
|
|
|