source: branches/beta/html/test/adachi/PLLagger/Lib/XML/Feed/tests/errors.php @ 15120

Revision 15120, 2.9 KB checked in by adati, 17 years ago (diff)

1.4.2betaのマージ

Line 
1<?php
2
3require_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 */
10class XML_Feed_Parser_ThrowErrors_TestCase extends XML_Feed_Parser_TestCase
11{
12   
13    function __construct($name)
14    {
15        $this->PHPUnit_TestCase($name);
16    }
17   
18    function setUp() {
19    }
20   
21    function tearDown() {
22    }
23   
24    function test_fakeFeedType()
25    {
26        $file = "<myfeed><myitem /></myfeed>";
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_badRSSVersion()
35    {
36        $file = "<?xml version=\"1.0\"?>
37        <rss version=\"0.8\">
38           <channel></channel></rss>";
39       try {
40           $feed = new XML_Feed_Parser($file, false, true);
41       } catch (Exception $e) {
42           $this->assertTrue($e instanceof XML_Feed_Parser_Exception);
43       }
44    }
45   
46    function test_emptyInput()
47    {
48        $file = null;
49        try {
50            $feed = new XML_Feed_Parser($file, false, true);
51        } catch (Exception $e) {
52            $this->assertTrue($e instanceof XML_Feed_Parser_Exception);
53        }
54    }
55
56    function test_nonXMLInput()
57    {
58        $file = "My string";
59        try {
60            $feed = new XML_Feed_Parser($file, false, true);
61        } catch (Exception $e) {
62            $this->assertTrue($e instanceof XML_Feed_Parser_Exception);
63        }
64    }
65   
66    function test_missingElement() {
67        $file = '<?xml version="1.0" encoding="utf-8"?>
68        <rss version="2.0">
69           <channel>
70              <title>sample blog</title>
71              <link>http://www.example.com/</link>
72              <description>sample rss2 feed</description>
73              <language>en</language>
74              <copyright>Copyright 2006</copyright>
75              <lastBuildDate>Tue, 25 Jul 2006 11:53:38 -0500</lastBuildDate>
76              <generator>http://www.sixapart.com/movabletype/?v=3.31</generator>
77              <docs>http://blogs.law.harvard.edu/tech/rss</docs>
78              <item>
79                 <title>A sample entry</title>
80                 <description>Sample content</description>
81                 <link>http://www.example.com/archives/2006/07</link>
82                 <guid>http://www.example.com/archives/2006/07</guid>
83                 <category>Examples</category>
84                 <pubDate>Tue, 25 Jul 2006 11:53:38 -0500</pubDate>
85              </item>
86            </channel></rss>';
87          $feed = new XML_Feed_Parser($file, false, true);
88          $entry = $feed->getEntryByOffset(0);
89          $this->assertFalse($entry->enclosure());
90    }
91}
92
93$suite = new PHPUnit_TestSuite;
94$suite->addTestSuite("XML_Feed_Parser_ThrowErrors_TestCase");
95$result = PHPUnit::run($suite, "123");
96echo $result->toString();
97
98?>
Note: See TracBrowser for help on using the repository browser.