PageRenderTime 38ms CodeModel.GetById 11ms RepoModel.GetById 0ms app.codeStats 0ms

/application/modules/catalogue/controllers/TestController.php

http://myzapp.googlecode.com/
PHP | 150 lines | 92 code | 55 blank | 3 comment | 5 complexity | 97076bbeda2a3c20f26bad77ae2fdb73 MD5 | raw file
Possible License(s): LGPL-2.1
  1. <?php
  2. class Catalogue_TestController extends Zend_Controller_Action {
  3. function init() {
  4. parent::init();
  5. //????????? ?????? ???????
  6. Workset_Module::loadModule('catalogue');
  7. }
  8. function objectAction() {
  9. $this->_helper->viewRenderer->setNoRender(true);
  10. try {
  11. $data = array(
  12. 'title' => 'object text 1',
  13. 'preview_text' => "preview",
  14. 'text' => "detail",
  15. 'created' => time()
  16. );
  17. $object = Catalogue_Model_Object::create($data);
  18. exprTest($object instanceof Catalogue_Model_Object, null, '?????? Catalogue_Model_Object');
  19. exprTest(array_intersect_key($object->toArray(), $data) == $data, null, '???? ?????????? ???????');
  20. exprTest(!$object->isModified(), null, '????? ??????, ??????? ? ?????? ? ????');
  21. $id = $object->save();
  22. exprTest($id > 0, null, '?????????? ???????');
  23. exprTest($object->getId() == $id, null, 'ID ???????????? ???????');
  24. $object->setData(array(
  25. 'title' => 'new title'
  26. ));
  27. exprTest(array_intersect_key($object->toArray(), $data) != $data, null, '????????? ????? ???????');
  28. exprTest($object->isModified(), null, '?????? ??????? ?????????');
  29. exprTest($object->updateData() === $id, null, '?????????? ??????? ? ????');
  30. exprTest(!$object->isModified(), null, '?????? ?? ??????? ????????? ????? ??????????');
  31. $data = array_intersect_key($object->toArray(), $data);
  32. $object['title'] = 'new title 2';
  33. exprTest(array_intersect_key($object->toArray(), $data) != $data, null, '????????? ????? ???????');
  34. exprTest($object->isModified(), null, '?????? ??????? ?????????');
  35. exprTest($object->updateData() === $id, null, '?????????? ??????? ? ????');
  36. exprTest(!$object->isModified(), null, '?????? ?? ??????? ????????? ????? ??????????');
  37. exprTest($object->delete() === $id, null, '???????? ??????? ? ????');
  38. try {
  39. $object = Catalogue_Model_Object::getInstance($id);
  40. } catch (Workset_Model_Exception $e) {
  41. exprTest(true, null, '????????????? ???????? ???????');
  42. }
  43. } catch (Zend_Exception $e) {
  44. echo $e->getMessage();
  45. }
  46. }
  47. function categoryAction() {
  48. $this->_helper->viewRenderer->setNoRender(true);
  49. try {
  50. //???????? ????? ?????????
  51. $category = Catalogue_Model_Category::create(array(
  52. 'name' => 'My category',
  53. 'code' => 'my_category',
  54. 'type' => 'my_type',
  55. 'description' => 'My description',
  56. ));
  57. exprTest($category instanceof Catalogue_Model_Category, null, '?????? Catalogue_Model_Category');
  58. exprTest(!$category->isModified(), null, '?????? ?? ????? ?????????');
  59. $category['description'] = 'new description';
  60. exprTest(!$category->isModified(), null, '?????? ?? ????? ?????????');
  61. $id = $category->save();
  62. exprTest($id > 0, null, '??????? ID ??????????? ?????????');
  63. $category['description'] = 'new description';
  64. exprTest($category->isModified(), null, '?????? ??????? ?????????');
  65. $id = $category->save();
  66. exprTest(!$category->isModified(), null, '?????? ?? ????? ????????? ????? ??????????');
  67. //?????????? ????????????
  68. $subcategory = Catalogue_Model_Category::create(array(
  69. 'name' => 'Subcategory',
  70. 'code' => 'subcategory',
  71. 'parent_id' => $id
  72. ));
  73. exprTest($subcategory->hasParent(), null, '???????????? ?????????');
  74. $subId = $subcategory->save();
  75. exprTest($subcategory->hasParent(), null, '???????????? ?????????');
  76. exprTest($subId > 0, null, '??????? ID ??????????? ????????????');
  77. exprTest($subcategory->getParentId() == $id, null, 'ID ???????????? ?????????');
  78. $category = Catalogue_Model_Category::getInstance($id);
  79. exprTest(!$category->isEmpty(), null, '???????????? ????????? ?? ??????');
  80. $subId = $subcategory->delete();
  81. exprTest($subId > 0, null, 'ID ????????? ????????????');
  82. $category = Catalogue_Model_Category::getInstance($id);
  83. exprTest($category->isEmpty(), null, '???????????? ????????? ??????');
  84. $id = $category->delete();
  85. exprTest($id > 0, null, 'ID ????????? ?????????');
  86. try {
  87. Catalogue_Model_Category::getInstance($id);
  88. } catch (Workset_Model_Exception $e) {
  89. exprTest(true, null, '????????????? ???????? ?????????');
  90. }
  91. } catch (Zend_Exception $e) {
  92. echo $e->getMessage();
  93. }
  94. }
  95. }