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: class RelationLookup_Test extends PHPUnit_Framework_TestCase {
48:
49: 50: 51: 52: 53: 54: 55:
56: protected function setUp() {
57: $rights = new RightsObject();
58: $rights->rebuildTable();
59:
60: $person = new PersonObject();
61: $person->rebuildTable();
62:
63: $article = new ArticleObject();
64: $article->rebuildTable();
65: }
66:
67: 68: 69: 70: 71: 72: 73:
74: protected function tearDown() {
75: $person = new PersonObject();
76: $person->dropTable();
77:
78: $rights = new RightsObject();
79: $rights->dropTable();
80: $rights->dropTable('Person2Rights');
81: $rights->dropTable('Person2Article');
82:
83: $article = new ArticleObject();
84: $article->dropTable();
85: }
86:
87: 88: 89: 90: 91:
92: public function testConstruct() {
93:
94: try{
95: $lookup = new RelationLookup('','');
96: $this->fail('testing the RelationLookup constructor');
97: }catch(IllegalArguementException $e) {
98: $this->assertEquals('Cannot create RelationLookup object without providing the left and right class names!', $e->getMessage(), 'testing the RelationLookup constructor');
99: }
100:
101: $article = new ArticleObject();
102:
103: try {
104: $article->dropTable();
105:
106: $lookup = new RelationLookup('PersonObject','ArticleObject');
107: $this->fail('testing the RelationLookup constructor');
108: }catch(FailedLookupCreateException $e) {
109: $this->assertEquals('Error trying to create a lookup table [Person2Article], as tables for BOs [PersonObject] or [ArticleObject] don\'t exist!', $e->getMessage(), 'testing the RelationLookup constructor');
110: }
111:
112: $article->rebuildTable();
113:
114: $lookup = new RelationLookup('PersonObject','ArticleObject');
115:
116: $this->assertTrue($lookup->checkTableExists(), 'testing the RelationLookup constructor');
117: }
118:
119: 120: 121: 122: 123:
124: public function testGetTableName() {
125:
126: $lookup = new RelationLookup('PersonObject','ArticleObject');
127: $this->assertEquals('Person2Article', $lookup->getTableName(), 'testing the getTableName() method');
128:
129: $lookup = new RelationLookup('ArticleObject','PersonObject');
130: $this->assertEquals('Article2Person', $lookup->getTableName(), 'testing the getTableName() method');
131: }
132:
133: 134: 135: 136: 137:
138: public function testSetValuePass() {
139: $lookup = new RelationLookup('PersonObject','ArticleObject');
140: $lookup->setValue(array(1,2));
141:
142: $this->assertTrue(is_array($lookup->getValue()), 'testing the setValue() method with good params');
143: $this->assertTrue(in_array(2, $lookup->getValue()), 'testing the setValue() method with good params');
144: }
145:
146: 147: 148: 149: 150:
151: public function testSetValueFail() {
152: $lookup = new RelationLookup('PersonObject','ArticleObject');
153:
154: try {
155: $lookup->setValue(2);
156: $this->fail('testing the setValue() method with bad params');
157: }catch (IllegalArguementException $e) {
158: $this->assertEquals('Array value passed to setValue is not valid [2], array should contain two OIDs', $e->getMessage(), 'testing the setValue() method with bad params');
159: }
160: }
161:
162: 163: 164: 165: 166:
167: public function testLoadAllbyAttribute() {
168: $group = new RightsObject();
169: $group->set('name', 'unittestgroup');
170: $group->save();
171:
172: $person1 = new PersonObject();
173: $person1->set('displayName', 'user1');
174: $person1->set('email', 'user1@test.com');
175: $person1->set('password', 'password');
176: $person1->save();
177: $lookup = $person1->getPropObject('rights')->getLookup();
178: $lookup->setValue(array($person1->getOID(), $group->getOID()));
179: $lookup->save();
180:
181: $person2 = new PersonObject();
182: $person2->set('displayName', 'user2');
183: $person2->set('email', 'user2@test.com');
184: $person2->set('password', 'password');
185: $person2->save();
186: $lookup = $person2->getPropObject('rights')->getLookup();
187: $lookup->setValue(array($person2->getOID(), $group->getOID()));
188: $lookup->save();
189:
190:
191:
192: $lookup = new RelationLookup('PersonObject','RightsObject');
193: $this->assertEquals(2, count($lookup->loadAllbyAttribute('rightID', $group->getOID())), 'testing the loadAllbyAttribute() method');
194: }
195: }
196:
197: ?>