BaseUrlCheckerTest.php 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  1. <?php
  2. /**
  3. * Copyright © Magento, Inc. All rights reserved.
  4. * See COPYING.txt for license details.
  5. */
  6. namespace Magento\Store\Test\Unit\Model;
  7. use Magento\Framework\App\Config;
  8. use Magento\Framework\App\Request\Http;
  9. use Magento\Store\Model\BaseUrlChecker;
  10. /**
  11. * Class BaseUrlCheckerTest covers Magento\Store\Model\BaseUrlChecker.
  12. */
  13. class BaseUrlCheckerTest extends \PHPUnit\Framework\TestCase
  14. {
  15. /**
  16. * Holder for BaseUrlChecker instance.
  17. *
  18. * @var BaseUrlChecker
  19. */
  20. private $baseUrlChecker;
  21. /**
  22. * Holder for Config mock.
  23. *
  24. * @var Config|\PHPUnit_Framework_MockObject_MockObject
  25. */
  26. private $scopeConfig;
  27. /**
  28. * Prepare subject for tests.
  29. */
  30. protected function setUp()
  31. {
  32. $this->scopeConfig = $this->getMockBuilder(Config::class)
  33. ->disableOriginalConstructor()
  34. ->getMock();
  35. $this->baseUrlChecker = new BaseUrlChecker(
  36. $this->scopeConfig
  37. );
  38. parent::setUp();
  39. }
  40. /**
  41. * @covers \Magento\Store\Model\BaseUrlChecker::execute()
  42. */
  43. public function testExecute()
  44. {
  45. $scheme = 'testScheme';
  46. $host = 'testHost';
  47. $requestUri = 'testRequestUri';
  48. /** @var Http|\PHPUnit_Framework_MockObject_MockObject $request */
  49. $request = $this->getMockBuilder(Http::class)
  50. ->disableOriginalConstructor()
  51. ->getMock();
  52. $request->expects($this->exactly(2))
  53. ->method('getRequestUri')
  54. ->willReturn($requestUri);
  55. $request->expects($this->once())
  56. ->method('getScheme')
  57. ->willReturn($scheme);
  58. $request->expects($this->once())
  59. ->method('getHttpHost')
  60. ->willReturn($host);
  61. $uri = [
  62. 'scheme' => $scheme,
  63. 'host' => $host,
  64. 'path' => $requestUri,
  65. ];
  66. $this->assertTrue($this->baseUrlChecker->execute($uri, $request));
  67. }
  68. /**
  69. * @covers \Magento\Store\Model\BaseUrlChecker::isEnabled()
  70. */
  71. public function testIsEnabled()
  72. {
  73. $this->scopeConfig->expects($this->once())
  74. ->method('isSetFlag')
  75. ->with('web/url/redirect_to_base', \Magento\Store\Model\ScopeInterface::SCOPE_STORE)
  76. ->willReturn(!!1);
  77. $this->assertTrue($this->baseUrlChecker->isEnabled());
  78. }
  79. /**
  80. * @covers \Magento\Store\Model\BaseUrlChecker::isFrontendSecure()
  81. */
  82. public function testIsFrontendSecure()
  83. {
  84. $this->scopeConfig->expects($this->once())
  85. ->method('getValue')
  86. ->with('web/unsecure/base_url', \Magento\Store\Model\ScopeInterface::SCOPE_STORE)
  87. ->willReturn('https://localhost');
  88. $this->scopeConfig->expects($this->once())
  89. ->method('isSetFlag')
  90. ->with('web/secure/use_in_frontend', \Magento\Store\Model\ScopeInterface::SCOPE_STORE)
  91. ->willReturn(!!1);
  92. $this->assertTrue($this->baseUrlChecker->isFrontendSecure());
  93. }
  94. }