|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace SilverStripe\View\Tests\Embed; |
|
4
|
|
|
|
|
5
|
|
|
use Embed\Extractor; |
|
6
|
|
|
use Embed\Http\Crawler; |
|
7
|
|
|
use SilverStripe\View\Embed\EmbedContainer; |
|
8
|
|
|
use SilverStripe\AssetAdmin\Controller\AssetAdmin; |
|
|
|
|
|
|
9
|
|
|
|
|
10
|
|
|
class EmbedContainerTest extends EmbedUnitTest |
|
11
|
|
|
{ |
|
12
|
|
|
public function testGetDimensions() |
|
13
|
|
|
{ |
|
14
|
|
|
$container = $this->getEmbedContainer(); |
|
15
|
|
|
$this->assertSame(480, $container->getWidth()); |
|
16
|
|
|
$this->assertSame(270, $container->getHeight()); |
|
17
|
|
|
$container = $this->getFallbackEmbedContainer(); |
|
18
|
|
|
$this->assertSame(100, $container->getWidth()); |
|
19
|
|
|
$this->assertSame(100, $container->getHeight()); |
|
20
|
|
|
} |
|
21
|
|
|
|
|
22
|
|
|
public function testGetPreviewURL() |
|
23
|
|
|
{ |
|
24
|
|
|
$container = $this->getEmbedContainer(); |
|
25
|
|
|
$this->assertSame('https://www.youtube.com/watch?v=iRXJXaLV0n4', $container->getPreviewURL()); |
|
26
|
|
|
$container = $this->getFallbackEmbedContainer(); |
|
27
|
|
|
if (class_exists(AssetAdmin::class)) { |
|
28
|
|
|
$this->assertStringContainsString('client/dist/images/icon_file.png', $container->getPreviewURL()); |
|
29
|
|
|
} |
|
30
|
|
|
} |
|
31
|
|
|
|
|
32
|
|
|
public function testGetName() |
|
33
|
|
|
{ |
|
34
|
|
|
$container = $this->getEmbedContainer(); |
|
35
|
|
|
$this->assertSame('Try to stay SERIOUS -The most popular CAT videos', $container->getName()); |
|
36
|
|
|
} |
|
37
|
|
|
|
|
38
|
|
|
public function testGetType() |
|
39
|
|
|
{ |
|
40
|
|
|
$container = $this->getEmbedContainer(); |
|
41
|
|
|
$this->assertSame('rich', $container->getType()); |
|
42
|
|
|
$container = $this->getEmbedContainer( |
|
43
|
|
|
<<<EOT |
|
44
|
|
|
<video width="320" height="240" controls> |
|
45
|
|
|
<source src="movie.ogg" type="video/ogg"> |
|
46
|
|
|
Your browser does not support the video tag. |
|
47
|
|
|
</video> |
|
48
|
|
|
EOT |
|
49
|
|
|
); |
|
50
|
|
|
$this->assertSame('video', $container->getType()); |
|
51
|
|
|
$container = $this->getEmbedContainer( |
|
52
|
|
|
<<<EOT |
|
53
|
|
|
<audio controls> |
|
54
|
|
|
<source src="horse.ogg" type="audio/ogg"> |
|
55
|
|
|
Your browser does not support the audio element. |
|
56
|
|
|
</audio> |
|
57
|
|
|
EOT |
|
58
|
|
|
); |
|
59
|
|
|
$this->assertSame('audio', $container->getType()); |
|
60
|
|
|
$container = $this->getEmbedContainer( |
|
61
|
|
|
<<<EOT |
|
62
|
|
|
<a data-flickr-embed="true" href="https://www.flickr.com/photos/philocycler/32119532132/"><img src="https://live.staticflickr.com/759/32119532132_50c3f7933f_b.jpg" width="1024" height="742" alt="bird"></a> |
|
63
|
|
|
EOT |
|
64
|
|
|
); |
|
65
|
|
|
$this->assertSame('photo', $container->getType()); |
|
66
|
|
|
$container = $this->getEmbedContainer('<p>Lorem ipsum</p>'); |
|
67
|
|
|
$this->assertSame('link', $container->getType()); |
|
68
|
|
|
} |
|
69
|
|
|
|
|
70
|
|
|
public function testValidate() |
|
71
|
|
|
{ |
|
72
|
|
|
$container = $this->getEmbedContainer(); |
|
73
|
|
|
$this->assertTrue($container->validate()); |
|
74
|
|
|
$container = $this->getFallbackEmbedContainer(); |
|
75
|
|
|
$this->assertFalse($container->validate()); |
|
76
|
|
|
} |
|
77
|
|
|
|
|
78
|
|
|
public function testOptions() |
|
79
|
|
|
{ |
|
80
|
|
|
$options = ['foo' => 'bar']; |
|
81
|
|
|
$container = $this->getEmbedContainer(); |
|
82
|
|
|
$this->assertSame([], $container->getOptions()); |
|
83
|
|
|
$container->setOptions($options); |
|
84
|
|
|
$this->assertSame($options, $container->getOptions()); |
|
85
|
|
|
} |
|
86
|
|
|
|
|
87
|
|
|
public function testGetExtractor() |
|
88
|
|
|
{ |
|
89
|
|
|
$container = $this->getEmbedContainer(); |
|
90
|
|
|
$extractor = $container->getExtractor(); |
|
91
|
|
|
$this->assertTrue($extractor instanceof Extractor); |
|
92
|
|
|
$this->assertSame('Try to stay SERIOUS -The most popular CAT videos', $extractor->title); |
|
93
|
|
|
} |
|
94
|
|
|
|
|
95
|
|
|
private function getFallbackEmbedContainer() |
|
96
|
|
|
{ |
|
97
|
|
|
return $this->createEmbedContainer('', '', '', ''); |
|
98
|
|
|
} |
|
99
|
|
|
|
|
100
|
|
|
private function getEmbedContainer(string $htmlOverride = '') |
|
101
|
|
|
{ |
|
102
|
|
|
$html = $htmlOverride ?: implode('', [ |
|
103
|
|
|
'<iframe width="480" height="270" src="https://www.youtube.com/embed/iRXJXaLV0n4?feature=oembed" ', |
|
104
|
|
|
'frameborder="0" allow="autoplay; encrypted-media" allowfullscreen></iframe>' |
|
105
|
|
|
]); |
|
106
|
|
|
$url = 'https://www.youtube.com/watch?v=iRXJXaLV0n4'; |
|
107
|
|
|
return $this->createEmbedContainer( |
|
108
|
|
|
$url, |
|
109
|
|
|
$url, |
|
110
|
|
|
implode('', [ |
|
111
|
|
|
'<html><link rel="alternate" type="application/json+oembed" ', |
|
112
|
|
|
'href="https://www.youtube.com/oembed?format=json&', |
|
113
|
|
|
'url=https%3A%2F%2Fwww.youtube.com%2Fwatch%3Fv%3DiRXJXaLV0n4" ', |
|
114
|
|
|
'title="Try to stay SERIOUS -The most popular CAT videos"></html>' |
|
115
|
|
|
]), |
|
116
|
|
|
json_encode([ |
|
117
|
|
|
'author_url' => 'https://www.youtube.com/channel/UCR2KG2dK1tAkwZZjm7rAiSg', |
|
118
|
|
|
'thumbnail_width' => 480, |
|
119
|
|
|
'title' => 'Try to stay SERIOUS -The most popular CAT videos', |
|
120
|
|
|
'width' => 480, |
|
121
|
|
|
'provider_name' => 'YouTube', |
|
122
|
|
|
'author_name' => 'Tiger Funnies', |
|
123
|
|
|
'height' => 270, |
|
124
|
|
|
'version' => '1.0', |
|
125
|
|
|
'type' => 'video', |
|
126
|
|
|
// phpcs:ignore |
|
127
|
|
|
'html' => $html, |
|
128
|
|
|
'provider_url' => 'https://www.youtube.com/', |
|
129
|
|
|
'thumbnail_height' => 360, |
|
130
|
|
|
'thumbnail_url' => 'https://i.ytimg.com/vi/iRXJXaLV0n4/hqdefault.jpg', |
|
131
|
|
|
]) |
|
132
|
|
|
); |
|
133
|
|
|
} |
|
134
|
|
|
} |
|
135
|
|
|
|
The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g.
excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths