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 XML_Feed_Parser_AtomCompat1_TestCase extends XML_Feed_Parser_TestCase |
---|
13 | { |
---|
14 | |
---|
15 | function __construct($name) |
---|
16 | { |
---|
17 | $this->PHPUnit_TestCase($name); |
---|
18 | $sample_dir = XML_Feed_Parser_TestCase::getSampleDir(); |
---|
19 | $this->file = file_get_contents($sample_dir . DIRECTORY_SEPARATOR . 'atom10-example1.xml'); |
---|
20 | $this->parser = new XML_Feed_Parser($this->file); |
---|
21 | $this->entry = $this->parser->getEntryByOffset(0); |
---|
22 | } |
---|
23 | |
---|
24 | function setUp() { |
---|
25 | } |
---|
26 | |
---|
27 | function tearDown() { |
---|
28 | } |
---|
29 | |
---|
30 | function checkString($attribute, $entry = false) { |
---|
31 | if ($entry) { |
---|
32 | $author = $this->entry->$attribute; |
---|
33 | } else { |
---|
34 | $author = $this->parser->$attribute; |
---|
35 | } |
---|
36 | if (is_string($author) or $author === false) { |
---|
37 | $test = true; |
---|
38 | } |
---|
39 | return $test; |
---|
40 | } |
---|
41 | |
---|
42 | function checkNumeric($attribute, $entry = false) { |
---|
43 | if ($entry) { |
---|
44 | $author = $this->entry->$attribute; |
---|
45 | } else { |
---|
46 | $author = $this->parser->$attribute; |
---|
47 | } |
---|
48 | if (is_numeric($author)) { |
---|
49 | $test = true; |
---|
50 | } else if ($author === false) { |
---|
51 | $test = true; |
---|
52 | } |
---|
53 | return $test; |
---|
54 | } |
---|
55 | |
---|
56 | function test_feedAuthor() { |
---|
57 | $this->assertTrue($this->checkString('author')); |
---|
58 | } |
---|
59 | |
---|
60 | function test_feedContributor() |
---|
61 | { |
---|
62 | $this->assertTrue($this->checkString('contributor')); |
---|
63 | } |
---|
64 | |
---|
65 | function test_feedIcon() { |
---|
66 | $this->assertTrue($this->checkString('icon')); |
---|
67 | } |
---|
68 | |
---|
69 | function test_feedId() { |
---|
70 | $this->assertTrue($this->checkString('id')); |
---|
71 | } |
---|
72 | |
---|
73 | function test_feedRights() { |
---|
74 | $this->assertTrue($this->checkString('rights')); |
---|
75 | } |
---|
76 | |
---|
77 | function test_feedTitle() { |
---|
78 | $this->assertTrue($this->checkString('title')); |
---|
79 | } |
---|
80 | |
---|
81 | function test_feedSubtitle() { |
---|
82 | $this->assertTrue($this->checkString('subtitle')); |
---|
83 | } |
---|
84 | |
---|
85 | function test_feedUpdated() { |
---|
86 | $this->assertTrue($this->checkNumeric('updated')); |
---|
87 | } |
---|
88 | |
---|
89 | function test_feedLink() { |
---|
90 | $this->assertTrue($this->checkString('link')); |
---|
91 | } |
---|
92 | |
---|
93 | function test_entryAuthor() { |
---|
94 | $this->assertTrue($this->checkString('author', true)); |
---|
95 | } |
---|
96 | |
---|
97 | function test_entryContributor() |
---|
98 | { |
---|
99 | $this->assertTrue($this->checkString('contributor', true)); |
---|
100 | } |
---|
101 | |
---|
102 | function test_entryId() { |
---|
103 | $this->assertTrue($this->checkString('id', true)); |
---|
104 | } |
---|
105 | |
---|
106 | function test_entryPublished() { |
---|
107 | $this->assertTrue($this->checkNumeric('published', true)); |
---|
108 | } |
---|
109 | |
---|
110 | function testEntryTitle() { |
---|
111 | $this->assertTrue($this->checkString('title', true)); |
---|
112 | } |
---|
113 | |
---|
114 | function testEntryRights() { |
---|
115 | $this->assertTrue($this->checkString('rights', true)); |
---|
116 | } |
---|
117 | |
---|
118 | function testEntrySummary() { |
---|
119 | $this->assertTrue($this->checkString('summary', true)); |
---|
120 | } |
---|
121 | |
---|
122 | function testEntryContent() { |
---|
123 | $this->assertTrue($this->checkString('content', true)); |
---|
124 | } |
---|
125 | |
---|
126 | function testEntryLink() { |
---|
127 | $this->assertTrue($this->checkString('link', true)); |
---|
128 | } |
---|
129 | } |
---|
130 | |
---|
131 | class XML_Feed_Parser_AtomCompat2_TestCase extends XML_Feed_Parser_AtomCompat1_TestCase |
---|
132 | { |
---|
133 | function __construct($name) |
---|
134 | { |
---|
135 | $this->PHPUnit_TestCase($name); |
---|
136 | $sample_dir = XML_Feed_Parser_TestCase::getSampleDir(); |
---|
137 | $this->file = file_get_contents($sample_dir . DIRECTORY_SEPARATOR . 'atom10-example2.xml'); |
---|
138 | $this->parser = new XML_Feed_Parser($this->file); |
---|
139 | $this->entry = $this->parser->getEntryByOffset(0); |
---|
140 | } |
---|
141 | } |
---|
142 | |
---|
143 | class XML_Feed_Parser_AtomCompat3_TestCase extends XML_Feed_Parser_AtomCompat1_TestCase |
---|
144 | { |
---|
145 | function __construct($name) |
---|
146 | { |
---|
147 | $this->PHPUnit_TestCase($name); |
---|
148 | $sample_dir = XML_Feed_Parser_TestCase::getSampleDir(); |
---|
149 | $this->file = file_get_contents($sample_dir . DIRECTORY_SEPARATOR . 'rss10-example1.xml'); |
---|
150 | $this->parser = new XML_Feed_Parser($this->file); |
---|
151 | $this->entry = $this->parser->getEntryByOffset(0); |
---|
152 | } |
---|
153 | } |
---|
154 | |
---|
155 | class XML_Feed_Parser_AtomCompat4_TestCase extends XML_Feed_Parser_AtomCompat1_TestCase |
---|
156 | { |
---|
157 | function __construct($name) |
---|
158 | { |
---|
159 | $this->PHPUnit_TestCase($name); |
---|
160 | $sample_dir = XML_Feed_Parser_TestCase::getSampleDir(); |
---|
161 | $this->file = file_get_contents($sample_dir . DIRECTORY_SEPARATOR . 'rss10-example2.xml'); |
---|
162 | $this->parser = new XML_Feed_Parser($this->file); |
---|
163 | $this->entry = $this->parser->getEntryByOffset(0); |
---|
164 | } |
---|
165 | } |
---|
166 | |
---|
167 | class XML_Feed_Parser_AtomCompat5_TestCase extends XML_Feed_Parser_AtomCompat1_TestCase |
---|
168 | { |
---|
169 | function __construct($name) |
---|
170 | { |
---|
171 | $this->PHPUnit_TestCase($name); |
---|
172 | $sample_dir = XML_Feed_Parser_TestCase::getSampleDir(); |
---|
173 | $this->file = file_get_contents($sample_dir . DIRECTORY_SEPARATOR . 'rss2sample.xml'); |
---|
174 | $this->parser = new XML_Feed_Parser($this->file); |
---|
175 | $this->entry = $this->parser->getEntryByOffset(0); |
---|
176 | } |
---|
177 | } |
---|
178 | |
---|
179 | class XML_Feed_Parser_AtomCompat6_TestCase extends XML_Feed_Parser_AtomCompat1_TestCase |
---|
180 | { |
---|
181 | function __construct($name) |
---|
182 | { |
---|
183 | $this->PHPUnit_TestCase($name); |
---|
184 | $sample_dir = XML_Feed_Parser_TestCase::getSampleDir(); |
---|
185 | $this->file = file_get_contents($sample_dir . DIRECTORY_SEPARATOR . 'delicious.feed'); |
---|
186 | $this->parser = new XML_Feed_Parser($this->file); |
---|
187 | $this->entry = $this->parser->getEntryByOffset(0); |
---|
188 | } |
---|
189 | } |
---|
190 | |
---|
191 | class XML_Feed_Parser_AtomCompat7_TestCase extends XML_Feed_Parser_AtomCompat1_TestCase |
---|
192 | { |
---|
193 | function __construct($name) |
---|
194 | { |
---|
195 | $this->PHPUnit_TestCase($name); |
---|
196 | $sample_dir = XML_Feed_Parser_TestCase::getSampleDir(); |
---|
197 | $this->file = file_get_contents($sample_dir . DIRECTORY_SEPARATOR . 'technorati.feed'); |
---|
198 | $this->parser = new XML_Feed_Parser($this->file); |
---|
199 | $this->entry = $this->parser->getEntryByOffset(0); |
---|
200 | } |
---|
201 | } |
---|
202 | |
---|
203 | class XML_Feed_Parser_AtomCompat8_TestCase extends XML_Feed_Parser_AtomCompat1_TestCase |
---|
204 | { |
---|
205 | function __construct($name) |
---|
206 | { |
---|
207 | $this->PHPUnit_TestCase($name); |
---|
208 | $sample_dir = XML_Feed_Parser_TestCase::getSampleDir(); |
---|
209 | $this->file = file_get_contents($sample_dir . DIRECTORY_SEPARATOR . 'grwifi-atom.xml'); |
---|
210 | $this->parser = new XML_Feed_Parser($this->file); |
---|
211 | $this->entry = $this->parser->getEntryByOffset(0); |
---|
212 | } |
---|
213 | } |
---|
214 | |
---|
215 | $suite = new PHPUnit_TestSuite; |
---|
216 | $suite->addTestSuite('XML_Feed_Parser_AtomCompat1_TestCase'); |
---|
217 | $suite->addTestSuite('XML_Feed_Parser_AtomCompat2_TestCase'); |
---|
218 | $suite->addTestSuite('XML_Feed_Parser_AtomCompat3_TestCase'); |
---|
219 | $suite->addTestSuite('XML_Feed_Parser_AtomCompat4_TestCase'); |
---|
220 | $suite->addTestSuite('XML_Feed_Parser_AtomCompat5_TestCase'); |
---|
221 | $suite->addTestSuite('XML_Feed_Parser_AtomCompat6_TestCase'); |
---|
222 | $suite->addTestSuite('XML_Feed_Parser_AtomCompat7_TestCase'); |
---|
223 | $suite->addTestSuite('XML_Feed_Parser_AtomCompat8_TestCase'); |
---|
224 | $result = PHPUnit::run($suite, '123'); |
---|
225 | echo $result->toString(); |
---|
226 | ?> |
---|