Overview

Packages

  • alpha::controller
  • alpha::controller::front
  • alpha::exceptions
  • alpha::model
  • alpha::model::types
  • alpha::tasks
  • alpha::tests
  • alpha::util
  • alpha::util::cache
  • alpha::util::codehighlight
  • alpha::util::convertors
  • alpha::util::feeds
  • alpha::util::filters
  • alpha::util::graphs
  • alpha::util::helpers
  • alpha::util::metrics
  • alpha::view
  • alpha::view::renderers
  • alpha::view::widgets

Classes

  • AlphaAgentUtils_Test
  • AlphaConfig_Test
  • AlphaController_Test
  • AlphaDAO_Test
  • AlphaFeed_Test
  • AlphaFilters_Test
  • AlphaValidator_Test
  • AlphaView_Test
  • Boolean_Test
  • Date_Test
  • DEnum_Test
  • Double_Test
  • Enum_Test
  • Exceptions_Test
  • FrontController_Test
  • Image_Test
  • Integer_Test
  • Relation_Test
  • Sequence_Test
  • String_Test
  • Tag_Test
  • Text_Test
  • Timestamp_Test
  • Overview
  • Package
  • Class
  • Tree
  • Deprecated
  1: <?php
  2: 
  3: /**
  4:  * Test cases for the AlphaFeed class and its children
  5:  * 
  6:  * @package alpha::tests
  7:  * @since 1.0
  8:  * @author John Collins <dev@alphaframework.org>
  9:  * @version $Id: AlphaFeed_Test.php 1496 2012-02-12 20:32:21Z alphadev $
 10:  * @license http://www.opensource.org/licenses/bsd-license.php The BSD License
 11:  * @copyright Copyright (c) 2012, John Collins (founder of Alpha Framework).  
 12:  * All rights reserved.
 13:  * 
 14:  * <pre>
 15:  * Redistribution and use in source and binary forms, with or 
 16:  * without modification, are permitted provided that the 
 17:  * following conditions are met:
 18:  * 
 19:  * * Redistributions of source code must retain the above 
 20:  *   copyright notice, this list of conditions and the 
 21:  *   following disclaimer.
 22:  * * Redistributions in binary form must reproduce the above 
 23:  *   copyright notice, this list of conditions and the 
 24:  *   following disclaimer in the documentation and/or other 
 25:  *   materials provided with the distribution.
 26:  * * Neither the name of the Alpha Framework nor the names 
 27:  *   of its contributors may be used to endorse or promote 
 28:  *   products derived from this software without specific 
 29:  *   prior written permission.
 30:  *   
 31:  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND 
 32:  * CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, 
 33:  * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF 
 34:  * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 
 35:  * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR 
 36:  * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 
 37:  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 
 38:  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 
 39:  * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 
 40:  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 
 41:  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE 
 42:  * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 
 43:  * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 44:  * </pre>
 45:  *  
 46:  */
 47: class AlphaFeed_Test extends PHPUnit_Framework_TestCase {
 48:     /**
 49:      * Test object to inject into a feed
 50:      * 
 51:      * @var ArticleObject
 52:      */
 53:     private $BO;
 54:     
 55:     /**
 56:      * Called before the test functions will be executed
 57:      * this function is defined in PHPUnit_TestCase and overwritten
 58:      * here
 59:      * 
 60:      * @since 1.0
 61:      */
 62:     protected function setUp() {
 63:         $denum = new DEnum();
 64:         $denum->rebuildTable();
 65:         
 66:         $item = new DEnumItem();
 67:         $item->rebuildTable();
 68:         
 69:         $this->BO = new ArticleObject();
 70:         $this->BO->set('title', 'Test Article Title');
 71:         $this->BO->set('description', 'Test Article Description');
 72:         $this->BO->set('created_ts', '2011-01-01 00:00:00');
 73:     }
 74:     
 75:     /** 
 76:      * Called after the test functions are executed
 77:      * this function is defined in PHPUnit_TestCase and overwritten
 78:      * here
 79:      * 
 80:      * @since 1.0
 81:      */    
 82:     protected function tearDown() {
 83:         unset($this->BO);
 84:         
 85:         $denum = new DEnum();
 86:         $denum->dropTable();
 87:         
 88:         $item = new DEnumItem();
 89:         $item->dropTable();
 90:     }
 91:     
 92:     public function testAddItemToRSSandParse() {
 93:         $feed = new RSS('ArticleObject', 'Test Feed Title', 'http://www.alphaframework.org/', 'Test Feed Description');
 94:         $feed->setFieldMappings('title', 'URL', 'description', 'created_ts', 'OID');
 95:         $feed->addBO($this->BO);
 96:         $xml = $feed->render();
 97:         
 98:         $reader = new XMLReader();
 99:         $validXML = $reader->XML($xml);
100:         
101:         $this->assertTrue($validXML, 'Confirming that the generated XML can be parsed correctly');
102:         
103:         $simpleXML = new SimpleXMLElement($xml);
104:         $simpleXML->registerXPathNamespace('rss', 'http://purl.org/rss/1.0/');
105: 
106:         $channels = $simpleXML->xpath('//rss:channel');
107:         $this->assertEquals('Test Feed Title', (string)$channels[0]->title, 'Testing that the feed title is present');
108:         $this->assertEquals('http://www.alphaframework.org/', (string)$channels[0]->link, 'Testing that the feed URL is present');
109:         
110:         $items = $simpleXML->xpath('//rss:item');
111:         $this->assertEquals('Test Article Title', (string)$items[0]->title, 'Testing that the feed item title is present');
112:         $this->assertEquals('Test Article Description', (string)$items[0]->description, 'Testing that the feed item description is present');
113:         $this->assertEquals('2011-01-01T00:00:00+00:00', (string)$items[0]->updated, 'Testing that the feed item publish time is present');
114:     }
115:     
116:     public function testAddItemToRSS2andParse() {
117:         $feed = new RSS2('ArticleObject', 'Test Feed Title', 'http://www.alphaframework.org/', 'Test Feed Description');
118:         $feed->setFieldMappings('title', 'URL', 'description', 'created_ts', 'OID');
119:         $feed->addBO($this->BO);
120:         $xml = $feed->render();
121:         
122:         $reader = new XMLReader();
123:         $validXML = $reader->XML($xml);
124:         
125:         $this->assertTrue($validXML, 'Confirming that the generated XML can be parsed correctly');
126:         
127:         $simpleXML = new SimpleXMLElement($xml);
128:         
129:         $channels = $simpleXML->xpath('channel');
130:         $this->assertEquals('Test Feed Title', (string)$channels[0]->title, 'Testing that the feed title is present');
131:         $this->assertEquals('http://www.alphaframework.org/', (string)$channels[0]->link, 'Testing that the feed URL is present');
132:         
133:         $items = $simpleXML->xpath('channel/item');
134:         $this->assertEquals('Test Article Title', (string)$items[0]->title, 'Testing that the feed item title is present');
135:         $this->assertEquals('Test Article Description', (string)$items[0]->description, 'Testing that the feed item description is present');
136:         $this->assertEquals('2011-01-01T00:00:00+00:00', (string)$items[0]->updated, 'Testing that the feed item publish time is present');
137:     }
138:     
139:     public function testAddItemToAtomandParse() {
140:         $feed = new Atom('ArticleObject', 'Test Feed Title', 'http://www.alphaframework.org/', 'Test Feed Description');
141:         $feed->setFieldMappings('title', 'URL', 'description', 'created_ts', 'OID');
142:         $feed->addBO($this->BO);
143:         $xml = $feed->render();
144:         
145:         $reader = new XMLReader();
146:         $validXML = $reader->XML($xml);
147:         
148:         $this->assertTrue($validXML, 'Confirming that the generated XML can be parsed correctly');
149:         
150:         $simpleXML = new SimpleXMLElement($xml);
151:         $simpleXML->registerXPathNamespace('atom', 'http://www.w3.org/2005/Atom');
152:         
153:         $feeds = $simpleXML->xpath('//atom:feed');
154:         $this->assertEquals('Test Feed Title', (string)$feeds[0]->title, 'Testing that the feed title is present');
155:         $this->assertEquals('http://www.alphaframework.org/', (string)$feeds[0]->link->attributes()->href, 'Testing that the feed URL is present');
156:         
157:         $items = $simpleXML->xpath('//atom:entry');
158:         $this->assertEquals('Test Article Title', (string)$items[0]->title, 'Testing that the feed item title is present');
159:         $this->assertEquals('Test Article Description', (string)$items[0]->summary, 'Testing that the feed item description is present');
160:         $this->assertEquals('2011-01-01T00:00:00+00:00', (string)$items[0]->updated, 'Testing that the feed item publish time is present');
161:     }
162: }
163: 
164: ?>
Alpha Framework API Documentation API documentation generated by ApiGen 2.8.0