NoRouteHandlerTest.php 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  1. <?php
  2. /**
  3. * Tests Magento\Framework\App\Router\NoRouteHandler
  4. *
  5. * Copyright © Magento, Inc. All rights reserved.
  6. * See COPYING.txt for license details.
  7. */
  8. namespace Magento\Framework\App\Test\Unit\Router;
  9. class NoRouteHandlerTest extends \Magento\Framework\TestFramework\Unit\BaseTestCase
  10. {
  11. /**
  12. * @var \Magento\Framework\App\Router\NoRouteHandler
  13. */
  14. private $model;
  15. /**
  16. * @var \PHPUnit_Framework_MockObject_MockObject|\Magento\Framework\App\Config\ScopeConfigInterface
  17. */
  18. private $configMock;
  19. /**
  20. * @var \PHPUnit_Framework_MockObject_MockObject|\Magento\Framework\App\Request\Http
  21. */
  22. private $requestMock;
  23. protected function setUp()
  24. {
  25. parent::setUp();
  26. $this->configMock = $this->basicMock(\Magento\Framework\App\Config\ScopeConfigInterface::class);
  27. $this->requestMock = $this->basicMock(\Magento\Framework\App\Request\Http::class);
  28. $this->model = $this->objectManager->getObject(
  29. \Magento\Framework\App\Router\NoRouteHandler::class,
  30. [
  31. 'config' => $this->configMock,
  32. ]
  33. );
  34. }
  35. public function testProcessDefault()
  36. {
  37. // Default path from config
  38. $default = 'moduleName/actionPath/actionName';
  39. $this->configMock->expects($this->once())
  40. ->method('getValue')
  41. ->with('web/default/no_route', 'default')
  42. ->willReturn($default);
  43. // Set expectations
  44. $this->requestMock->expects($this->once())
  45. ->method('setModuleName')
  46. ->with('moduleName')
  47. ->willReturnSelf();
  48. $this->requestMock->expects($this->once())
  49. ->method('setControllerName')
  50. ->with('actionPath')
  51. ->willReturnSelf();
  52. $this->requestMock->expects($this->once())
  53. ->method('setActionName')
  54. ->with('actionName')
  55. ->willReturnSelf();
  56. // Test
  57. $this->assertTrue($this->model->process($this->requestMock));
  58. }
  59. public function testProcessNoDefault()
  60. {
  61. // Default path from config
  62. $this->configMock->expects($this->once())
  63. ->method('getValue')
  64. ->with('web/default/no_route', 'default')
  65. ->willReturn(null);
  66. // Set expectations
  67. $this->requestMock->expects($this->once())
  68. ->method('setModuleName')
  69. ->with('core')
  70. ->willReturnSelf();
  71. $this->requestMock->expects($this->once())
  72. ->method('setControllerName')
  73. ->with('index')
  74. ->willReturnSelf();
  75. $this->requestMock->expects($this->once())
  76. ->method('setActionName')
  77. ->with('index')
  78. ->willReturnSelf();
  79. // Test
  80. $this->assertTrue($this->model->process($this->requestMock));
  81. }
  82. }