[limb-svn] r5991 - in 3.x/trunk/limb/cms: src/controller tests/cases tests/cases/.fixtures tests/cases/controller

svn at limb-project.com svn at limb-project.com
Wed Jun 13 18:00:25 MSD 2007


Author: tony
Date: 2007-06-13 18:00:24 +0400 (Wed, 13 Jun 2007)
New Revision: 5991
URL: http://fisheye.limb-project.com/changelog/limb/?cs=5991

Added:
   3.x/trunk/limb/cms/tests/cases/controller/
   3.x/trunk/limb/cms/tests/cases/controller/AdminNodeControllerTest.class.php
   3.x/trunk/limb/cms/tests/cases/controller/AdminNodeWithObjectControllerTest.class.php
   3.x/trunk/limb/cms/tests/cases/controller/AdminObjectControllerTest.class.php
Modified:
   3.x/trunk/limb/cms/src/controller/AdminNodeController.class.php
   3.x/trunk/limb/cms/src/controller/AdminNodeWithObjectController.class.php
   3.x/trunk/limb/cms/src/controller/AdminObjectController.class.php
   3.x/trunk/limb/cms/tests/cases/.fixtures/init_tests.mysql
Log:
-- added event methods to AdminNodeController, AdminNodeWithObjectController, AdminObjectController:
  * _onAfterSave()
  * _onBeforeCreate()
  * _onAfterCreate()
  * _onBeforeEdit()
  * _onAfterEdit()
  * _onBeforeDelete() (initial implementation)
  * _onAfterDelete() (initial implementation)

Modified: 3.x/trunk/limb/cms/src/controller/AdminNodeController.class.php
===================================================================
--- 3.x/trunk/limb/cms/src/controller/AdminNodeController.class.php	2007-06-13 13:57:19 UTC (rev 5990)
+++ 3.x/trunk/limb/cms/src/controller/AdminNodeController.class.php	2007-06-13 14:00:24 UTC (rev 5991)
@@ -1,19 +1,19 @@
 <?php
-/*
- * Limb PHP Framework
- *
- * @link http://limb-project.com 
- * @copyright  Copyright &copy; 2004-2007 BIT(http://bit-creative.com)
- * @license    LGPL http://www.gnu.org/copyleft/lesser.html 
+/*
+ * Limb PHP Framework
+ *
+ * @link http://limb-project.com
+ * @copyright  Copyright &copy; 2004-2007 BIT(http://bit-creative.com)
+ * @license    LGPL http://www.gnu.org/copyleft/lesser.html
  */
-lmb_require('limb/web_app/src/controller/lmbController.class.php');
-
+lmb_require('limb/web_app/src/controller/lmbController.class.php');
+
 /**
  * abstract class AdminNodeController.
  *
  * @package cms
  * @version $Id$
- */
+ */
 abstract class AdminNodeController extends lmbController
 {
   protected $_form_id = 'node_form';
@@ -41,7 +41,7 @@
       if($this->request->get('auto_identifier'))
         $this->node->setIdentifier(lmbCmsNode :: generateIdentifier($this->request->get('parent')));
 
-      $this->_validateAndSave();
+      $this->_validateAndSave(true);
     }
     else
     {
@@ -58,7 +58,7 @@
     if($this->request->hasPost())
     {
       $this->_import();
-      $this->_validateAndSave();
+      $this->_validateAndSave(false);
     }
     else
     {
@@ -71,20 +71,33 @@
     $this->node->import($this->request);
   }
 
-  protected function _validateAndSave()
+  protected function _validateAndSave($is_create = false)
   {
+    $this->_onBeforeValidate();
     $this->node->validate($this->error_list);
+    $this->_onAfterValidate();
 
     if($this->error_list->isValid())
     {
+      if($is_create)
+        $this->_onBeforeCreate();
+      else
+        $this->_onBeforeEdit();
+
+      $this->_onBeforeSave();
       $this->node->saveSkipValidation();
+      $this->_onAfterSave();
+
+      if($is_create)
+        $this->_onAfterCreate();
+      else
+        $this->_onAfterEdit();
+
       $this->closePopup();
     }
   }
 
-  protected function _initCreateForm()
-  {
-  }
+  protected function _initCreateForm(){}
 
   protected function _initEditForm()
   {
@@ -92,9 +105,24 @@
     $this->request->set('node', $this->node);
   }
 
+  protected function _onBeforeSave() {}
+  protected function _onAfterSave() {}
+  protected function _onBeforeCreate() {}
+  protected function _onAfterCreate() {}
+  protected function _onBeforeEdit() {}
+  protected function _onAfterEdit() {}
+  protected function _onBeforeDelete() {}
+  protected function _onAfterDelete() {}
+  protected function _onBeforeValidate() {}
+  protected function _onAfterValidate() {}
+
   function doDelete()
   {
+    if($this->request->hasPost())
+      $this->_onBeforeDelete();
     $this->performCommand('limb/cms/src/command/lmbCmsDeleteNodeCommand');
+    if($this->request->hasPost())
+      $this->_onAfterDelete();
   }
 }
 

Modified: 3.x/trunk/limb/cms/src/controller/AdminNodeWithObjectController.class.php
===================================================================
--- 3.x/trunk/limb/cms/src/controller/AdminNodeWithObjectController.class.php	2007-06-13 13:57:19 UTC (rev 5990)
+++ 3.x/trunk/limb/cms/src/controller/AdminNodeWithObjectController.class.php	2007-06-13 14:00:24 UTC (rev 5991)
@@ -1,20 +1,20 @@
 <?php
-/*
- * Limb PHP Framework
- *
- * @link http://limb-project.com 
- * @copyright  Copyright &copy; 2004-2007 BIT(http://bit-creative.com)
- * @license    LGPL http://www.gnu.org/copyleft/lesser.html 
+/*
+ * Limb PHP Framework
+ *
+ * @link http://limb-project.com
+ * @copyright  Copyright &copy; 2004-2007 BIT(http://bit-creative.com)
+ * @license    LGPL http://www.gnu.org/copyleft/lesser.html
  */
 lmb_require('limb/web_app/src/controller/lmbController.class.php');
-lmb_require('limb/cms/src/model/lmbCmsNode.class.php');
-
+lmb_require('limb/cms/src/model/lmbCmsNode.class.php');
+
 /**
  * abstract class AdminNodeWithObjectController.
  *
  * @package cms
  * @version $Id$
- */
+ */
 abstract class AdminNodeWithObjectController extends lmbController
 {
   protected $_form_name = 'object_form';
@@ -52,7 +52,7 @@
       if($this->_generate_identifier || $this->request->get('auto_identifier'))
         $this->node->setIdentifier(lmbCmsNode :: generateIdentifier($this->request->get('parent')));
 
-      $this->_validateAndSave();
+      $this->_validateAndSave(true);
     }
     else
     {
@@ -70,7 +70,7 @@
     if($this->request->hasPost())
     {
       $this->_import();
-      $this->_validateAndSave();
+      $this->_validateAndSave(false);
     }
     else
     {
@@ -84,17 +84,30 @@
     $this->item->import($this->request);
   }
 
-  protected function _validateAndSave()
+  protected function _validateAndSave($is_create = false)
   {
+    $this->_onBeforeValidate();
     $this->node->validate($this->error_list);
     $this->item->validate($this->error_list);
+    $this->_onAfterValidate();
 
-    $this->_onBeforeSave();
-
     if($this->error_list->isValid())
     {
+      if($is_create)
+        $this->_onBeforeCreate();
+      else
+        $this->_onBeforeEdit();
+
+      $this->_onBeforeSave();
       $this->node->saveSkipValidation();
       $this->item->saveSkipValidation();
+      $this->_onAfterSave();
+
+      if($is_create)
+        $this->_onAfterCreate();
+      else
+        $this->_onAfterEdit();
+
       $this->closePopup();
     }
   }
@@ -119,11 +132,24 @@
 
   function doDelete()
   {
+    if($this->request->hasPost())
+      $this->_onBeforeDelete();
     $this->performCommand('limb/cms/src/command/lmbCmsDeleteNodeCommand');
+    if($this->request->hasPost())
+      $this->_onAfterDelete();
   }
 
   protected function _initCreateForm() {}
   protected function _onBeforeSave() {}
+  protected function _onAfterSave() {}
+  protected function _onBeforeCreate() {}
+  protected function _onAfterCreate() {}
+  protected function _onBeforeEdit() {}
+  protected function _onAfterEdit() {}
+  protected function _onBeforeDelete() {}
+  protected function _onAfterDelete() {}
+  protected function _onBeforeValidate() {}
+  protected function _onAfterValidate() {}
 }
 
 ?>

Modified: 3.x/trunk/limb/cms/src/controller/AdminObjectController.class.php
===================================================================
--- 3.x/trunk/limb/cms/src/controller/AdminObjectController.class.php	2007-06-13 13:57:19 UTC (rev 5990)
+++ 3.x/trunk/limb/cms/src/controller/AdminObjectController.class.php	2007-06-13 14:00:24 UTC (rev 5991)
@@ -1,19 +1,19 @@
 <?php
-/*
- * Limb PHP Framework
- *
- * @link http://limb-project.com 
- * @copyright  Copyright &copy; 2004-2007 BIT(http://bit-creative.com)
- * @license    LGPL http://www.gnu.org/copyleft/lesser.html 
+/*
+ * Limb PHP Framework
+ *
+ * @link http://limb-project.com
+ * @copyright  Copyright &copy; 2004-2007 BIT(http://bit-creative.com)
+ * @license    LGPL http://www.gnu.org/copyleft/lesser.html
  */
-lmb_require('limb/web_app/src/controller/lmbController.class.php');
-
+lmb_require('limb/web_app/src/controller/lmbController.class.php');
+
 /**
  * abstract class AdminObjectController.
  *
  * @package cms
  * @version $Id$
- */
+ */
 abstract class AdminObjectController extends lmbController
 {
   protected $_form_name = 'object_form';
@@ -39,7 +39,7 @@
     if($this->request->hasPost())
     {
       $this->_import();
-      $this->_validateAndSave();
+      $this->_validateAndSave(true);
     }
     else
     {
@@ -56,7 +56,7 @@
     if($this->request->hasPost())
     {
       $this->_import();
-      $this->_validateAndSave();
+      $this->_validateAndSave(false);
     }
     else
     {
@@ -69,15 +69,28 @@
     $this->item->import($this->request);
   }
 
-  protected function _validateAndSave()
+  protected function _validateAndSave($is_create = false)
   {
+    $this->_onBeforeValidate();
     $this->item->validate($this->error_list);
+    $this->_onAfterValidate();
 
-    $this->_onBeforeSave();
-
     if($this->error_list->isValid())
     {
+      if($is_create)
+        $this->_onBeforeCreate();
+      else
+        $this->_onBeforeEdit();
+
+      $this->_onBeforeSave();
       $this->item->saveSkipValidation();
+      $this->_onAfterSave();
+
+      if($is_create)
+        $this->_onAfterCreate();
+      else
+        $this->_onAfterEdit();
+
       $this->closePopup();
     }
   }
@@ -85,6 +98,15 @@
   protected function _initCreateForm() {}
   protected function _initEditForm() {}
   protected function _onBeforeSave() {}
+  protected function _onAfterSave() {}
+  protected function _onBeforeCreate() {}
+  protected function _onAfterCreate() {}
+  protected function _onBeforeEdit() {}
+  protected function _onAfterEdit() {}
+  protected function _onBeforeDelete() {}
+  protected function _onAfterDelete() {}
+  protected function _onBeforeValidate() {}
+  protected function _onAfterValidate() {}
 
   function performPublishCommand()
   {
@@ -98,7 +120,11 @@
 
   function doDelete()
   {
+    if($this->request->hasPost())
+      $this->_onBeforeDelete();
     $this->performCommand('limb/cms/src/command/lmbCmsDeleteObjectCommand', $this->_object_class_name);
+    if($this->request->hasPost())
+      $this->_onAfterDelete();
   }
 }
 

Modified: 3.x/trunk/limb/cms/tests/cases/.fixtures/init_tests.mysql
===================================================================
--- 3.x/trunk/limb/cms/tests/cases/.fixtures/init_tests.mysql	2007-06-13 13:57:19 UTC (rev 5990)
+++ 3.x/trunk/limb/cms/tests/cases/.fixtures/init_tests.mysql	2007-06-13 14:00:24 UTC (rev 5991)
@@ -159,3 +159,12 @@
   PRIMARY KEY  (`id`),
   KEY `node_id` (`node_id`)
 ) ENGINE=InnoDB DEFAULT CHARSET=utf8;
+
+DROP TABLE IF EXISTS `object_for_testing`;
+CREATE TABLE `object_for_testing` (
+ `id` bigint(20) NOT NULL auto_increment,
+ `field` varchar(255) default NULL,
+ `node_id` bigint(20) default NULL,
+ PRIMARY KEY  (`id`),
+ KEY `node_id` (`node_id`)
+) ENGINE=InnoDB DEFAULT CHARSET=utf8;

Added: 3.x/trunk/limb/cms/tests/cases/controller/AdminNodeControllerTest.class.php
===================================================================
--- 3.x/trunk/limb/cms/tests/cases/controller/AdminNodeControllerTest.class.php	                        (rev 0)
+++ 3.x/trunk/limb/cms/tests/cases/controller/AdminNodeControllerTest.class.php	2007-06-13 14:00:24 UTC (rev 5991)
@@ -0,0 +1,159 @@
+<?php
+/*
+ * Limb PHP Framework
+ *
+ * @link http://limb-project.com
+ * @copyright Copyright &copy; 2004-2007 BIT(http://bit-creative.com)
+ * @license LGPL http://www.gnu.org/copyleft/lesser.html
+ */
+lmb_require('limb/cms/src/controller/AdminNodeController.class.php');
+lmb_require('limb/active_record/src/lmbActiveRecord.class.php');
+lmb_require('limb/net/src/lmbHttpRequest.class.php');
+lmb_require('limb/web_app/src/tests/lmbWebApplicationSandbox.class.php');
+
+class TestAdminNodeController extends AdminNodeController
+{
+  protected $in_popup = false;
+
+  protected function _onBeforeSave() { $this->response->append('onBeforeSave|'); }
+  protected function _onAfterSave() { $this->response->append('onAfterSave|'); }
+
+  protected function _onBeforeValidate() { $this->response->append('onBeforeValidate|'); }
+  protected function _onAfterValidate() { $this->response->append('onAfterValidate|'); }
+
+  protected function _onBeforeCreate() { $this->response->append('onBeforeCreate|'); }
+  protected function _onAfterCreate() { $this->response->append('onAfterCreate|'); }
+
+  protected function _onBeforeEdit() { $this->response->append('onBeforeEdit|'); }
+  protected function _onAfterEdit() { $this->response->append('onAfterEdit|'); }
+
+  protected function _onBeforeDelete() { $this->response->append('onBeforeDelete|'); }
+  protected function _onAfterDelete() { $this->response->append('onAfterDelete|'); }
+
+  protected function _initCreateForm() { $this->response->append('initCreateForm|'); }
+  protected function _initEditForm() { $this->response->append('initEditForm|'); }
+}
+
+class AdminNodeControllerTest extends UnitTestCase
+{
+  protected $toolkit;
+
+  function setUp()
+  {
+    $this->toolkit = lmbToolkit :: save();
+    $this->_cleanUp();
+  }
+
+  function tearDown()
+  {
+    lmbToolkit :: restore();
+    $this->_cleanUp();
+  }
+
+  function _cleanUp()
+  {
+    try
+    {
+      lmbActiveRecord :: delete('lmbCmsNode');
+    }
+    catch(lmbException $e) {}
+  }
+
+  function testEventsOnPerformCreateActionFirstTime()
+  {
+    $request = new lmbHttpRequest('/test_admin_node/create');
+
+    $app = new lmbWebApplicationSandbox();
+    $response = $app->imitate($request);
+
+    $this->assertEqual($response->getResponseString(), 'initCreateForm|');
+  }
+
+  function testEventsOnPerformCreateActionWithPost()
+  {
+    $request = new lmbHttpRequest('/test_admin_node/create', array(), array('title' => 'test',
+                                                                            'identifier' => 'test'));
+
+    $app = new lmbWebApplicationSandbox();
+    $response = $app->imitate($request);
+
+    $expected_callchain = 'onBeforeValidate|onAfterValidate|onBeforeCreate|onBeforeSave|onAfterSave|onAfterCreate|';
+    $this->assertEqual($response->getResponseString(), $expected_callchain);
+  }
+
+  function testEventsOnPerformCreateActionWithPostNotValid()
+  {
+    $request = new lmbHttpRequest('/test_admin_node/create', array(), array('title' => ''));
+
+    $app = new lmbWebApplicationSandbox();
+    $response = $app->imitate($request);
+
+    $expected_callchain = 'onBeforeValidate|onAfterValidate|';
+    $this->assertEqual($response->getResponseString(), $expected_callchain);
+  }
+
+  function testEventsOnPerformEditActionFirstTime()
+  {
+    $node = new lmbCmsNode();
+    $node->setIdentifier('test');
+    $node->setTitle('test');
+    $node->save();
+
+    $request = new lmbHttpRequest('/test_admin_node/edit/' . $node->getId());
+
+    $app = new lmbWebApplicationSandbox();
+    $response = $app->imitate($request);
+
+    $this->assertEqual($response->getResponseString(), 'initEditForm|');
+  }
+
+  function testEventsOnPerformEditActionWithPostNotValid()
+  {
+    $node = new lmbCmsNode();
+    $node->setIdentifier('test');
+    $node->setTitle('test');
+    $node->save();
+
+    $request = new lmbHttpRequest('/test_admin_node/edit/' . $node->getId(), array(), array('id' => $node->getId(), 'title' => ''));
+
+    $app = new lmbWebApplicationSandbox();
+    $response = $app->imitate($request);
+
+    $expected_callchain = 'onBeforeValidate|onAfterValidate|';
+    $this->assertEqual($response->getResponseString(), $expected_callchain);
+  }
+
+  function testEventsOnPerformEditActionWithPost()
+  {
+    $node = new lmbCmsNode();
+    $node->setIdentifier('test');
+    $node->setTitle('test');
+    $node->save();
+
+    $request = new lmbHttpRequest('/test_admin_node/edit/' . $node->getId(), array(), array('id' => $node->getId()));
+
+    $app = new lmbWebApplicationSandbox();
+    $response = $app->imitate($request);
+
+    $expected_callchain = 'onBeforeValidate|onAfterValidate|onBeforeEdit|onBeforeSave|onAfterSave|onAfterEdit|';
+    $this->assertEqual($response->getResponseString(), $expected_callchain);
+  }
+
+  function testEventsOnPerformDeleteAction()
+  {
+    $node = new lmbCmsNode();
+    $node->setIdentifier('test');
+    $node->setTitle('test');
+    $node->save();
+
+    $request = new lmbHttpRequest('/test_admin_node/delete/' . $node->getId(), array(), array('id' => $node->getId()));
+
+    $app = new lmbWebApplicationSandbox();
+    $response = $app->imitate($request);
+
+    $expected_callchain = 'onBeforeDelete|onAfterDelete|';
+    $this->assertEqual($response->getResponseString(), $expected_callchain);
+  }
+}
+
+?>
\ No newline at end of file

Added: 3.x/trunk/limb/cms/tests/cases/controller/AdminNodeWithObjectControllerTest.class.php
===================================================================
--- 3.x/trunk/limb/cms/tests/cases/controller/AdminNodeWithObjectControllerTest.class.php	                        (rev 0)
+++ 3.x/trunk/limb/cms/tests/cases/controller/AdminNodeWithObjectControllerTest.class.php	2007-06-13 14:00:24 UTC (rev 5991)
@@ -0,0 +1,182 @@
+<?php
+/*
+ * Limb PHP Framework
+ *
+ * @link http://limb-project.com
+ * @copyright Copyright &copy; 2004-2007 BIT(http://bit-creative.com)
+ * @license LGPL http://www.gnu.org/copyleft/lesser.html
+ */
+lmb_require('limb/cms/src/controller/AdminNodeWithObjectController.class.php');
+lmb_require('limb/active_record/src/lmbActiveRecord.class.php');
+lmb_require('limb/net/src/lmbHttpRequest.class.php');
+lmb_require('limb/web_app/src/tests/lmbWebApplicationSandbox.class.php');
+
+class NodeObjectForTesting extends lmbActiveRecord
+{
+  protected $_db_table_name = 'object_for_testing';
+
+  protected function _createValidator()
+  {
+    $validator = new lmbValidator();
+    $validator->addRequiredRule('field');
+    return $validator;
+  }
+}
+
+class TestAdminNodeWithObjectController extends AdminNodeWithObjectController
+{
+  protected $_object_class_name = 'NodeObjectForTesting';
+  protected $_controller_name = 'node';
+  protected $in_popup = false;
+
+  protected function _onBeforeSave() { $this->response->append('onBeforeSave|'); }
+  protected function _onAfterSave() { $this->response->append('onAfterSave|'); }
+
+  protected function _onBeforeValidate() { $this->response->append('onBeforeValidate|'); }
+  protected function _onAfterValidate() { $this->response->append('onAfterValidate|'); }
+
+  protected function _onBeforeCreate() { $this->response->append('onBeforeCreate|'); }
+  protected function _onAfterCreate() { $this->response->append('onAfterCreate|'); }
+
+  protected function _onBeforeEdit() { $this->response->append('onBeforeEdit|'); }
+  protected function _onAfterEdit() { $this->response->append('onAfterEdit|'); }
+
+  protected function _onBeforeDelete() { $this->response->append('onBeforeDelete|'); }
+  protected function _onAfterDelete() { $this->response->append('onAfterDelete|'); }
+
+  protected function _initCreateForm() { $this->response->append('initCreateForm|'); }
+  protected function _initEditForm() { $this->response->append('initEditForm|'); }
+}
+
+class AdminNodeWithObjectControllerTest extends UnitTestCase
+{
+  protected $toolkit;
+
+  function setUp()
+  {
+    $this->toolkit = lmbToolkit :: save();
+    $this->_cleanUp();
+  }
+
+  function tearDown()
+  {
+    lmbToolkit :: restore();
+    $this->_cleanUp();
+  }
+
+  function _cleanUp()
+  {
+    try
+    {
+      lmbActiveRecord :: delete('lmbCmsNode');
+      lmbActiveRecord :: delete('ObjectForTesting');
+    }
+    catch(lmbException $e) {}
+  }
+
+  function testEventsOnPerformCreateActionFirstTime()
+  {
+    $request = new lmbHttpRequest('/test_admin_node_with_object/create');
+
+    $app = new lmbWebApplicationSandbox();
+    $response = $app->imitate($request);
+
+    $this->assertEqual($response->getResponseString(), 'initCreateForm|');
+  }
+
+  function testEventsOnPerformCreateActionWithPost()
+  {
+    $request = new lmbHttpRequest('/test_admin_node_with_object/create', array(), array('title' => 'test',
+                                                                                        'identifier' => 'test',
+                                                                                        'field' => 'test'));
+
+    $app = new lmbWebApplicationSandbox();
+    $response = $app->imitate($request);
+
+    $expected_callchain = 'onBeforeValidate|onAfterValidate|onBeforeCreate|onBeforeSave|onAfterSave|onAfterCreate|';
+    $this->assertEqual($response->getResponseString(), $expected_callchain);
+  }
+
+  function testEventsOnPerformCreateActionWithPostNotValid()
+  {
+    $request = new lmbHttpRequest('/test_admin_node_with_object/create', array(), array('title' => ''));
+
+    $app = new lmbWebApplicationSandbox();
+    $response = $app->imitate($request);
+
+    $expected_callchain = 'onBeforeValidate|onAfterValidate|';
+    $this->assertEqual($response->getResponseString(), $expected_callchain);
+  }
+
+  function testEventsOnPerformEditActionFirstTime()
+  {
+    $node = new lmbCmsNode();
+    $node->setIdentifier('test');
+    $node->setTitle('test');
+    $node->save();
+
+    $request = new lmbHttpRequest('/test_admin_node_with_object/edit/' . $node->getId());
+
+    $app = new lmbWebApplicationSandbox();
+    $response = $app->imitate($request);
+
+    $this->assertEqual($response->getResponseString(), 'initEditForm|');
+  }
+
+  function testEventsOnPerformEditActionWithPostNotValid()
+  {
+    $node = $this->_createNodeWithObject();
+
+    $request = new lmbHttpRequest('/test_admin_node_with_object/edit/' . $node->getId(), array(), array('id' => $node->getId(), 'title' => ''));
+
+    $app = new lmbWebApplicationSandbox();
+    $response = $app->imitate($request);
+
+    $expected_callchain = 'onBeforeValidate|onAfterValidate|';
+    $this->assertEqual($response->getResponseString(), $expected_callchain);
+  }
+
+  function testEventsOnPerformEditActionWithPost()
+  {
+    $node = $this->_createNodeWithObject();
+
+    $request = new lmbHttpRequest('/test_admin_node_with_object/edit/' . $node->getId(), array(), array('id' => $node->getId()));
+
+    $app = new lmbWebApplicationSandbox();
+    $response = $app->imitate($request);
+
+    $expected_callchain = 'onBeforeValidate|onAfterValidate|onBeforeEdit|onBeforeSave|onAfterSave|onAfterEdit|';
+    $this->assertEqual($response->getResponseString(), $expected_callchain);
+  }
+
+  function testEventsOnPerformDeleteAction()
+  {
+    $node = $this->_createNodeWithObject();
+
+    $request = new lmbHttpRequest('/test_admin_node_with_object/delete/' . $node->getId(), array(), array('id' => $node->getId()));
+
+    $app = new lmbWebApplicationSandbox();
+    $response = $app->imitate($request);
+
+    $expected_callchain = 'onBeforeDelete|onAfterDelete|';
+    $this->assertEqual($response->getResponseString(), $expected_callchain);
+  }
+
+  protected function _createNodeWithObject()
+  {
+    $node = new lmbCmsNode();
+    $node->setIdentifier('test');
+    $node->setTitle('test');
+
+    $object = new NodeObjectForTesting();
+    $object->setField('test');
+    $node->setObject($object);
+    $object->setNode($node);
+
+    $object->save();
+    $node->save();
+    return $node;
+  }
+}
+
+?>
\ No newline at end of file

Added: 3.x/trunk/limb/cms/tests/cases/controller/AdminObjectControllerTest.class.php
===================================================================
--- 3.x/trunk/limb/cms/tests/cases/controller/AdminObjectControllerTest.class.php	                        (rev 0)
+++ 3.x/trunk/limb/cms/tests/cases/controller/AdminObjectControllerTest.class.php	2007-06-13 14:00:24 UTC (rev 5991)
@@ -0,0 +1,161 @@
+<?php
+/*
+ * Limb PHP Framework
+ *
+ * @link http://limb-project.com
+ * @copyright Copyright &copy; 2004-2007 BIT(http://bit-creative.com)
+ * @license LGPL http://www.gnu.org/copyleft/lesser.html
+ */
+lmb_require('limb/cms/src/controller/AdminObjectController.class.php');
+lmb_require('limb/active_record/src/lmbActiveRecord.class.php');
+lmb_require('limb/net/src/lmbHttpRequest.class.php');
+lmb_require('limb/web_app/src/tests/lmbWebApplicationSandbox.class.php');
+
+class ObjectForTesting extends lmbActiveRecord
+{
+  protected function _createValidator()
+  {
+    $validator = new lmbValidator();
+    $validator->addRequiredRule('field');
+    return $validator;
+  }
+}
+
+class TestAdminObjectController extends AdminObjectController
+{
+  protected $_object_class_name = 'ObjectForTesting';
+  protected $in_popup = false;
+
+  protected function _onBeforeSave() { $this->response->append('onBeforeSave|'); }
+  protected function _onAfterSave() { $this->response->append('onAfterSave|'); }
+
+  protected function _onBeforeValidate() { $this->response->append('onBeforeValidate|'); }
+  protected function _onAfterValidate() { $this->response->append('onAfterValidate|'); }
+
+  protected function _onBeforeCreate() { $this->response->append('onBeforeCreate|'); }
+  protected function _onAfterCreate() { $this->response->append('onAfterCreate|'); }
+
+  protected function _onBeforeEdit() { $this->response->append('onBeforeEdit|'); }
+  protected function _onAfterEdit() { $this->response->append('onAfterEdit|'); }
+
+  protected function _onBeforeDelete() { $this->response->append('onBeforeDelete|'); }
+  protected function _onAfterDelete() { $this->response->append('onAfterDelete|'); }
+
+  protected function _initCreateForm() { $this->response->append('initCreateForm|'); }
+  protected function _initEditForm() { $this->response->append('initEditForm|'); }
+}
+
+class AdminObjectControllerTest extends UnitTestCase
+{
+  protected $toolkit;
+
+  function setUp()
+  {
+    $this->toolkit = lmbToolkit :: save();
+    $this->_cleanUp();
+  }
+
+  function tearDown()
+  {
+    $this->_cleanUp();
+    lmbToolkit :: restore();
+  }
+
+  function _cleanUp()
+  {
+    lmbActiveRecord :: delete('ObjectForTesting');
+  }
+
+  function testEventsOnPerformCreateActionFirstTime()
+  {
+    $request = new lmbHttpRequest('/test_admin_object/create');
+
+    $app = new lmbWebApplicationSandbox();
+    $response = $app->imitate($request);
+
+    $this->assertEqual($response->getResponseString(), 'initCreateForm|');
+  }
+
+  function testEventsOnPerformCreateActionWithPost()
+  {
+    $request = new lmbHttpRequest('/test_admin_object/create', array(), array('field' => 'test'));
+
+    $app = new lmbWebApplicationSandbox();
+    $response = $app->imitate($request);
+
+    $expected_callchain = 'onBeforeValidate|onAfterValidate|onBeforeCreate|onBeforeSave|onAfterSave|onAfterCreate|';
+    $this->assertEqual($response->getResponseString(), $expected_callchain);
+  }
+
+  function testEventsOnPerformCreateActionWithPostNotValid()
+  {
+    $request = new lmbHttpRequest('/test_admin_object/create', array(), array('field' => ''));
+
+    $app = new lmbWebApplicationSandbox();
+    $response = $app->imitate($request);
+
+    $expected_callchain = 'onBeforeValidate|onAfterValidate|';
+    $this->assertEqual($response->getResponseString(), $expected_callchain);
+  }
+
+  function testEventsOnPerformEditActionFirstTime()
+  {
+    $object = new ObjectForTesting();
+    $object->setField('test');
+    $object->save();
+
+    $request = new lmbHttpRequest('/test_admin_object/edit/' . $object->getId());
+
+    $app = new lmbWebApplicationSandbox();
+    $response = $app->imitate($request);
+
+    $this->assertEqual($response->getResponseString(), 'initEditForm|');
+  }
+
+  function testEventsOnPerformEditActionWithPostNotValid()
+  {
+    $object = new ObjectForTesting();
+    $object->setField('test');
+    $object->save();
+
+    $request = new lmbHttpRequest('/test_admin_object/edit/' . $object->getId(), array(), array('id' => $object->getId(), 'field' => ''));
+
+    $app = new lmbWebApplicationSandbox();
+    $response = $app->imitate($request);
+
+    $expected_callchain = 'onBeforeValidate|onAfterValidate|';
+    $this->assertEqual($response->getResponseString(), $expected_callchain);
+  }
+
+  function testEventsOnPerformEditActionWithPost()
+  {
+    $object = new ObjectForTesting();
+    $object->setField('test');
+    $object->save();
+
+    $request = new lmbHttpRequest('/test_admin_object/edit/' . $object->getId(), array(), array('id' => $object->getId()));
+
+    $app = new lmbWebApplicationSandbox();
+    $response = $app->imitate($request);
+
+    $expected_callchain = 'onBeforeValidate|onAfterValidate|onBeforeEdit|onBeforeSave|onAfterSave|onAfterEdit|';
+    $this->assertEqual($response->getResponseString(), $expected_callchain);
+  }
+
+  function testEventsOnPerformDeleteAction()
+  {
+    $object = new ObjectForTesting();
+    $object->setField('test');
+    $object->save();
+
+    $request = new lmbHttpRequest('/test_admin_object/delete/' . $object->getId(), array(), array('id' => $object->getId()));
+
+    $app = new lmbWebApplicationSandbox();
+    $response = $app->imitate($request);
+
+    $expected_callchain = 'onBeforeDelete|onAfterDelete|';
+    $this->assertEqual($response->getResponseString(), $expected_callchain);
+  }
+}
+
+?>
\ No newline at end of file



More information about the limb-svn mailing list