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

Source for file Relation_Test.php

Documentation is available at Relation_Test.php

  1. <?php
  2.  
  3. /**
  4.  *
  5.  * Test case for the Relation data type
  6.  * 
  7.  * @package alpha::tests
  8.  * @since 1.0
  9.  * @author John Collins <dev@alphaframework.org>
  10.  * @version $Id: Relation_Test.php 1341 2011-03-17 15:02:02Z johnc $
  11.  * @license http://www.opensource.org/licenses/bsd-license.php The BSD License
  12.  * @copyright Copyright (c) 2011, John Collins (founder of Alpha Framework).
  13.  *  All rights reserved.
  14.  * 
  15.  *  <pre>
  16.  *  Redistribution and use in source and binary forms, with or
  17.  *  without modification, are permitted provided that the
  18.  *  following conditions are met:
  19.  * 
  20.  *  * Redistributions of source code must retain the above
  21.  *    copyright notice, this list of conditions and the
  22.  *    following disclaimer.
  23.  *  * Redistributions in binary form must reproduce the above
  24.  *    copyright notice, this list of conditions and the
  25.  *    following disclaimer in the documentation and/or other
  26.  *    materials provided with the distribution.
  27.  *  * Neither the name of the Alpha Framework nor the names
  28.  *    of its contributors may be used to endorse or promote
  29.  *    products derived from this software without specific
  30.  *    prior written permission.
  31.  *   
  32.  *  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND
  33.  *  CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
  34.  *  INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
  35.  *  MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
  36.  *  DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
  37.  *  CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
  38.  *  SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
  39.  *  NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
  40.  *  LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
  41.  *  HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
  42.  *  CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
  43.  *  OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
  44.  *  SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  45.  *  </pre>
  46.  *  
  47.  */
  48. class Relation_Test extends PHPUnit_Framework_TestCase {
  49.     /**
  50.      * A Relation for testing
  51.      * 
  52.      * @var Relation 
  53.      * @since 1.0
  54.      */
  55.     private $rel1;    
  56.     
  57.     /**
  58.      * Called before the test functions will be executed
  59.      * this function is defined in PHPUnit_TestCase and overwritten
  60.      * here
  61.      * 
  62.      * @since 1.0
  63.      */
  64.     protected function setUp({        
  65.         $this->rel1 new Relation();
  66.         
  67.         $person new PersonObject();
  68.         $person->set('displayName'$_SESSION['currentUser']->getDisplayName());
  69.         $person->set('email'$_SESSION['currentUser']->get('email'));
  70.         $person->set('password''password');
  71.         $person->rebuildTable();
  72.         $person->save();
  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->rel1);
  84.         $person new PersonObject();
  85.         $person->dropTable();
  86.         
  87.         $rights new RightsObject();
  88.         $rights->dropTable();
  89.         $rights->dropTable('Person2Rights');
  90.     }
  91.     
  92.     /**
  93.      * Testing passing a valid BO name to setRelatedClass
  94.      * 
  95.      * @since 1.0
  96.      */
  97.     public function testSetRelatedClassPass({
  98.         try {
  99.             $this->rel1->setRelatedClass('ArticleObject');
  100.         }catch (AlphaException $e{
  101.             $this->fail('Testing passing a valid BO name to setRelatedClass');
  102.         }
  103.     }
  104.     
  105.     /**
  106.      * Testing passing an invalid BO name to setRelatedClass
  107.      * 
  108.      * @since 1.0
  109.      */
  110.     public function testSetRelatedClassFail({
  111.         try {
  112.             $this->rel1->setRelatedClass('XyzObject');
  113.             $this->fail('Testing passing an invalid BO name to setRelatedClass');
  114.         }catch (AlphaException $e{
  115.             $this->assertEquals('The class [XyzObject] is not defined anywhere!'
  116.                 $e->getMessage()
  117.                 'Testing passing an invalid BO name to setRelatedClass');
  118.         }
  119.     }
  120.     
  121.     /**
  122.      * Testing passing a valid field name to setRelatedClassField
  123.      * 
  124.      * @since 1.0
  125.      */
  126.     public function testSetRelatedClassFieldPass({
  127.         try {
  128.             $this->rel1->setRelatedClass('PersonObject');
  129.             $this->rel1->setRelatedClassField('email');
  130.         }catch (AlphaException $e{
  131.             $this->fail('Testing passing a valid field name to setRelatedClassField');
  132.         }
  133.     }
  134.     
  135.     /**
  136.      * Testing passing an invalid field name to setRelatedClassField
  137.      * 
  138.      * @since 1.0
  139.      */
  140.     public function testSetRelatedClassFieldFail({
  141.         try {
  142.             $this->rel1->setRelatedClass('PersonObject');
  143.             $this->rel1->setRelatedClassField('doesNotExist');
  144.             $this->fail('Testing passing an invalid field name to setRelatedClassField');
  145.         }catch (AlphaException $e{
  146.             $this->assertEquals('The field [doesNotExist] was not found in the class [PersonObject]'
  147.                 $e->getMessage()
  148.                 'Testing passing an invalid field name to setRelatedClassField');
  149.         }
  150.     }
  151.     
  152.     /**
  153.      * Testing passing a valid type name to setRelationType
  154.      * 
  155.      * @since 1.0
  156.      */
  157.     public function testSetRelationTypePass({
  158.         try {
  159.             $this->rel1->setRelationType('MANY-TO-ONE');
  160.         }catch (AlphaException $e{
  161.             $this->fail('Testing passing a valid type name to setRelationType');
  162.         }
  163.     }
  164.     
  165.     /**
  166.      * Testing passing an invalid type name to setRelationType
  167.      * 
  168.      * @since 1.0
  169.      */
  170.     public function testSetRelationTypeFail({
  171.         try {
  172.             $this->rel1->setRelationType('blah');            
  173.             $this->fail('Testing passing an invalid type name to setRelationType');
  174.         }catch (AlphaException $e{
  175.             $this->assertEquals('Relation type of [blah] is invalid!'
  176.                 $e->getMessage()
  177.                 'Testing passing an invalid type name to setRelationType');
  178.         }
  179.     }
  180.     
  181.     /**
  182.      * Testing setValue method with a valid value
  183.      * 
  184.      * @since 1.0
  185.      */
  186.     public function testSetValuePass({
  187.         try {
  188.             $this->rel1->setValue(100);
  189.             $this->rel1->setValue('2777');
  190.         }catch (AlphaException $e{
  191.             $this->fail('Testing setValue method with a valid value');
  192.         }
  193.     }
  194.     
  195.     /**
  196.      * Testing setValue method with an invalid value
  197.      * 
  198.      * @since 1.0
  199.      */
  200.     public function testSetValueFail({
  201.         try {
  202.             $this->rel1->setValue('xyz');
  203.             $this->fail('Testing setValue method with an invalid value');
  204.         }catch (AlphaException $e{
  205.             $this->assertEquals('[xyz] not a valid Relation value!  A maximum of 11 characters is allowed.'
  206.                 $e->getMessage()
  207.                 'Testing setValue method with an invalid value');
  208.         }
  209.     }
  210.     
  211.     /**
  212.      * Testing that the display field value of the related class is accessed correctly
  213.      * 
  214.      * @since 1.0
  215.      */
  216.     public function testSetRelatedClassDisplayFieldPass({
  217.         try {
  218.             $this->rel1->setRelatedClass('PersonObject');
  219.             // assuming here that user #1 is the default Administrator account
  220.             $this->rel1->setValue(1);
  221.             $this->rel1->setRelatedClassDisplayField('state');
  222.             $this->assertEquals('Active'$this->rel1->getRelatedClassDisplayFieldValue()'Testing that the display field value of the related class is accessed correctly');            
  223.         }catch (AlphaException $e{
  224.             $this->fail('Testing that the display field value of the related class is accessed correctly');
  225.         }
  226.     }
  227.     
  228.     /**
  229.      * Testing that getRelatedClassDisplayFieldValue() will fail to load an invalid class definition
  230.      * 
  231.      * @since 1.0
  232.      */
  233.     public function testGetRelatedClassDisplayFieldValueFail({
  234.         try {            
  235.             $this->rel1->setRelatedClassDisplayField('someField');
  236.             $value $this->rel1->getRelatedClassDisplayFieldValue();
  237.             $this->fail('Testing that getRelatedClassDisplayFieldValue() will fail to load an invalid class definition');
  238.         }catch (AlphaException $e{
  239.             $this->assertEquals('The class [] is not defined anywhere!'
  240.                 $e->getMessage()
  241.                 'Testing that getRelatedClassDisplayFieldValue() will fail to load an invalid class definition');
  242.         }
  243.     }
  244. }
  245.  
  246. ?>

Documentation generated on Thu, 17 Mar 2011 16:44:45 +0000 by phpDocumentor 1.4.3