|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace SilverStripe\View\Tests\Embed; |
|
4
|
|
|
|
|
5
|
|
|
// use Embed\Adapters\Adapter; |
|
6
|
|
|
// use Embed\Http\DispatcherInteOrface; |
|
7
|
|
|
// use Embed\Http\Response; |
|
8
|
|
|
// use Psr\Http\Client\ClientInterface; |
|
9
|
|
|
use Embed\Extractor; |
|
10
|
|
|
use Embed\Http\Crawler; |
|
11
|
|
|
use Psr\Http\Message\ResponseInterface; |
|
12
|
|
|
use Psr\Http\Message\StreamInterface; |
|
13
|
|
|
use Psr\Http\Message\UriInterface; |
|
14
|
|
|
use Response; |
|
|
|
|
|
|
15
|
|
|
use Embed\Http\Url; |
|
|
|
|
|
|
16
|
|
|
use SilverStripe\Core\Injector\Injector; |
|
17
|
|
|
use SilverStripe\Dev\SapphireTest; |
|
18
|
|
|
use SilverStripe\View\Embed\EmbedContainer; |
|
19
|
|
|
|
|
20
|
|
|
class EmbedContainerTest extends SapphireTest |
|
21
|
|
|
{ |
|
22
|
|
|
public function testGetEmbed() |
|
23
|
|
|
{ |
|
24
|
|
|
$url = 'https://www.youtube.com/watch?v=iRXJXaLV0n4'; |
|
25
|
|
|
$crawlerMock = $this->createMock(Crawler::class); |
|
26
|
|
|
$crawlerMock->expects($this->atLeastOnce())->method('sendRequest')->willReturn($this->mockResponse()); |
|
27
|
|
|
$crawlerMock->expects($this->atLeastOnce())->method('getResponseUri')->willReturn($this->getUri()); |
|
28
|
|
|
|
|
29
|
|
|
$embed = new EmbedContainer($url); |
|
30
|
|
|
$embed->setCrawler($crawlerMock); |
|
31
|
|
|
$this->assertEmpty($embed->getOptions()); |
|
32
|
|
|
|
|
33
|
|
|
$this->assertSame('watch', $embed->getName()); |
|
34
|
|
|
|
|
35
|
|
|
$embed->setOptions(['foo' => 'bar']); |
|
36
|
|
|
|
|
37
|
|
|
$extractor = $embed->getExtractor(); |
|
38
|
|
|
$this->assertInstanceOf(Extractor::class, $extractor); |
|
39
|
|
|
$this->assertSame('Try to stay SERIOUS -The most popular CAT videos', $extractor->title); |
|
40
|
|
|
} |
|
41
|
|
|
|
|
42
|
|
|
private function getUri(): UriInterface |
|
43
|
|
|
{ |
|
44
|
|
|
$c = new class implements UriInterface |
|
45
|
|
|
{ |
|
46
|
|
|
public function getScheme() |
|
47
|
|
|
{ |
|
48
|
|
|
return 'https'; |
|
49
|
|
|
} |
|
50
|
|
|
public function getHost() |
|
51
|
|
|
{ |
|
52
|
|
|
return 'youtube.com'; |
|
53
|
|
|
} |
|
54
|
|
|
public function getPath() |
|
55
|
|
|
{ |
|
56
|
|
|
return '/watch?v=iRXJXaLV0n4'; |
|
57
|
|
|
} |
|
58
|
|
|
public function __toString() |
|
59
|
|
|
{ |
|
60
|
|
|
return ''; |
|
61
|
|
|
} |
|
62
|
|
|
public function getAuthority() |
|
63
|
|
|
{ |
|
64
|
|
|
} |
|
65
|
|
|
public function getUserInfo() |
|
66
|
|
|
{ |
|
67
|
|
|
} |
|
68
|
|
|
public function getPort() |
|
69
|
|
|
{ |
|
70
|
|
|
} |
|
71
|
|
|
public function getQuery() |
|
72
|
|
|
{ |
|
73
|
|
|
} |
|
74
|
|
|
public function getFragment() |
|
75
|
|
|
{ |
|
76
|
|
|
} |
|
77
|
|
|
public function withScheme($scheme) |
|
78
|
|
|
{ |
|
79
|
|
|
} |
|
80
|
|
|
public function withUserInfo($user, $password = null) |
|
81
|
|
|
{ |
|
82
|
|
|
} |
|
83
|
|
|
public function withHost($host) |
|
84
|
|
|
{ |
|
85
|
|
|
} |
|
86
|
|
|
public function withPort($port) |
|
87
|
|
|
{ |
|
88
|
|
|
} |
|
89
|
|
|
public function withPath($path) |
|
90
|
|
|
{ |
|
91
|
|
|
} |
|
92
|
|
|
public function withQuery($query) |
|
93
|
|
|
{ |
|
94
|
|
|
} |
|
95
|
|
|
public function withFragment($fragment) |
|
96
|
|
|
{ |
|
97
|
|
|
} |
|
98
|
|
|
}; |
|
99
|
|
|
return new $c(); |
|
100
|
|
|
} |
|
101
|
|
|
|
|
102
|
|
|
private function mockResponse(): ResponseInterface |
|
103
|
|
|
{ |
|
104
|
|
|
$c = new class implements ResponseInterface |
|
105
|
|
|
{ |
|
106
|
|
|
public function getStatusCode() |
|
107
|
|
|
{ |
|
108
|
|
|
return 200; |
|
109
|
|
|
} |
|
110
|
|
|
public function getBody() |
|
111
|
|
|
{ |
|
112
|
|
|
return json_encode([ |
|
113
|
|
|
'author_url' => 'https://www.youtube.com/channel/UCR2KG2dK1tAkwZZjm7rAiSg', |
|
114
|
|
|
'thumbnail_width' => 480, |
|
115
|
|
|
'title' => 'Try to stay SERIOUS -The most popular CAT videos', |
|
116
|
|
|
'width' => 480, |
|
117
|
|
|
'provider_name' => 'YouTube', |
|
118
|
|
|
'author_name' => 'Tiger Funnies', |
|
119
|
|
|
'height' => 270, |
|
120
|
|
|
'version' => '1.0', |
|
121
|
|
|
'type' => 'video', |
|
122
|
|
|
// phpcs:ignore |
|
123
|
|
|
'html' => '<iframe width="480" height="270" src="https://www.youtube.com/embed/iRXJXaLV0n4?feature=oembed" frameborder="0" allow="autoplay; encrypted-media" allowfullscreen></iframe>', |
|
124
|
|
|
'provider_url' => 'https://www.youtube.com/', |
|
125
|
|
|
'thumbnail_height' => 360, |
|
126
|
|
|
'thumbnail_url' => 'https://i.ytimg.com/vi/iRXJXaLV0n4/hqdefault.jpg', |
|
127
|
|
|
]); |
|
128
|
|
|
} |
|
129
|
|
|
public function withStatus($code, $reasonPhrase = '') |
|
130
|
|
|
{ |
|
131
|
|
|
} |
|
132
|
|
|
public function getReasonPhrase() |
|
133
|
|
|
{ |
|
134
|
|
|
} |
|
135
|
|
|
public function getProtocolVersion() |
|
136
|
|
|
{ |
|
137
|
|
|
} |
|
138
|
|
|
public function withProtocolVersion($version) |
|
139
|
|
|
{ |
|
140
|
|
|
} |
|
141
|
|
|
public function getHeaders() |
|
142
|
|
|
{ |
|
143
|
|
|
} |
|
144
|
|
|
public function hasHeader($name) |
|
145
|
|
|
{ |
|
146
|
|
|
} |
|
147
|
|
|
public function getHeader($name) |
|
148
|
|
|
{ |
|
149
|
|
|
} |
|
150
|
|
|
public function getHeaderLine($name) |
|
151
|
|
|
{ |
|
152
|
|
|
} |
|
153
|
|
|
public function withHeader($name, $value) |
|
154
|
|
|
{ |
|
155
|
|
|
} |
|
156
|
|
|
public function withAddedHeader($name, $value) |
|
157
|
|
|
{ |
|
158
|
|
|
} |
|
159
|
|
|
public function withoutHeader($name) |
|
160
|
|
|
{ |
|
161
|
|
|
} |
|
162
|
|
|
public function withBody(StreamInterface $body) |
|
163
|
|
|
{ |
|
164
|
|
|
} |
|
165
|
|
|
}; |
|
166
|
|
|
return new $c(); |
|
167
|
|
|
} |
|
168
|
|
|
} |
|
169
|
|
|
|
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