ConfigProviderTest.php 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146
  1. <?php
  2. /**
  3. * Copyright © Magento, Inc. All rights reserved.
  4. * See COPYING.txt for license details.
  5. */
  6. namespace Magento\Customer\Test\Unit\Model\Checkout;
  7. use Magento\Customer\Model\Checkout\ConfigProvider;
  8. use Magento\Framework\UrlInterface;
  9. use Magento\Store\Model\StoreManagerInterface;
  10. use Magento\Store\Api\Data\StoreInterface;
  11. use Magento\Framework\App\Config\ScopeConfigInterface;
  12. use Magento\Customer\Model\Url;
  13. use Magento\Customer\Model\Form;
  14. use Magento\Store\Model\ScopeInterface;
  15. class ConfigProviderTest extends \PHPUnit\Framework\TestCase
  16. {
  17. /**
  18. * @var ConfigProvider
  19. */
  20. protected $provider;
  21. /**
  22. * @var StoreManagerInterface|\PHPUnit_Framework_MockObject_MockObject
  23. */
  24. protected $storeManager;
  25. /**
  26. * @var UrlInterface|\PHPUnit_Framework_MockObject_MockObject
  27. */
  28. protected $urlBuilder;
  29. /**
  30. * @var ScopeConfigInterface|\PHPUnit_Framework_MockObject_MockObject
  31. */
  32. protected $scopeConfig;
  33. /**
  34. * @var StoreInterface|\PHPUnit_Framework_MockObject_MockObject
  35. */
  36. protected $store;
  37. /**
  38. * @var Url|\PHPUnit_Framework_MockObject_MockObject
  39. */
  40. private $customerUrl;
  41. protected function setUp()
  42. {
  43. $this->storeManager = $this->getMockForAbstractClass(
  44. \Magento\Store\Model\StoreManagerInterface::class,
  45. [],
  46. '',
  47. false
  48. );
  49. $this->urlBuilder = $this->getMockForAbstractClass(
  50. \Magento\Framework\UrlInterface::class,
  51. [],
  52. '',
  53. false
  54. );
  55. $this->scopeConfig = $this->getMockForAbstractClass(
  56. \Magento\Framework\App\Config\ScopeConfigInterface::class,
  57. [],
  58. '',
  59. false
  60. );
  61. $this->store = $this->getMockForAbstractClass(
  62. \Magento\Store\Api\Data\StoreInterface::class,
  63. [],
  64. '',
  65. false,
  66. false,
  67. true,
  68. ['getBaseUrl']
  69. );
  70. $this->customerUrl = $this->createMock(\Magento\Customer\Model\Url::class);
  71. $this->provider = new ConfigProvider(
  72. $this->urlBuilder,
  73. $this->storeManager,
  74. $this->scopeConfig,
  75. $this->customerUrl
  76. );
  77. }
  78. public function testGetConfigWithoutRedirect()
  79. {
  80. $loginUrl = 'http://url.test/customer/login';
  81. $baseUrl = 'http://base-url.test';
  82. $this->customerUrl->expects($this->exactly(2))
  83. ->method('getLoginUrl')
  84. ->willReturn($loginUrl);
  85. $this->storeManager->expects($this->once())
  86. ->method('getStore')
  87. ->willReturn($this->store);
  88. $this->store->expects($this->once())
  89. ->method('getBaseUrl')
  90. ->willReturn($baseUrl);
  91. $this->scopeConfig->expects($this->once())
  92. ->method('getValue')
  93. ->with(Form::XML_PATH_ENABLE_AUTOCOMPLETE, ScopeInterface::SCOPE_STORE)
  94. ->willReturn(1);
  95. $this->assertEquals(
  96. [
  97. 'customerLoginUrl' => $loginUrl,
  98. 'isRedirectRequired' => true,
  99. 'autocomplete' => 'on',
  100. ],
  101. $this->provider->getConfig()
  102. );
  103. }
  104. public function testGetConfig()
  105. {
  106. $loginUrl = 'http://base-url.test/customer/login';
  107. $baseUrl = 'http://base-url.test';
  108. $this->customerUrl->expects($this->exactly(2))
  109. ->method('getLoginUrl')
  110. ->willReturn($loginUrl);
  111. $this->storeManager->expects($this->once())
  112. ->method('getStore')
  113. ->willReturn($this->store);
  114. $this->store->expects($this->once())
  115. ->method('getBaseUrl')
  116. ->willReturn($baseUrl);
  117. $this->scopeConfig->expects($this->once())
  118. ->method('getValue')
  119. ->with(Form::XML_PATH_ENABLE_AUTOCOMPLETE, ScopeInterface::SCOPE_STORE)
  120. ->willReturn(0);
  121. $this->assertEquals(
  122. [
  123. 'customerLoginUrl' => $loginUrl,
  124. 'isRedirectRequired' => false,
  125. 'autocomplete' => 'off',
  126. ],
  127. $this->provider->getConfig()
  128. );
  129. }
  130. }