BaseUrlConfigPluginTest.php 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144
  1. <?php
  2. /**
  3. * Copyright © Magento, Inc. All rights reserved.
  4. * See COPYING.txt for license details.
  5. */
  6. namespace Magento\Analytics\Test\Unit\Model\Plugin;
  7. use Magento\Analytics\Model\Config\Backend\Baseurl\SubscriptionUpdateHandler;
  8. use Magento\Analytics\Model\Plugin\BaseUrlConfigPlugin;
  9. use Magento\Analytics\Model\SubscriptionStatusProvider;
  10. use Magento\Framework\App\Config\ScopeConfigInterface;
  11. use Magento\Framework\App\Config\Value;
  12. use Magento\Framework\TestFramework\Unit\Helper\ObjectManager as ObjectManagerHelper;
  13. use Magento\Store\Model\ScopeInterface;
  14. use Magento\Store\Model\Store;
  15. class BaseUrlConfigPluginTest extends \PHPUnit\Framework\TestCase
  16. {
  17. /**
  18. * @var SubscriptionUpdateHandler | \PHPUnit_Framework_MockObject_MockObject
  19. */
  20. private $subscriptionUpdateHandlerMock;
  21. /**
  22. * @var Value | \PHPUnit_Framework_MockObject_MockObject
  23. */
  24. private $configValueMock;
  25. /**
  26. * @var ObjectManagerHelper
  27. */
  28. private $objectManagerHelper;
  29. /**
  30. * @var BaseUrlConfigPlugin
  31. */
  32. private $plugin;
  33. /**
  34. * @return void
  35. */
  36. protected function setUp()
  37. {
  38. $this->subscriptionUpdateHandlerMock = $this->getMockBuilder(SubscriptionUpdateHandler::class)
  39. ->disableOriginalConstructor()
  40. ->getMock();
  41. $this->configValueMock = $this->getMockBuilder(Value::class)
  42. ->disableOriginalConstructor()
  43. ->setMethods(['isValueChanged', 'getPath', 'getScope', 'getOldValue'])
  44. ->getMock();
  45. $this->objectManagerHelper = new ObjectManagerHelper($this);
  46. $this->plugin = $this->objectManagerHelper->getObject(
  47. BaseUrlConfigPlugin::class,
  48. [
  49. 'subscriptionUpdateHandler' => $this->subscriptionUpdateHandlerMock,
  50. ]
  51. );
  52. }
  53. /**
  54. * @param array $configValueData
  55. * @return void
  56. * @dataProvider afterSavePluginIsNotApplicableDataProvider
  57. */
  58. public function testAfterSavePluginIsNotApplicable(
  59. array $configValueData
  60. ) {
  61. $this->configValueMock
  62. ->method('isValueChanged')
  63. ->willReturn($configValueData['isValueChanged']);
  64. $this->configValueMock
  65. ->method('getPath')
  66. ->willReturn($configValueData['path']);
  67. $this->configValueMock
  68. ->method('getScope')
  69. ->willReturn($configValueData['scope']);
  70. $this->subscriptionUpdateHandlerMock
  71. ->expects($this->never())
  72. ->method('processUrlUpdate');
  73. $this->assertEquals(
  74. $this->configValueMock,
  75. $this->plugin->afterAfterSave($this->configValueMock, $this->configValueMock)
  76. );
  77. }
  78. /**
  79. * @return array
  80. */
  81. public function afterSavePluginIsNotApplicableDataProvider()
  82. {
  83. return [
  84. 'Value has not been changed' => [
  85. 'Config Value Data' => [
  86. 'isValueChanged' => false,
  87. 'path' => Store::XML_PATH_SECURE_BASE_URL,
  88. 'scope' => ScopeConfigInterface::SCOPE_TYPE_DEFAULT
  89. ],
  90. ],
  91. 'Unsecure URL has been changed' => [
  92. 'Config Value Data' => [
  93. 'isValueChanged' => true,
  94. 'path' => Store::XML_PATH_UNSECURE_BASE_URL,
  95. 'scope' => ScopeConfigInterface::SCOPE_TYPE_DEFAULT
  96. ],
  97. ],
  98. 'Secure URL has been changed not in the Default scope' => [
  99. 'Config Value Data' => [
  100. 'isValueChanged' => true,
  101. 'path' => Store::XML_PATH_SECURE_BASE_URL,
  102. 'scope' => ScopeInterface::SCOPE_STORES
  103. ],
  104. ],
  105. ];
  106. }
  107. /**
  108. * @return void
  109. */
  110. public function testAfterSavePluginIsApplicable()
  111. {
  112. $this->configValueMock
  113. ->method('isValueChanged')
  114. ->willReturn(true);
  115. $this->configValueMock
  116. ->method('getPath')
  117. ->willReturn(Store::XML_PATH_SECURE_BASE_URL);
  118. $this->configValueMock
  119. ->method('getScope')
  120. ->willReturn(ScopeConfigInterface::SCOPE_TYPE_DEFAULT);
  121. $this->configValueMock
  122. ->method('getOldValue')
  123. ->willReturn('http://store.com');
  124. $this->subscriptionUpdateHandlerMock
  125. ->expects($this->once())
  126. ->method('processUrlUpdate')
  127. ->with('http://store.com');
  128. $this->assertEquals(
  129. $this->configValueMock,
  130. $this->plugin->afterAfterSave($this->configValueMock, $this->configValueMock)
  131. );
  132. }
  133. }