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.3 KiB

  1. <?php
  2. /**
  3. * @copyright NetMonsters <team@netmonsters.ru>
  4. * @link http://netmonsters.ru
  5. * @package Majestic
  6. * @subpackage UnitTests
  7. * @since 04-06-2012
  8. * @user: agrebnev
  9. */
  10. require_once dirname(__FILE__) . '/../../Registry.php';
  11. require_once dirname(__FILE__) . '/../../Config.php';
  12. require_once dirname(__FILE__) . '/../../exception/ErrorHandler.php';
  13. require_once dirname(__FILE__) . '/../../exception/GeneralException.php';
  14. require_once dirname(__FILE__) . '/../../app/FrontController.php';
  15. require_once dirname(__FILE__) . '/../../layout/Layout.php';
  16. require_once dirname(__FILE__) . '/../../layout/Error.layout.php';
  17. /**
  18. * @runTestsInSeparateProcesses
  19. */
  20. class ErrorLayoutTest extends PHPUnit_Framework_TestCase
  21. {
  22. public function run(PHPUnit_Framework_TestResult $result = NULL)
  23. {
  24. $this->setPreserveGlobalState(false);
  25. return parent::run($result);
  26. }
  27. public function setUp()
  28. {
  29. if (!class_exists('RouterMock')) {
  30. $this->getMock('Router', array(), array(), 'RouterMock', false);
  31. }
  32. if (!class_exists('PHPViewMock')) {
  33. $this->getMock('PHPView', array('fetch', 'append', 'prepend', 'assign', 'getTemplate'), array(), 'PHPViewMock', false);
  34. }
  35. set_new_overload(array($this, 'newCallback'));
  36. }
  37. public function testSetException()
  38. {
  39. Config::set('DEBUG', false);
  40. $layout = new ErrorLayout();
  41. $layout->setException(new GeneralException());
  42. $this->assertAttributeInstanceOf('GeneralException', 'exception', $layout);
  43. }
  44. public function testExecute()
  45. {
  46. Config::set('DEBUG', false);
  47. $action = $this->getMock('Action', array('fetch'));
  48. $action->expects($this->once())
  49. ->method('fetch')
  50. ->will($this->returnValue('this is the result of Action::fetch()'));
  51. $layout = new ErrorLayout();
  52. $layout->fetch($action);
  53. }
  54. protected function newCallback($className)
  55. {
  56. switch ($className) {
  57. case 'Router':
  58. return 'RouterMock';
  59. case 'PHPView':
  60. return 'PHPViewMock';
  61. default:
  62. return $className;
  63. }
  64. }
  65. public function tearDown()
  66. {
  67. unset_new_overload();
  68. }
  69. }