Changeset 1597

Show
Ignore:
Timestamp:
05/26/08 00:55:32 (3 months ago)
Author:
mikey
Message:

improved coverage of generator classes

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/src/main/php/net/stubbles/xml/rss/stubRSSFeedGenerator.php

    r1596 r1597  
    77 * @subpackage  xml_rss 
    88 */ 
    9 stubClassLoader::load('net::stubbles::xml::rss::stubRSSFeedItem', 
     9stubClassLoader::load('net::stubbles::lang::exceptions::stubIllegalArgumentException', 
     10                      'net::stubbles::xml::rss::stubRSSFeedItem', 
    1011                      'net::stubbles::xml::stubXMLStreamWriter' 
    1112); 
     
    195196 
    196197    /** 
     198     * returns the generator of the feed 
     199     * 
     200     * @return  string 
     201     */ 
     202    public function getGenerator() 
     203    { 
     204        return $this->generator; 
     205    } 
     206 
     207    /** 
    197208     * append a stylesheet to the document 
    198209     * 
     
    203214        $this->stylesheets[] = $stylesheet; 
    204215    } 
    205      
     216 
    206217    /** 
    207218     * set the language the channel is written in 
     
    233244        $this->copyright = $copyright; 
    234245    } 
    235      
     246 
     247    /** 
     248     * returns the copyright notice 
     249     * 
     250     * @return  string 
     251     */ 
     252    public function getCopyright() 
     253    { 
     254        return $this->copyright; 
     255    } 
     256 
    236257    /** 
    237258     * set email address for person responsible for editorial content 
     
    247268        } 
    248269    } 
    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 
    250281    /** 
    251282     * set email address for person responsible for technical issues relating to channel 
     
    261292        } 
    262293    } 
    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 
    264305    /** 
    265306     * set the last time when the content of the channel changed 
    266307     * 
    267308     * @param   string|int   $lastBuildDate  last time the content of the channel changed 
    268      * @throws  stubXMLException 
     309     * @throws  stubIllegalArgumentException 
    269310     */ 
    270311    public function setLastBuildDate($lastBuildDate) 
    271312    { 
    272         if (is_int($lastBuildDate) == false) { 
     313        if (is_int($lastBuildDate) === false) { 
    273314            $lastBuildDate = strtotime($lastBuildDate); 
    274315            if (false === $lastBuildDate) { 
    275                 throw new stubXMLException('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.'); 
    276317            } 
    277318        } 
     
    279320        $this->lastBuildDate = date('D d M Y H:i:s O', $lastBuildDate); 
    280321    } 
    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 
    282333    /** 
    283334     * set number of minutes that indicates how long a channel can be cached 
     
    290341        $this->ttl = $ttl; 
    291342    } 
    292      
     343 
    293344    /** 
    294345     * specify a GIF, JPEG or PNG image to be displayed with the channel 
     
    298349     * @param   int     $width        indicating the width of the image in pixels, must be 0 < $width <= 144, default 88 
    299350     * @param   int     $height       indicating the height of the image in pixels, must be 0 < $height <= 400, default 31 
    300      * @throws  stubXMLException  in case $width or $height have invalid values 
     351     * @throws  stubIllegalArgumentException  in case $width or $height have invalid values 
    301352     */ 
    302353    public function setImage($url, $description, $width = 88, $height = 31) 
    303354    { 
    304355        if (144 < $width || 0 > $width) { 
    305             throw new stubXMLException('Width must be a value between 0 and 144.'); 
     356            throw new stubIllegalArgumentException('Width must be a value between 0 and 144.'); 
    306357        } 
    307358         
    308359        if (400 < $height || 0 > $height) { 
    309             throw new stubXMLException('Height must be a value between 0 and 400.'); 
     360            throw new stubIllegalArgumentException('Height must be a value between 0 and 400.'); 
    310361        } 
    311362         
  • trunk/src/main/php/net/stubbles/xml/rss/stubRSSFeedItem.php

    r1590 r1597  
    77 * @subpackage  xml_rss 
    88 */ 
    9 stubClassLoader::load('net::stubbles::xml::stubXMLStreamWriter'); 
     9stubClassLoader::load('net::stubbles::lang::exceptions::stubIllegalArgumentException', 
     10                      'net::stubbles::xml::stubXMLStreamWriter' 
     11); 
    1012/** 
    1113 * Class for a rss 2.0 feed item. 
     
    198200     * @param   string|int       $pubDate  publishing date of rss feed item 
    199201     * @return  stubRSSFeedItem 
    200      * @throws  stubXMLException 
     202     * @throws  stubIllegalArgumentException 
    201203     */ 
    202204    public function publishedOn($pubDate) 
    203205    { 
    204         if (is_int($pubDate) == false) { 
     206        if (is_int($pubDate) === false) { 
    205207            $pubDate = strtotime($pubDate); 
    206208            if (false === $pubDate) { 
    207                 throw new stubXMLException('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.'); 
    208210            } 
    209211        } 
  • trunk/src/test/php/net/stubbles/xml/rss/stubRSSFeedGeneratorTestCase.php

    r1592 r1597  
    3232 
    3333    /** 
     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    /** 
    3446     * test that the values are handles as expexted 
    3547     * 
     
    4759        $this->assertSame($mockXmlStreamWriter, $this->rssFeedGenerator->serialize($mockXmlStreamWriter)); 
    4860    } 
    49      
     61 
    5062    /** 
    5163     * test that the values are handles as expexted 
     
    6375        $this->assertSame($mockXmlStreamWriter, $this->rssFeedGenerator->serialize($mockXmlStreamWriter)); 
    6476    } 
    65      
     77 
    6678    /** 
    6779     * test that the values are handles as expexted 
     
    8193        $this->assertSame($mockXmlStreamWriter, $this->rssFeedGenerator->serialize($mockXmlStreamWriter)); 
    8294    } 
    83      
     95 
    8496    /** 
    8597     * test that optional channel elements are handled as expected 
     
    89101    public function withAllChannelElements() 
    90102    { 
     103        $this->assertEquals('Stubbles RSSFeedGenerator', $this->rssFeedGenerator->getGenerator()); 
    91104        $this->rssFeedGenerator->setLanguage('en_EN'); 
     105        $this->assertEquals('en_EN', $this->rssFeedGenerator->getLanguage()); 
    92106        $this->rssFeedGenerator->setCopyright('© 2007 Stubbles Development Team'); 
     107        $this->assertEquals('© 2007 Stubbles Development Team', $this->rssFeedGenerator->getCopyright()); 
    93108        $this->rssFeedGenerator->setManagingEditor('mikey'); 
     109        $this->assertEquals('nospam@example.com (mikey)', $this->rssFeedGenerator->getManagingEditor()); 
    94110        $this->rssFeedGenerator->setWebMaster('schst'); 
     111        $this->assertEquals('nospam@example.com (schst)', $this->rssFeedGenerator->getWebMaster()); 
    95112        $this->rssFeedGenerator->setLastBuildDate(50); 
     113        $this->assertEquals('Thu 01 Jan 1970 01:00:50 +0100', $this->rssFeedGenerator->getLastBuildDate()); 
    96114        $this->rssFeedGenerator->setTimeToLive(60); 
    97115        $this->rssFeedGenerator->setImage('http://example.org/example.gif', 'foo'); 
     
    104122        $this->assertSame($mockXmlStreamWriter, $this->rssFeedGenerator->serialize($mockXmlStreamWriter)); 
    105123    } 
    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 
    112160     */ 
    113161    public function invalidLastBuildDate() 
     
    115163        $this->rssFeedGenerator->setLastBuildDate('foo'); 
    116164    } 
    117      
    118     /** 
    119      * assure that an invalid width throws a stubXMLException 
    120      * 
    121      * @test 
    122      * @expectedException  stubXMLException 
     165 
     166    /** 
     167     * assure that an invalid width throws a stubIllegalArgumentException 
     168     * 
     169     * @test 
     170     * @expectedException  stubIllegalArgumentException 
    123171     */ 
    124172    public function imageWidthTooSmall() 
     
    126174        $this->rssFeedGenerator->setImage('http://example.org/example.gif', 'foo', -1); 
    127175    } 
    128      
    129     /** 
    130      * assure that an invalid width throws a stubXMLException 
    131      * 
    132      * @test 
    133      * @expectedException  stubXMLException 
     176 
     177    /** 
     178     * assure that an invalid width throws a stubIllegalArgumentException 
     179     * 
     180     * @test 
     181     * @expectedException  stubIllegalArgumentException 
    134182     */ 
    135183    public function imageWidthTooGreat() 
     
    137185        $this->rssFeedGenerator->setImage('http://example.org/example.gif', 'foo', 145); 
    138186    } 
    139      
    140     /** 
    141      * assure that an invalid height throws a stubXMLException 
    142      * 
    143      * @test 
    144      * @expectedException  stubXMLException 
     187 
     188    /** 
     189     * assure that an invalid height throws a stubIllegalArgumentException 
     190     * 
     191     * @test 
     192     * @expectedException  stubIllegalArgumentException 
    145193     */ 
    146194    public function imageHeightTooSmall() 
    147195    { 
    148          $this->rssFeedGenerator->setImage('http://example.org/example.gif', 'foo', -1); 
    149     } 
    150      
    151     /** 
    152      * assure that an invalid height throws a stubXMLException 
    153      * 
    154      * @test 
    155      * @expectedException  stubXMLException 
     196         $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 
    156204     */ 
    157205    public function imageHeightTooGreat() 
    158206    { 
    159         $this->rssFeedGenerator->setImage('http://example.org/example.gif', 'foo', 401); 
     207        $this->rssFeedGenerator->setImage('http://example.org/example.gif', 'foo', 88, 401); 
    160208    } 
    161209} 
  • trunk/src/test/php/net/stubbles/xml/rss/stubRSSFeedItemTestCase.php

    r1592 r1597  
    139139        $this->rssFeedItem2->serialize($mockXmlStreamWriter); 
    140140    } 
     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    } 
    141163} 
    142164?>