Passed
Push — master ( 23d885...58cf5d )
by Shashi Prakash
02:57 queued 12s
created

testFetchReturnsEmptyArrayForWebsiteWithNoMetadataAndReturnedNotFound()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 8
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 4
c 1
b 0
f 0
nc 1
nop 0
dl 0
loc 8
rs 10
1
<?php
2
3
namespace shweshi\OpenGraph\Test;
4
5
use PHPUnit\Framework\TestCase;
6
use shweshi\OpenGraph\OpenGraph;
7
8
class OpenGraphTest extends TestCase
9
{
10
    /** @test */
11
    public function testFetch()
12
    {
13
        $opengraph = new OpenGraph();
14
        $data = $opengraph->fetch(
15
            'https://www.ogp.me/'
16
        );
17
        $this->assertArrayHasKey('title', $data);
18
        $this->assertArrayHasKey('description', $data);
19
        $this->assertArrayHasKey('type', $data);
20
        $this->assertArrayHasKey('url', $data);
21
        $this->assertArrayHasKey('image', $data);
22
    }
23
24
    /** @test */
25
    public function testFetchAllMetadata()
26
    {
27
        $opengraph = new OpenGraph();
28
        $data = $opengraph->fetch(
29
            'https://www.ogp.me/',
30
            true
31
        );
32
        $this->assertArrayHasKey('title', $data);
33
        $this->assertArrayHasKey('description', $data);
34
        $this->assertArrayHasKey('type', $data);
35
        $this->assertArrayHasKey('url', $data);
36
        $this->assertArrayHasKey('image', $data);
37
        $this->assertArrayHasKey('fb:app_id', $data);
38
    }
39
40
    /** @test */
41
    public function testFetchReturnsEmptyArrayForWebsiteWithNoMetadata()
42
    {
43
        $opengraph = new OpenGraph();
44
        $data = $opengraph->fetch(
45
            'https://www.example.com/'
46
        );
47
48
        $this->assertEmpty($data);
49
    }
50
51
    /** @test */
52
    public function testFetchReturnsEmptyArrayForWebsiteWithNoMetadataAndReturnedNotFound()
53
    {
54
        $opengraph = new OpenGraph();
55
        $data = $opengraph->fetch(
56
            'https://www.example.com/not-found'
57
        );
58
59
        $this->assertEmpty($data);
60
    }
61
62
    /** @test */
63
    public function testFetchMustacheMetasData()
64
    {
65
        $opengraph = new OpenGraph();
66
        $data = $opengraph->fetch(
67
            'https://raw.githubusercontent.com/jurgenbosch/OpenGraph/master/tests/__mocks__/angular-headers.html',
68
            true
69
        );
70
        $this->assertArrayHasKey('title', $data);
71
        $this->assertArrayHasKey('description', $data);
72
        $this->assertArrayHasKey('image', $data);
73
        $this->assertEmpty($data['image']);
74
    }
75
76
    /** @test */
77
    public function testFetchNonAsciiImageUrlData()
78
    {
79
        $opengraph = new OpenGraph();
80
        $data = $opengraph->fetch(
81
            'https://unitedwithisrael.org/iranians-fall-in-love-with-israel-as-netanyahu-reaches-out-in-persian/',
82
            true
83
        );
84
        $this->assertArrayHasKey('title', $data);
85
        $this->assertArrayHasKey('description', $data);
86
        $this->assertArrayHasKey('image', $data);
87
        $this->assertNotEmpty($data['image']);
88
    }
89
}
90