| 1 | <?php |
|---|
| 2 | |
|---|
| 3 | |
|---|
| 4 | |
|---|
| 5 | |
|---|
| 6 | |
|---|
| 7 | |
|---|
| 8 | |
|---|
| 9 | stubClassLoader::load('net::stubbles::xml::rss::stubRSSFeedGenerator'); |
|---|
| 10 | |
|---|
| 11 | |
|---|
| 12 | |
|---|
| 13 | |
|---|
| 14 | |
|---|
| 15 | |
|---|
| 16 | |
|---|
| 17 | |
|---|
| 18 | class stubRSSFeedGeneratorTestCase extends PHPUnit_Framework_TestCase |
|---|
| 19 | { |
|---|
| 20 | |
|---|
| 21 | |
|---|
| 22 | |
|---|
| 23 | |
|---|
| 24 | |
|---|
| 25 | protected $rssFeedGenerator; |
|---|
| 26 | |
|---|
| 27 | |
|---|
| 28 | |
|---|
| 29 | |
|---|
| 30 | public function setUp() |
|---|
| 31 | { |
|---|
| 32 | $this->rssFeedGenerator = new stubRSSFeedGenerator('test', 'http://stubbles.net/', 'description'); |
|---|
| 33 | } |
|---|
| 34 | |
|---|
| 35 | |
|---|
| 36 | |
|---|
| 37 | |
|---|
| 38 | |
|---|
| 39 | |
|---|
| 40 | public function initialProperties() |
|---|
| 41 | { |
|---|
| 42 | $this->assertEquals('test', $this->rssFeedGenerator->getTitle()); |
|---|
| 43 | $this->assertEquals('http://stubbles.net/', $this->rssFeedGenerator->getLink()); |
|---|
| 44 | $this->assertEquals('description', $this->rssFeedGenerator->getDescription()); |
|---|
| 45 | } |
|---|
| 46 | |
|---|
| 47 | |
|---|
| 48 | |
|---|
| 49 | |
|---|
| 50 | |
|---|
| 51 | |
|---|
| 52 | public function noItemsNoStylesheets() |
|---|
| 53 | { |
|---|
| 54 | $this->assertEquals(0, $this->rssFeedGenerator->countItems()); |
|---|
| 55 | |
|---|
| 56 | $mockXmlStreamWriter = $this->getMock('stubXMLStreamWriter'); |
|---|
| 57 | $mockXmlStreamWriter->expects($this->never())->method('writeProcessingInstruction'); |
|---|
| 58 | $mockXmlStreamWriter->expects($this->exactly(2))->method('writeStartElement'); |
|---|
| 59 | $mockXmlStreamWriter->expects($this->exactly(2))->method('writeEndElement'); |
|---|
| 60 | $mockXmlStreamWriter->expects($this->exactly(4))->method('writeElement'); |
|---|
| 61 | $this->assertSame($mockXmlStreamWriter, $this->rssFeedGenerator->serialize($mockXmlStreamWriter)); |
|---|
| 62 | } |
|---|
| 63 | |
|---|
| 64 | |
|---|
| 65 | |
|---|
| 66 | |
|---|
| 67 | |
|---|
| 68 | |
|---|
| 69 | public function noItemsWithStylesheets() |
|---|
| 70 | { |
|---|
| 71 | $this->rssFeedGenerator->appendStylesheet('foo.xsl'); |
|---|
| 72 | $mockXmlStreamWriter = $this->getMock('stubXMLStreamWriter'); |
|---|
| 73 | $mockXmlStreamWriter->expects($this->once())->method('writeProcessingInstruction'); |
|---|
| 74 | $mockXmlStreamWriter->expects($this->exactly(2))->method('writeStartElement'); |
|---|
| 75 | $mockXmlStreamWriter->expects($this->exactly(2))->method('writeEndElement'); |
|---|
| 76 | $mockXmlStreamWriter->expects($this->exactly(4))->method('writeElement'); |
|---|
| 77 | $this->assertSame($mockXmlStreamWriter, $this->rssFeedGenerator->serialize($mockXmlStreamWriter)); |
|---|
| 78 | } |
|---|
| 79 | |
|---|
| 80 | |
|---|
| 81 | |
|---|
| 82 | |
|---|
| 83 | |
|---|
| 84 | |
|---|
| 85 | public function withItemsNoStylesheets() |
|---|
| 86 | { |
|---|
| 87 | $this->assertEquals(0, $this->rssFeedGenerator->countItems()); |
|---|
| 88 | $this->rssFeedGenerator->addItem('foo', 'bar', 'baz'); |
|---|
| 89 | $this->assertEquals(1, $this->rssFeedGenerator->countItems()); |
|---|
| 90 | $mockXmlStreamWriter = $this->getMock('stubXMLStreamWriter'); |
|---|
| 91 | $mockXmlStreamWriter->expects($this->never())->method('writeProcessingInstruction'); |
|---|
| 92 | $mockXmlStreamWriter->expects($this->exactly(3))->method('writeStartElement'); |
|---|
| 93 | $mockXmlStreamWriter->expects($this->exactly(3))->method('writeEndElement'); |
|---|
| 94 | $mockXmlStreamWriter->expects($this->exactly(7))->method('writeElement'); |
|---|
| 95 | $this->assertSame($mockXmlStreamWriter, $this->rssFeedGenerator->serialize($mockXmlStreamWriter)); |
|---|
| 96 | } |
|---|
| 97 | |
|---|
| 98 | |
|---|
| 99 | |
|---|
| 100 | |
|---|
| 101 | |
|---|
| 102 | |
|---|
| 103 | public function withAllChannelElements() |
|---|
| 104 | { |
|---|
| 105 | $this->assertEquals('Stubbles RSSFeedGenerator', $this->rssFeedGenerator->getGenerator()); |
|---|
| 106 | $this->rssFeedGenerator->setLanguage('en_EN'); |
|---|
| 107 | $this->assertEquals('en_EN', $this->rssFeedGenerator->getLanguage()); |
|---|
| 108 | $this->rssFeedGenerator->setCopyright('ᅵ 2007 Stubbles Development Team'); |
|---|
| 109 | $this->assertEquals('ᅵ 2007 Stubbles Development Team', $this->rssFeedGenerator->getCopyright()); |
|---|
| 110 | $this->rssFeedGenerator->setManagingEditor('mikey'); |
|---|
| 111 | $this->assertEquals('nospam@example.com (mikey)', $this->rssFeedGenerator->getManagingEditor()); |
|---|
| 112 | $this->rssFeedGenerator->setWebMaster('schst'); |
|---|
| 113 | $this->assertEquals('nospam@example.com (schst)', $this->rssFeedGenerator->getWebMaster()); |
|---|
| 114 | $this->rssFeedGenerator->setLastBuildDate(50); |
|---|
| 115 | $this->assertEquals('Thu 01 Jan 1970 01:00:50 +0100', $this->rssFeedGenerator->getLastBuildDate()); |
|---|
| 116 | $this->rssFeedGenerator->setTimeToLive(60); |
|---|
| 117 | $this->rssFeedGenerator->setImage('http://example.org/example.gif', 'foo'); |
|---|
| 118 | |
|---|
| 119 | $mockXmlStreamWriter = $this->getMock('stubXMLStreamWriter'); |
|---|
| 120 | $mockXmlStreamWriter->expects($this->never())->method('writeProcessingInstruction'); |
|---|
| 121 | $mockXmlStreamWriter->expects($this->exactly(3))->method('writeStartElement'); |
|---|
| 122 | $mockXmlStreamWriter->expects($this->exactly(3))->method('writeEndElement'); |
|---|
| 123 | $mockXmlStreamWriter->expects($this->exactly(16))->method('writeElement'); |
|---|
| 124 | $this->assertSame($mockXmlStreamWriter, $this->rssFeedGenerator->serialize($mockXmlStreamWriter)); |
|---|
| 125 | } |
|---|
| 126 | |
|---|
| 127 | |
|---|
| 128 | |
|---|
| 129 | |
|---|
| 130 | |
|---|
| 131 | |
|---|
| 132 | public function withAllChannelElementsSecondVersion() |
|---|
| 133 | { |
|---|
| 134 | $this->rssFeedGenerator->setGenerator('test'); |
|---|
| 135 | $this->assertEquals('test', $this->rssFeedGenerator->getGenerator()); |
|---|
| 136 | $this->rssFeedGenerator->setLanguage('en_EN'); |
|---|
| 137 | $this->assertEquals('en_EN', $this->rssFeedGenerator->getLanguage()); |
|---|
| 138 | $this->rssFeedGenerator->setCopyright('ᅵ 2007 Stubbles Development Team'); |
|---|
| 139 | $this->assertEquals('ᅵ 2007 Stubbles Development Team', $this->rssFeedGenerator->getCopyright()); |
|---|
| 140 | $this->rssFeedGenerator->setManagingEditor('example@example.org (mikey)'); |
|---|
| 141 | $this->assertEquals('example@example.org (mikey)', $this->rssFeedGenerator->getManagingEditor()); |
|---|
| 142 | $this->rssFeedGenerator->setWebMaster('example@example.org (schst)'); |
|---|
| 143 | $this->assertEquals('example@example.org (schst)', $this->rssFeedGenerator->getWebMaster()); |
|---|
| 144 | $this->rssFeedGenerator->setLastBuildDate('2008-05-24'); |
|---|
| 145 | $this->assertEquals('Sat 24 May 2008 00:00:00 +0200', $this->rssFeedGenerator->getLastBuildDate()); |
|---|
| 146 | $this->rssFeedGenerator->setTimeToLive(60); |
|---|
| 147 | $this->rssFeedGenerator->setImage('http://example.org/example.gif', 'foo'); |
|---|
| 148 | |
|---|
| 149 | $mockXmlStreamWriter = $this->getMock('stubXMLStreamWriter'); |
|---|
| 150 | $mockXmlStreamWriter->expects($this->never())->method('writeProcessingInstruction'); |
|---|
| 151 | $mockXmlStreamWriter->expects($this->exactly(3))->method('writeStartElement'); |
|---|
| 152 | $mockXmlStreamWriter->expects($this->exactly(3))->method('writeEndElement'); |
|---|
| 153 | $mockXmlStreamWriter->expects($this->exactly(16))->method('writeElement'); |
|---|
| 154 | $this->assertSame($mockXmlStreamWriter, $this->rssFeedGenerator->serialize($mockXmlStreamWriter)); |
|---|
| 155 | } |
|---|
| 156 | |
|---|
| 157 | |
|---|
| 158 | |
|---|
| 159 | |
|---|
| 160 | |
|---|
| 161 | |
|---|
| 162 | |
|---|
| 163 | public function invalidLastBuildDate() |
|---|
| 164 | { |
|---|
| 165 | $this->rssFeedGenerator->setLastBuildDate('foo'); |
|---|
| 166 | } |
|---|
| 167 | |
|---|
| 168 | |
|---|
| 169 | |
|---|
| 170 | |
|---|
| 171 | |
|---|
| 172 | |
|---|
| 173 | |
|---|
| 174 | public function imageWidthTooSmall() |
|---|
| 175 | { |
|---|
| 176 | $this->rssFeedGenerator->setImage('http://example.org/example.gif', 'foo', -1); |
|---|
| 177 | } |
|---|
| 178 | |
|---|
| 179 | |
|---|
| 180 | |
|---|
| 181 | |
|---|
| 182 | |
|---|
| 183 | |
|---|
| 184 | |
|---|
| 185 | public function imageWidthTooGreat() |
|---|
| 186 | { |
|---|
| 187 | $this->rssFeedGenerator->setImage('http://example.org/example.gif', 'foo', 145); |
|---|
| 188 | } |
|---|
| 189 | |
|---|
| 190 | |
|---|
| 191 | |
|---|
| 192 | |
|---|
| 193 | |
|---|
| 194 | |
|---|
| 195 | |
|---|
| 196 | public function imageHeightTooSmall() |
|---|
| 197 | { |
|---|
| 198 | $this->rssFeedGenerator->setImage('http://example.org/example.gif', 'foo', 88, -1); |
|---|
| 199 | } |
|---|
| 200 | |
|---|
| 201 | |
|---|
| 202 | |
|---|
| 203 | |
|---|
| 204 | |
|---|
| 205 | |
|---|
| 206 | |
|---|
| 207 | public function imageHeightTooGreat() |
|---|
| 208 | { |
|---|
| 209 | $this->rssFeedGenerator->setImage('http://example.org/example.gif', 'foo', 88, 401); |
|---|
| 210 | } |
|---|
| 211 | } |
|---|
| 212 | ?> |
|---|