[ Index ]

PHP Cross Reference of Limb3

title

Body

[close]

/active_record/tests/cases/ -> lmbARAttributesLazyLoadingTest.class.php (source)

   1  <?php
   2  /*

   3   * Limb PHP Framework

   4   *

   5   * @link http://limb-project.com

   6   * @copyright  Copyright &copy; 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  lmb_require('limb/dbal/src/lmbTableGateway.class.php');
  12  
  13  class LazyTestOneTableObject extends lmbActiveRecord
  14  {
  15    protected $_db_table_name = 'test_one_table_object';
  16    protected $_lazy_attributes = array('annotation', 'content');
  17  }
  18  
  19  class lmbARAttributesLazyLoadingTest extends UnitTestCase
  20  {
  21    var $conn = null;
  22    var $db = null;
  23  
  24    function setUp()
  25    {
  26      $this->conn = lmbToolkit :: instance()->getDefaultDbConnection();
  27      $this->db = new lmbSimpleDb($this->conn);
  28      $this->_cleanUp();
  29    }
  30  
  31    function tearDown()
  32    {
  33      $this->_cleanUp();
  34    }
  35  
  36    function _cleanUp()
  37    {
  38      $this->db->delete('test_one_table_object');
  39    }
  40  
  41    function testLazyFind()
  42    {
  43      $object = $this->_createActiveRecord($annotation = 'Some annotation', $content = 'Some content');
  44      $object2 = lmbActiveRecord :: findById('LazyTestOneTableObject', $object->getId());
  45  
  46      $this->_checkLazyness($object2, $annotation, $content);
  47    }
  48  
  49    function testLazyLoadById()
  50    {
  51      $object = $this->_createActiveRecord($annotation = 'Some annotation', $content = 'Some content');
  52  
  53      $object2 = new LazyTestOneTableObject();
  54      $object2->loadById($object->getId());
  55  
  56      $this->_checkLazyness($object2, $annotation, $content);
  57    }
  58  
  59    function testExportIsNotLazy()
  60    {
  61      $object = $this->_createActiveRecord($annotation = 'Some annotation', $content = 'Some content');
  62      $object2 = lmbActiveRecord :: findById('LazyTestOneTableObject', $object->getId());
  63      $exported = $object2->export();
  64      $this->assertEqual($exported['annotation'], $annotation);
  65      $this->assertEqual($exported['content'], $content);
  66    }
  67  
  68    protected function _checkLazyness($object, $annotation, $content)
  69    {
  70      $this->assertTrue($object->hasAttribute('news_date'));
  71  
  72      $this->assertFalse($object->hasAttribute('annotation'));
  73      $this->assertEqual($object->getAnnotation(), $annotation);
  74      $this->assertTrue($object->hasAttribute('annotation'));
  75  
  76      $this->assertFalse($object->hasAttribute('content'));
  77      $this->assertEqual($object->getContent(), $content);
  78      $this->assertTrue($object->hasAttribute('content'));
  79    }
  80  
  81    protected function _createActiveRecord($annotation, $content)
  82    {
  83      $object = new LazyTestOneTableObject();
  84      $object->setAnnotation($annotation);
  85      $object->setContent($content);
  86      $object->save();
  87      return $object;
  88    }
  89  }
  90  ?>


Generated: Sat Nov 22 03:48:54 2008 Cross-referenced by PHPXref 0.7