1: <?php
2:
3: /**
4: *
5: * Test case for the DEnum data type
6: *
7: * @package alpha::tests
8: * @since 1.0
9: * @author John Collins <dev@alphaframework.org>
10: * @version $Id: DEnum_Test.php 1496 2012-02-12 20:32:21Z alphadev $
11: * @license http://www.opensource.org/licenses/bsd-license.php The BSD License
12: * @copyright Copyright (c) 2012, 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 DEnum_Test extends PHPUnit_Framework_TestCase {
49: /**
50: * A DEnum for testing
51: *
52: * @var DEnum
53: * @since 1.0
54: */
55: private $denum1;
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: $denum = new DEnum();
66: $denum->rebuildTable();
67: $item = new DEnumItem();
68: $item->rebuildTable();
69:
70: $this->denum1 = new DEnum('ArticleObject::section');
71: $item->set('DEnumID', $this->denum1->getOID());
72: $item->set('value', 'Test');
73: $item->save();
74: }
75:
76: /**
77: * Called after the test functions are executed
78: * this function is defined in PHPUnit_TestCase and overwritten
79: * here
80: *
81: * @since 1.0
82: */
83: protected function tearDown() {
84: $item = new DEnumItem();
85: $item->dropTable();
86: $this->denum1->dropTable();
87: unset($this->denum1);
88: }
89:
90: /**
91: * Test to check that the denum options loaded from the database
92: *
93: * @since 1.0
94: */
95: public function testDEnumLoadedOptionsFromDB() {
96: $this->assertGreaterThan(0, count($this->denum1->getOptions()), 'test to check that the denum options loaded from the database');
97: }
98:
99: /**
100: * Testing the setValue method with a bad options array index value
101: *
102: * @since 1.0
103: */
104: public function testSetValueInvalid() {
105: try {
106: $this->denum1->setValue('blah');
107: $this->fail('testing the setValue method with a bad options array index value');
108: }catch (AlphaException $e) {
109: $this->assertEquals('Not a valid denum option!'
110: , $e->getMessage()
111: , 'testing the setValue method with a bad options array index value');
112: }
113: }
114:
115: /**
116: * Testing the setValue method with a good options index array value
117: *
118: * @since 1.0
119: */
120: public function testSetValueValid() {
121: try {
122: $options = $this->denum1->getOptions();
123: $optionIDs = array_keys($options);
124: $this->denum1->setValue($optionIDs[0]);
125: }catch (AlphaFrameworkException $e) {
126: $this->fail('testing the setValue method with a good options index array value, exception: '.$e->getMessage());
127: }
128: }
129:
130: /**
131: * Testing the getDisplayValue method
132: *
133: * @since 1.0
134: */
135: public function testGetDisplayValue() {
136: try {
137: $options = $this->denum1->getOptions();
138: $optionIDs = array_keys($options);
139: $this->denum1->setValue($optionIDs[0]);
140:
141: $this->assertEquals($options[$optionIDs[0]], $this->denum1->getDisplayValue(), 'testing the getDisplayValue method');
142: }catch (AlphaFrameworkException $e) {
143: $this->fail('testing the getDisplayValue method, exception: '.$e->getMessage());
144: }
145: }
146:
147: /**
148: * Testing the getOptionID method
149: *
150: * @since 1.0
151: */
152: public function testGetOptionID() {
153: try {
154: $options = $this->denum1->getOptions();
155: $optionIDs = array_keys($options);
156:
157: $this->assertEquals($optionIDs[0], $this->denum1->getOptionID($options[$optionIDs[0]]), 'testing the getOptionID method');
158: }catch (AlphaFrameworkException $e) {
159: $this->fail('testing the getOptionID method, exception: '.$e->getMessage());
160: }
161: }
162:
163: /**
164: * Testing the getItemCount method
165: *
166: * @since 1.0
167: */
168: public function testGetItemCount() {
169: $options = $this->denum1->getOptions();
170:
171: $this->assertEquals(count($options), $this->denum1->getItemCount(), 'testing the getItemCount method');
172: }
173: }
174:
175: ?>