| 1 |
lars |
1 |
<?php
|
|
|
2 |
|
|
|
3 |
require_once 'XML_Feed_Parser_TestCase.php';
|
|
|
4 |
|
|
|
5 |
/**
|
|
|
6 |
* This test is to make sure that we get errors when we should. In
|
|
|
7 |
* particular we check that it throws an exception if we hand in an
|
|
|
8 |
* illegal feed type.
|
|
|
9 |
*/
|
|
|
10 |
class errors extends XML_Feed_Parser_TestCase
|
|
|
11 |
{
|
|
|
12 |
function test_fakeFeedType()
|
|
|
13 |
{
|
|
|
14 |
$file = "<myfeed><myitem /></myfeed>";
|
|
|
15 |
try {
|
|
|
16 |
$feed = new XML_Feed_Parser($file, false, true);
|
|
|
17 |
} catch (Exception $e) {
|
|
|
18 |
$this->assertTrue($e instanceof XML_Feed_Parser_Exception);
|
|
|
19 |
}
|
|
|
20 |
}
|
|
|
21 |
|
|
|
22 |
function test_badRSSVersion()
|
|
|
23 |
{
|
|
|
24 |
$file = "<?xml version=\"1.0\"?>
|
|
|
25 |
<rss version=\"0.8\">
|
|
|
26 |
<channel></channel></rss>";
|
|
|
27 |
try {
|
|
|
28 |
$feed = new XML_Feed_Parser($file, false, true);
|
|
|
29 |
} catch (Exception $e) {
|
|
|
30 |
$this->assertTrue($e instanceof XML_Feed_Parser_Exception);
|
|
|
31 |
}
|
|
|
32 |
}
|
|
|
33 |
|
|
|
34 |
function test_emptyInput()
|
|
|
35 |
{
|
|
|
36 |
$file = null;
|
|
|
37 |
try {
|
|
|
38 |
$feed = new XML_Feed_Parser($file, false, true);
|
|
|
39 |
} catch (Exception $e) {
|
|
|
40 |
$this->assertTrue($e instanceof XML_Feed_Parser_Exception);
|
|
|
41 |
}
|
|
|
42 |
}
|
|
|
43 |
|
|
|
44 |
function test_nonXMLInput()
|
|
|
45 |
{
|
|
|
46 |
$file = "My string";
|
|
|
47 |
try {
|
|
|
48 |
$feed = new XML_Feed_Parser($file, false, true);
|
|
|
49 |
} catch (Exception $e) {
|
|
|
50 |
$this->assertTrue($e instanceof XML_Feed_Parser_Exception);
|
|
|
51 |
}
|
|
|
52 |
}
|
|
|
53 |
|
|
|
54 |
function test_missingElement() {
|
|
|
55 |
$file = '<?xml version="1.0" encoding="utf-8"?>
|
|
|
56 |
<rss version="2.0">
|
|
|
57 |
<channel>
|
|
|
58 |
<title>sample blog</title>
|
|
|
59 |
<link>http://www.example.com/</link>
|
|
|
60 |
<description>sample rss2 feed</description>
|
|
|
61 |
<language>en</language>
|
|
|
62 |
<copyright>Copyright 2006</copyright>
|
|
|
63 |
<lastBuildDate>Tue, 25 Jul 2006 11:53:38 -0500</lastBuildDate>
|
|
|
64 |
<generator>http://www.sixapart.com/movabletype/?v=3.31</generator>
|
|
|
65 |
<docs>http://blogs.law.harvard.edu/tech/rss</docs>
|
|
|
66 |
<item>
|
|
|
67 |
<title>A sample entry</title>
|
|
|
68 |
<description>Sample content</description>
|
|
|
69 |
<link>http://www.example.com/archives/2006/07</link>
|
|
|
70 |
<guid>http://www.example.com/archives/2006/07</guid>
|
|
|
71 |
<category>Examples</category>
|
|
|
72 |
<pubDate>Tue, 25 Jul 2006 11:53:38 -0500</pubDate>
|
|
|
73 |
</item>
|
|
|
74 |
</channel></rss>';
|
|
|
75 |
$feed = new XML_Feed_Parser($file, false, true);
|
|
|
76 |
$entry = $feed->getEntryByOffset(0);
|
|
|
77 |
$this->assertFalse($entry->enclosure());
|
|
|
78 |
}
|
|
|
79 |
}
|
|
|
80 |
|
|
|
81 |
?>
|