Skip to content

Commit b948c39

Browse files
John ZolperJohn Zolper
authored andcommitted
Merge branch 'MC-4239' of github.com:magento-borg/magento2ce into MC-4239
2 parents 511c04a + 2b15be4 commit b948c39

File tree

6 files changed

+120
-18
lines changed

6 files changed

+120
-18
lines changed

app/code/Magento/AuthorizenetAcceptjs/Setup/Patch/Data/CopyCurrentConfig.php

Lines changed: 79 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,11 @@
1010
use Magento\Framework\App\Config\ConfigResource\ConfigInterface;
1111
use Magento\Framework\App\Config\ScopeConfigInterface;
1212
use Magento\Framework\Encryption\EncryptorInterface;
13-
use Magento\Framework\Setup\InstallDataInterface;
14-
use Magento\Framework\Setup\ModuleContextInterface;
1513
use Magento\Framework\Setup\ModuleDataSetupInterface;
1614
use Magento\Framework\Setup\Patch\DataPatchInterface;
17-
use Magento\Framework\Setup\Patch\PatchInterface;
1815
use Magento\Store\Model\ScopeInterface;
16+
use Magento\Store\Model\StoreManagerInterface;
17+
use Magento\Store\Api\Data\WebsiteInterface;
1918

2019
/**
2120
* Copies the Authorize.net DirectPost configuration values to the new Accept.js module.
@@ -46,6 +45,11 @@ class CopyCurrentConfig implements DataPatchInterface
4645
*/
4746
private $moduleDataSetup;
4847

48+
/**
49+
* @var StoreManagerInterface
50+
*/
51+
private $storeManager;
52+
4953
/**
5054
* @var array
5155
*/
@@ -76,26 +80,40 @@ class CopyCurrentConfig implements DataPatchInterface
7680
* @param ScopeConfigInterface $scopeConfig
7781
* @param ConfigInterface $resourceConfig
7882
* @param EncryptorInterface $encryptor
83+
* @param StoreManagerInterface $storeManager
7984
*/
8085
public function __construct(
8186
ModuleDataSetupInterface $moduleDataSetup,
8287
ScopeConfigInterface $scopeConfig,
8388
ConfigInterface $resourceConfig,
84-
EncryptorInterface $encryptor
89+
EncryptorInterface $encryptor,
90+
StoreManagerInterface $storeManager
8591
) {
8692
$this->scopeConfig = $scopeConfig;
8793
$this->resourceConfig = $resourceConfig;
8894
$this->encryptor = $encryptor;
8995
$this->moduleDataSetup = $moduleDataSetup;
96+
$this->storeManager = $storeManager;
9097
}
9198

9299
/**
93100
* @inheritdoc
94101
*/
95-
public function apply()
102+
public function apply(): void
96103
{
97104
$this->moduleDataSetup->startSetup();
105+
$this->migrateDefaultValues();
106+
$this->migrateWebsiteValues();
107+
$this->moduleDataSetup->endSetup();
108+
}
98109

110+
/**
111+
* Migrate configuration values from DirectPost to Accept.js on default scope
112+
*
113+
* @return void
114+
*/
115+
private function migrateDefaultValues(): void
116+
{
99117
foreach ($this->configFieldsToMigrate as $field) {
100118
$configValue = $this->getOldConfigValue($field);
101119

@@ -108,24 +126,62 @@ public function apply()
108126
$configValue = $this->getOldConfigValue($field);
109127

110128
if (!empty($configValue)) {
111-
$this->saveNewConfigValue($field, $configValue, true);
129+
$this->saveNewConfigValue(
130+
$field,
131+
$configValue,
132+
ScopeConfigInterface::SCOPE_TYPE_DEFAULT,
133+
0,
134+
true
135+
);
112136
}
113137
}
138+
}
114139

115-
$this->moduleDataSetup->endSetup();
140+
/**
141+
* Migrate configuration values from DirectPost to Accept.js on all website scopes
142+
*
143+
* @return void
144+
*/
145+
private function migrateWebsiteValues(): void
146+
{
147+
foreach ($this->storeManager->getWebsites() as $website) {
148+
$websiteID = (int) $website->getId();
149+
150+
foreach ($this->configFieldsToMigrate as $field) {
151+
$configValue = $this->getOldConfigValue($field, ScopeInterface::SCOPE_WEBSITES, $websiteID);
152+
153+
if (!empty($configValue)) {
154+
$this->saveNewConfigValue($field, $configValue, ScopeInterface::SCOPE_WEBSITES, $websiteID);
155+
}
156+
}
157+
158+
foreach ($this->encryptedConfigFieldsToMigrate as $field) {
159+
$configValue = $this->getOldConfigValue($field, ScopeInterface::SCOPE_WEBSITES, $websiteID);
160+
161+
if (!empty($configValue)) {
162+
$this->saveNewConfigValue($field, $configValue, ScopeInterface::SCOPE_WEBSITES, $websiteID, true);
163+
}
164+
}
165+
}
116166
}
117167

118168
/**
119169
* Get old configuration value from the DirectPost module's configuration on the store scope
120170
*
121171
* @param string $field
172+
* @param string $scope
173+
* @param int $scopeID
122174
* @return mixed
123175
*/
124-
private function getOldConfigValue(string $field)
125-
{
176+
private function getOldConfigValue(
177+
string $field,
178+
string $scope = ScopeConfigInterface::SCOPE_TYPE_DEFAULT,
179+
int $scopeID = null
180+
) {
126181
return $this->scopeConfig->getValue(
127182
sprintf(self::PAYMENT_PATH_FORMAT, self::DIRECTPOST_PATH, $field),
128-
ScopeInterface::SCOPE_STORE
183+
$scope,
184+
$scopeID
129185
);
130186
}
131187

@@ -134,15 +190,25 @@ private function getOldConfigValue(string $field)
134190
*
135191
* @param string $field
136192
* @param mixed $value
193+
* @param string $scope
194+
* @param int $scopeID
137195
* @param bool $isEncrypted
196+
* @return void
138197
*/
139-
private function saveNewConfigValue(string $field, $value, $isEncrypted = false): void
140-
{
198+
private function saveNewConfigValue(
199+
string $field,
200+
$value,
201+
string $scope = ScopeConfigInterface::SCOPE_TYPE_DEFAULT,
202+
int $scopeID = 0,
203+
bool $isEncrypted = false
204+
): void {
141205
$value = $isEncrypted ? $this->encryptor->encrypt($value) : $value;
206+
142207
$this->resourceConfig->saveConfig(
143208
sprintf(self::PAYMENT_PATH_FORMAT, self::ACCEPTJS_PATH, $field),
144209
$value,
145-
ScopeInterface::SCOPE_STORE
210+
$scope,
211+
$scopeID
146212
);
147213
}
148214

app/code/Magento/AuthorizenetAcceptjs/Test/Unit/Setup/Patch/Data/CopyCurrentConfigTest.php

Lines changed: 33 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@
1515
use Magento\Framework\TestFramework\Unit\Helper\ObjectManager;
1616
use Magento\Setup\Module\DataSetup;
1717
use Magento\Setup\Model\ModuleContext;
18+
use Magento\Store\Model\StoreManagerInterface;
19+
use Magento\Store\Model\Website;
1820
use PHPUnit\Framework\TestCase;
1921

2022
class CopyCurrentConfigTest extends TestCase
@@ -44,6 +46,16 @@ class CopyCurrentConfigTest extends TestCase
4446
*/
4547
private $context;
4648

49+
/**
50+
* @var \Magento\Store\Model\StoreManager
51+
*/
52+
private $storeManager;
53+
54+
/**
55+
* @var \Magento\Store\Model\Website
56+
*/
57+
private $website;
58+
4759
protected function setUp(): void
4860
{
4961
$this->scopeConfig = $this->createMock(Config::class);
@@ -60,22 +72,32 @@ protected function setUp(): void
6072
->willReturn(null);
6173

6274
$this->context = $this->createMock(ModuleContext::class);
75+
$this->storeManager = $this->createMock(StoreManagerInterface::class);
76+
$this->website = $this->createMock(Website::class);
6377
}
6478

6579
public function testMigrateData(): void
6680
{
67-
$this->scopeConfig->expects($this->exactly(13))
81+
$this->scopeConfig->expects($this->exactly(26))
6882
->method('getValue')
6983
->willReturn('TestValue');
7084

71-
$this->resourceConfig->expects($this->exactly(13))
85+
$this->resourceConfig->expects($this->exactly(26))
7286
->method('saveConfig')
7387
->willReturn(null);
7488

75-
$this->encryptor->expects($this->exactly(3))
89+
$this->encryptor->expects($this->exactly(6))
7690
->method('encrypt')
7791
->willReturn('TestValue');
7892

93+
$this->website->expects($this->once())
94+
->method('getId')
95+
->willReturn(1);
96+
97+
$this->storeManager->expects($this->once())
98+
->method('getWebsites')
99+
->willReturn([$this->website]);
100+
79101
$objectManager = new ObjectManager($this);
80102

81103
$installer = $objectManager->getObject(
@@ -84,7 +106,8 @@ public function testMigrateData(): void
84106
'moduleDataSetup' => $this->setup,
85107
'scopeConfig' => $this->scopeConfig,
86108
'resourceConfig' => $this->resourceConfig,
87-
'encryptor' => $this->encryptor
109+
'encryptor' => $this->encryptor,
110+
'storeManager' => $this->storeManager
88111
]
89112
);
90113

@@ -104,6 +127,10 @@ public function testMigrateDataNullFields(): void
104127
$this->encryptor->expects($this->never())
105128
->method('encrypt');
106129

130+
$this->storeManager->expects($this->once())
131+
->method('getWebsites')
132+
->willReturn([]);
133+
107134
$objectManager = new ObjectManager($this);
108135

109136
$installer = $objectManager->getObject(
@@ -112,7 +139,8 @@ public function testMigrateDataNullFields(): void
112139
'moduleDataSetup' => $this->setup,
113140
'scopeConfig' => $this->scopeConfig,
114141
'resourceConfig' => $this->resourceConfig,
115-
'encryptor' => $this->encryptor
142+
'encryptor' => $this->encryptor,
143+
'storeManager' => $this->storeManager
116144
]
117145
);
118146

app/code/Magento/Catalog/Test/Mftf/Test/AdminProductImageAssignmentForMultipleStoresTest.xml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,9 @@
1818
<testCaseId value="MAGETWO-58718"/>
1919
<group value="product"/>
2020
<group value="WYSIWYGDisabled"/>
21+
<skip>
22+
<issueId value="MC-13841"/>
23+
</skip>
2124
</annotations>
2225
<before>
2326
<!-- Login Admin -->

app/code/Magento/Cms/Test/Mftf/Test/CheckStaticBlocksTest.xml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
<group value="Cms"/>
2020
</annotations>
2121
<before>
22+
<magentoCLI command="config:set cms/wysiwyg/enabled disabled" stepKey="disableWYSIWYG"/>
2223
<actionGroup ref="LoginAsAdmin" stepKey="LoginAsAdmin"/>
2324
<actionGroup ref="AdminCreateWebsiteActionGroup" stepKey="AdminCreateWebsite">
2425
<argument name="newWebsiteName" value="secondWebsite"/>
@@ -67,6 +68,7 @@
6768
<argument name="websiteName" value="secondWebsite"/>
6869
</actionGroup>
6970
<actionGroup ref="DeleteCMSBlockActionGroup" stepKey="DeleteCMSBlockActionGroup"/>
71+
<magentoCLI command="config:set cms/wysiwyg/enabled enabled" stepKey="enableWYSIWYG"/>
7072
</after>
7173
</test>
7274
</tests>

app/code/Magento/Swatches/Test/Mftf/Test/StorefrontSwatchAttributesDisplayInWidgetCMSTest.xml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
</annotations>
2121

2222
<before>
23+
<magentoCLI command="config:set cms/wysiwyg/enabled disabled" stepKey="disableWYSIWYG"/>
2324
<createData entity="NewRootCategory" stepKey="createRootCategory"/>
2425
</before>
2526

@@ -44,6 +45,7 @@
4445
<waitForElementVisible selector="{{AdminCategoryModalSection.ok}}" stepKey="waitForModalDeleteDefaultRootCategory" />
4546
<click selector="{{AdminCategoryModalSection.ok}}" stepKey="acceptModal1"/>
4647
<waitForElementVisible selector="{{AdminCategoryMessagesSection.SuccessMessage}}" stepKey="waitForPageReloadAfterDeleteDefaultCategory"/>
48+
<magentoCLI command="config:set cms/wysiwyg/enabled enabled" stepKey="enableWYSIWYG"/>
4749
<!--logout-->
4850
<actionGroup ref="logout" stepKey="logoutFromAdmin"/>
4951
</after>

dev/tests/functional/tests/app/Magento/Cms/Test/TestCase/CreateCmsPageEntityMultipleStoreViewsTest.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="../../../../../../vendor/magento/mtf/etc/variations.xsd">
99
<testCase name="Magento\Cms\Test\TestCase\CreateCmsPageEntityMultipleStoreViewsTest" summary="Page cache for different CMS pages on multiple store views" ticketId="MAGETWO-52467">
1010
<variation name="CreateCmsPageEntityMultipleStoreViewsTestVariation1">
11+
<data name="issue" xsi:type="string">MC-13801: Test "Page cache for different CMS pages on multiple store views" fails on Jenkins</data>
1112
<data name="cmsPages/0/is_active" xsi:type="string">Yes</data>
1213
<data name="cmsPages/0/title" xsi:type="string">NewCmsPage</data>
1314
<data name="cmsPages/0/store_id/dataset" xsi:type="string">default</data>

0 commit comments

Comments
 (0)