Passed
Branch master (d6f66f)
by Shashi Prakash
02:42
created

OpenGraphTest::testFetchMustacheMetasData()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 10
Code Lines 7

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 7
c 0
b 0
f 0
nc 1
nop 0
dl 0
loc 10
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/', true
30
        );
31
        $this->assertArrayHasKey('title', $data);
32
        $this->assertArrayHasKey('description', $data);
33
        $this->assertArrayHasKey('type', $data);
34
        $this->assertArrayHasKey('url', $data);
35
        $this->assertArrayHasKey('image', $data);
36
        $this->assertArrayHasKey('fb:app_id', $data);
37
    }
38
39
    /** @test */
40
    public function testFetchReturnsEmptyArrayForWebsiteWithNoMetadata()
41
    {
42
        $opengraph = new OpenGraph();
43
        $data = $opengraph->fetch(
44
        'https://www.example.com/'
45
        );
46
47
        $this->assertEmpty($data);
48
    }
49
50
    /** @test */
51
    public function testFetchMustacheMetasData()
52
    {
53
        $opengraph = new OpenGraph();
54
        $data = $opengraph->fetch(
55
            'https://raw.githubusercontent.com/jurgenbosch/OpenGraph/master/tests/__mocks__/angular-headers.html', true
56
        );
57
        $this->assertArrayHasKey('title', $data);
58
        $this->assertArrayHasKey('description', $data);
59
        $this->assertArrayHasKey('image', $data);
60
        $this->assertEmpty($data['image']);
61
    }
62
    
63
        /** @test */
64
    public function testFetchNonAsciiImageUrlData()
65
    {
66
        $opengraph = new OpenGraph();
67
        $data = $opengraph->fetch(
68
            'https://unitedwithisrael.org/iranians-fall-in-love-with-israel-as-netanyahu-reaches-out-in-persian/', true
69
        );
70
        $this->assertArrayHasKey('title', $data);
71
        $this->assertArrayHasKey('description', $data);
72
        $this->assertArrayHasKey('image', $data);
73
        $this->assertNotEmpty($data['image']);
74
    }
75
}
76