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 AlphaDAO_Test extends PHPUnit_Framework_TestCase {
49: 50: 51: 52: 53: 54:
55: private $person;
56:
57: 58: 59: 60: 61: 62: 63:
64: protected function setUp() {
65: AlphaDAO::begin();
66:
67: $rights = new RightsObject();
68: $rights->rebuildTable();
69:
70: $request = new BadRequestObject();
71: $request->rebuildTable();
72:
73: $this->person = $this->createPersonObject('unitTestUser');
74: $this->person->rebuildTable();
75:
76:
77: $this->person->deleteAllByAttribute('URL', 'http://unitTestUser/');
78: $this->person->deleteAllByAttribute('displayName', 'unitTestUser');
79: }
80:
81: 82: 83: 84: 85: 86: 87:
88: protected function tearDown() {
89: AlphaDAO::rollback();
90: $this->person->dropTable();
91: unset($this->person);
92: $rights = new RightsObject();
93: $rights->dropTable();
94: $rights->dropTable('Person2Rights');
95: $request = new BadRequestObject();
96: $request->dropTable();
97: }
98:
99: 100: 101: 102: 103: 104:
105: private function createPersonObject($name) {
106: $person = new PersonObject();
107: $person->setDisplayname($name);
108: $person->set('email', $name.'@test.com');
109: $person->set('password', 'passwordTest');
110: $person->set('URL', 'http://unitTestUser/');
111:
112: return $person;
113: }
114:
115: 116: 117: 118: 119:
120: public function testDefaultHouseKeepingValues() {
121:
122: $this->assertEquals($_SESSION['currentUser']->getID(), $this->person->getCreatorId()->getValue(),
123: 'test that the constructor sets the correct values of the "house keeping" attributes');
124: $this->assertEquals($_SESSION['currentUser']->getID(), $this->person->getUpdatorId()->getValue(),
125: 'test that the constructor sets the correct values of the "house keeping" attributes');
126:
127: $this->assertEquals(0, $this->person->getVersionNumber()->getValue(),
128: 'test that the constructor sets the correct values of the "house keeping" attributes');
129:
130:
131: $today = date('Y-m-d');
132: $this->assertEquals($today, $this->person->getCreateTS()->getDate(),
133: 'test that the constructor sets the correct values of the "house keeping" attributes');
134: $this->assertEquals($today, $this->person->getUpdateTS()->getDate(),
135: 'test that the constructor sets the correct values of the "house keeping" attributes');
136:
137:
138: $this->assertTrue($this->person->isTransient(), 'test that the constructor sets the correct values of the "house keeping" attributes');
139: }
140:
141: 142: 143: 144: 145:
146: public function testBasicLoadSave() {
147: $this->person->save();
148: $id = $this->person->getMAX();
149: $this->person->load($id);
150: $this->assertEquals('unitTestUser', $this->person->getDisplayname()->getValue(), 'Testing the basic load/save functionality');
151: }
152:
153: 154: 155: 156: 157:
158: public function testCheckRecordExists() {
159: $this->person->save();
160: $person = new PersonObject();
161: $this->assertTrue($person->checkRecordExists($this->person->getOID()), 'Testing the checkRecordExists method');
162: }
163:
164: 165: 166: 167: 168:
169: public function testLoadByAttribute() {
170: $this->person->save();
171: $this->person->loadByAttribute('displayName','unitTestUser');
172: $this->assertEquals('unitTestUser@test.com', $this->person->get('email'), 'Testing the loadByAttribute method');
173: $this->person->loadByAttribute('email','unitTestUser@test.com');
174: $this->assertEquals('unitTestUser', $this->person->getDisplayname()->getValue(), 'Testing the loadByAttribute method');
175: }
176:
177: 178: 179: 180: 181:
182: public function testLoadAll() {
183: $this->person->save();
184: $peopleCount = $this->person->getCount();
185: $people = $this->person->loadAll();
186: $this->assertEquals($peopleCount, count($people), 'Testing loadAll method');
187:
188: $people = $this->person->loadAll(0, 1);
189: $this->assertEquals(1, count($people), 'Testing loadAll method');
190: }
191:
192: 193: 194: 195: 196:
197: public function testLoadAllByAttribute() {
198: $this->person->save();
199: $people = $this->person->loadAllByAttribute('email','unitTestUser@test.com');
200: $this->assertEquals(1, count($people), 'Testing the loadAllByAttribute method');
201: $this->assertEquals('unitTestUser', $people[0]->getDisplayname()->getValue(), 'Testing the loadAllByAttribute method');
202: $people[0]->delete();
203: }
204:
205: 206: 207: 208: 209:
210: public function testLoadAllByAttributes() {
211: $this->person->save();
212: $people = $this->person->loadAllByAttributes(array('OID'),array($this->person->getOID()));
213: $this->assertEquals(1, count($people), 'Testing the loadAllByAttribute method');
214: $this->assertEquals('unitTestUser', $people[0]->getDisplayname()->getValue(), 'Testing the loadAllByAttributes method');
215: $people[0]->delete();
216: }
217:
218: 219: 220: 221: 222:
223: public function testLoadAllByDayUpdated() {
224: $this->person->save();
225: $people = $this->person->loadAllByDayUpdated(date('Y-m-d'));
226: $this->assertGreaterThan(0, count($people), 'Testing the loadAllByDayUpdated method');
227: $people[0]->delete();
228: }
229:
230: 231: 232: 233: 234:
235: public function testLoadAllFieldValuesByAttribute() {
236: $this->person->save();
237: $emails = $this->person->loadAllFieldValuesByAttribute('email', $this->person->get('email'), 'email');
238: $this->assertEquals($this->person->get('email'), $emails[0], 'Testing the loadAllFieldValuesByAttribute method');
239: }
240:
241: 242: 243: 244: 245:
246: public function testSaveTransientOrPersistent() {
247: $this->assertTrue($this->person->isTransient(), 'Testing the save method on transient and non-transient objects');
248: $this->assertEquals(0, $this->person->getVersionNumber()->getValue(), 'Testing the save method on transient and non-transient objects');
249:
250: $this->person->save();
251:
252: $this->assertFalse($this->person->isTransient(), 'Testing the save method on transient and non-transient objects');
253: $this->assertEquals(1, $this->person->getVersionNumber()->getValue(), 'Testing the save method on transient and non-transient objects');
254: }
255:
256: 257: 258: 259: 260:
261: public function testSaveTransientOID() {
262: $this->assertTrue($this->person->isTransient(), 'Testing to ensure that a transient object, once saved, will have an OID');
263: $this->person->save();
264: $this->assertGreaterThan(0, $this->person->getID(), 'Testing to ensure that a transient object, once saved, will have an OID');
265: $this->assertFalse($this->person->isTransient(), 'Testing to ensure that a transient object, once saved, will have an OID');
266: }
267:
268: 269: 270: 271: 272:
273: public function testSaveObjectLocking() {
274: try {
275: $this->person->save();
276:
277: $personInstance1 = new PersonObject();
278: $personInstance1->load($this->person->getID());
279: $personInstance2 = new PersonObject();
280: $personInstance2->load($this->person->getID());
281:
282: $personInstance1->save();
283: $personInstance2->save();
284: $this->fail('Testing optimistic locking mechanism');
285: }catch (LockingException $e) {
286: $this->assertEquals('Could not save the object as it has been updated by another user. Please try saving again.',
287: $e->getMessage(),
288: 'Testing optimistic locking mechanism');
289: }
290: }
291:
292: 293: 294: 295: 296:
297: public function testValidation() {
298: try {
299: $person = new PersonObject();
300: $person->save();
301: $this->fail('Testing the validation method');
302: }catch (ValidationException $e) {
303: $this->assertEquals('Failed to save, validation error is:',
304: mb_substr($e->getMessage(), 0, 36),
305: 'Testing the validation method');
306: }
307: }
308:
309: 310: 311: 312: 313:
314: public function testDelete() {
315: $this->person->save();
316: $this->assertFalse($this->person->isTransient(), 'Testing the delete method');
317: $id = $this->person->getID();
318: $this->person->delete();
319:
320: $this->assertEquals(0, count(get_object_vars($this->person)), 'Testing the delete method');
321:
322: try {
323: $this->person = new PersonObject();
324: $this->person->load($id);
325: $this->fail('Testing the delete method');
326: }catch (BONotFoundException $e) {
327: $this->assertEquals('Failed to load object',
328: mb_substr($e->getMessage(), 0, 21),
329: 'Testing the delete method');
330: }
331: }
332:
333: 334: 335: 336: 337:
338: public function testDeleteAllByAttribute() {
339: $person1 = new PersonObject();
340: $person1->setDisplayname('unitTestUser1');
341: $person1->set('email', 'unitTestUser1@test.com');
342: $person1->set('password', 'passwordTest');
343: $person1->set('URL', 'http://unitTestUser/');
344:
345: $person2 = new PersonObject();
346: $person2->setDisplayname('unitTestUser2');
347: $person2->set('email', 'unitTestUser2@test.com');
348: $person2->set('password', 'passwordTest');
349: $person2->set('URL', 'http://unitTestUser/');
350:
351: $person3 = new PersonObject();
352: $person3->setDisplayname('unitTestUser3');
353: $person3->set('email', 'unitTestUser3@test.com');
354: $person3->set('password', 'passwordTest');
355: $person3->set('URL', 'http://unitTestUser/');
356:
357: $person1->save();
358: $person2->save();
359: $person3->save();
360: $this->assertEquals(3, $this->person->deleteAllByAttribute('URL', 'http://unitTestUser/'), 'Testing the deleteAllByAttribute method');
361: }
362:
363: 364: 365: 366: 367:
368: public function testGetVersion() {
369: $this->assertEquals(0, $this->person->getVersion(), 'Testing the version numbers of business objects');
370: $this->assertEquals(0, $this->person->getVersionNumber()->getValue(), 'Testing the version numbers of business objects');
371: $this->person->save();
372: $this->assertEquals(1, $this->person->getVersion(), 'Testing the version numbers of business objects');
373: $this->assertEquals(1, $this->person->getVersionNumber()->getValue(), 'Testing the version numbers of business objects');
374: $this->person->save();
375: $this->assertEquals(2, $this->person->getVersion(), 'Testing the version numbers of business objects');
376: $this->assertEquals(2, $this->person->getVersionNumber()->getValue(), 'Testing the version numbers of business objects');
377: }
378:
379: 380: 381: 382: 383:
384: public function testGetMAX() {
385: $this->person->save();
386: $max = $this->person->getMAX();
387: $person2 = $this->createPersonObject('unitTestUser2');
388: $person2->save();
389: $this->assertEquals($max+1, $this->person->getMAX(), 'Testing the getMAX method');
390: }
391:
392: 393: 394: 395: 396:
397: public function testGetCount() {
398: $count = $this->person->getCount();
399: $this->person->save();
400: $this->assertEquals($count+1, $this->person->getCount(), 'Testing the getCount method');
401: }
402:
403: 404: 405: 406: 407:
408: public function testSetEnumOptions() {
409: $this->person->save();
410: $id = $this->person->getMAX();
411: $this->person->load($id);
412: $this->assertTrue(in_array('Active', $this->person->getPropObject('state')->getOptions()),
413: 'Testing the setEnumOptions method is loading enum options correctly');
414: }
415:
416: 417: 418: 419: 420:
421: public function testCheckTableExists() {
422: $this->assertTrue($this->person->checkTableExists(), 'Testing that checkTableExists returns true for the person BO');
423: }
424:
425: 426: 427: 428: 429:
430: public function testCheckTableNeedsUpdate() {
431: $this->assertFalse($this->person->checkTableNeedsUpdate(), 'Testing that checkTableNeedsUpdate returns false for the person BO');
432: }
433:
434: 435: 436: 437: 438:
439: public function testGetTableName() {
440: $this->assertEquals('Person', $this->person->getTableName(),
441: 'Testing to ensure that the getTableName method can read the TABLE_NAME constant declared in the child class');
442: }
443:
444: 445: 446: 447: 448:
449: public function testGetDataLabel() {
450: $this->assertEquals('E-mail Address', $this->person->getDataLabel('email'), 'Testing the getDataLabel method');
451: }
452:
453: 454: 455: 456: 457:
458: public function testGetNoChildMethod() {
459: $email = $this->person->get('email');
460:
461: $this->assertEquals('unitTestUser@test.com', $email, 'Testing get on a String attribute with no child get method available');
462: }
463:
464: 465: 466: 467: 468:
469: public function testGetNoChildMethodsDisabled() {
470: $state = $this->person->getPropObject('state');
471:
472: $this->assertEquals('Enum', get_class($state),
473: 'Testing get on an Enum attribute with a child method avaialble, with $noChildMethods disabled (default)');
474: $this->assertEquals('Active', $state->getValue(),
475: 'Testing get on an Enum attribute with a child method avaialble, with $noChildMethods disabled (default)');
476: }
477:
478: 479: 480: 481: 482:
483: public function testGetNoChildMethodsEnabled() {
484: $state = $this->person->get('state', true);
485:
486: $this->assertEquals('Active', $state, 'Testing get on an Enum attribute with a child method avaialble, with $noChildMethods enabled');
487: }
488:
489: 490: 491: 492: 493:
494: public function testGetSimpleType() {
495: $labels = $this->person->get('dataLabels');
496:
497: $this->assertTrue(is_array($labels), 'Testing get on a simple data type');
498: }
499:
500: 501: 502: 503: 504:
505: public function testSetNoChildMethod() {
506: $this->person->set('email','test@test.com');
507:
508: $this->assertEquals('test@test.com', $this->person->get('email'), 'Testing set on a String attribute with no child get method available');
509: }
510:
511: 512: 513: 514: 515:
516: public function testSetNoChildMethodsDisabled() {
517: $this->person->set('state','Active');
518:
519: $this->assertEquals('Active', $this->person->get('state'),
520: 'Testing set on an Enum attribute with a child method avaialble, with $noChildMethods disabled (default)');
521: }
522:
523: 524: 525: 526: 527:
528: public function testSetNoChildMethodsEnabled() {
529: $this->person->set('state','Active', true);
530:
531: $this->assertEquals('Active', $this->person->get('state'),
532: 'Testing set on an Enum attribute with a child method avaialble, with $noChildMethods enabled');
533: }
534:
535: 536: 537: 538: 539:
540: public function testSetSimpleType() {
541: $this->person->set('dataLabels', array('key'=>'value'));
542:
543: $labels = $this->person->get('dataLabels');
544:
545: $this->assertTrue(is_array($labels), 'Testing set on a simple data type');
546: $this->assertEquals('value', $labels['key'], 'Testing set on a simple data type');
547: }
548:
549: 550: 551: 552: 553:
554: public function testGetPropObjectComplexType() {
555: $state = $this->person->getPropObject('state');
556:
557: $this->assertEquals('Enum', get_class($state), 'Testing getPropObject on a complex type');
558: $this->assertEquals('Active', $state->getValue(), 'Testing getPropObject on a complex type');
559: }
560:
561: 562: 563: 564: 565:
566: public function testGetPropObjectSimpleType() {
567: $labels = $this->person->getPropObject('dataLabels');
568:
569: $this->assertTrue(is_array($labels), 'Testing getPropObject on a simple type');
570: $this->assertEquals('E-mail Address', $labels['email'], 'Testing getPropObject on a simple type');
571: }
572:
573: 574: 575: 576: 577:
578: public function testMarkTransientPersistent() {
579:
580: $this->person->save();
581:
582:
583: $this->person->markTransient('URL');
584: $this->assertTrue(in_array('URL', $this->person->getTransientAttributes()), 'Testing that markTransient and markPersistent methods');
585: $this->person->set('URL','http://www.alphaframework.org/');
586: $this->person->save();
587:
588:
589: $this->person->markPersistent('URL');
590: $this->assertFalse(in_array('URL', $this->person->getTransientAttributes()), 'Testing that markTransient and markPersistent methods');
591:
592: $this->person->reload();
593:
594: $this->assertEquals('http://unitTestUser/', $this->person->get('URL'), 'Testing that markTransient and markPersistent methods');
595: }
596:
597: 598: 599: 600: 601:
602: public function testGetDataLabels() {
603: $this->assertTrue(is_array($this->person->getDataLabels()), 'Testing the getDataLabels method');
604: $labels = $this->person->getDataLabels();
605: $this->assertTrue(in_array('OID', array_keys($labels)), 'Testing the getDataLabels method');
606: $this->assertTrue(in_array('E-mail Address', $labels), 'Testing the getDataLabels method');
607: }
608:
609: 610: 611: 612: 613:
614: public function testGetTransientAttributes() {
615: $this->assertTrue(is_array($this->person->getTransientAttributes()),
616: 'Testing the getTransientAttributes method in conjunction with markTransient/markPersistent');
617: $this->person->markTransient('URL');
618: $this->assertTrue(in_array('URL', $this->person->getTransientAttributes()),
619: 'Testing the getTransientAttributes method in conjunction with markTransient/markPersistent');
620: $this->person->markPersistent('URL');
621: $this->assertFalse(in_array('URL', $this->person->getTransientAttributes()),
622: 'Testing the getTransientAttributes method in conjunction with markTransient/markPersistent');
623: }
624:
625: 626: 627: 628: 629:
630: public function testIsTransient() {
631: $this->assertTrue($this->person->isTransient(), 'Testing isTransient before and after save');
632: $this->person->save();
633: $this->assertFalse($this->person->isTransient(), 'Testing isTransient before and after save');
634: }
635:
636: 637: 638: 639: 640:
641: public function testGetLastQuery() {
642:
643: global $config;
644:
645: $this->person->save();
646:
647: if($config->get('db.provider.name') == 'AlphaDAOProviderMySQL') {
648: $this->assertEquals('INSERT INTO Person', mb_substr($this->person->getLastQuery(), 0, 18),
649: 'Testing the getLastQuery method after various persistance calls');
650: $this->person->checkTableNeedsUpdate();
651: $this->assertEquals('SHOW INDEX FROM Person', mb_substr($this->person->getLastQuery(), 0, 22),
652: 'Testing the getLastQuery method after various persistance calls');
653: $this->person->getCount();
654: $this->assertEquals('SELECT COUNT(OID)', mb_substr($this->person->getLastQuery(), 0, 17),
655: 'Testing the getLastQuery method after various persistance calls');
656: $this->person->getMAX();
657: $this->assertEquals('SELECT MAX(OID)', mb_substr($this->person->getLastQuery(), 0, 15),
658: 'Testing the getLastQuery method after various persistance calls');
659: $this->person->load($this->person->getID());
660: $this->assertEquals('SHOW COLUMNS FROM Person', mb_substr($this->person->getLastQuery(), 0, 24),
661: 'Testing the getLastQuery method after various persistance calls');
662: }
663:
664: if($config->get('db.provider.name') == 'AlphaDAOProviderSQLite') {
665: $this->assertEquals('PRAGMA table_info(Person)', mb_substr($this->person->getLastQuery(), 0, 25),
666: 'Testing the getLastQuery method after various persistance calls');
667: $this->person->checkTableNeedsUpdate();
668: $this->assertEquals('SELECT name FROM sqlite_master WHERE type=\'index\'', mb_substr($this->person->getLastQuery(), 0, 49),
669: 'Testing the getLastQuery method after various persistance calls');
670: $this->person->getCount();
671: $this->assertEquals('SELECT COUNT(OID)', mb_substr($this->person->getLastQuery(), 0, 17),
672: 'Testing the getLastQuery method after various persistance calls');
673: $this->person->getMAX();
674: $this->assertEquals('SELECT MAX(OID)', mb_substr($this->person->getLastQuery(), 0, 15),
675: 'Testing the getLastQuery method after various persistance calls');
676: $this->person->load($this->person->getID());
677: $this->assertEquals('SELECT displayName,email,password,state,URL,OID,version_num,created_ts,created_by,updated_ts,updated_by FROM Person WHERE OID = :OID LIMIT 1;',
678: mb_substr($this->person->getLastQuery(), 0, 150),
679: 'Testing the getLastQuery method after various persistance calls');
680: }
681: }
682:
683: 684: 685: 686: 687:
688: public function testClear() {
689: $state = $this->person->get('state');
690: $this->assertTrue(!empty($state), 'Testing the clear method for unsetting the attributes of an object');
691:
692: $reflection = new ReflectionClass(get_class($this->person));
693: $properties = $reflection->getProperties();
694:
695: foreach($properties as $propObj) {
696: $propName = $propObj->name;
697: if(!in_array($propName, $this->person->getDefaultAttributes()) && !in_array($propName, $this->person->getTransientAttributes())) {
698: $this->assertNotNull($this->person->get($propName), 'Testing the clear method for unsetting the attributes of an object');
699: }
700: }
701:
702:
703: $this->person->delete();
704:
705: try {
706: $state = $this->person->get('state');
707: $this->fail('Testing the clear method for unsetting the attributes of an object');
708: } catch (AlphaException $e) {
709: $reflection = new ReflectionClass(get_class($this->person));
710: $properties = $reflection->getProperties();
711:
712: foreach($properties as $propObj) {
713: $propName = $propObj->name;
714:
715: try {
716: $this->person->get($propName);
717: } catch (PHPException $e) {
718: $this->assertEquals(preg_match("/Undefined property/", $e->getMessage()), 1,
719: 'Testing the clear method for unsetting the attributes of an object');
720: } catch (AlphaException $e) {
721: $this->assertEquals('Could not access the property ['.$propName.'] on the object of class [PersonObject]', $e->getMessage(),
722: 'Testing the clear method for unsetting the attributes of an object');
723: }
724: }
725: }
726: }
727:
728: 729: 730: 731: 732:
733: public function testSaveAttribute() {
734: $this->person->save();
735: $this->person->saveAttribute('displayName', 'unitTestUserNew');
736:
737: $this->assertEquals('unitTestUserNew', $this->person->getDisplayName()->getValue(),
738: 'Testing that the value was set on the object in memory along with saving to the database');
739:
740: $person = new PersonObject();
741:
742: try {
743: $person->loadByAttribute('displayName', 'unitTestUserNew');
744: $this->assertEquals('unitTestUserNew', $person->getDisplayName()->getValue(), 'Testing that the value was saved to the database');
745: } catch (BONotFoundException $e) {
746: $this->fail('Failed to load the BO that was updated with the saveAttribute method');
747: }
748: }
749:
750: 751: 752: 753: 754:
755: public function testHistoryTableCreated() {
756: $this->person->setMaintainHistory(true);
757: $this->person->rebuildTable();
758:
759: $this->assertTrue($this->person->checkTableExists(true), 'Testing to ensure that a history table was created automatically');
760:
761: $this->person->dropTable('Person_history');
762: }
763:
764: 765: 766: 767: 768:
769: public function testSaveHistory() {
770: $this->person->setMaintainHistory(true);
771: $this->person->rebuildTable();
772:
773: $this->person->set('password', 'passwordhist1');
774: $this->person->save();
775:
776: $this->assertEquals(1, $this->person->getHistoryCount(), 'Testing that a normal save is propegated to the history table for this class');
777: $this->person->setMaintainHistory(true);
778: $this->person->saveAttribute('password', 'passwordhist2');
779:
780: $this->assertEquals(2, $this->person->getHistoryCount(), 'Testing that an attribute save is propegated to the history table for this class');
781:
782: $this->person->dropTable('Person_history');
783: }
784:
785: 786: 787: 788: 789:
790: public function testHasAttribute() {
791: $this->assertTrue($this->person->hasAttribute('password'), 'testing the hasAttribute method for true');
792: $this->assertFalse($this->person->hasAttribute('doesnotexist'), 'testing the hasAttribute method for false');
793: }
794:
795: 796: 797: 798: 799:
800: public function testAddToCache() {
801: global $config;
802:
803: $oldSetting = $config->get('cache.provider.name');
804: $config->set('cache.provider.name', 'AlphaCacheProviderArray');
805:
806: $this->person->setOID('123');
807: $this->person->addToCache();
808:
809: $fromCache = new PersonObject();
810: $fromCache->setOID($this->person->getOID());
811:
812: $this->assertTrue($fromCache->loadFromCache(), 'testing that the item loads from the cache');
813: $this->assertEquals('unitTestUser', $fromCache->get('displayName', true), 'testing that you can add a DAO directly to the cache without saving');
814:
815: $config->set('cache.provider.name', $oldSetting);
816: }
817:
818: 819: 820: 821: 822:
823: public function testLoadFromCache() {
824:
825: global $config;
826:
827: $oldSetting = $config->get('cache.provider.name');
828: $config->set('cache.provider.name', 'AlphaCacheProviderArray');
829:
830: $this->person->save();
831:
832: $fromCache = new PersonObject();
833: $fromCache->setOID($this->person->getOID());
834:
835: $this->assertTrue($fromCache->loadFromCache(), 'testing that the item loads from the cache');
836: $this->assertEquals('unitTestUser', $fromCache->get('displayName', true), 'testing that a saved record is subsequently retrievable from the cache');
837:
838: $config->set('cache.provider.name', $oldSetting);
839: }
840:
841: 842: 843: 844: 845:
846: public function testRemoveFromCache() {
847:
848: global $config;
849:
850: $oldSetting = $config->get('cache.provider.name');
851: $config->set('cache.provider.name', 'AlphaCacheProviderArray');
852:
853: $this->person->save();
854:
855: $fromCache = new PersonObject();
856: $fromCache->setOID($this->person->getOID());
857:
858: $this->assertTrue($fromCache->loadFromCache(), 'testing that the item loads from the cache');
859:
860: $fromCache->removeFromCache();
861:
862: $this->assertFalse($fromCache->loadFromCache(), 'testing that the item is gone from the cache');
863:
864: $config->set('cache.provider.name', $oldSetting);
865: }
866:
867: 868: 869: 870: 871:
872: public function testGetFriendlyClassName() {
873: $person = new PersonObject();
874: $article = new ArticleObject();
875: $comment = new ArticleCommentObject();
876:
877: $this->assertEquals('Person', $person->getFriendlyClassName(), 'testing the getFriendlyClassName() method');
878: $this->assertEquals('Article', $article->getFriendlyClassName(), 'testing the getFriendlyClassName() method');
879: $this->assertEquals('ArticleComment', $comment->getFriendlyClassName(), 'testing the getFriendlyClassName() method');
880: }
881:
882: 883: 884: 885: 886:
887: public function testCast() {
888: $original = new BadRequestObject();
889: $original->set('IP', '127.0.0.1');
890: $copy = $original->cast('BlacklistedIPObject', $original);
891:
892: $this->assertTrue($copy instanceof BlacklistedIPObject, 'testing the cast() method');
893: $this->assertTrue($copy->hasAttribute('IP'), 'testing the cast() method');
894: $this->assertEquals($original->get('IP'), $copy->get('IP'), 'testing the cast() method');
895: }
896: }
897:
898: ?>