[ Index ]

PHP Cross Reference of Limb3

title

Body

[close]

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


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