| [ Index ] |
PHP Cross Reference of Limb3 |
[Summary view] [Print] [Text view]
1 <?php 2 /* 3 * Limb PHP Framework 4 * 5 * @link http://limb-project.com 6 * @copyright Copyright © 2004-2007 BIT(http://bit-creative.com) 7 * @license LGPL http://www.gnu.org/copyleft/lesser.html 8 */ 9 lmb_require('limb/active_record/src/lmbActiveRecord.class.php'); 10 lmb_require('limb/dbal/src/lmbSimpleDb.class.php'); 11 12 class TestingValueObject 13 { 14 var $value; 15 16 function __construct($value) 17 { 18 $this->value = $value; 19 } 20 21 function getValue() 22 { 23 return $this->value; 24 } 25 } 26 27 class LessonForTest extends lmbActiveRecord 28 { 29 protected $_composed_of = array('date_start' => array('field' => 'date_start', 30 'class' => 'TestingValueObject', 31 'getter' => 'getValue'), 32 'date_end' => array('field' => 'date_end', 33 'class' => 'TestingValueObject', 34 'getter' => 'getValue')); 35 } 36 37 class LazyLessonForTest extends lmbActiveRecord 38 { 39 protected $_db_table_name = 'lesson_for_test'; 40 protected $_lazy_attributes = array('date_start'); 41 protected $_composed_of = array('date_start' => array('field' => 'date_start', 42 'class' => 'TestingValueObject', 43 'getter' => 'getValue'), 44 'date_end' => array('field' => 'date_end', 45 'class' => 'TestingValueObject', 46 'getter' => 'getValue')); 47 48 } 49 50 class lmbARValueObjectTest extends UnitTestCase 51 { 52 function setUp() 53 { 54 $this->_dbCleanUp(); 55 } 56 57 function tearDown() 58 { 59 $this->_dbCleanUp(); 60 } 61 62 function _dbCleanUp() 63 { 64 lmbActiveRecord :: delete('LessonForTest'); 65 } 66 67 function testNewObjectReturnsNullValueObjects() 68 { 69 $lesson = new LessonForTest(); 70 $this->assertNull($lesson->getDateStart()); 71 $this->assertNull($lesson->getDateEnd()); 72 } 73 74 function testSaveLoadValueObjects() 75 { 76 $lesson = new LessonForTest(); 77 78 $lesson->setDateStart(new TestingValueObject($v1 = time())); 79 $lesson->setDateEnd(new TestingValueObject($v2 = time() + 100)); 80 81 $lesson->save(); 82 83 $lesson2 = lmbActiveRecord :: findById('LessonForTest', $lesson->getId()); 84 $this->assertEqual($lesson2->getDateStart()->getValue(), $v1); 85 $this->assertEqual($lesson2->getDateEnd()->getValue(), $v2); 86 } 87 88 function testGenericGetReturnsAlreadyExistingObject() 89 { 90 $lesson = new LessonForTest(); 91 92 $lesson->setDateStart(new TestingValueObject($v1 = time() - 100)); 93 $lesson->setDateEnd(new TestingValueObject($v2 = time() + 100)); 94 95 $this->assertEqual($lesson->get('date_start')->getValue(), $v1); 96 $this->assertEqual($lesson->get('date_end')->getValue(), $v2); 97 } 98 99 function testLazyValueObjects() 100 { 101 $lesson = new LessonForTest(); 102 103 $lesson->setDateStart(new TestingValueObject($v1 = time())); 104 $lesson->setDateEnd(new TestingValueObject($v2 = time() + 100)); 105 106 $lesson->save(); 107 108 $lesson2 = new LazyLessonForTest($lesson->getId()); 109 110 $this->assertEqual($lesson2->getDateStart()->getValue(), $v1); 111 $this->assertEqual($lesson2->getDateEnd()->getValue(), $v2); 112 } 113 114 function testValueObjectsAreImportedProperly() 115 { 116 $lesson = new LessonForTest(); 117 $lesson->setDateStart(new TestingValueObject($v1 = time())); 118 $lesson->setDateEnd(new TestingValueObject($v2 = time() + 100)); 119 120 $lesson2 = new LessonForTest($lesson->export()); 121 122 $this->assertEqual($lesson2->getDateStart()->getValue(), $v1); 123 $this->assertEqual($lesson2->getDateEnd()->getValue(), $v2); 124 } 125 } 126 127 ?>
title
Description
Body
title
Description
Body
title
Description
Body
title
Body
| Generated: Sat Sep 6 04:46:52 2008 | Cross-referenced by PHPXref 0.7 |