NoRouteHandlerTest.php 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109
  1. <?php
  2. /**
  3. * Copyright © Magento, Inc. All rights reserved.
  4. * See COPYING.txt for license details.
  5. */
  6. namespace Magento\Backend\Test\Unit\App\Router;
  7. class NoRouteHandlerTest extends \PHPUnit\Framework\TestCase
  8. {
  9. /**
  10. * @var \PHPUnit_Framework_MockObject_MockObject
  11. */
  12. protected $_helperMock;
  13. /**
  14. * @var \PHPUnit_Framework_MockObject_MockObject
  15. */
  16. protected $_requestMock;
  17. /**
  18. * @var \PHPUnit_Framework_MockObject_MockObject
  19. */
  20. protected $_routeConfigMock;
  21. /**
  22. * @var \Magento\Backend\App\Router\NoRouteHandler
  23. */
  24. protected $_model;
  25. protected function setUp()
  26. {
  27. $this->_requestMock = $this->createMock(\Magento\Framework\App\Request\Http::class);
  28. $this->_routeConfigMock = $this->createMock(\Magento\Framework\App\Route\ConfigInterface::class);
  29. $this->_helperMock = $this->createMock(\Magento\Backend\Helper\Data::class);
  30. $this->_helperMock->expects($this->any())->method('getAreaFrontName')->will($this->returnValue('backend'));
  31. $this->_model = new \Magento\Backend\App\Router\NoRouteHandler($this->_helperMock, $this->_routeConfigMock);
  32. }
  33. /**
  34. * @covers \Magento\Backend\App\Router\NoRouteHandler::process
  35. */
  36. public function testProcessWithBackendAreaFrontName()
  37. {
  38. $this->_routeConfigMock
  39. ->expects($this->once())
  40. ->method('getRouteFrontName')
  41. ->with('adminhtml')
  42. ->will($this->returnValue('admin'));
  43. $this->_requestMock
  44. ->expects($this->once())
  45. ->method('getPathInfo')
  46. ->will($this->returnValue('backend/admin/custom'));
  47. $this->_requestMock->expects(
  48. $this->once()
  49. )->method(
  50. 'setModuleName'
  51. )->with(
  52. 'admin'
  53. )->will(
  54. $this->returnValue($this->_requestMock)
  55. );
  56. $this->_requestMock->expects(
  57. $this->once()
  58. )->method(
  59. 'setControllerName'
  60. )->with(
  61. 'noroute'
  62. )->will(
  63. $this->returnValue($this->_requestMock)
  64. );
  65. $this->_requestMock->expects(
  66. $this->once()
  67. )->method(
  68. 'setActionName'
  69. )->with(
  70. 'index'
  71. )->will(
  72. $this->returnValue($this->_requestMock)
  73. );
  74. $this->assertEquals(true, $this->_model->process($this->_requestMock));
  75. }
  76. /**
  77. * @covers \Magento\Backend\App\Router\NoRouteHandler::process
  78. */
  79. public function testProcessWithoutAreaFrontName()
  80. {
  81. $this->_requestMock->expects(
  82. $this->once()
  83. )->method(
  84. 'getPathInfo'
  85. )->will(
  86. $this->returnValue('module/controller/action')
  87. );
  88. $this->_requestMock->expects($this->never())->method('setModuleName');
  89. $this->_requestMock->expects($this->never())->method('setControllerName');
  90. $this->_requestMock->expects($this->never())->method('setActionName');
  91. $this->assertEquals(false, $this->_model->process($this->_requestMock));
  92. }
  93. }