5
5
*/
6
6
namespace Magento \Deploy \Console \Command \App ;
7
7
8
+ use Magento \Config \Model \Config \Backend \Currency \Cron ;
9
+ use Magento \Deploy \Model \DeploymentConfig \Hash ;
8
10
use Magento \Framework \App \CacheInterface ;
11
+ use Magento \Framework \App \Config \ReinitableConfigInterface ;
9
12
use Magento \Framework \App \DeploymentConfig ;
13
+ use Magento \Framework \App \Filesystem \DirectoryList ;
10
14
use Magento \Framework \Config \File \ConfigFilePool ;
15
+ use Magento \Framework \Console \Cli ;
16
+ use Magento \Framework \Filesystem ;
11
17
use Magento \Framework \Flag ;
12
18
use Magento \Framework \FlagFactory ;
19
+ use Magento \Framework \ObjectManagerInterface ;
13
20
use Magento \Store \Model \GroupFactory ;
14
21
use Magento \Store \Model \StoreFactory ;
15
22
use Magento \Store \Model \WebsiteFactory ;
16
23
use Magento \TestFramework \Helper \Bootstrap ;
17
- use Magento \Framework \ObjectManagerInterface ;
18
- use Magento \Framework \Console \Cli ;
19
- use Magento \Framework \Filesystem ;
20
- use Magento \Framework \App \Filesystem \DirectoryList ;
21
24
use Symfony \Component \Console \Tester \CommandTester ;
22
- use Magento \Deploy \Model \DeploymentConfig \Hash ;
23
- use Magento \Framework \App \Config \ReinitableConfigInterface ;
24
25
25
26
/**
26
27
* @SuppressWarnings(PHPMD.CouplingBetweenObjects)
28
+ * phpcs:disable
27
29
*/
28
30
class ConfigImportCommandTest extends \PHPUnit \Framework \TestCase
29
31
{
@@ -160,7 +162,7 @@ public function testImportStores()
160
162
$ command = $ this ->objectManager ->create (ConfigImportCommand::class);
161
163
$ commandTester = new CommandTester ($ command );
162
164
163
- $ this ->runConfigImportCommand ($ commandTester );
165
+ $ this ->runConfigImportCommand ($ commandTester, ' Stores were processed ' );
164
166
165
167
/** @var StoreFactory $storeFactory */
166
168
$ storeFactory = $ this ->objectManager ->get (StoreFactory::class);
@@ -189,7 +191,7 @@ public function testImportStores()
189
191
require __DIR__ . '/../../../_files/scopes/config_with_changed_stores.php '
190
192
);
191
193
192
- $ this ->runConfigImportCommand ($ commandTester );
194
+ $ this ->runConfigImportCommand ($ commandTester, ' Stores were processed ' );
193
195
194
196
$ store = $ storeFactory ->create ();
195
197
$ store ->getResource ()->load ($ store , 'test ' , 'code ' );
@@ -212,7 +214,7 @@ public function testImportStores()
212
214
require __DIR__ . '/../../../_files/scopes/config_with_removed_stores.php '
213
215
);
214
216
215
- $ this ->runConfigImportCommand ($ commandTester );
217
+ $ this ->runConfigImportCommand ($ commandTester, ' Stores were processed ' );
216
218
217
219
$ group = $ groupFactory ->create ();
218
220
$ group ->getResource ()->load ($ group , 'test_website_store ' , 'code ' );
@@ -341,6 +343,64 @@ public function testImportConfig()
341
343
$ this ->assertSame (Cli::RETURN_SUCCESS , $ commandTester ->getStatusCode ());
342
344
}
343
345
346
+ /**
347
+ * @magentoDbIsolation disabled
348
+ */
349
+ public function testImportCurrencyImportSchedule ()
350
+ {
351
+ $ this ->assertEmpty ($ this ->hash ->get ());
352
+
353
+ $ dumpCommand = $ this ->objectManager ->create (ApplicationDumpCommand::class);
354
+ $ dumpCommandTester = new CommandTester ($ dumpCommand );
355
+ $ dumpCommandTester ->execute ([]);
356
+ $ dumpedData = $ this ->reader ->load (ConfigFilePool::APP_CONFIG );
357
+
358
+ $ command = $ this ->objectManager ->create (ConfigImportCommand::class);
359
+ $ commandTester = new CommandTester ($ command );
360
+
361
+ /** @var Cron $currencyImportSettings */
362
+ $ currencyImportSettings = $ this ->objectManager ->get (Cron::class);
363
+ /** @var $valueFactory \Magento\Framework\App\Config\ValueFactory */
364
+ $ reflectionProperty = new \ReflectionProperty (
365
+ $ currencyImportSettings ,
366
+ '_configValueFactory '
367
+ );
368
+ $ reflectionProperty ->setAccessible (true );
369
+ $ valueFactory = $ reflectionProperty ->getValue ($ currencyImportSettings );
370
+ /** @var $configValue \Magento\Framework\App\Config\ValueInterface */
371
+ $ configValue = $ valueFactory ->create ();
372
+
373
+ $ hour = rand (0 , 23 );
374
+ $ min = rand (0 , 59 );
375
+ $ data = [
376
+ 'system ' => [
377
+ 'default ' => [
378
+ 'currency ' => [
379
+ 'import ' => [
380
+ 'enabled ' => '1 ' ,
381
+ 'service ' => 'fixerio ' ,
382
+ 'time ' => sprintf ("%02d " , $ hour ) . ', ' . sprintf ("%02d " , $ min ) . ',00 ' ,
383
+ 'frequency ' => 'D ' ,
384
+ 'error_email_identity ' => 'general ' ,
385
+ 'error_email_template ' => 'currency_import_error_email_template ' ,
386
+ ],
387
+ ],
388
+ ],
389
+ ]
390
+ ];
391
+
392
+ $ this ->writeConfig (
393
+ $ dumpedData ,
394
+ $ data
395
+ );
396
+ $ this ->runConfigImportCommand ($ commandTester , 'System config was processed ' );
397
+
398
+ $ configValue ->load (Cron::CRON_STRING_PATH , 'path ' );
399
+ $ configValue ->getFieldsetDataValue ('path ' );
400
+ $ time = $ configValue ->getValue ();
401
+ $ this ->assertSame ($ time , "$ min $ hour * * * " );
402
+ }
403
+
344
404
/**
345
405
* Saves new data.
346
406
*
@@ -393,7 +453,7 @@ private function loadEnvConfig()
393
453
*
394
454
* @param $commandTester
395
455
*/
396
- private function runConfigImportCommand ($ commandTester )
456
+ private function runConfigImportCommand ($ commandTester, $ assertPartialString )
397
457
{
398
458
$ this ->appConfig ->reinit ();
399
459
$ commandTester ->execute ([], ['interactive ' => false ]);
@@ -402,7 +462,7 @@ private function runConfigImportCommand($commandTester)
402
462
'Processing configurations data from configuration file... ' ,
403
463
$ commandTester ->getDisplay ()
404
464
);
405
- $ this ->assertStringContainsString (' Stores were processed ' , $ commandTester ->getDisplay ());
465
+ $ this ->assertStringContainsString ($ assertPartialString , $ commandTester ->getDisplay ());
406
466
$ this ->assertSame (Cli::RETURN_SUCCESS , $ commandTester ->getStatusCode ());
407
467
}
408
468
}
0 commit comments