| 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 sane values back for all
|
|
|
7 |
* elements specified by the atom specification. It is okay for a feed
|
|
|
8 |
* to not have some of these, but if they're not present we should
|
|
|
9 |
* get a null or false return rather than an error. This test begins
|
|
|
10 |
* to ensure consistency of our API.
|
|
|
11 |
*/
|
|
|
12 |
class atomCompliance extends XML_Feed_Parser_TestCase
|
|
|
13 |
{
|
|
|
14 |
|
|
|
15 |
function setUp()
|
|
|
16 |
{
|
|
|
17 |
$this->sample_dir = XML_Feed_Parser_TestCase::getSampleDir();
|
|
|
18 |
$this->files = array('atom10-example1.xml', 'atom10-example2.xml', 'rss10-example1.xml',
|
|
|
19 |
'rss10-example2.xml', 'rss2sample.xml', 'delicious.feed', 'technorati.feed', 'grwifi-atom.xml');
|
|
|
20 |
}
|
|
|
21 |
|
|
|
22 |
function checkString($attribute, $element) {
|
|
|
23 |
$item = $element->$attribute;
|
|
|
24 |
$test = (is_string($item) or $item === false);
|
|
|
25 |
return $test;
|
|
|
26 |
}
|
|
|
27 |
|
|
|
28 |
function checkNumeric($attribute, $element) {
|
|
|
29 |
$item = $element->$attribute;
|
|
|
30 |
$test = (is_numeric($item) or $item === false);
|
|
|
31 |
return $test;
|
|
|
32 |
}
|
|
|
33 |
|
|
|
34 |
function test_feedAuthor() {
|
|
|
35 |
foreach ($this->files as $file) {
|
|
|
36 |
$contents = file_get_contents($this->sample_dir . DIRECTORY_SEPARATOR . $file);
|
|
|
37 |
$feed = new XML_Feed_Parser($contents);
|
|
|
38 |
$this->assertTrue($this->checkString('author', $feed), "Failed for $file");
|
|
|
39 |
}
|
|
|
40 |
}
|
|
|
41 |
|
|
|
42 |
function test_feedContributor()
|
|
|
43 |
{
|
|
|
44 |
foreach ($this->files as $file) {
|
|
|
45 |
$contents = file_get_contents($this->sample_dir . DIRECTORY_SEPARATOR . $file);
|
|
|
46 |
$feed = new XML_Feed_Parser($contents);
|
|
|
47 |
$this->assertTrue($this->checkString('contributor', $feed), "Failed for $file");
|
|
|
48 |
}
|
|
|
49 |
}
|
|
|
50 |
|
|
|
51 |
function test_feedIcon() {
|
|
|
52 |
foreach ($this->files as $file) {
|
|
|
53 |
$contents = file_get_contents($this->sample_dir . DIRECTORY_SEPARATOR . $file);
|
|
|
54 |
$feed = new XML_Feed_Parser($contents);
|
|
|
55 |
$this->assertTrue($this->checkString('icon', $feed), "Failed for $file");
|
|
|
56 |
}
|
|
|
57 |
}
|
|
|
58 |
|
|
|
59 |
function test_feedId() {
|
|
|
60 |
foreach ($this->files as $file) {
|
|
|
61 |
$contents = file_get_contents($this->sample_dir . DIRECTORY_SEPARATOR . $file);
|
|
|
62 |
$feed = new XML_Feed_Parser($contents);
|
|
|
63 |
$this->assertTrue($this->checkString('id', $feed), "Failed for $file");
|
|
|
64 |
}
|
|
|
65 |
}
|
|
|
66 |
|
|
|
67 |
function test_feedRights() {
|
|
|
68 |
foreach ($this->files as $file) {
|
|
|
69 |
$contents = file_get_contents($this->sample_dir . DIRECTORY_SEPARATOR . $file);
|
|
|
70 |
$feed = new XML_Feed_Parser($contents);
|
|
|
71 |
$this->assertTrue($this->checkString('rights', $feed), "Failed for $file");
|
|
|
72 |
}
|
|
|
73 |
}
|
|
|
74 |
|
|
|
75 |
function test_feedTitle() {
|
|
|
76 |
foreach ($this->files as $file) {
|
|
|
77 |
$contents = file_get_contents($this->sample_dir . DIRECTORY_SEPARATOR . $file);
|
|
|
78 |
$feed = new XML_Feed_Parser($contents);
|
|
|
79 |
$this->assertTrue($this->checkString('title', $feed), "Failed for $file");
|
|
|
80 |
}
|
|
|
81 |
}
|
|
|
82 |
|
|
|
83 |
function test_feedSubtitle() {
|
|
|
84 |
foreach ($this->files as $file) {
|
|
|
85 |
$contents = file_get_contents($this->sample_dir . DIRECTORY_SEPARATOR . $file);
|
|
|
86 |
$feed = new XML_Feed_Parser($contents);
|
|
|
87 |
$this->assertTrue($this->checkString('subtitle', $feed), "Failed for $file");
|
|
|
88 |
}
|
|
|
89 |
}
|
|
|
90 |
|
|
|
91 |
function test_feedUpdated() {
|
|
|
92 |
foreach ($this->files as $file) {
|
|
|
93 |
$contents = file_get_contents($this->sample_dir . DIRECTORY_SEPARATOR . $file);
|
|
|
94 |
$feed = new XML_Feed_Parser($contents);
|
|
|
95 |
$this->assertTrue($this->checkNumeric('updated', $feed), "Failed for $file");
|
|
|
96 |
}
|
|
|
97 |
}
|
|
|
98 |
|
|
|
99 |
function test_feedLink() {
|
|
|
100 |
foreach ($this->files as $file) {
|
|
|
101 |
$contents = file_get_contents($this->sample_dir . DIRECTORY_SEPARATOR . $file);
|
|
|
102 |
$feed = new XML_Feed_Parser($contents);
|
|
|
103 |
$this->assertTrue($this->checkString('link', $feed), "Failed for $file");
|
|
|
104 |
}
|
|
|
105 |
}
|
|
|
106 |
|
|
|
107 |
function test_entryAuthor() {
|
|
|
108 |
foreach ($this->files as $file) {
|
|
|
109 |
$contents = file_get_contents($this->sample_dir . DIRECTORY_SEPARATOR . $file);
|
|
|
110 |
$feed = new XML_Feed_Parser($contents);
|
|
|
111 |
$entry = $feed->getEntryByOffset(0);
|
|
|
112 |
$this->assertTrue($this->checkString('author', $entry), "Failed for $file");
|
|
|
113 |
}
|
|
|
114 |
}
|
|
|
115 |
|
|
|
116 |
function test_entryContributor()
|
|
|
117 |
{
|
|
|
118 |
foreach ($this->files as $file) {
|
|
|
119 |
$contents = file_get_contents($this->sample_dir . DIRECTORY_SEPARATOR . $file);
|
|
|
120 |
$feed = new XML_Feed_Parser($contents);
|
|
|
121 |
$entry = $feed->getEntryByOffset(0);
|
|
|
122 |
$this->assertTrue($this->checkString('contributor', $entry), "Failed for $file");
|
|
|
123 |
}
|
|
|
124 |
}
|
|
|
125 |
|
|
|
126 |
function test_entryId() {
|
|
|
127 |
foreach ($this->files as $file) {
|
|
|
128 |
$contents = file_get_contents($this->sample_dir . DIRECTORY_SEPARATOR . $file);
|
|
|
129 |
$feed = new XML_Feed_Parser($contents);
|
|
|
130 |
$entry = $feed->getEntryByOffset(0);
|
|
|
131 |
$this->assertTrue($this->checkString('id', $entry), "Failed for $file");
|
|
|
132 |
}
|
|
|
133 |
}
|
|
|
134 |
|
|
|
135 |
function test_entryPublished() {
|
|
|
136 |
foreach ($this->files as $file) {
|
|
|
137 |
$contents = file_get_contents($this->sample_dir . DIRECTORY_SEPARATOR . $file);
|
|
|
138 |
$feed = new XML_Feed_Parser($contents);
|
|
|
139 |
$entry = $feed->getEntryByOffset(0);
|
|
|
140 |
$this->assertTrue($this->checkNumeric('published', $entry), "Failed for $file");
|
|
|
141 |
}
|
|
|
142 |
}
|
|
|
143 |
|
|
|
144 |
function testEntryTitle() {
|
|
|
145 |
foreach ($this->files as $file) {
|
|
|
146 |
$contents = file_get_contents($this->sample_dir . DIRECTORY_SEPARATOR . $file);
|
|
|
147 |
$feed = new XML_Feed_Parser($contents);
|
|
|
148 |
$entry = $feed->getEntryByOffset(0);
|
|
|
149 |
$this->assertTrue($this->checkString('title', $entry), "Failed for $file");
|
|
|
150 |
}
|
|
|
151 |
}
|
|
|
152 |
|
|
|
153 |
function testEntryRights() {
|
|
|
154 |
foreach ($this->files as $file) {
|
|
|
155 |
$contents = file_get_contents($this->sample_dir . DIRECTORY_SEPARATOR . $file);
|
|
|
156 |
$feed = new XML_Feed_Parser($contents);
|
|
|
157 |
$entry = $feed->getEntryByOffset(0);
|
|
|
158 |
$this->assertTrue($this->checkString('rights', $entry), "Failed for $file");
|
|
|
159 |
}
|
|
|
160 |
}
|
|
|
161 |
|
|
|
162 |
function testEntrySummary() {
|
|
|
163 |
foreach ($this->files as $file) {
|
|
|
164 |
$contents = file_get_contents($this->sample_dir . DIRECTORY_SEPARATOR . $file);
|
|
|
165 |
$feed = new XML_Feed_Parser($contents);
|
|
|
166 |
$entry = $feed->getEntryByOffset(0);
|
|
|
167 |
$this->assertTrue($this->checkString('summary', $entry), "Failed for $file");
|
|
|
168 |
}
|
|
|
169 |
}
|
|
|
170 |
|
|
|
171 |
function testEntryContent() {
|
|
|
172 |
foreach ($this->files as $file) {
|
|
|
173 |
$contents = file_get_contents($this->sample_dir . DIRECTORY_SEPARATOR . $file);
|
|
|
174 |
$feed = new XML_Feed_Parser($contents);
|
|
|
175 |
$entry = $feed->getEntryByOffset(0);
|
|
|
176 |
$this->assertTrue($this->checkString('content', $entry), "Failed for $file");
|
|
|
177 |
}
|
|
|
178 |
}
|
|
|
179 |
|
|
|
180 |
function testEntryLink() {
|
|
|
181 |
foreach ($this->files as $file) {
|
|
|
182 |
$contents = file_get_contents($this->sample_dir . DIRECTORY_SEPARATOR . $file);
|
|
|
183 |
$feed = new XML_Feed_Parser($contents);
|
|
|
184 |
$entry = $feed->getEntryByOffset(0);
|
|
|
185 |
$this->assertTrue($this->checkString('link', $entry), "Failed for $file");
|
|
|
186 |
}
|
|
|
187 |
}
|
|
|
188 |
}
|
|
|
189 |
|