/application/modules/catalogue/controllers/TestController.php
PHP | 150 lines | 92 code | 55 blank | 3 comment | 5 complexity | 97076bbeda2a3c20f26bad77ae2fdb73 MD5 | raw file
Possible License(s): LGPL-2.1
- <?php
-
- class Catalogue_TestController extends Zend_Controller_Action {
-
- function init() {
- parent::init();
-
- //????????? ?????? ???????
- Workset_Module::loadModule('catalogue');
- }
-
- function objectAction() {
- $this->_helper->viewRenderer->setNoRender(true);
- try {
-
- $data = array(
- 'title' => 'object text 1',
- 'preview_text' => "preview",
- 'text' => "detail",
- 'created' => time()
- );
-
- $object = Catalogue_Model_Object::create($data);
-
- exprTest($object instanceof Catalogue_Model_Object, null, '?????? Catalogue_Model_Object');
- exprTest(array_intersect_key($object->toArray(), $data) == $data, null, '???? ?????????? ???????');
-
- exprTest(!$object->isModified(), null, '????? ??????, ??????? ? ?????? ? ????');
-
- $id = $object->save();
- exprTest($id > 0, null, '?????????? ???????');
-
- exprTest($object->getId() == $id, null, 'ID ???????????? ???????');
-
- $object->setData(array(
- 'title' => 'new title'
- ));
-
- exprTest(array_intersect_key($object->toArray(), $data) != $data, null, '????????? ????? ???????');
-
- exprTest($object->isModified(), null, '?????? ??????? ?????????');
-
- exprTest($object->updateData() === $id, null, '?????????? ??????? ? ????');
-
- exprTest(!$object->isModified(), null, '?????? ?? ??????? ????????? ????? ??????????');
-
- $data = array_intersect_key($object->toArray(), $data);
- $object['title'] = 'new title 2';
-
- exprTest(array_intersect_key($object->toArray(), $data) != $data, null, '????????? ????? ???????');
-
- exprTest($object->isModified(), null, '?????? ??????? ?????????');
-
- exprTest($object->updateData() === $id, null, '?????????? ??????? ? ????');
-
- exprTest(!$object->isModified(), null, '?????? ?? ??????? ????????? ????? ??????????');
-
- exprTest($object->delete() === $id, null, '???????? ??????? ? ????');
-
- try {
- $object = Catalogue_Model_Object::getInstance($id);
- } catch (Workset_Model_Exception $e) {
- exprTest(true, null, '????????????? ???????? ???????');
- }
-
-
- } catch (Zend_Exception $e) {
- echo $e->getMessage();
- }
- }
-
- function categoryAction() {
- $this->_helper->viewRenderer->setNoRender(true);
- try {
-
- //???????? ????? ?????????
- $category = Catalogue_Model_Category::create(array(
- 'name' => 'My category',
- 'code' => 'my_category',
- 'type' => 'my_type',
- 'description' => 'My description',
- ));
-
- exprTest($category instanceof Catalogue_Model_Category, null, '?????? Catalogue_Model_Category');
-
- exprTest(!$category->isModified(), null, '?????? ?? ????? ?????????');
-
- $category['description'] = 'new description';
-
- exprTest(!$category->isModified(), null, '?????? ?? ????? ?????????');
-
- $id = $category->save();
-
- exprTest($id > 0, null, '??????? ID ??????????? ?????????');
-
- $category['description'] = 'new description';
-
- exprTest($category->isModified(), null, '?????? ??????? ?????????');
-
- $id = $category->save();
-
- exprTest(!$category->isModified(), null, '?????? ?? ????? ????????? ????? ??????????');
-
- //?????????? ????????????
- $subcategory = Catalogue_Model_Category::create(array(
- 'name' => 'Subcategory',
- 'code' => 'subcategory',
- 'parent_id' => $id
- ));
-
- exprTest($subcategory->hasParent(), null, '???????????? ?????????');
-
- $subId = $subcategory->save();
-
- exprTest($subcategory->hasParent(), null, '???????????? ?????????');
-
- exprTest($subId > 0, null, '??????? ID ??????????? ????????????');
-
- exprTest($subcategory->getParentId() == $id, null, 'ID ???????????? ?????????');
-
- $category = Catalogue_Model_Category::getInstance($id);
-
- exprTest(!$category->isEmpty(), null, '???????????? ????????? ?? ??????');
-
- $subId = $subcategory->delete();
-
- exprTest($subId > 0, null, 'ID ????????? ????????????');
-
- $category = Catalogue_Model_Category::getInstance($id);
-
- exprTest($category->isEmpty(), null, '???????????? ????????? ??????');
-
- $id = $category->delete();
-
- exprTest($id > 0, null, 'ID ????????? ?????????');
-
- try {
- Catalogue_Model_Category::getInstance($id);
- } catch (Workset_Model_Exception $e) {
- exprTest(true, null, '????????????? ???????? ?????????');
- }
-
- } catch (Zend_Exception $e) {
- echo $e->getMessage();
- }
-
- }
-
- }
-