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)
@@ -160,7 +161,7 @@ public function testImportStores()
160161 $ command = $ this ->objectManager ->create (ConfigImportCommand::class);
161162 $ commandTester = new CommandTester ($ command );
162163
163- $ this ->runConfigImportCommand ($ commandTester );
164+ $ this ->runConfigImportCommand ($ commandTester, ' Stores were processed ' );
164165
165166 /** @var StoreFactory $storeFactory */
166167 $ storeFactory = $ this ->objectManager ->get (StoreFactory::class);
@@ -189,7 +190,7 @@ public function testImportStores()
189190 require __DIR__ . '/../../../_files/scopes/config_with_changed_stores.php '
190191 );
191192
192- $ this ->runConfigImportCommand ($ commandTester );
193+ $ this ->runConfigImportCommand ($ commandTester, ' Stores were processed ' );
193194
194195 $ store = $ storeFactory ->create ();
195196 $ store ->getResource ()->load ($ store , 'test ' , 'code ' );
@@ -212,7 +213,7 @@ public function testImportStores()
212213 require __DIR__ . '/../../../_files/scopes/config_with_removed_stores.php '
213214 );
214215
215- $ this ->runConfigImportCommand ($ commandTester );
216+ $ this ->runConfigImportCommand ($ commandTester, ' Stores were processed ' );
216217
217218 $ group = $ groupFactory ->create ();
218219 $ group ->getResource ()->load ($ group , 'test_website_store ' , 'code ' );
@@ -341,6 +342,64 @@ public function testImportConfig()
341342 $ this ->assertSame (Cli::RETURN_SUCCESS , $ commandTester ->getStatusCode ());
342343 }
343344
345+ /**
346+ * @magentoDbIsolation disabled
347+ */
348+ public function testImportCurrencyImportSchedule ()
349+ {
350+ $ this ->assertEmpty ($ this ->hash ->get ());
351+
352+ $ dumpCommand = $ this ->objectManager ->create (ApplicationDumpCommand::class);
353+ $ dumpCommandTester = new CommandTester ($ dumpCommand );
354+ $ dumpCommandTester ->execute ([]);
355+ $ dumpedData = $ this ->reader ->load (ConfigFilePool::APP_CONFIG );
356+
357+ $ command = $ this ->objectManager ->create (ConfigImportCommand::class);
358+ $ commandTester = new CommandTester ($ command );
359+
360+ /** @var Cron $currencyImportSettings */
361+ $ currencyImportSettings = $ this ->objectManager ->get (Cron::class);
362+ /** @var $valueFactory \Magento\Framework\App\Config\ValueFactory */
363+ $ reflectionProperty = new \ReflectionProperty (
364+ $ currencyImportSettings ,
365+ '_configValueFactory '
366+ );
367+ $ reflectionProperty ->setAccessible (true );
368+ $ valueFactory = $ reflectionProperty ->getValue ($ currencyImportSettings );
369+ /** @var $configValue \Magento\Framework\App\Config\ValueInterface */
370+ $ configValue = $ valueFactory ->create ();
371+
372+ $ hour = rand (0 , 23 );
373+ $ min = rand (0 , 59 );
374+ $ data = [
375+ 'system ' => [
376+ 'default ' => [
377+ 'currency ' => [
378+ 'import ' => [
379+ 'enabled ' => '1 ' ,
380+ 'service ' => 'fixerio ' ,
381+ 'time ' => sprintf ("%02d " , $ hour ) . ', ' . sprintf ("%02d " , $ min ) . ',00 ' ,
382+ 'frequency ' => 'D ' ,
383+ 'error_email_identity ' => 'general ' ,
384+ 'error_email_template ' => 'currency_import_error_email_template ' ,
385+ ],
386+ ],
387+ ],
388+ ]
389+ ];
390+
391+ $ this ->writeConfig (
392+ $ dumpedData ,
393+ $ data
394+ );
395+ $ this ->runConfigImportCommand ($ commandTester , 'System config was processed ' );
396+
397+ $ configValue ->load (Cron::CRON_STRING_PATH , Cron::CONFIG_FIELD );
398+ $ configValue ->getFieldsetDataValue (Cron::CONFIG_FIELD );
399+ $ time = $ configValue ->getValue ();
400+ $ this ->assertSame ($ time , "$ min $ hour * * * " );
401+ }
402+
344403 /**
345404 * Saves new data.
346405 *
@@ -393,7 +452,7 @@ private function loadEnvConfig()
393452 *
394453 * @param $commandTester
395454 */
396- private function runConfigImportCommand ($ commandTester )
455+ private function runConfigImportCommand ($ commandTester, $ assertPartialString )
397456 {
398457 $ this ->appConfig ->reinit ();
399458 $ commandTester ->execute ([], ['interactive ' => false ]);
@@ -402,7 +461,7 @@ private function runConfigImportCommand($commandTester)
402461 'Processing configurations data from configuration file... ' ,
403462 $ commandTester ->getDisplay ()
404463 );
405- $ this ->assertStringContainsString (' Stores were processed ' , $ commandTester ->getDisplay ());
464+ $ this ->assertStringContainsString ($ assertPartialString , $ commandTester ->getDisplay ());
406465 $ this ->assertSame (Cli::RETURN_SUCCESS , $ commandTester ->getStatusCode ());
407466 }
408467}
0 commit comments