1: <?php
2:
3: 4: 5: 6: 7: 8: 9: 10: 11: 12: 13: 14: 15: 16: 17: 18: 19: 20: 21: 22: 23: 24: 25: 26: 27: 28: 29: 30: 31: 32: 33: 34: 35: 36: 37: 38: 39: 40: 41: 42: 43: 44: 45: 46: 47:
48: class Relation_Test extends PHPUnit_Framework_TestCase {
49: 50: 51: 52: 53: 54:
55: private $rel1;
56:
57: 58: 59: 60: 61: 62: 63:
64: protected function setUp() {
65: $this->rel1 = new Relation();
66:
67: $rights = new RightsObject();
68: $rights->rebuildTable();
69:
70: $person = new PersonObject();
71: $person->set('displayName', $_SESSION['currentUser']->getDisplayName());
72: $person->set('email', $_SESSION['currentUser']->get('email'));
73: $person->set('password', 'password');
74: $person->rebuildTable();
75: $person->save();
76: }
77:
78: 79: 80: 81: 82: 83: 84:
85: protected function tearDown() {
86: unset($this->rel1);
87: $person = new PersonObject();
88: $person->dropTable();
89:
90: $rights = new RightsObject();
91: $rights->dropTable();
92: $rights->dropTable('Person2Rights');
93: }
94:
95: 96: 97: 98: 99:
100: public function testSetRelatedClassPass() {
101: try {
102: $this->rel1->setRelatedClass('ArticleObject');
103: }catch (AlphaException $e) {
104: $this->fail('Testing passing a valid BO name to setRelatedClass');
105: }
106: }
107:
108: 109: 110: 111: 112:
113: public function testSetRelatedClassFail() {
114: try {
115: $this->rel1->setRelatedClass('XyzObject');
116: $this->fail('Testing passing an invalid BO name to setRelatedClass');
117: }catch (AlphaException $e) {
118: $this->assertEquals('The class [XyzObject] is not defined anywhere!'
119: , $e->getMessage()
120: , 'Testing passing an invalid BO name to setRelatedClass');
121: }
122: }
123:
124: 125: 126: 127: 128:
129: public function testSetRelatedClassFieldPass() {
130: try {
131: $this->rel1->setRelatedClass('PersonObject');
132: $this->rel1->setRelatedClassField('email');
133: }catch (AlphaException $e) {
134: $this->fail('Testing passing a valid field name to setRelatedClassField');
135: }
136: }
137:
138: 139: 140: 141: 142:
143: public function testSetRelatedClassFieldFail() {
144: try {
145: $this->rel1->setRelatedClass('PersonObject');
146: $this->rel1->setRelatedClassField('doesNotExist');
147: $this->fail('Testing passing an invalid field name to setRelatedClassField');
148: }catch (AlphaException $e) {
149: $this->assertEquals('The field [doesNotExist] was not found in the class [PersonObject]'
150: , $e->getMessage()
151: , 'Testing passing an invalid field name to setRelatedClassField');
152: }
153: }
154:
155: 156: 157: 158: 159:
160: public function testSetRelationTypePass() {
161: try {
162: $this->rel1->setRelationType('MANY-TO-ONE');
163: }catch (AlphaException $e) {
164: $this->fail('Testing passing a valid type name to setRelationType');
165: }
166: }
167:
168: 169: 170: 171: 172:
173: public function testSetRelationTypeFail() {
174: try {
175: $this->rel1->setRelationType('blah');
176: $this->fail('Testing passing an invalid type name to setRelationType');
177: }catch (AlphaException $e) {
178: $this->assertEquals('Relation type of [blah] is invalid!'
179: , $e->getMessage()
180: , 'Testing passing an invalid type name to setRelationType');
181: }
182: }
183:
184: 185: 186: 187: 188:
189: public function testSetValuePass() {
190: try {
191: $this->rel1->setValue(100);
192: $this->rel1->setValue('2777');
193: }catch (AlphaException $e) {
194: $this->fail('Testing setValue method with a valid value');
195: }
196: }
197:
198: 199: 200: 201: 202:
203: public function testSetValueFail() {
204: try {
205: $this->rel1->setValue('xyz');
206: $this->fail('Testing setValue method with an invalid value');
207: }catch (AlphaException $e) {
208: $this->assertEquals('[xyz] not a valid Relation value! A maximum of 11 characters is allowed.'
209: , $e->getMessage()
210: , 'Testing setValue method with an invalid value');
211: }
212: }
213:
214: 215: 216: 217: 218:
219: public function testSetRelatedClassDisplayFieldPass() {
220: try {
221: $this->rel1->setRelatedClass('PersonObject');
222:
223: $this->rel1->setValue(1);
224: $this->rel1->setRelatedClassDisplayField('state');
225: $this->assertEquals('Active', $this->rel1->getRelatedClassDisplayFieldValue(), 'Testing that the display field value of the related class is accessed correctly');
226: }catch (AlphaException $e) {
227: $this->fail('Testing that the display field value of the related class is accessed correctly');
228: }
229: }
230:
231: 232: 233: 234: 235:
236: public function testGetRelatedClassDisplayFieldValueFail() {
237: try {
238: $this->rel1->setRelatedClassDisplayField('someField');
239: $value = $this->rel1->getRelatedClassDisplayFieldValue();
240: $this->fail('Testing that getRelatedClassDisplayFieldValue() will fail to load an invalid class definition');
241: }catch (AlphaException $e) {
242: $this->assertEquals('The class [] is not defined anywhere!'
243: , $e->getMessage()
244: , 'Testing that getRelatedClassDisplayFieldValue() will fail to load an invalid class definition');
245: }
246: }
247: }
248:
249: ?>