|
8 | 8 |
|
9 | 9 | use Magento\Framework\App\DeploymentConfig;
|
10 | 10 | use Magento\Framework\Exception\LocalizedException;
|
| 11 | +use Magento\RemoteStorage\Driver\DriverFactoryInterface; |
11 | 12 | use Magento\RemoteStorage\Driver\DriverFactoryPool;
|
12 | 13 | use Magento\RemoteStorage\Driver\RemoteDriverInterface;
|
13 | 14 | use Magento\RemoteStorage\Setup\ConfigOptionsList;
|
14 |
| -use Magento\RemoteStorage\Driver\DriverFactoryInterface; |
15 | 15 | use PHPUnit\Framework\MockObject\MockObject;
|
16 | 16 | use PHPUnit\Framework\TestCase;
|
17 | 17 | use Psr\Log\LoggerInterface;
|
@@ -188,4 +188,115 @@ public function validateDataProvider()
|
188 | 188 | ],
|
189 | 189 | ];
|
190 | 190 | }
|
| 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 | + } |
191 | 302 | }
|
0 commit comments