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.2 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. if (!defined('DEBUG')) {
  38. define('DEBUG', false);
  39. }
  40. $layout = new ErrorLayout();
  41. $layout->setException(new GeneralException());
  42. $this->assertAttributeInstanceOf('GeneralException', 'exception', $layout);
  43. }
  44. public function testExecute()
  45. {
  46. if (!defined('DEBUG')) {
  47. define('DEBUG', false);
  48. }
  49. $action = $this->getMock('Action', array('fetch'));
  50. $action->expects($this->once())
  51. ->method('fetch')
  52. ->will($this->returnValue('this is the result of Action::fetch()'));
  53. $layout = new ErrorLayout();
  54. $layout->fetch($action);
  55. }
  56. protected function newCallback($className)
  57. {
  58. switch ($className) {
  59. case 'Router':
  60. return 'RouterMock';
  61. case 'PHPView':
  62. return 'PHPViewMock';
  63. default:
  64. return $className;
  65. }
  66. }
  67. public function tearDown()
  68. {
  69. unset_new_overload();
  70. }
  71. }