Blame view

libs/XML_Feed_Parser-1.0.2/tests/errors.php 2.92 KB
42868d70   andryeyev   Создал GIT
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
  <?php
  
  require_once 'XML_Feed_Parser_TestCase.php';
  
  /**
   * This test is to make sure that we get errors when we should. In
   * particular we check that it throws an exception if we hand in an
   * illegal feed type.
   */
  class XML_Feed_Parser_ThrowErrors_TestCase extends XML_Feed_Parser_TestCase
  {
      
      function __construct($name)
      {
          $this->PHPUnit_TestCase($name);
      }
      
      function setUp() {
      }
      
      function tearDown() {
      }
      
      function test_fakeFeedType()
      {
          $file = "<myfeed><myitem /></myfeed>";
          try {
              $feed = new XML_Feed_Parser($file, false, true);
          } catch (Exception $e) {
              $this->assertTrue($e instanceof XML_Feed_Parser_Exception);
          }
      }
      
      function test_badRSSVersion()
      {
          $file = "<?xml version=\"1.0\"?>
          <rss version=\"0.8\">
             <channel></channel></rss>";
         try {
             $feed = new XML_Feed_Parser($file, false, true);
         } catch (Exception $e) {
             $this->assertTrue($e instanceof XML_Feed_Parser_Exception);
         }
      }
      
      function test_emptyInput()
      {
          $file = null;
          try {
              $feed = new XML_Feed_Parser($file, false, true);
          } catch (Exception $e) {
              $this->assertTrue($e instanceof XML_Feed_Parser_Exception);
          }
      }
  
      function test_nonXMLInput()
      {
          $file = "My string";
          try {
              $feed = new XML_Feed_Parser($file, false, true);
          } catch (Exception $e) {
              $this->assertTrue($e instanceof XML_Feed_Parser_Exception);
          }
      }
      
      function test_missingElement() {
          $file = '<?xml version="1.0" encoding="utf-8"?>
          <rss version="2.0">
             <channel>
                <title>sample blog</title>
                <link>http://www.example.com/</link>
                <description>sample rss2 feed</description>
                <language>en</language>
                <copyright>Copyright 2006</copyright>
                <lastBuildDate>Tue, 25 Jul 2006 11:53:38 -0500</lastBuildDate>
                <generator>http://www.sixapart.com/movabletype/?v=3.31</generator>
                <docs>http://blogs.law.harvard.edu/tech/rss</docs> 
                <item>
                   <title>A sample entry</title>
                   <description>Sample content</description>
                   <link>http://www.example.com/archives/2006/07</link>
                   <guid>http://www.example.com/archives/2006/07</guid>
                   <category>Examples</category>
                   <pubDate>Tue, 25 Jul 2006 11:53:38 -0500</pubDate>
                </item>
              </channel></rss>';
            $feed = new XML_Feed_Parser($file, false, true);
            $entry = $feed->getEntryByOffset(0);
            $this->assertFalse($entry->enclosure());
      }
  }
  
  $suite = new PHPUnit_TestSuite;
  $suite->addTestSuite("XML_Feed_Parser_ThrowErrors_TestCase");
  $result = PHPUnit::run($suite, "123");
  echo $result->toString();
  
  ?>