[ Index ]

PHP Cross Reference of Limb3

title

Body

[close]

/cms/tests/cases/controller/ -> AdminNodeWithObjectControllerTest.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/cms/src/controller/AdminNodeWithObjectController.class.php');
  10  lmb_require('limb/active_record/src/lmbActiveRecord.class.php');
  11  lmb_require('limb/net/src/lmbHttpRequest.class.php');
  12  lmb_require('limb/web_app/src/tests/lmbWebApplicationSandbox.class.php');
  13  
  14  class NodeObjectForTesting extends lmbActiveRecord
  15  {
  16    protected $_db_table_name = 'object_for_testing';
  17  
  18    protected function _createValidator()
  19    {
  20      $validator = new lmbValidator();
  21      $validator->addRequiredRule('field');
  22      return $validator;
  23    }
  24  }
  25  
  26  class TestAdminNodeWithObjectController extends AdminNodeWithObjectController
  27  {
  28    protected $_object_class_name = 'NodeObjectForTesting';
  29    protected $_controller_name = 'node';
  30    protected $in_popup = false;
  31  
  32    protected function _onBeforeSave() { $this->response->append('onBeforeSave|'); }
  33    protected function _onAfterSave() { $this->response->append('onAfterSave|'); }
  34  
  35    protected function _onBeforeValidate() { $this->response->append('onBeforeValidate|'); }
  36    protected function _onAfterValidate() { $this->response->append('onAfterValidate|'); }
  37  
  38    protected function _onBeforeCreate() { $this->response->append('onBeforeCreate|'); }
  39    protected function _onAfterCreate() { $this->response->append('onAfterCreate|'); }
  40  
  41    protected function _onBeforeEdit() { $this->response->append('onBeforeEdit|'); }
  42    protected function _onAfterEdit() { $this->response->append('onAfterEdit|'); }
  43  
  44    protected function _onBeforeDelete() { $this->response->append('onBeforeDelete|'); }
  45    protected function _onAfterDelete() { $this->response->append('onAfterDelete|'); }
  46  
  47    protected function _initCreateForm() { $this->response->append('initCreateForm|'); }
  48    protected function _initEditForm() { $this->response->append('initEditForm|'); }
  49  }
  50  
  51  class AdminNodeWithObjectControllerTest extends UnitTestCase
  52  {
  53    protected $toolkit;
  54  
  55    function setUp()
  56    {
  57      $this->toolkit = lmbToolkit :: save();
  58      $this->_cleanUp();
  59    }
  60  
  61    function tearDown()
  62    {
  63      lmbToolkit :: restore();
  64      $this->_cleanUp();
  65    }
  66  
  67    function _cleanUp()
  68    {
  69      try
  70      {
  71        lmbActiveRecord :: delete('lmbCmsNode');
  72        lmbActiveRecord :: delete('ObjectForTesting');
  73      }
  74      catch(lmbException $e) {}
  75    }
  76  
  77    function testEventsOnPerformCreateActionFirstTime()
  78    {
  79      $request = new lmbHttpRequest('/test_admin_node_with_object/create');
  80  
  81      $app = new lmbWebApplicationSandbox();
  82      $response = $app->imitate($request);
  83  
  84      $this->assertEqual($response->getResponseString(), 'initCreateForm|');
  85    }
  86  
  87    function testEventsOnPerformCreateActionWithPost()
  88    {
  89      $request = new lmbHttpRequest('/test_admin_node_with_object/create', array(), array('title' => 'test',
  90                                                                                          'identifier' => 'test',
  91                                                                                          'field' => 'test'));
  92  
  93      $app = new lmbWebApplicationSandbox();
  94      $response = $app->imitate($request);
  95  
  96      $expected_callchain = 'onBeforeValidate|onAfterValidate|onBeforeCreate|onBeforeSave|onAfterSave|onAfterCreate|';
  97      $this->assertEqual($response->getResponseString(), $expected_callchain);
  98    }
  99  
 100    function testEventsOnPerformCreateActionWithPostNotValid()
 101    {
 102      $request = new lmbHttpRequest('/test_admin_node_with_object/create', array(), array('title' => ''));
 103  
 104      $app = new lmbWebApplicationSandbox();
 105      $response = $app->imitate($request);
 106  
 107      $expected_callchain = 'onBeforeValidate|onAfterValidate|';
 108      $this->assertEqual($response->getResponseString(), $expected_callchain);
 109    }
 110  
 111    function testEventsOnPerformEditActionFirstTime()
 112    {
 113      $node = new lmbCmsNode();
 114      $node->setIdentifier('test');
 115      $node->setTitle('test');
 116      $node->save();
 117  
 118      $request = new lmbHttpRequest('/test_admin_node_with_object/edit/' . $node->getId());
 119  
 120      $app = new lmbWebApplicationSandbox();
 121      $response = $app->imitate($request);
 122  
 123      $this->assertEqual($response->getResponseString(), 'initEditForm|');
 124    }
 125  
 126    function testEventsOnPerformEditActionWithPostNotValid()
 127    {
 128      $node = $this->_createNodeWithObject();
 129  
 130      $request = new lmbHttpRequest('/test_admin_node_with_object/edit/' . $node->getId(), array(), array('id' => $node->getId(), 'title' => ''));
 131  
 132      $app = new lmbWebApplicationSandbox();
 133      $response = $app->imitate($request);
 134  
 135      $expected_callchain = 'onBeforeValidate|onAfterValidate|';
 136      $this->assertEqual($response->getResponseString(), $expected_callchain);
 137    }
 138  
 139    function testEventsOnPerformEditActionWithPost()
 140    {
 141      $node = $this->_createNodeWithObject();
 142  
 143      $request = new lmbHttpRequest('/test_admin_node_with_object/edit/' . $node->getId(), array(), array('id' => $node->getId()));
 144  
 145      $app = new lmbWebApplicationSandbox();
 146      $response = $app->imitate($request);
 147  
 148      $expected_callchain = 'onBeforeValidate|onAfterValidate|onBeforeEdit|onBeforeSave|onAfterSave|onAfterEdit|';
 149      $this->assertEqual($response->getResponseString(), $expected_callchain);
 150    }
 151  
 152    function testEventsOnPerformDeleteAction()
 153    {
 154      $node = $this->_createNodeWithObject();
 155  
 156      $request = new lmbHttpRequest('/test_admin_node_with_object/delete/' . $node->getId(), array(), array('id' => $node->getId()));
 157  
 158      $app = new lmbWebApplicationSandbox();
 159      $response = $app->imitate($request);
 160  
 161      $expected_callchain = 'onBeforeDelete|onAfterDelete|';
 162      $this->assertEqual($response->getResponseString(), $expected_callchain);
 163    }
 164  
 165    protected function _createNodeWithObject()
 166    {
 167      $node = new lmbCmsNode();
 168      $node->setIdentifier('test');
 169      $node->setTitle('test');
 170  
 171      $object = new NodeObjectForTesting();
 172      $object->setField('test');
 173      $node->setObject($object);
 174      $object->setNode($node);
 175  
 176      $object->save();
 177      $node->save();
 178      return $node;
 179    }
 180  }
 181  
 182  ?>


Generated: Fri Dec 5 04:05:07 2008 Cross-referenced by PHPXref 0.7