Alpha Framework alpha--tests
[ class tree: alpha--tests ] [ index: alpha--tests ] [ all elements ]

Source for file AlphaFeed_Test.php

Documentation is available at AlphaFeed_Test.php

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

Documentation generated on Tue, 13 Dec 2011 20:26:04 +0000 by phpDocumentor 1.4.3