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.

80 lines
2.1 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__) . '/../../exception/ErrorHandler.php';
  11. require_once dirname(__FILE__) . '/../../exception/GeneralException.php';
  12. require_once dirname(__FILE__) . '/../../app/FrontController.php';
  13. require_once dirname(__FILE__) . '/../../layout/Layout.php';
  14. require_once dirname(__FILE__) . '/../../layout/Error.layout.php';
  15. /**
  16. * @runTestsInSeparateProcesses
  17. */
  18. class ErrorLayoutTest extends PHPUnit_Framework_TestCase
  19. {
  20. public function run(PHPUnit_Framework_TestResult $result = NULL)
  21. {
  22. $this->setPreserveGlobalState(false);
  23. return parent::run($result);
  24. }
  25. public function setUp()
  26. {
  27. if (!class_exists('RouterMock')) {
  28. $this->getMock('Router', array(), array(), 'RouterMock', false);
  29. }
  30. if (!class_exists('PHPViewMock')) {
  31. $this->getMock('PHPView', array('fetch', 'append', 'prepend', 'assign', 'getTemplate'), array(), 'PHPViewMock', false);
  32. }
  33. set_new_overload(array($this, 'newCallback'));
  34. }
  35. public function testSetException()
  36. {
  37. Config::set('DEBUG', 0);
  38. $layout = new ErrorLayout();
  39. $layout->setException(new GeneralException());
  40. $this->assertAttributeInstanceOf('GeneralException', 'exception', $layout);
  41. }
  42. public function testExecute()
  43. {
  44. Config::set('DEBUG', 0);
  45. $action = $this->getMock('Action', array('fetch'));
  46. $action->expects($this->once())
  47. ->method('fetch')
  48. ->will($this->returnValue('this is the result of Action::fetch()'));
  49. $layout = new ErrorLayout();
  50. $layout->fetch($action);
  51. }
  52. protected function newCallback($className)
  53. {
  54. switch ($className) {
  55. case 'Router':
  56. return 'RouterMock';
  57. case 'PHPView':
  58. return 'PHPViewMock';
  59. default:
  60. return $className;
  61. }
  62. }
  63. public function tearDown()
  64. {
  65. unset_new_overload();
  66. }
  67. }