Skip to content

Commit 0a95fc6

Browse files
committed
Merge branch 'B2B-2134' of https://github.com/magento-arcticfoxes/magento2ce into B2B-2140
2 parents 9146d6c + 3c20c5c commit 0a95fc6

File tree

2 files changed

+119
-1
lines changed

2 files changed

+119
-1
lines changed

app/code/Magento/RemoteStorage/Setup/ConfigOptionsList.php

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -142,6 +142,13 @@ public function getOptions(): array
142142
*/
143143
public function createConfig(array $options, DeploymentConfig $deploymentConfig): array
144144
{
145+
$isRemoteStorageDeploymentConfigExists = isset($deploymentConfig->getConfigData()['remote_storage']);
146+
147+
// if remote storage config is already present and driver is not in $options, return early to prevent overwrite
148+
if ($isRemoteStorageDeploymentConfigExists && !isset($options[self::OPTION_REMOTE_STORAGE_DRIVER])) {
149+
return [];
150+
}
151+
145152
$driver = $options[self::OPTION_REMOTE_STORAGE_DRIVER] ?? DriverPool::FILE;
146153

147154
if ($driver === DriverPool::FILE) {

app/code/Magento/RemoteStorage/Test/Unit/Setup/ConfigOptionsListTest.php

Lines changed: 112 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,10 @@
88

99
use Magento\Framework\App\DeploymentConfig;
1010
use Magento\Framework\Exception\LocalizedException;
11+
use Magento\RemoteStorage\Driver\DriverFactoryInterface;
1112
use Magento\RemoteStorage\Driver\DriverFactoryPool;
1213
use Magento\RemoteStorage\Driver\RemoteDriverInterface;
1314
use Magento\RemoteStorage\Setup\ConfigOptionsList;
14-
use Magento\RemoteStorage\Driver\DriverFactoryInterface;
1515
use PHPUnit\Framework\MockObject\MockObject;
1616
use PHPUnit\Framework\TestCase;
1717
use Psr\Log\LoggerInterface;
@@ -188,4 +188,115 @@ public function validateDataProvider()
188188
],
189189
];
190190
}
191+
192+
/**
193+
* @param array $options
194+
* @param array $deploymentConfig
195+
* @param array $expectedConfigArr
196+
* @dataProvider createConfigProvider
197+
*/
198+
public function testCreateConfig(array $options, array $deploymentConfig, array $expectedConfigArr)
199+
{
200+
$deploymentConfigMock = $this->getMockBuilder(DeploymentConfig::class)
201+
->disableOriginalConstructor()
202+
->getMock();
203+
204+
$deploymentConfigMock
205+
->expects(static::once())
206+
->method('getConfigData')
207+
->willReturn($deploymentConfig);
208+
209+
$configDataListArr = $this->configOptionsList->createConfig($options, $deploymentConfigMock);
210+
211+
if (count($configDataListArr)) {
212+
$this->assertCount(1, $configDataListArr);
213+
$configDataArr = $configDataListArr[0]->getData();
214+
} else {
215+
$configDataArr = [];
216+
}
217+
218+
$this->assertEquals(
219+
$expectedConfigArr,
220+
$configDataArr
221+
);
222+
}
223+
224+
/**
225+
* @return array
226+
*/
227+
public function createConfigProvider()
228+
{
229+
return [
230+
'Remote Storage Options Missing and Remote Storage Deployment Config Present' => [
231+
[
232+
'backend-frontname' => 'admin2022',
233+
],
234+
[
235+
'remote_storage' => [
236+
'driver' => 'aws-s3',
237+
]
238+
],
239+
// no config data will be passed to write to deployment config
240+
[]
241+
],
242+
'Remote Storage Options Missing and Remote Storage Deployment Config Missing' => [
243+
[
244+
'backend-frontname' => 'admin2022',
245+
],
246+
[],
247+
[
248+
// will create default config with file driver
249+
'remote_storage' => [
250+
'driver' => 'file',
251+
]
252+
]
253+
],
254+
'Remote Storage Options Present and Remote Storage Deployment Config Missing' => [
255+
[
256+
'remote-storage-driver' => 'aws-s3',
257+
'remote-storage-region' => 'us-east-1',
258+
'remote-storage-bucket' => 'bucket1',
259+
'remote-storage-prefix' => 'pre_',
260+
],
261+
[],
262+
[
263+
'remote_storage' => [
264+
'driver' => 'aws-s3',
265+
'prefix' => 'pre_',
266+
'config' => [
267+
'bucket' => 'bucket1',
268+
'region' => 'us-east-1',
269+
],
270+
]
271+
]
272+
],
273+
'Remote Storage Options Present and Remote Storage Deployment Config Present' => [
274+
[
275+
'remote-storage-driver' => 'aws-s3',
276+
'remote-storage-region' => 'us-east-1_NEW',
277+
'remote-storage-bucket' => 'bucket_NEW',
278+
],
279+
[
280+
'remote_storage' => [
281+
'driver' => 'aws-s3',
282+
'prefix' => 'pre_OLD',
283+
'config' => [
284+
'bucket' => 'bucket_OLD',
285+
'region' => 'us-east-1_OLD',
286+
],
287+
]
288+
],
289+
[
290+
'remote_storage' => [
291+
'driver' => 'aws-s3',
292+
// prefix should be removed as it was not passed in options
293+
'config' => [
294+
'bucket' => 'bucket_NEW',
295+
'region' => 'us-east-1_NEW',
296+
],
297+
]
298+
]
299+
],
300+
];
301+
}
191302
}

0 commit comments

Comments
 (0)