Source for file Enum_Test.php
Documentation is available at Enum_Test.php
* Test case for the Enum data type
* @author John Collins <dev@alphaframework.org>
* @version $Id: Enum_Test.php 1453 2011-12-04 15:12:54Z johnc $
* @license http://www.opensource.org/licenses/bsd-license.php The BSD License
* @copyright Copyright (c) 2011, John Collins (founder of Alpha Framework).
* Redistribution and use in source and binary forms, with or
* without modification, are permitted provided that the
* following conditions are met:
* * Redistributions of source code must retain the above
* copyright notice, this list of conditions and the
* * Redistributions in binary form must reproduce the above
* copyright notice, this list of conditions and the
* following disclaimer in the documentation and/or other
* materials provided with the distribution.
* * Neither the name of the Alpha Framework nor the names
* of its contributors may be used to endorse or promote
* products derived from this software without specific
* prior written permission.
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND
* CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
* INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
* OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
class Enum_Test extends PHPUnit_Framework_TestCase {
* Called before the test functions will be executed
* this function is defined in PHPUnit_TestCase and overwritten
protected function setUp() {
$this->enum1 = new Enum();
$this->person->set('displayName', $_SESSION['currentUser']->getDisplayName());
$this->person->set('email', $_SESSION['currentUser']->get('email'));
$this->person->set('password', 'password');
$this->person->rebuildTable();
* Called after the test functions are executed
* this function is defined in PHPUnit_TestCase and overwritten
$this->person->dropTable();
$rights->dropTable('Person2Rights');
* Testing that enum options are loaded correctly from the database
$this->person->loadByAttribute('displayName', $_SESSION['currentUser']->getDisplayName(), true);
$this->assertEquals('Active', $this->person->getPropObject('state')->getValue(), "testing that enum options are loaded correctly from the database");
* Testing the set/get enum option methods
$this->enum1->setOptions(array('a','b','c'));
$this->assertEquals($this->enum1->getOptions(), array('a','b','c'), "testing the set/get enum option methods");
* Testing the setValue method with good and bad values
$this->enum1->setOptions(array('a','b','c'));
$this->enum1->setValue('b');
}catch (AlphaFrameworkException $e) {
$this->fail('testing the setValue method with a good value');
$this->enum1->setValue('z');
$this->fail('testing the setValue method with a good value');
$this->assertEquals('Not a valid enum option!'
, 'testing the setValue method with a bad value');
* Testing the getValue method
$this->enum1->setOptions(array('a','b','c'));
$this->enum1->setValue('b');
}catch (AlphaFrameworkException $e) {
$this->fail('testing the getValue method');
$this->assertEquals('b', $this->enum1->getValue(), 'testing the getValue method');
* Test the constructor failing when a bad array is provided
$enum = new Enum('blah');
$this->fail('test the constructor failing when a bad array is provided');
$this->assertEquals('Not a valid enum option array!'
, 'test the constructor failing when a bad array is provided');
* Testing the default (non-alphabetical) sort order on the enum
$this->enum1 = new Enum(array("alpha","gamma","beta"));
$options = $this->enum1->getOptions();
$this->assertEquals($options[1], 'gamma', 'testing the default (non-alphabetical) sort order on the enum');
* Testing the alphabetical sort order on the enum
$this->enum1 = new Enum(array("alpha","gamma","beta"));
$options = $this->enum1->getOptions(true);
$this->assertEquals($options[1], 'beta', 'testing the alphabetical sort order on the enum');
|