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

Source for file AlphaView_Test.php

Documentation is available at AlphaView_Test.php

  1. <?php
  2.  
  3. require_once $config->get('sysRoot').'alpha/view/AlphaView.inc';
  4. require_once $config->get('sysRoot').'alpha/view/ArticleView.inc';
  5. require_once $config->get('sysRoot').'alpha/model/ArticleObject.inc';
  6.  
  7. /**
  8.  *
  9.  * Test cases for the AlphaView class.
  10.  * 
  11.  * @package alpha::tests
  12.  * @since 1.0
  13.  * @author John Collins <dev@alphaframework.org>
  14.  * @version $Id: AlphaView_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 AlphaView_Test extends PHPUnit_Framework_TestCase {
  53.     /**
  54.      * View class for testing
  55.      * 
  56.      * @var AlphaView 
  57.      * @since 1.0
  58.      */
  59.     private $view;
  60.         
  61.     /**
  62.      * (non-PHPdoc)
  63.      * @see alpha/lib/PEAR/PHPUnit-3.2.9/PHPUnit/Framework/PHPUnit_Framework_TestCase::setUp()
  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->view AlphaView::getInstance(new ArticleObject());
  75.     }
  76.     
  77.     /**
  78.      * (non-PHPdoc)
  79.      * @see alpha/lib/PEAR/PHPUnit-3.2.9/PHPUnit/Framework/PHPUnit_Framework_TestCase::tearDown()
  80.      * 
  81.      * @since 1.0
  82.      */
  83.     protected function tearDown({
  84.         unset($this->view);
  85.         
  86.         $denum new DEnum();
  87.         $denum->dropTable();
  88.         
  89.         $item new DEnumItem();
  90.         $item->dropTable();
  91.     }
  92.     
  93.     /**
  94.      * Testing that passing a bad object to the getInstance method will throw an IllegalArguementException
  95.      * 
  96.      * @since 1.0
  97.      */
  98.     public function testGetInstanceBad({
  99.         try {
  100.             $bad AlphaView::getInstance(new AlphaView_Test());
  101.             $this->fail('testing that passing a bad object to the getInstance method will throw an IllegalArguementException');
  102.         }catch (IllegalArguementException $e{
  103.             $this->assertEquals('The BO provided [AlphaView_Test] is not defined anywhere!'$e->getMessage()'testing that passing a bad object to the getInstance method will throw an IllegalArguementException');
  104.         }
  105.     }
  106.     
  107.     /**
  108.      * Testing that passing a good object to the getInstance method will return the child view object
  109.      * 
  110.      * @since 1.0
  111.      */
  112.     public function testGetInstanceGood({
  113.         try{
  114.             $good AlphaView::getInstance(new ArticleObject());
  115.             $this->assertTrue($good instanceof ArticleView'testing that passing a good object to the getInstance method will return the child view object');
  116.         }catch (IllegalArguementException $e{
  117.             $this->fail($e->getMessage());
  118.         }
  119.     }
  120.     
  121.     /**
  122.      * Testing that we can force the return of an AlphaView object even when a child definition for the provided BO exists
  123.      * 
  124.      * @since 1.0
  125.      */
  126.     public function testGetInstanceForceParent({
  127.         try{
  128.             $good AlphaView::getInstance(new ArticleObject()true);
  129.             $this->assertTrue($good instanceof AlphaView'testing that we can force the return of an AlphaView object even when a child definition for the provided BO exists');
  130.         }catch (IllegalArguementException $e{
  131.             $this->fail($e->getMessage());
  132.         }
  133.     }
  134.     
  135.     /**
  136.      * Testing that we can attach a good BO to an existing view object
  137.      * 
  138.      * @since 1.0
  139.      */
  140.     public function testSetBOGood({
  141.         try{
  142.             $this->view->setBO(new ArticleObject());
  143.             $this->assertTrue(true);
  144.         }catch (IllegalArguementException $e{
  145.             $this->fail($e->getMessage());
  146.         }
  147.     }
  148.     
  149.     /**
  150.      * Testing that attempting to attach a bad BO object to an existing view object will cause an exception
  151.      * 
  152.      * @since 1.0
  153.      */
  154.     public function testSetBOBad({
  155.         try{
  156.             $this->view->setBO(new AlphaView_Test());
  157.             $this->fail('testing that attempting to attach a bad BO object to an existing view object will cause an exception');
  158.         }catch (IllegalArguementException $e{
  159.             $this->assertTrue(true);
  160.         }
  161.     }
  162.     
  163.     /**
  164.      * Testing that a bad mode param provided to the loadTemplate method will throw an exception
  165.      * 
  166.      * @since 1.0
  167.      */
  168.     public function testLoadTemplateBad({
  169.         try {
  170.             $this->view->loadTemplate($this->view->getBO()'BadMode'array());
  171.             $this->fail('testing that a bad mode param provided to the loadTemplate method will throw an exception');
  172.         }catch (IllegalArguementException $e{
  173.             $this->assertEquals('No [BadMode] HTML template found for class [ArticleObject]'$e->getMessage()'testing that a bad mode param provided to the loadTemplate method will throw an exception');
  174.         }
  175.     }
  176.     
  177.     /**
  178.      * Testing accessing the attached BO via getBO()
  179.      * 
  180.      * @since 1.0
  181.      */
  182.     public function testGetBO({
  183.         $article new ArticleObject();
  184.         $article->set('title''Test Article');
  185.         $this->view->setBO($article);
  186.         
  187.         $this->assertEquals('Test Article'$this->view->getBO()->get('title')'testing accessing the attached BO via getBO()');
  188.     }
  189. }
  190.  
  191. ?>

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