summaryrefslogtreecommitdiffstats
path: root/vendor/fguillot/picofeed/tests/Parser/AtomParserTest.php
blob: b94f64b1de0f7c68adde2a04db7985231be07fc9 (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
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
<?php
namespace PicoFeed\Parser;

use PHPUnit_Framework_TestCase;


class AtomParserTest extends PHPUnit_Framework_TestCase
{
    /**
     * @expectedException PicoFeed\Parser\MalformedXmlException
     */
    public function testBadInput()
    {
        $parser = new Atom('boo');
        $parser->execute();
    }

    public function testFeedTitle()
    {
        $parser = new Atom(file_get_contents('tests/fixtures/atom.xml'));
        $feed = $parser->execute();
        $this->assertEquals('The Official Google Blog', $feed->getTitle());

        $parser = new Atom(file_get_contents('tests/fixtures/atomsample.xml'));
        $feed = $parser->execute();
        $this->assertEquals('Example Feed', $feed->getTitle());
    }

    public function testFeedDescription()
    {
        $parser = new Atom(file_get_contents('tests/fixtures/atom.xml'));
        $feed = $parser->execute();
        $this->assertEquals('Insights from Googlers into our products, technology, and the Google culture.', $feed->getDescription());

        $parser = new Atom(file_get_contents('tests/fixtures/atomsample.xml'));
        $feed = $parser->execute();
        $this->assertEquals('', $feed->getDescription());
    }

    public function testFeedLogo()
    {
        $parser = new Atom(file_get_contents('tests/fixtures/atom.xml'));
        $feed = $parser->execute();
        $this->assertEquals('', $feed->getLogo());

        $parser = new Atom(file_get_contents('tests/fixtures/bbc_urdu.xml'));
        $feed = $parser->execute();
        $this->assertEquals('http://www.bbc.co.uk/urdu/images/gel/rss_logo.gif', $feed->getLogo());
    }

    public function testFeedUrl()
    {
        $parser = new Atom(file_get_contents('tests/fixtures/atom.xml'));
        $feed = $parser->execute();
        $this->assertEquals('http://googleblog.blogspot.com/', $feed->getUrl());

        $parser = new Atom(file_get_contents('tests/fixtures/atomsample.xml'));
        $feed = $parser->execute();
        $this->assertEquals('http://example.org/', $feed->getUrl());

        $parser = new Atom(file_get_contents('tests/fixtures/lagrange.xml'));
        $feed = $parser->execute();
        $this->assertEquals('http://www.la-grange.net/', $feed->getUrl());
    }

    public function testFeedId()
    {
        $parser = new Atom(file_get_contents('tests/fixtures/atom.xml'));
        $feed = $parser->execute();
        $this->assertEquals('tag:blogger.com,1999:blog-10861780', $feed->getId());

        $parser = new Atom(file_get_contents('tests/fixtures/atomsample.xml'));
        $feed = $parser->execute();
        $this->assertEquals('urn:uuid:60a76c80-d399-11d9-b93C-0003939e0af6', $feed->getId());
    }

    public function testFeedDate()
    {
        $parser = new Atom(file_get_contents('tests/fixtures/atom.xml'));
        $feed = $parser->execute();
        $this->assertEquals(1360148333, $feed->getDate());

        $parser = new Atom(file_get_contents('tests/fixtures/atomsample.xml'));
        $feed = $parser->execute();
        $this->assertEquals(1071340202, $feed->getDate());
    }

    public function testFeedLanguage()
    {
        $parser = new Atom(file_get_contents('tests/fixtures/atom.xml'));
        $feed = $parser->execute();
        $this->assertEquals('', $feed->getLanguage());
        $this->assertEquals('', $feed->items[0]->getLanguage());

        $parser = new Atom(file_get_contents('tests/fixtures/bbc_urdu.xml'));
        $feed = $parser->execute();
        $this->assertNotEmpty($feed->items);
        $this->assertEquals('ur', $feed->getLanguage());
        $this->assertEquals('ur', $feed->items[0]->getLanguage());

        $parser = new Atom(file_get_contents('tests/fixtures/lagrange.xml'));
        $feed = $parser->execute();
        $this->assertNotEmpty($feed->items);
        $this->assertEquals('fr', $feed->getLanguage());
        $this->assertEquals('fr', $feed->items[0]->getLanguage());
    }

    public function testItemId()
    {
        $parser = new Atom(file_get_contents('tests/fixtures/atomsample.xml'));
        $feed = $parser->execute();
        $this->assertNotEmpty($feed->items);
        $this->assertEquals('3841e5cf232f5111fc5841e9eba5f4b26d95e7d7124902e0f7272729d65601a6', $feed->items[0]->getId());
    }

    public function testItemUrl()
    {
        $parser = new Atom(file_get_contents('tests/fixtures/atom.xml'));
        $feed = $parser->execute();
        $this->assertNotEmpty($feed->items);
        $this->assertEquals('http://feedproxy.google.com/~r/blogspot/MKuf/~3/S_hccisqTW8/a-chrome-experiment-made-with-some.html', $feed->items[0]->getUrl());
    }

    public function testItemTitle()
    {
        $parser = new Atom(file_get_contents('tests/fixtures/atom.xml'));
        $feed = $parser->execute();
        $this->assertNotEmpty($feed->items);
        $this->assertEquals('Safer Internet Day: How we help you stay secure online', $feed->items[1]->getTitle());
    }

    public function testItemDate()
    {
        $parser = new Atom(file_get_contents('tests/fixtures/atom.xml'));
        $feed = $parser->execute();
        $this->assertNotEmpty($feed->items);
        $this->assertEquals(1360011661, $feed->items[1]->getDate());

        $parser = new Atom(file_get_contents('tests/fixtures/atomsample.xml'));
        $feed = $parser->execute();
        $this->assertNotEmpty($feed->items);
        $this->assertEquals(1071340202, $feed->items[0]->getDate());

        $parser = new Atom(file_get_contents('tests/fixtures/youtube.xml'));
        $feed = $parser->execute();
        $this->assertNotEmpty($feed->items);
        $this->assertEquals(1336825342, $feed->items[1]->getDate()); // Should return the published date
    }

    public function testItemLanguage()
    {
        $parser = new Atom(file_get_contents('tests/fixtures/atom.xml'));
        $feed = $parser->execute();
        $this->assertNotEmpty($feed->items);
        $this->assertEquals('', $feed->items[1]->getLanguage());
    }

    public function testItemAuthor()
    {
        $parser = new Atom(file_get_contents('tests/fixtures/atom.xml'));
        $feed = $parser->execute();
        $this->assertNotEmpty($feed->items);
        $this->assertEquals('Emily Wood', $feed->items[1]->getAuthor());

        $parser = new Atom(file_get_contents('tests/fixtures/atomsample.xml'));
        $feed = $parser->execute();
        $this->assertNotEmpty($feed->items);
        $this->assertEquals('John Doe', $feed->items[0]->getAuthor());
    }

    public function testItemContent()
    {
        $parser = new Atom(file_get_contents('tests/fixtures/atom.xml'));
        $feed = $parser->execute();
        $this->assertNotEmpty($feed->items);
        $this->assertTrue(strpos($feed->items[1]->getContent(), '<p>Technology can') === 0);

        $parser = new Atom(file_get_contents('tests/fixtures/atomsample.xml'));
        $feed = $parser->execute();
        $this->assertNotEmpty($feed->items);
        $this->assertTrue(strpos($feed->items[0]->getContent(), '<p>Some text.') === 0);
    }
}