summaryrefslogtreecommitdiffstats
path: root/3rdparty/fguillot/picofeed/tests/FaviconTest.php
blob: 46ac13461d8e9c5be71b43ed90cd70628aa60285 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
<?php

require_once 'lib/PicoFeed/PicoFeed.php';

use PicoFeed\Favicon;
use PicoFeed\Url;

class FaviconTest extends PHPUnit_Framework_TestCase
{
    public function testExtract()
    {
        $favicon = new Favicon;

        $html = '<!DOCTYPE html><html><head>
                <link rel="shortcut icon" href="http://example.com/myicon.ico" />
                </head><body><p>boo</p></body></html>';

        $this->assertEquals(array('http://example.com/myicon.ico'), $favicon->extract($html));

        $html = '<!DOCTYPE html><html><head>
                <link rel="icon" href="http://example.com/myicon.ico" />
                </head><body><p>boo</p></body></html>';

        $this->assertEquals(array('http://example.com/myicon.ico'), $favicon->extract($html));

        $html = '<!DOCTYPE html><html><head>
                <link rel="icon" type="image/vnd.microsoft.icon" href="http://example.com/image.ico" />
                </head><body><p>boo</p></body></html>';

        $this->assertEquals(array('http://example.com/image.ico'), $favicon->extract($html));

        $html = '<!DOCTYPE html><html><head>
                <link rel="icon" type="image/png" href="http://example.com/image.png" />
                </head><body><p>boo</p></body></html>';

        $this->assertEquals(array('http://example.com/image.png'), $favicon->extract($html));

        $html = '<!DOCTYPE html><html><head>
                <link rel="icon" type="image/gif" href="http://example.com/image.gif" />
                </head><body><p>boo</p></body></html>';

        $this->assertEquals(array('http://example.com/image.gif'), $favicon->extract($html));

        $html = '<!DOCTYPE html><html><head>
                <link rel="icon" type="image/x-icon" href="http://example.com/image.ico"/>
                </head><body><p>boo</p></body></html>';

        $this->assertEquals(array('http://example.com/image.ico'), $favicon->extract($html));

        $html = '<!DOCTYPE html><html><head>
                <link rel="apple-touch-icon" href="assets/img/touch-icon-iphone.png">
                <link rel="icon" type="image/png" href="http://example.com/image.png" />
                <link rel="icon" type="image/x-icon" href="http://example.com/image.ico"/>
                </head><body><p>boo</p></body></html>';

        $this->assertEquals(array('http://example.com/image.png', 'http://example.com/image.ico'), $favicon->extract($html));
    }
/*
    public function testHasFile()
    {
        $favicon = new Favicon;
        $this->assertTrue($favicon->exists('https://en.wikipedia.org/favicon.ico'));
        $this->assertFalse($favicon->exists('http://minicoders.com/favicon.ico'));
        $this->assertFalse($favicon->exists('http://blabla'));
    }
*/
    public function testConvertLink()
    {
        $favicon = new Favicon;

        $this->assertEquals(
            'http://miniflux.net/assets/img/favicon.png',
            $favicon->convertLink(new Url('http://miniflux.net'), new Url('assets/img/favicon.png'))
        );

        $this->assertEquals(
            'https://miniflux.net/assets/img/favicon.png',
            $favicon->convertLink(new Url('https://miniflux.net'), new Url('assets/img/favicon.png'))
        );

        $this->assertEquals(
            'http://google.com/assets/img/favicon.png',
            $favicon->convertLink(new Url('http://miniflux.net'), new Url('//google.com/assets/img/favicon.png'))
        );

        $this->assertEquals(
            'https://google.com/assets/img/favicon.png',
            $favicon->convertLink(new Url('https://miniflux.net'), new Url('//google.com/assets/img/favicon.png'))
        );
    }

    public function testFind()
    {
        $favicon = new Favicon;

        // Relative favicon in html
        $this->assertEquals(
            'http://miniflux.net/assets/img/favicon.png',
            $favicon->find('http://miniflux.net')
        );

        $this->assertNotEmpty($favicon->getContent());

        // Absolute html favicon
        $this->assertEquals(
            'http://php.net/favicon.ico',
            $favicon->find('http://php.net/parse_url')
        );

        $this->assertNotEmpty($favicon->getContent());

        // Protocol relative favicon
        $this->assertEquals(
            'https://bits.wikimedia.org/favicon/wikipedia.ico',
            $favicon->find('https://en.wikipedia.org/')
        );

        $this->assertNotEmpty($favicon->getContent());

        // fluid-icon + https
        $this->assertEquals(
            'https://github.com/fluidicon.png',
            $favicon->find('https://github.com')
        );

        $this->assertNotEmpty($favicon->getContent());

        // favicon in meta
        $this->assertEquals(
            'http://www.microsoft.com/favicon.ico?v2',
            $favicon->find('http://www.microsoft.com')
        );

        $this->assertNotEmpty($favicon->getContent());

        // no icon
        $this->assertEquals(
            '',
            $favicon->find('http://minicoders.com/favicon.ico')
        );

        $this->assertEmpty($favicon->getContent());
    }
}