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.

75 lines
2.3 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. Config::set('DEBUG', false);
  20. Env::setParams(array('param1' => 'value1', 'param2' => 'value2'));
  21. $action = $this->getMockForAbstractClass('Action' );
  22. $this->assertSame('value1', $action->param1);
  23. }
  24. /**
  25. * @runInSeparateProcess
  26. */
  27. public function testFetch()
  28. {
  29. Config::set('DEBUG', false);
  30. $load = new ReflectionClass('Load');
  31. $classes = $load->getProperty('autoload');
  32. $classes->setAccessible(true);
  33. $classes->setValue('autoload', array('ActionMock' =>'some/path/to/action.php'));
  34. Env::setParams(array('template' => 'SomeTemplate', 'param2' => 'value2'));
  35. $controller = FrontController::getInstance();
  36. $controller->setView('SomeView');
  37. $action = $this->getMockForAbstractClass('Action', array(), 'ActionMock');
  38. $result = $action->fetch();
  39. $this->assertSame('/actions/to/SomeTemplate', $result['template']);
  40. }
  41. /**
  42. * @runInSeparateProcess
  43. */
  44. public function testFetchNoTemplate()
  45. {
  46. Config::set('DEBUG', false);
  47. Env::setParams(array('template' => ''));
  48. $controller = FrontController::getInstance();
  49. $controller->setView('SomeView');
  50. $action = $this->getMockForAbstractClass('Action', array(), 'ActionMock');
  51. $result = $action->fetch();
  52. $this->assertSame('/actions//Acti', $result['template']);
  53. }
  54. /**
  55. * @runInSeparateProcess
  56. */
  57. public function testRedirect()
  58. {
  59. set_exit_overload(function() { return false; });
  60. Config::set('DEBUG', false);
  61. $load = new ReflectionClass('Action');
  62. $redirect = $load->getMethod('redirect');
  63. $redirect->setAccessible(true);
  64. $action = $this->getMockForAbstractClass('Action', array(), 'ActionMock');
  65. $this->assertNull($redirect->invoke($action, '/some/url'));
  66. unset_exit_overload();
  67. }
  68. }