| [ Index ] |
PHP Cross Reference of Limb3 |
[Summary view] [Print] [Text view]
1 <?php 2 /* 3 * Limb PHP Framework 4 * 5 * @link http://limb-project.com 6 * @copyright Copyright © 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/AdminObjectController.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 ObjectForTesting extends lmbActiveRecord 15 { 16 protected function _createValidator() 17 { 18 $validator = new lmbValidator(); 19 $validator->addRequiredRule('field'); 20 return $validator; 21 } 22 } 23 24 class TestAdminObjectController extends AdminObjectController 25 { 26 protected $_object_class_name = 'ObjectForTesting'; 27 protected $in_popup = false; 28 29 protected function _onBeforeSave() { $this->response->append('onBeforeSave|'); } 30 protected function _onAfterSave() { $this->response->append('onAfterSave|'); } 31 32 protected function _onBeforeValidate() { $this->response->append('onBeforeValidate|'); } 33 protected function _onAfterValidate() { $this->response->append('onAfterValidate|'); } 34 35 protected function _onBeforeCreate() { $this->response->append('onBeforeCreate|'); } 36 protected function _onAfterCreate() { $this->response->append('onAfterCreate|'); } 37 38 protected function _onBeforeEdit() { $this->response->append('onBeforeEdit|'); } 39 protected function _onAfterEdit() { $this->response->append('onAfterEdit|'); } 40 41 protected function _onBeforeDelete() { $this->response->append('onBeforeDelete|'); } 42 protected function _onAfterDelete() { $this->response->append('onAfterDelete|'); } 43 44 protected function _initCreateForm() { $this->response->append('initCreateForm|'); } 45 protected function _initEditForm() { $this->response->append('initEditForm|'); } 46 } 47 48 class AdminObjectControllerTest extends UnitTestCase 49 { 50 protected $toolkit; 51 52 function setUp() 53 { 54 $this->toolkit = lmbToolkit :: save(); 55 $this->_cleanUp(); 56 } 57 58 function tearDown() 59 { 60 $this->_cleanUp(); 61 lmbToolkit :: restore(); 62 } 63 64 function _cleanUp() 65 { 66 lmbActiveRecord :: delete('ObjectForTesting'); 67 } 68 69 function testEventsOnPerformCreateActionFirstTime() 70 { 71 $request = new lmbHttpRequest('/test_admin_object/create'); 72 73 $app = new lmbWebApplicationSandbox(); 74 $response = $app->imitate($request); 75 76 $this->assertEqual($response->getResponseString(), 'initCreateForm|'); 77 } 78 79 function testEventsOnPerformCreateActionWithPost() 80 { 81 $request = new lmbHttpRequest('/test_admin_object/create', array(), array('field' => 'test')); 82 83 $app = new lmbWebApplicationSandbox(); 84 $response = $app->imitate($request); 85 86 $expected_callchain = 'onBeforeValidate|onAfterValidate|onBeforeCreate|onBeforeSave|onAfterSave|onAfterCreate|'; 87 $this->assertEqual($response->getResponseString(), $expected_callchain); 88 } 89 90 function testEventsOnPerformCreateActionWithPostNotValid() 91 { 92 $request = new lmbHttpRequest('/test_admin_object/create', array(), array('field' => '')); 93 94 $app = new lmbWebApplicationSandbox(); 95 $response = $app->imitate($request); 96 97 $expected_callchain = 'onBeforeValidate|onAfterValidate|'; 98 $this->assertEqual($response->getResponseString(), $expected_callchain); 99 } 100 101 function testEventsOnPerformEditActionFirstTime() 102 { 103 $object = new ObjectForTesting(); 104 $object->setField('test'); 105 $object->save(); 106 107 $request = new lmbHttpRequest('/test_admin_object/edit/' . $object->getId()); 108 109 $app = new lmbWebApplicationSandbox(); 110 $response = $app->imitate($request); 111 112 $this->assertEqual($response->getResponseString(), 'initEditForm|'); 113 } 114 115 function testEventsOnPerformEditActionWithPostNotValid() 116 { 117 $object = new ObjectForTesting(); 118 $object->setField('test'); 119 $object->save(); 120 121 $request = new lmbHttpRequest('/test_admin_object/edit/' . $object->getId(), array(), array('id' => $object->getId(), 'field' => '')); 122 123 $app = new lmbWebApplicationSandbox(); 124 $response = $app->imitate($request); 125 126 $expected_callchain = 'onBeforeValidate|onAfterValidate|'; 127 $this->assertEqual($response->getResponseString(), $expected_callchain); 128 } 129 130 function testEventsOnPerformEditActionWithPost() 131 { 132 $object = new ObjectForTesting(); 133 $object->setField('test'); 134 $object->save(); 135 136 $request = new lmbHttpRequest('/test_admin_object/edit/' . $object->getId(), array(), array('id' => $object->getId())); 137 138 $app = new lmbWebApplicationSandbox(); 139 $response = $app->imitate($request); 140 141 $expected_callchain = 'onBeforeValidate|onAfterValidate|onBeforeEdit|onBeforeSave|onAfterSave|onAfterEdit|'; 142 $this->assertEqual($response->getResponseString(), $expected_callchain); 143 } 144 145 function testEventsOnPerformDeleteAction() 146 { 147 $object = new ObjectForTesting(); 148 $object->setField('test'); 149 $object->save(); 150 151 $request = new lmbHttpRequest('/test_admin_object/delete/' . $object->getId(), array(), array('id' => $object->getId())); 152 153 $app = new lmbWebApplicationSandbox(); 154 $response = $app->imitate($request); 155 156 $expected_callchain = 'onBeforeDelete|onAfterDelete|'; 157 $this->assertEqual($response->getResponseString(), $expected_callchain); 158 } 159 } 160 161 ?>
title
Description
Body
title
Description
Body
title
Description
Body
title
Body
| Generated: Fri Dec 5 04:05:07 2008 | Cross-referenced by PHPXref 0.7 |