[ Index ]

PHP Cross Reference of Limb3

title

Body

[close]

/web_app/tests/cases/db/template/tags/ -> lmbActiveRecordFetchTagTest.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  
  11  class TestObjectTagVersion extends lmbActiveRecord
  12  {
  13    protected $_db_table_name = 'test_object';
  14  
  15    static function findCustom()
  16    {
  17      return new lmbCollection(array(array('method' => 'Custom')));
  18    }
  19  
  20    static function findByTitle($title)
  21    {
  22      return lmbActiveRecord :: find('TestObjectTagVersion', 'title = "' . $title . '"');
  23    }
  24  }
  25  
  26  class lmbActiveRecordFetchTagTest extends lmbWactTestCase
  27  {
  28    function setUp()
  29    {
  30      parent :: setUp();
  31      $this->_dbCleanUp();
  32    }
  33  
  34    function tearDown()
  35    {
  36      $this->_dbCleanUp();
  37      parent :: tearDown();
  38    }
  39  
  40    function _dbCleanUp()
  41    {
  42      lmbActiveRecord :: delete('TestObjectTagVersion');
  43    }
  44  
  45    function testFetchAll()
  46    {
  47      $c1 = $this->_createObject();
  48      $c2 = $this->_createObject();
  49  
  50      $template = '<active_record:fetch class_path="TestObjectTagVersion" target="testTarget" />' .
  51                  '<list:LIST id="testTarget"><list:ITEM>{$title}|</list:ITEM></list:LIST>';
  52  
  53      $this->registerTestingTemplate('/limb/ar_fetch_all.html', $template);
  54  
  55      $page = $this->initTemplate('/limb/ar_fetch_all.html');
  56  
  57      $this->assertEqual(trim($page->capture()), $c1->getTitle() . '|' . $c2->getTitle() . '|');
  58    }
  59  
  60    function testFetchAllAttributeUsing()
  61    {
  62      $c1 = $this->_createObject();
  63      $c2 = $this->_createObject();
  64  
  65      $template = '<active_record:fetch using="TestObjectTagVersion" target="testTarget" />' .
  66                  '<list:LIST id="testTarget"><list:ITEM>{$title}|</list:ITEM></list:LIST>';
  67  
  68      $this->registerTestingTemplate('/limb/ar_fetch_all2.html', $template);
  69  
  70      $page = $this->initTemplate('/limb/ar_fetch_all2.html');
  71  
  72      $this->assertEqual(trim($page->capture()), $c1->getTitle() . '|' . $c2->getTitle() . '|');
  73    }
  74  
  75    function testFetchNoObject()
  76    {
  77      $template = '<active_record:fetch class_path="TestObjectTagVersion" target="testTarget" first="true">' .
  78                      '<fetch:param record_id="3" />'.
  79                  '</active_record:fetch>'.
  80                  '<core:datasource id="testTarget">'.
  81                  '<core:optional for="id">id={$id}</core:optional>'.
  82                  '<core:default for="id">no object</core:default>'.
  83                  '</core:datasource>';
  84  
  85      $this->registerTestingTemplate('/limb/ar_fetch_noobject.html', $template);
  86  
  87      $page = $this->initTemplate('/limb/ar_fetch_noobject.html');
  88  
  89      $this->assertEqual(trim($page->capture()), 'no object');
  90    }
  91  
  92    function testFetchWithCustomFindMethod()
  93    {
  94      $template = '<active_record:fetch using="TestObjectTagVersion" target="testTarget" find="custom" first="true" />' .
  95                  '<core:datasource id="testTarget">{$method}</core:datasource>';
  96  
  97      $this->registerTestingTemplate('/limb/ar_fetch_with_custom_find.html', $template);
  98  
  99      $page = $this->initTemplate('/limb/ar_fetch_with_custom_find.html');
 100  
 101      $this->assertEqual($page->capture(), 'Custom');
 102    }
 103  
 104  
 105    function _createObject()
 106    {
 107      $object = new TestObjectTagVersion();
 108      $object->setTitle('some title' . mt_rand());
 109      $object->save();
 110      return $object;
 111    }
 112  }
 113  ?>


Generated: Fri Aug 29 04:49:26 2008 Cross-referenced by PHPXref 0.7