1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace shweshi\OpenGraph\Test; |
4
|
|
|
|
5
|
|
|
use PHPUnit\Framework\Attributes\Test; |
|
|
|
|
6
|
|
|
use PHPUnit\Framework\TestCase; |
7
|
|
|
use shweshi\OpenGraph\OpenGraph; |
|
|
|
|
8
|
|
|
|
9
|
|
|
class OpenGraphTest extends TestCase |
10
|
|
|
{ |
11
|
|
|
#[Test] |
12
|
|
|
public function testFetch() |
13
|
|
|
{ |
14
|
|
|
$opengraph = new OpenGraph(); |
15
|
|
|
$data = $opengraph->fetch( |
16
|
|
|
'https://www.ogp.me/' |
17
|
|
|
); |
18
|
|
|
$this->assertArrayHasKey('title', $data); |
19
|
|
|
$this->assertArrayHasKey('description', $data); |
20
|
|
|
$this->assertArrayHasKey('type', $data); |
21
|
|
|
$this->assertArrayHasKey('url', $data); |
22
|
|
|
$this->assertArrayHasKey('image', $data); |
23
|
|
|
} |
24
|
|
|
|
25
|
|
|
#[Test] |
26
|
|
|
public function testFetchAllMetadata() |
27
|
|
|
{ |
28
|
|
|
$opengraph = new OpenGraph(); |
29
|
|
|
$data = $opengraph->fetch( |
30
|
|
|
'https://www.ogp.me/', |
31
|
|
|
true |
32
|
|
|
); |
33
|
|
|
$this->assertArrayHasKey('title', $data); |
34
|
|
|
$this->assertArrayHasKey('description', $data); |
35
|
|
|
$this->assertArrayHasKey('type', $data); |
36
|
|
|
$this->assertArrayHasKey('url', $data); |
37
|
|
|
$this->assertArrayHasKey('image', $data); |
38
|
|
|
$this->assertArrayHasKey('fb:app_id', $data); |
39
|
|
|
} |
40
|
|
|
|
41
|
|
|
#[Test] |
42
|
|
|
public function testFetchReturnsEmptyArrayForWebsiteWithNoMetadata() |
43
|
|
|
{ |
44
|
|
|
$opengraph = new OpenGraph(); |
45
|
|
|
$data = $opengraph->fetch( |
46
|
|
|
'https://www.example.com/' |
47
|
|
|
); |
48
|
|
|
|
49
|
|
|
$this->assertEmpty($data); |
50
|
|
|
} |
51
|
|
|
|
52
|
|
|
#[Test] |
53
|
|
|
public function testFetchReturnsEmptyArrayForWebsiteWithNoMetadataAndReturnedNotFound() |
54
|
|
|
{ |
55
|
|
|
$opengraph = new OpenGraph(); |
56
|
|
|
$data = $opengraph->fetch( |
57
|
|
|
'https://www.example.com/not-found' |
58
|
|
|
); |
59
|
|
|
|
60
|
|
|
$this->assertEmpty($data); |
61
|
|
|
} |
62
|
|
|
|
63
|
|
|
#[Test] |
64
|
|
|
public function testFetchMustacheMetasData() |
65
|
|
|
{ |
66
|
|
|
$opengraph = new OpenGraph(); |
67
|
|
|
$data = $opengraph->fetch( |
68
|
|
|
'https://raw.githubusercontent.com/jurgenbosch/OpenGraph/master/tests/__mocks__/angular-headers.html', |
69
|
|
|
true |
70
|
|
|
); |
71
|
|
|
$this->assertArrayHasKey('title', $data); |
72
|
|
|
$this->assertArrayHasKey('description', $data); |
73
|
|
|
$this->assertArrayHasKey('image', $data); |
74
|
|
|
$this->assertEmpty($data['image']); |
75
|
|
|
} |
76
|
|
|
|
77
|
|
|
#[Test] |
78
|
|
|
public function testFetchNonAsciiImageUrlData() |
79
|
|
|
{ |
80
|
|
|
$opengraph = new OpenGraph(); |
81
|
|
|
$data = $opengraph->fetch( |
82
|
|
|
'https://unitedwithisrael.org/iranians-fall-in-love-with-israel-as-netanyahu-reaches-out-in-persian/', |
83
|
|
|
true |
84
|
|
|
); |
85
|
|
|
$this->assertArrayHasKey('title', $data); |
86
|
|
|
$this->assertArrayHasKey('description', $data); |
87
|
|
|
$this->assertArrayHasKey('image', $data); |
88
|
|
|
$this->assertNotEmpty($data['image']); |
89
|
|
|
} |
90
|
|
|
|
91
|
|
|
#[Test] |
92
|
|
|
public function testGetHeadersReturns403() |
93
|
|
|
{ |
94
|
|
|
$urlToFetch = 'https://www.icreatemagazine.nl/nieuws/airtag-hond-of-kat/'; |
95
|
|
|
$graph = new OpenGraph(); |
96
|
|
|
$meta = $graph->fetch($urlToFetch, true); |
97
|
|
|
|
98
|
|
|
self::assertEquals('', $meta['image']); |
99
|
|
|
|
100
|
|
|
$meta = $graph->userAgent('Mozilla/5.0')->fetch($urlToFetch, true); |
101
|
|
|
self::assertnotEmpty($meta['image']); |
102
|
|
|
} |
103
|
|
|
} |
104
|
|
|
|
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