Source for file DEnum_Test.php
Documentation is available at DEnum_Test.php
* Test case for the DEnum data type
* @author John Collins <dev@alphaframework.org>
* @version $Id: DEnum_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 DEnum_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->denum1 = new DEnum('ArticleObject::section');
$item->set('DEnumID', $this->denum1->getOID());
$item->set('value', 'Test');
* Called after the test functions are executed
* this function is defined in PHPUnit_TestCase and overwritten
$this->denum1->dropTable();
* Test to check that the denum options loaded from the database
$this->assertGreaterThan(0, count($this->denum1->getOptions()), 'test to check that the denum options loaded from the database');
* Testing the setValue method with a bad options array index value
$this->denum1->setValue('blah');
$this->fail('testing the setValue method with a bad options array index value');
$this->assertEquals('Not a valid denum option!'
, 'testing the setValue method with a bad options array index value');
* Testing the setValue method with a good options index array value
$options = $this->denum1->getOptions();
$this->denum1->setValue($optionIDs[0]);
}catch (AlphaFrameworkException $e) {
$this->fail('testing the setValue method with a good options index array value, exception: '. $e->getMessage());
* Testing the getDisplayValue method
$options = $this->denum1->getOptions();
$this->denum1->setValue($optionIDs[0]);
$this->assertEquals($options[$optionIDs[0]], $this->denum1->getDisplayValue(), 'testing the getDisplayValue method');
}catch (AlphaFrameworkException $e) {
$this->fail('testing the getDisplayValue method, exception: '. $e->getMessage());
* Testing the getOptionID method
$options = $this->denum1->getOptions();
$this->assertEquals($optionIDs[0], $this->denum1->getOptionID($options[$optionIDs[0]]), 'testing the getOptionID method');
}catch (AlphaFrameworkException $e) {
$this->fail('testing the getOptionID method, exception: '. $e->getMessage());
* Testing the getItemCount method
$options = $this->denum1->getOptions();
$this->assertEquals(count($options), $this->denum1->getItemCount(), 'testing the getItemCount method');
|