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.

62 lines
1.7 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. Config::set('DEBUG', 0);
  21. Env::setParams(array('ajax' => 'AjaxTemplate', 'param2' => 'value2'));
  22. $action = $this->getMockForAbstractClass('AjaxAction' );
  23. $this->assertAttributeEquals('ajax', 'template', $action);
  24. }
  25. /**
  26. * @runInSeparateProcess
  27. */
  28. public function testFetchWithEncode()
  29. {
  30. Config::set('DEBUG', 0);
  31. $controller = FrontController::getInstance();
  32. $controller->setView('SomeView');
  33. $action = $this->getMockForAbstractClass('AjaxAction' );
  34. $action->data = array('var' => 'val');
  35. $result = $action->fetch();
  36. $this->assertSame('/actions//ajax', $result['template']);
  37. $this->assertSame('{"var":"val"}', $result['data']);
  38. }
  39. /**
  40. * @runInSeparateProcess
  41. */
  42. public function testFetchNoEncode()
  43. {
  44. Config::set('DEBUG', 0);
  45. Env::setParams(array('encode' => false));
  46. $controller = FrontController::getInstance();
  47. $controller->setView('SomeView');
  48. $action = $this->getMockForAbstractClass('AjaxAction' );
  49. $action->data = array('var' => 'val');
  50. $result = $action->fetch();
  51. $this->assertSame('/actions//ajax', $result['template']);
  52. $this->assertSame( $action->data, $result['data']);
  53. }
  54. }