root/framework/trunk/src/test/php/net/stubbles/xml/rss/stubRSSFeedGeneratorTestCase.php @ 1763

Revision 1763, 8.5 kB (checked in by mikey, 2 years ago)

enable id keyword

  • Property svn:keywords set to Id
Line 
1<?php
2/**
3 * Test for net::stubbles::xml::rss::stubRSSFeedGenerator.
4 *
5 * @author      Frank Kleine <mikey@stubbles.net>
6 * @package     stubbles
7 * @subpackage  xml_rss_test
8 */
9stubClassLoader::load('net::stubbles::xml::rss::stubRSSFeedGenerator');
10/**
11 * Test for net::stubbles::xml::rss::stubRSSFeedGenerator.
12 *
13 * @package     stubbles
14 * @subpackage  xml_rss_test
15 * @group       xml
16 * @group       xml_rss
17 */
18class stubRSSFeedGeneratorTestCase extends PHPUnit_Framework_TestCase
19{
20    /**
21     * instance to test
22     *
23     * @var  stubRSSFeedGenerator
24     */
25    protected $rssFeedGenerator;
26
27    /**
28     * set up test environment
29     */
30    public function setUp()
31    {
32        $this->rssFeedGenerator = new stubRSSFeedGenerator('test', 'http://stubbles.net/', 'description');
33    }
34
35    /**
36     * initial properties should be set correct
37     *
38     * @test
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     * test that the values are handles as expexted
49     *
50     * @test
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     * test that the values are handles as expexted
66     *
67     * @test
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     * test that the values are handles as expexted
82     *
83     * @test
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     * test that optional channel elements are handled as expected
100     *
101     * @test
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     * test that optional channel elements are handled as expected
129     *
130     * @test
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     * assure that invalid dates throw a stubIllegalArgumentException
159     *
160     * @test
161     * @expectedException  stubIllegalArgumentException
162     */
163    public function invalidLastBuildDate()
164    {
165        $this->rssFeedGenerator->setLastBuildDate('foo');
166    }
167
168    /**
169     * assure that an invalid width throws a stubIllegalArgumentException
170     *
171     * @test
172     * @expectedException  stubIllegalArgumentException
173     */
174    public function imageWidthTooSmall()
175    {
176        $this->rssFeedGenerator->setImage('http://example.org/example.gif', 'foo', -1);
177    }
178
179    /**
180     * assure that an invalid width throws a stubIllegalArgumentException
181     *
182     * @test
183     * @expectedException  stubIllegalArgumentException
184     */
185    public function imageWidthTooGreat()
186    {
187        $this->rssFeedGenerator->setImage('http://example.org/example.gif', 'foo', 145);
188    }
189
190    /**
191     * assure that an invalid height throws a stubIllegalArgumentException
192     *
193     * @test
194     * @expectedException  stubIllegalArgumentException
195     */
196    public function imageHeightTooSmall()
197    {
198         $this->rssFeedGenerator->setImage('http://example.org/example.gif', 'foo', 88, -1);
199    }
200
201    /**
202     * assure that an invalid height throws a stubIllegalArgumentException
203     *
204     * @test
205     * @expectedException  stubIllegalArgumentException
206     */
207    public function imageHeightTooGreat()
208    {
209        $this->rssFeedGenerator->setImage('http://example.org/example.gif', 'foo', 88, 401);
210    }
211}
212?>
Note: See TracBrowser for help on using the browser.