Subversion-Projekte lars-tiefland.php_share

Revision

Details | Letzte Änderung | Log anzeigen | RSS feed

Revision Autor Zeilennr. Zeile
1 lars 1
<?php
2
 
3
require_once 'XML_Feed_Parser_TestCase.php';
4
 
5
class atomValues extends XML_Feed_Parser_TestCase
6
{
7
    function setUp()
8
    {
9
        $sample_dir = XML_Feed_Parser_TestCase::getSampleDir();
10
        $this->file = file_get_contents($sample_dir . DIRECTORY_SEPARATOR . 'atom10-example2.xml');
11
        $this->feed = new XML_Feed_Parser($this->file);
12
        $this->entry = $this->feed->getEntryByOffset(0);
13
    }
14
 
15
    function test_feedNumberItems()
16
    {
17
        $value = 1;
18
        $this->assertEquals($value, $this->feed->numberEntries);
19
    }
20
 
21
    function test_FeedTitle()
22
    {
23
        $value = 'dive into mark';
24
        $this->assertEquals($value, $this->feed->title);
25
    }
26
 
27
    function test_feedSubtitle()
28
    {
29
        $value = 'A <em>lot</em> of effort
30
  went into making this effortless';
31
        $content = trim($this->feed->subtitle);
32
        $content = preg_replace('/\t/', ' ', $content);
33
        $content = preg_replace('/(  )+/', ' ', $content);
34
        $this->assertEquals($content, $value);
35
    }
36
 
37
    function test_feedUpdated()
38
    {
39
        $value = strtotime('2005-07-31T12:29:29Z');
40
        $this->assertEquals($this->feed->updated, $value);
41
    }
42
 
43
    function test_feedId()
44
    {
45
        $value = 'tag:example.org,2003:3';
46
        $this->assertEquals($this->feed->id, $value);
47
    }
48
 
49
    function test_feedRights()
50
    {
51
        $value = 'Copyright (c) 2003, Mark Pilgrim';
52
        $this->assertEquals($this->feed->rights, $value);
53
    }
54
 
55
    function test_feedLinkPlain()
56
    {
57
        $value = 'http://example.org/';
58
        $this->assertEquals($this->feed->link, $value);
59
    }
60
 
61
    function test_feedLinkAttributes()
62
    {
63
        $value = 'self';
64
        $link = $this->feed->link(0, 'rel', array('type' => 'application/atom+xml'));
65
        $this->assertEquals($link, $value);
66
    }
67
 
68
    function test_feedGenerator()
69
    {
70
        $value = 'Example Toolkit';
71
        $this->assertEquals($value, trim($this->feed->generator));
72
    }
73
 
74
    function test_entryTitle()
75
    {
76
        $value = 'Atom draft-07 snapshot';
77
        $this->assertEquals($value, trim($this->entry->title));
78
    }
79
 
80
    function test_entryLink()
81
    {
82
        $value = 'http://example.org/2005/04/02/atom';
83
        $this->assertEquals($value, trim($this->entry->link));
84
    }
85
 
86
    function test_entryId()
87
    {
88
        $value = 'tag:example.org,2003:3.2397';
89
        $this->assertEquals($value, trim($this->entry->id));
90
    }
91
    function test_entryUpdated()
92
    {
93
        $value = strtotime('2005-07-31T12:29:29Z');
94
        $this->assertEquals($value, $this->entry->updated);
95
    }
96
 
97
    function test_entryPublished()
98
    {
99
        $value = strtotime('2003-12-13T08:29:29-04:00');
100
        $this->assertEquals($value, $this->entry->published);
101
    }
102
 
103
    function test_entryContent()
104
    {
105
        $value = '<p><i>[Update: The Atom draft is finished.]</i></p>';
106
        $content = trim($this->entry->content);
107
        $content = preg_replace('/\t/', ' ', $content);
108
        $content = preg_replace('/(  )+/', ' ', $content);
109
        $this->assertEquals($value, $content);
110
    }
111
 
112
    function test_entryAuthorURL()
113
    {
114
        $value = 'http://example.org/';
115
        $name = $this->entry->author(false, array('param' => 'uri'));
116
        $this->assertEquals($value, $name);
117
    }
118
 
119
    function test_entryAuthorName()
120
    {
121
        $value = 'Mark Pilgrim';
122
        $this->assertEquals($value, $this->entry->author);
123
    }
124
 
125
    function test_entryContributor()
126
    {
127
        $value = 'Sam Ruby';
128
        $this->assertEquals($value, $this->entry->contributor);
129
    }
130
 
131
    function test_entryContributorOffset()
132
    {
133
        $value = 'Joe Gregorio';
134
        $this->assertEquals($value, $this->entry->contributor(1));
135
    }
136
 
137
    # According to RFC4287 section 4.2.7.2:
138
    # [..]If the 'rel' attribute is not present, the link element MUST be
139
    # interpreted as if the link relation type is "alternate".
140
    function test_getsLinkWithoutRel()
141
    {
142
        $source = '<?xml version="1.0" ?>
143
        <entry xmlns="http://www.w3.org/2005/Atom">
144
        <link href="http://example.org/2005/04/02/atom" />
145
        </entry>
146
        ';
147
        $feed = new XML_Feed_Parser($source);
148
        $entry = $feed->getEntryByOffset(0);
149
 
150
        // Output
151
        $this->assertEquals( "http://example.org/2005/04/02/atom",
152
            $entry->link(0, 'href', array('rel'=>'alternate')));
153
    }
154
 
155
    function test_htmlUnencoding() {
156
      $source = '<entry xmlns="http://www.w3.org/2005/Atom">
157
        ...
158
        <summary type="html">
159
          &lt;P&gt;The &amp;lt;EM&amp;gt; tag emphasizes the content.&lt;/P&gt;
160
        </summary>
161
      </entry>';
162
 
163
      $atom = new XML_Feed_Parser($source);
164
      $this->assertEquals("<P>The &lt;EM&gt; tag emphasizes the content.</P>",
165
        trim($atom->getEntryByOffset(0)->summary));
166
    }
167
}
168
 
169
?>