atomValues.php
4.57 KB
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
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
<?php
require_once 'XML_Feed_Parser_TestCase.php';
class XML_Feed_Parser_Atom_valueValidity_TestCase extends XML_Feed_Parser_TestCase
{
function __construct($name)
{
$this->PHPUnit_TestCase($name);
$sample_dir = XML_Feed_Parser_TestCase::getSampleDir();
$this->file = file_get_contents($sample_dir . DIRECTORY_SEPARATOR . 'atom10-example2.xml');
$this->feed = new XML_Feed_Parser($this->file);
$this->entry = $this->feed->getEntryByOffset(0);
}
function test_feedNumberItems()
{
$value = 1;
$this->assertEquals($value, $this->feed->numberEntries);
}
function test_FeedTitle()
{
$value = 'dive into mark';
$this->assertEquals($value, $this->feed->title);
}
function test_feedSubtitle()
{
$value = 'A <em>lot</em> of effort
went into making this effortless';
$content = trim($this->feed->subtitle);
$content = preg_replace('/\t/', ' ', $content);
$content = preg_replace('/( )+/', ' ', $content);
$this->assertEquals($content, $value);
}
function test_feedUpdated()
{
$value = strtotime('2005-07-31T12:29:29Z');
$this->assertEquals($this->feed->updated, $value);
}
function test_feedId()
{
$value = 'tag:example.org,2003:3';
$this->assertEquals($this->feed->id, $value);
}
function test_feedRights()
{
$value = 'Copyright (c) 2003, Mark Pilgrim';
$this->assertEquals($this->feed->rights, $value);
}
function test_feedLinkPlain()
{
$value = 'http://example.org/';
$this->assertEquals($this->feed->link, $value);
}
function test_feedLinkAttributes()
{
$value = 'self';
$link = $this->feed->link(0, 'rel', array('type' => 'application/atom+xml'));
$this->assertEquals($link, $value);
}
function test_feedGenerator()
{
$value = 'Example Toolkit';
$this->assertEquals($value, trim($this->feed->generator));
}
function test_entryTitle()
{
$value = 'Atom draft-07 snapshot';
$this->assertEquals($value, trim($this->entry->title));
}
function test_entryLink()
{
$value = 'http://example.org/2005/04/02/atom';
$this->assertEquals($value, trim($this->entry->link));
}
function test_entryId()
{
$value = 'tag:example.org,2003:3.2397';
$this->assertEquals($value, trim($this->entry->id));
}
function test_entryUpdated()
{
$value = strtotime('2005-07-31T12:29:29Z');
$this->assertEquals($value, $this->entry->updated);
}
function test_entryPublished()
{
$value = strtotime('2003-12-13T08:29:29-04:00');
$this->assertEquals($value, $this->entry->published);
}
function test_entryContent()
{
$value = '<p><i>[Update: The Atom draft is finished.]</i></p>';
$content = trim($this->entry->content);
$content = preg_replace('/\t/', ' ', $content);
$content = preg_replace('/( )+/', ' ', $content);
$this->assertEquals($value, $content);
}
function test_entryAuthorURL()
{
$value = 'http://example.org/';
$name = $this->entry->author(false, array('param' => 'uri'));
$this->assertEquals($value, $name);
}
function test_entryAuthorName()
{
$value = 'Mark Pilgrim';
$this->assertEquals($value, $this->entry->author);
}
function test_entryContributor()
{
$value = 'Sam Ruby';
$this->assertEquals($value, $this->entry->contributor);
}
function test_entryContributorOffset()
{
$value = 'Joe Gregorio';
$this->assertEquals($value, $this->entry->contributor(1));
}
# According to RFC4287 section 4.2.7.2:
# [..]If the 'rel' attribute is not present, the link element MUST be
# interpreted as if the link relation type is "alternate".
function test_getsLinkWithoutRel()
{
$source = '<?xml version="1.0" ?>
<entry xmlns="http://www.w3.org/2005/Atom">
<link href="http://example.org/2005/04/02/atom" />
</entry>
';
$feed = new XML_Feed_Parser($source);
$entry = $feed->getEntryByOffset(0);
// Output
$this->assertEquals( "http://example.org/2005/04/02/atom",
$entry->link(0, 'href', array('rel'=>'alternate')));
}
}
$suite = new PHPUnit_TestSuite('XML_Feed_Parser_Atom_valueValidity_TestCase');
$result = PHPUnit::run($suite, '123');
echo $result->toString();
?>