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.

82 lines
2.4 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 Action class
  10. */
  11. require_once dirname(__FILE__) . '/Action_TestCase.php';
  12. class ActionTest extends Action_TestCase
  13. {
  14. /**
  15. * @runInSeparateProcess
  16. */
  17. public function testActionConstructWithParams()
  18. {
  19. if(!defined('DEBUG')) {
  20. define('DEBUG', false);
  21. }
  22. Env::setParams(array('param1' => 'value1', 'param2' => 'value2'));
  23. $action = $this->getMockForAbstractClass('Action' );
  24. $this->assertSame('value1', $action->param1);
  25. }
  26. /**
  27. * @runInSeparateProcess
  28. */
  29. public function testFetch()
  30. {
  31. if(!defined('DEBUG')) {
  32. define('DEBUG', false);
  33. }
  34. $load = new ReflectionClass('Load');
  35. $classes = $load->getProperty('autoload');
  36. $classes->setAccessible(true);
  37. $classes->setValue('autoload', array('ActionMock' =>'some/path/to/action.php'));
  38. Env::setParams(array('template' => 'SomeTemplate', 'param2' => 'value2'));
  39. $controller = FrontController::getInstance();
  40. $controller->setView('SomeView');
  41. $action = $this->getMockForAbstractClass('Action', array(), 'ActionMock');
  42. $result = $action->fetch();
  43. $this->assertSame('/actions/to/SomeTemplate', $result['template']);
  44. }
  45. /**
  46. * @runInSeparateProcess
  47. */
  48. public function testFetchNoTemplate()
  49. {
  50. if(!defined('DEBUG')) {
  51. define('DEBUG', false);
  52. }
  53. Env::setParams(array('template' => ''));
  54. $controller = FrontController::getInstance();
  55. $controller->setView('SomeView');
  56. $action = $this->getMockForAbstractClass('Action', array(), 'ActionMock');
  57. $result = $action->fetch();
  58. $this->assertSame('/actions//Acti', $result['template']);
  59. }
  60. /**
  61. * @runInSeparateProcess
  62. */
  63. public function testRedirect()
  64. {
  65. set_exit_overload(function() { return false; });
  66. if(!defined('DEBUG')) {
  67. define('DEBUG', false);
  68. }
  69. $load = new ReflectionClass('Action');
  70. $redirect = $load->getMethod('redirect');
  71. $redirect->setAccessible(true);
  72. $action = $this->getMockForAbstractClass('Action', array(), 'ActionMock');
  73. $this->assertNull($redirect->invoke($action, '/some/url'));
  74. unset_exit_overload();
  75. }
  76. }