55 */
66namespace Magento \Deploy \Console \Command \App ;
77
8+ use Magento \Config \Model \Config \Backend \Currency \Cron ;
9+ use Magento \Deploy \Model \DeploymentConfig \Hash ;
810use Magento \Framework \App \CacheInterface ;
11+ use Magento \Framework \App \Config \ReinitableConfigInterface ;
912use Magento \Framework \App \DeploymentConfig ;
13+ use Magento \Framework \App \Filesystem \DirectoryList ;
1014use Magento \Framework \Config \File \ConfigFilePool ;
15+ use Magento \Framework \Console \Cli ;
16+ use Magento \Framework \Filesystem ;
1117use Magento \Framework \Flag ;
1218use Magento \Framework \FlagFactory ;
19+ use Magento \Framework \ObjectManagerInterface ;
1320use Magento \Store \Model \GroupFactory ;
1421use Magento \Store \Model \StoreFactory ;
1522use Magento \Store \Model \WebsiteFactory ;
1623use 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 ;
2124use Symfony \Component \Console \Tester \CommandTester ;
22- use Magento \Deploy \Model \DeploymentConfig \Hash ;
23- use Magento \Framework \App \Config \ReinitableConfigInterface ;
2425
2526/**
2627 * @SuppressWarnings(PHPMD.CouplingBetweenObjects)
28+ * phpcs:disable
2729 */
2830class ConfigImportCommandTest extends \PHPUnit \Framework \TestCase
2931{
@@ -160,7 +162,7 @@ public function testImportStores()
160162 $ command = $ this ->objectManager ->create (ConfigImportCommand::class);
161163 $ commandTester = new CommandTester ($ command );
162164
163- $ this ->runConfigImportCommand ($ commandTester );
165+ $ this ->runConfigImportCommand ($ commandTester, ' Stores were processed ' );
164166
165167 /** @var StoreFactory $storeFactory */
166168 $ storeFactory = $ this ->objectManager ->get (StoreFactory::class);
@@ -189,7 +191,7 @@ public function testImportStores()
189191 require __DIR__ . '/../../../_files/scopes/config_with_changed_stores.php '
190192 );
191193
192- $ this ->runConfigImportCommand ($ commandTester );
194+ $ this ->runConfigImportCommand ($ commandTester, ' Stores were processed ' );
193195
194196 $ store = $ storeFactory ->create ();
195197 $ store ->getResource ()->load ($ store , 'test ' , 'code ' );
@@ -212,7 +214,7 @@ public function testImportStores()
212214 require __DIR__ . '/../../../_files/scopes/config_with_removed_stores.php '
213215 );
214216
215- $ this ->runConfigImportCommand ($ commandTester );
217+ $ this ->runConfigImportCommand ($ commandTester, ' Stores were processed ' );
216218
217219 $ group = $ groupFactory ->create ();
218220 $ group ->getResource ()->load ($ group , 'test_website_store ' , 'code ' );
@@ -341,6 +343,64 @@ public function testImportConfig()
341343 $ this ->assertSame (Cli::RETURN_SUCCESS , $ commandTester ->getStatusCode ());
342344 }
343345
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+
344404 /**
345405 * Saves new data.
346406 *
@@ -393,7 +453,7 @@ private function loadEnvConfig()
393453 *
394454 * @param $commandTester
395455 */
396- private function runConfigImportCommand ($ commandTester )
456+ private function runConfigImportCommand ($ commandTester, $ assertPartialString )
397457 {
398458 $ this ->appConfig ->reinit ();
399459 $ commandTester ->execute ([], ['interactive ' => false ]);
@@ -402,7 +462,7 @@ private function runConfigImportCommand($commandTester)
402462 'Processing configurations data from configuration file... ' ,
403463 $ commandTester ->getDisplay ()
404464 );
405- $ this ->assertStringContainsString (' Stores were processed ' , $ commandTester ->getDisplay ());
465+ $ this ->assertStringContainsString ($ assertPartialString , $ commandTester ->getDisplay ());
406466 $ this ->assertSame (Cli::RETURN_SUCCESS , $ commandTester ->getStatusCode ());
407467 }
408468}
0 commit comments