1<?php
2
3require_once 'XML_Feed_Parser_TestCase.php';
4
5class rss2Values extends XML_Feed_Parser_TestCase
6{
7
8    protected function setUp()
9    {
10      $sample_dir = XML_Feed_Parser_TestCase::getSampleDir();
11      $this->file = file_get_contents($sample_dir . DIRECTORY_SEPARATOR . "rss2sample.xml");
12      $this->feed = new XML_Feed_Parser($this->file);
13      $this->entry = $this->feed->getEntryByOffset(2);
14    }
15
16    function test_feedNumberItems()
17    {
18        $value = 4;
19        $this->assertEquals($value, $this->feed->numberEntries);
20    }
21
22    function test_feedTitle()
23    {
24        $value = "Liftoff News";
25        $this->assertEquals($value, $this->feed->title);
26    }
27
28    function test_feedLink()
29    {
30        $value = "http://liftoff.msfc.nasa.gov/";
31        $this->assertEquals($value, $this->feed->link);
32    }
33
34    function test_feedDescription()
35    {
36        $value = "Liftoff to Space Exploration.";
37        $this->assertEquals($value, $this->feed->description);
38    }
39
40    function test_feedSubtitleEquivalence()
41    {
42        $value = "Liftoff to Space Exploration.";
43        $this->assertEquals($value, $this->feed->subtitle);
44    }
45
46    function test_feedDate()
47    {
48        $value = strtotime("Tue, 10 Jun 2003 04:00:00 GMT");
49        $this->assertEquals($value, $this->feed->date);
50    }
51
52    function test_feedLastBuildDate()
53    {
54        $value = strtotime("Tue, 10 Jun 2003 09:41:01 GMT");
55        $this->assertEquals($value, $this->feed->lastBuildDate);
56    }
57
58    function test_feedUpdatedEquivalence()
59    {
60        $value = strtotime("Tue, 10 Jun 2003 09:41:01 GMT");
61        $this->assertEquals($value, $this->feed->updated);
62    }
63
64    function test_feedGenerator()
65    {
66        $value = 'Weblog Editor 2.0';
67        $this->assertEquals($value, $this->feed->generator);
68    }
69
70    function test_feedLanguage()
71    {
72        $value = "en-us";
73        $this->assertEquals($value, $this->feed->language);
74    }
75
76    function test_feedDocs()
77    {
78        $value = "http://blogs.law.harvard.edu/tech/rss";
79        $this->assertEquals($value, $this->feed->docs);
80    }
81
82    function test_feedManagingEditor()
83    {
84        $value = "editor@example.com";
85        $this->assertEquals($value, $this->feed->managingEditor);
86    }
87
88    function test_feedAuthorEquivalence()
89    {
90        $value = "editor@example.com";
91        $this->assertEquals($value, $this->feed->author);
92    }
93
94    function test_feedWebmaster()
95    {
96        $value = "webmaster@example.com";
97        $this->assertEquals($value, $this->feed->webMaster);
98    }
99
100    function test_entryTitle()
101    {
102        $value = "The Engine That Does More";
103        $this->assertEquals($value, $this->entry->title);
104    }
105
106    function test_entryLink()
107    {
108        $value = "http://liftoff.msfc.nasa.gov/news/2003/news-VASIMR.asp";
109        $this->assertEquals($value, $this->entry->link);
110    }
111
112    function test_entryDescription()
113    {
114        $value = "Before man travels to Mars, NASA hopes to design new engines that will let us fly through the Solar System more quickly.  The proposed VASIMR engine would do that.";
115        $this->assertEquals($value, $this->entry->description);
116    }
117
118    function test_entryPubDate()
119    {
120        $value = strtotime("Tue, 27 May 2003 08:37:32 GMT");
121        $this->assertEquals($value, $this->entry->pubDate);
122    }
123
124    function test_entryGuid()
125    {
126        $value = "http://liftoff.msfc.nasa.gov/2003/05/27.html#item571";
127        $this->assertEquals($value, $this->entry->guid);
128    }
129
130    function test_entryIdEquivalence()
131    {
132        $value = "http://liftoff.msfc.nasa.gov/2003/05/27.html#item571";
133        $this->assertEquals($value, $this->entry->id);
134    }
135
136    function test_entryContent()
137    {
138      $value = "<p>Test content</p>";
139      $this->assertEquals($value, $this->entry->content);
140    }
141
142    function test_imageNodeInDifferentNamespaces()
143    {
144      $value = '<?xml version="1.0" encoding="utf-8"?>
145      <rss version="2.0"
146      xmlns:itunes="http://www.itunes.com/dtds/podcast-1.0.dtd">
147      <channel>
148        <title>Tobbis-Podcast</title>
149        <itunes:image href="http://www.herbertschuette.de/Bilder/logo5.jpg" />
150        <image>
151          <url>http://www.herbertschuette.de/Bilder/logo5.jpg</url>
152          <title>Tobbis-Podcast</title>
153          <link>http://www.tobbis-podcast.de/</link>
154        </image>
155      </channel>
156      </rss>';
157      $parsed = new XML_Feed_Parser($value);
158
159      $this->assertEquals("http://www.herbertschuette.de/Bilder/logo5.jpg", $parsed->image['url']);
160    }
161
162    function test_imageNodeAtDifferentLevels()
163    {
164      $sample_dir = XML_Feed_Parser_TestCase::getSampleDir();
165      $value = file_get_contents($sample_dir . DIRECTORY_SEPARATOR . "rss2sample.xml");
166      $parsed = new XML_Feed_Parser($value);
167      $this->assertEquals(false, $parsed->image);
168    }
169
170    function test_handlesEmptyPubdates()
171    {
172      $value = '<?xml version="1.0" encoding="utf-8"?>
173      <rss version="2.0"
174      xmlns:itunes="http://www.itunes.com/dtds/podcast-1.0.dtd">
175      <channel>
176        <title>Tobbis-Podcast</title>
177        <item>
178          <title>Entry</title>
179        </item>
180      </channel>
181      </rss>';
182      $parsed = new XML_Feed_Parser($value);
183      $this->assertEquals(false, $parsed->pubDate);
184      $entry = $parsed->entries(0);
185      $this->assertEquals(false, $entry['pubDate']);
186    }
187}
188
189?>