You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

65 lines
1.9 KiB

  1. <?php
  2. /*
  3. * @copyright NetMonsters <team@netmonsters.ru>
  4. * @link http://netmonsters.ru
  5. * @package Majestic
  6. * @subpackage UnitTests
  7. * @since 2011-11-1
  8. *
  9. * Unit tests for AjaxAction class
  10. */
  11. require_once dirname(__FILE__) . '/Action_TestCase.php';
  12. require_once dirname(__FILE__) . '/../../app/AjaxAction.php';
  13. class AjaxActionTest extends Action_TestCase
  14. {
  15. /**
  16. * @runInSeparateProcess
  17. */
  18. public function testConstruct()
  19. {
  20. if(!defined('DEBUG')) {
  21. define('DEBUG', false);
  22. }
  23. Env::setParams(array('ajax' => 'AjaxTemplate', 'param2' => 'value2'));
  24. $action = $this->getMockForAbstractClass('AjaxAction' );
  25. $this->assertAttributeEquals('ajax', 'template', $action);
  26. }
  27. /**
  28. * @runInSeparateProcess
  29. */
  30. public function testFetchWithEncode()
  31. {
  32. if(!defined('DEBUG')) {
  33. define('DEBUG', false);
  34. }
  35. $controller = FrontController::getInstance();
  36. $controller->setView('SomeView');
  37. $action = $this->getMockForAbstractClass('AjaxAction' );
  38. $action->data = array('var' => 'val');
  39. $result = $action->fetch();
  40. $this->assertSame('/actions//ajax', $result['template']);
  41. $this->assertSame('{"var":"val"}', $result['data']);
  42. }
  43. /**
  44. * @runInSeparateProcess
  45. */
  46. public function testFetchNoEncode()
  47. {
  48. if(!defined('DEBUG')) {
  49. define('DEBUG', false);
  50. }
  51. Env::setParams(array('encode' => false));
  52. $controller = FrontController::getInstance();
  53. $controller->setView('SomeView');
  54. $action = $this->getMockForAbstractClass('AjaxAction' );
  55. $action->data = array('var' => 'val');
  56. $result = $action->fetch();
  57. $this->assertSame('/actions//ajax', $result['template']);
  58. $this->assertSame( $action->data, $result['data']);
  59. }
  60. }