Changeset 1597
- Timestamp:
- 05/26/08 00:55:32 (3 months ago)
- Files:
-
- trunk/src/main/php/net/stubbles/xml/rss/stubRSSFeedGenerator.php (modified) (9 diffs)
- trunk/src/main/php/net/stubbles/xml/rss/stubRSSFeedItem.php (modified) (2 diffs)
- trunk/src/test/php/net/stubbles/xml/rss/stubRSSFeedGeneratorTestCase.php (modified) (9 diffs)
- trunk/src/test/php/net/stubbles/xml/rss/stubRSSFeedItemTestCase.php (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
trunk/src/main/php/net/stubbles/xml/rss/stubRSSFeedGenerator.php
r1596 r1597 7 7 * @subpackage xml_rss 8 8 */ 9 stubClassLoader::load('net::stubbles::xml::rss::stubRSSFeedItem', 9 stubClassLoader::load('net::stubbles::lang::exceptions::stubIllegalArgumentException', 10 'net::stubbles::xml::rss::stubRSSFeedItem', 10 11 'net::stubbles::xml::stubXMLStreamWriter' 11 12 ); … … 195 196 196 197 /** 198 * returns the generator of the feed 199 * 200 * @return string 201 */ 202 public function getGenerator() 203 { 204 return $this->generator; 205 } 206 207 /** 197 208 * append a stylesheet to the document 198 209 * … … 203 214 $this->stylesheets[] = $stylesheet; 204 215 } 205 216 206 217 /** 207 218 * set the language the channel is written in … … 233 244 $this->copyright = $copyright; 234 245 } 235 246 247 /** 248 * returns the copyright notice 249 * 250 * @return string 251 */ 252 public function getCopyright() 253 { 254 return $this->copyright; 255 } 256 236 257 /** 237 258 * set email address for person responsible for editorial content … … 247 268 } 248 269 } 249 270 271 /** 272 * returns the email address for person responsible for editorial content 273 * 274 * @return string 275 */ 276 public function getManagingEditor() 277 { 278 return $this->managingEditor; 279 } 280 250 281 /** 251 282 * set email address for person responsible for technical issues relating to channel … … 261 292 } 262 293 } 263 294 295 /** 296 * returns the email address for person responsible for technical issues relating to channel 297 * 298 * @return string 299 */ 300 public function getWebMaster() 301 { 302 return $this->webMaster; 303 } 304 264 305 /** 265 306 * set the last time when the content of the channel changed 266 307 * 267 308 * @param string|int $lastBuildDate last time the content of the channel changed 268 * @throws stub XMLException309 * @throws stubIllegalArgumentException 269 310 */ 270 311 public function setLastBuildDate($lastBuildDate) 271 312 { 272 if (is_int($lastBuildDate) == false) {313 if (is_int($lastBuildDate) === false) { 273 314 $lastBuildDate = strtotime($lastBuildDate); 274 315 if (false === $lastBuildDate) { 275 throw new stub XMLException('Argument must be a unix timestamp or a valid string representation of a time.');316 throw new stubIllegalArgumentException('Argument must be a unix timestamp or a valid string representation of a time.'); 276 317 } 277 318 } … … 279 320 $this->lastBuildDate = date('D d M Y H:i:s O', $lastBuildDate); 280 321 } 281 322 323 /** 324 * returns the last build date 325 * 326 * @return string 327 */ 328 public function getLastBuildDate() 329 { 330 return $this->lastBuildDate; 331 } 332 282 333 /** 283 334 * set number of minutes that indicates how long a channel can be cached … … 290 341 $this->ttl = $ttl; 291 342 } 292 343 293 344 /** 294 345 * specify a GIF, JPEG or PNG image to be displayed with the channel … … 298 349 * @param int $width indicating the width of the image in pixels, must be 0 < $width <= 144, default 88 299 350 * @param int $height indicating the height of the image in pixels, must be 0 < $height <= 400, default 31 300 * @throws stub XMLException in case $width or $height have invalid values351 * @throws stubIllegalArgumentException in case $width or $height have invalid values 301 352 */ 302 353 public function setImage($url, $description, $width = 88, $height = 31) 303 354 { 304 355 if (144 < $width || 0 > $width) { 305 throw new stub XMLException('Width must be a value between 0 and 144.');356 throw new stubIllegalArgumentException('Width must be a value between 0 and 144.'); 306 357 } 307 358 308 359 if (400 < $height || 0 > $height) { 309 throw new stub XMLException('Height must be a value between 0 and 400.');360 throw new stubIllegalArgumentException('Height must be a value between 0 and 400.'); 310 361 } 311 362 trunk/src/main/php/net/stubbles/xml/rss/stubRSSFeedItem.php
r1590 r1597 7 7 * @subpackage xml_rss 8 8 */ 9 stubClassLoader::load('net::stubbles::xml::stubXMLStreamWriter'); 9 stubClassLoader::load('net::stubbles::lang::exceptions::stubIllegalArgumentException', 10 'net::stubbles::xml::stubXMLStreamWriter' 11 ); 10 12 /** 11 13 * Class for a rss 2.0 feed item. … … 198 200 * @param string|int $pubDate publishing date of rss feed item 199 201 * @return stubRSSFeedItem 200 * @throws stub XMLException202 * @throws stubIllegalArgumentException 201 203 */ 202 204 public function publishedOn($pubDate) 203 205 { 204 if (is_int($pubDate) == false) {206 if (is_int($pubDate) === false) { 205 207 $pubDate = strtotime($pubDate); 206 208 if (false === $pubDate) { 207 throw new stub XMLException('Argument must be a unix timestamp or a valid string representation of a time.');209 throw new stubIllegalArgumentException('Argument must be a unix timestamp or a valid string representation of a time.'); 208 210 } 209 211 } trunk/src/test/php/net/stubbles/xml/rss/stubRSSFeedGeneratorTestCase.php
r1592 r1597 32 32 33 33 /** 34 * initial properties should be set correct 35 * 36 * @test 37 */ 38 public function initialProperties() 39 { 40 $this->assertEquals('test', $this->rssFeedGenerator->getTitle()); 41 $this->assertEquals('http://stubbles.net/', $this->rssFeedGenerator->getLink()); 42 $this->assertEquals('description', $this->rssFeedGenerator->getDescription()); 43 } 44 45 /** 34 46 * test that the values are handles as expexted 35 47 * … … 47 59 $this->assertSame($mockXmlStreamWriter, $this->rssFeedGenerator->serialize($mockXmlStreamWriter)); 48 60 } 49 61 50 62 /** 51 63 * test that the values are handles as expexted … … 63 75 $this->assertSame($mockXmlStreamWriter, $this->rssFeedGenerator->serialize($mockXmlStreamWriter)); 64 76 } 65 77 66 78 /** 67 79 * test that the values are handles as expexted … … 81 93 $this->assertSame($mockXmlStreamWriter, $this->rssFeedGenerator->serialize($mockXmlStreamWriter)); 82 94 } 83 95 84 96 /** 85 97 * test that optional channel elements are handled as expected … … 89 101 public function withAllChannelElements() 90 102 { 103 $this->assertEquals('Stubbles RSSFeedGenerator', $this->rssFeedGenerator->getGenerator()); 91 104 $this->rssFeedGenerator->setLanguage('en_EN'); 105 $this->assertEquals('en_EN', $this->rssFeedGenerator->getLanguage()); 92 106 $this->rssFeedGenerator->setCopyright('© 2007 Stubbles Development Team'); 107 $this->assertEquals('© 2007 Stubbles Development Team', $this->rssFeedGenerator->getCopyright()); 93 108 $this->rssFeedGenerator->setManagingEditor('mikey'); 109 $this->assertEquals('nospam@example.com (mikey)', $this->rssFeedGenerator->getManagingEditor()); 94 110 $this->rssFeedGenerator->setWebMaster('schst'); 111 $this->assertEquals('nospam@example.com (schst)', $this->rssFeedGenerator->getWebMaster()); 95 112 $this->rssFeedGenerator->setLastBuildDate(50); 113 $this->assertEquals('Thu 01 Jan 1970 01:00:50 +0100', $this->rssFeedGenerator->getLastBuildDate()); 96 114 $this->rssFeedGenerator->setTimeToLive(60); 97 115 $this->rssFeedGenerator->setImage('http://example.org/example.gif', 'foo'); … … 104 122 $this->assertSame($mockXmlStreamWriter, $this->rssFeedGenerator->serialize($mockXmlStreamWriter)); 105 123 } 106 107 /** 108 * assure that invalid dates throw a stubXMLException 109 * 110 * @test 111 * @expectedException stubXMLException 124 125 /** 126 * test that optional channel elements are handled as expected 127 * 128 * @test 129 */ 130 public function withAllChannelElementsSecondVersion() 131 { 132 $this->rssFeedGenerator->setGenerator('test'); 133 $this->assertEquals('test', $this->rssFeedGenerator->getGenerator()); 134 $this->rssFeedGenerator->setLanguage('en_EN'); 135 $this->assertEquals('en_EN', $this->rssFeedGenerator->getLanguage()); 136 $this->rssFeedGenerator->setCopyright('© 2007 Stubbles Development Team'); 137 $this->assertEquals('© 2007 Stubbles Development Team', $this->rssFeedGenerator->getCopyright()); 138 $this->rssFeedGenerator->setManagingEditor('example@example.org (mikey)'); 139 $this->assertEquals('example@example.org (mikey)', $this->rssFeedGenerator->getManagingEditor()); 140 $this->rssFeedGenerator->setWebMaster('example@example.org (schst)'); 141 $this->assertEquals('example@example.org (schst)', $this->rssFeedGenerator->getWebMaster()); 142 $this->rssFeedGenerator->setLastBuildDate('2008-05-24'); 143 $this->assertEquals('Sat 24 May 2008 00:00:00 +0200', $this->rssFeedGenerator->getLastBuildDate()); 144 $this->rssFeedGenerator->setTimeToLive(60); 145 $this->rssFeedGenerator->setImage('http://example.org/example.gif', 'foo'); 146 147 $mockXmlStreamWriter = $this->getMock('stubXMLStreamWriter'); 148 $mockXmlStreamWriter->expects($this->never())->method('writeProcessingInstruction'); 149 $mockXmlStreamWriter->expects($this->exactly(3))->method('writeStartElement'); 150 $mockXmlStreamWriter->expects($this->exactly(3))->method('writeEndElement'); 151 $mockXmlStreamWriter->expects($this->exactly(16))->method('writeElement'); 152 $this->assertSame($mockXmlStreamWriter, $this->rssFeedGenerator->serialize($mockXmlStreamWriter)); 153 } 154 155 /** 156 * assure that invalid dates throw a stubIllegalArgumentException 157 * 158 * @test 159 * @expectedException stubIllegalArgumentException 112 160 */ 113 161 public function invalidLastBuildDate() … … 115 163 $this->rssFeedGenerator->setLastBuildDate('foo'); 116 164 } 117 118 /** 119 * assure that an invalid width throws a stub XMLException120 * 121 * @test 122 * @expectedException stub XMLException165 166 /** 167 * assure that an invalid width throws a stubIllegalArgumentException 168 * 169 * @test 170 * @expectedException stubIllegalArgumentException 123 171 */ 124 172 public function imageWidthTooSmall() … … 126 174 $this->rssFeedGenerator->setImage('http://example.org/example.gif', 'foo', -1); 127 175 } 128 129 /** 130 * assure that an invalid width throws a stub XMLException131 * 132 * @test 133 * @expectedException stub XMLException176 177 /** 178 * assure that an invalid width throws a stubIllegalArgumentException 179 * 180 * @test 181 * @expectedException stubIllegalArgumentException 134 182 */ 135 183 public function imageWidthTooGreat() … … 137 185 $this->rssFeedGenerator->setImage('http://example.org/example.gif', 'foo', 145); 138 186 } 139 140 /** 141 * assure that an invalid height throws a stub XMLException142 * 143 * @test 144 * @expectedException stub XMLException187 188 /** 189 * assure that an invalid height throws a stubIllegalArgumentException 190 * 191 * @test 192 * @expectedException stubIllegalArgumentException 145 193 */ 146 194 public function imageHeightTooSmall() 147 195 { 148 $this->rssFeedGenerator->setImage('http://example.org/example.gif', 'foo', -1);149 } 150 151 /** 152 * assure that an invalid height throws a stub XMLException153 * 154 * @test 155 * @expectedException stub XMLException196 $this->rssFeedGenerator->setImage('http://example.org/example.gif', 'foo', 88, -1); 197 } 198 199 /** 200 * assure that an invalid height throws a stubIllegalArgumentException 201 * 202 * @test 203 * @expectedException stubIllegalArgumentException 156 204 */ 157 205 public function imageHeightTooGreat() 158 206 { 159 $this->rssFeedGenerator->setImage('http://example.org/example.gif', 'foo', 401);207 $this->rssFeedGenerator->setImage('http://example.org/example.gif', 'foo', 88, 401); 160 208 } 161 209 } trunk/src/test/php/net/stubbles/xml/rss/stubRSSFeedItemTestCase.php
r1592 r1597 139 139 $this->rssFeedItem2->serialize($mockXmlStreamWriter); 140 140 } 141 142 /** 143 * alternate publishing date should be valid as well 144 * 145 * @test 146 */ 147 public function alternativePublishingDate() 148 { 149 $this->assertSame($this->rssFeedItem1, $this->rssFeedItem1->publishedOn('2008-05-24')); 150 $this->assertEquals('Sat 24 May 2008 00:00:00 +0200', $this->rssFeedItem1->getPubDate()); 151 } 152 153 /** 154 * assure that invalid dates throw a stubIllegalArgumentException 155 * 156 * @test 157 * @expectedException stubIllegalArgumentException 158 */ 159 public function invalidPublishingDate() 160 { 161 $this->rssFeedItem1->publishedOn('foo'); 162 } 141 163 } 142 164 ?>
