Skip to content

Commit 3f04c08

Browse files
Merge remote-tracking branch 'remotes/github/MAGETWO-94919-rebase' into EPAM-PR-85
2 parents aab1ce3 + 929b2b9 commit 3f04c08

19 files changed

+847
-79
lines changed
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<!--
3+
/**
4+
* Copyright © Magento, Inc. All rights reserved.
5+
* See COPYING.txt for license details.
6+
*/
7+
-->
8+
9+
<entities xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
10+
xsi:noNamespaceSchemaLocation="urn:magento:mftf:DataGenerator/etc/dataProfileSchema.xsd">
11+
<entity name="CatalogPriceScopeWebsiteConfigData">
12+
<data key="path">catalog/price/scope</data>
13+
<data key="value">1</data>
14+
</entity>
15+
<entity name="CatalogPriceScopeGlobalConfigData">
16+
<data key="path">catalog/price/scope</data>
17+
<data key="value">0</data>
18+
</entity>
19+
</entities>

app/code/Magento/CurrencySymbol/Controller/Adminhtml/System/Currency/FetchRates.php

Lines changed: 57 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -3,40 +3,83 @@
33
* Copyright © Magento, Inc. All rights reserved.
44
* See COPYING.txt for license details.
55
*/
6+
declare(strict_types=1);
67

78
namespace Magento\CurrencySymbol\Controller\Adminhtml\System\Currency;
89

10+
use Magento\Backend\App\Action\Context;
11+
use Magento\Backend\Model\View\Result\Redirect;
12+
use Magento\Backend\Model\Session as BackendSession;
13+
use Magento\CurrencySymbol\Controller\Adminhtml\System\Currency as CurrencyAction;
14+
use Magento\Directory\Model\Currency\Import\Factory as CurrencyImportFactory;
15+
use Magento\Directory\Model\Currency\Import\ImportInterface as CurrencyImport;
916
use Magento\Framework\App\Action\HttpGetActionInterface;
1017
use Magento\Framework\App\Action\HttpPostActionInterface as HttpPostActionInterface;
18+
use Magento\Framework\App\ObjectManager;
19+
use Magento\Framework\Escaper;
1120
use Magento\Framework\Exception\LocalizedException;
1221
use Magento\Framework\Controller\ResultFactory;
13-
use Magento\CurrencySymbol\Controller\Adminhtml\System\Currency as CurrencyAction;
22+
use Magento\Framework\Registry;
23+
use Exception;
1424

1525
/**
16-
* Class FetchRates
26+
* Fetch rates controller.
1727
*/
1828
class FetchRates extends CurrencyAction implements HttpGetActionInterface, HttpPostActionInterface
1929
{
30+
/**
31+
* @var BackendSession
32+
*/
33+
private $backendSession;
34+
35+
/**
36+
* @var CurrencyImportFactory
37+
*/
38+
private $currencyImportFactory;
39+
40+
/**
41+
* @var Escaper
42+
*/
43+
private $escaper;
44+
45+
/**
46+
* @param Context $context
47+
* @param Registry $coreRegistry
48+
* @param BackendSession|null $backendSession
49+
* @param CurrencyImportFactory|null $currencyImportFactory
50+
* @param Escaper|null $escaper
51+
*/
52+
public function __construct(
53+
Context $context,
54+
Registry $coreRegistry,
55+
?BackendSession $backendSession = null,
56+
?CurrencyImportFactory $currencyImportFactory = null,
57+
?Escaper $escaper = null
58+
) {
59+
parent::__construct($context, $coreRegistry);
60+
$this->backendSession = $backendSession ?: ObjectManager::getInstance()->get(BackendSession::class);
61+
$this->currencyImportFactory = $currencyImportFactory ?: ObjectManager::getInstance()
62+
->get(CurrencyImportFactory::class);
63+
$this->escaper = $escaper ?: ObjectManager::getInstance()->get(Escaper::class);
64+
}
65+
2066
/**
2167
* Fetch rates action
2268
*
23-
* @return \Magento\Backend\Model\View\Result\Redirect
69+
* @return Redirect
2470
*/
2571
public function execute()
2672
{
27-
/** @var \Magento\Backend\Model\Session $backendSession */
28-
$backendSession = $this->_objectManager->get(\Magento\Backend\Model\Session::class);
2973
try {
3074
$service = $this->getRequest()->getParam('rate_services');
3175
$this->_getSession()->setCurrencyRateService($service);
3276
if (!$service) {
3377
throw new LocalizedException(__('The Import Service is incorrect. Verify the service and try again.'));
3478
}
3579
try {
36-
/** @var \Magento\Directory\Model\Currency\Import\ImportInterface $importModel */
37-
$importModel = $this->_objectManager->get(\Magento\Directory\Model\Currency\Import\Factory::class)
38-
->create($service);
39-
} catch (\Exception $e) {
80+
/** @var CurrencyImport $importModel */
81+
$importModel = $this->currencyImportFactory->create($service);
82+
} catch (Exception $e) {
4083
throw new LocalizedException(
4184
__("The import model can't be initialized. Verify the model and try again.")
4285
);
@@ -45,7 +88,8 @@ public function execute()
4588
$errors = $importModel->getMessages();
4689
if (count($errors) > 0) {
4790
foreach ($errors as $error) {
48-
$this->messageManager->addWarningMessage($error);
91+
$escapedError = $this->escaper->escapeHtml($error);
92+
$this->messageManager->addWarningMessage($escapedError);
4993
}
5094
$this->messageManager->addWarningMessage(
5195
__('Click "Save" to apply the rates we found.')
@@ -54,12 +98,12 @@ public function execute()
5498
$this->messageManager->addSuccessMessage(__('Click "Save" to apply the rates we found.'));
5599
}
56100

57-
$backendSession->setRates($rates);
58-
} catch (\Exception $e) {
101+
$this->backendSession->setRates($rates);
102+
} catch (Exception $e) {
59103
$this->messageManager->addErrorMessage($e->getMessage());
60104
}
61105

62-
/** @var \Magento\Backend\Model\View\Result\Redirect $resultRedirect */
106+
/** @var Redirect $resultRedirect */
63107
$resultRedirect = $this->resultFactory->create(ResultFactory::TYPE_REDIRECT);
64108
return $resultRedirect->setPath('adminhtml/*/');
65109
}
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<!--
3+
/**
4+
* Copyright © Magento, Inc. All rights reserved.
5+
* See COPYING.txt for license details.
6+
*/
7+
-->
8+
9+
<actionGroups xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
10+
xsi:noNamespaceSchemaLocation="urn:magento:mftf:Test/etc/actionGroupSchema.xsd">
11+
<actionGroup name="AdminImportCurrencyRatesActionGroup">
12+
<arguments>
13+
<argument name="rateService" type="string" defaultValue="Fixer.io"/>
14+
</arguments>
15+
<selectOption selector="{{AdminCurrencyRatesSection.rateService}}" userInput="{{rateService}}" stepKey="selectRateService"/>
16+
<click selector="{{AdminCurrencyRatesSection.import}}" stepKey="clickImport"/>
17+
<waitForElementVisible selector="{{AdminCurrencyRatesSection.oldRate}}" stepKey="waitForOldRateVisible"/>
18+
</actionGroup>
19+
<actionGroup name="AdminSaveCurrencyRatesActionGroup">
20+
<click selector="{{AdminCurrencyRatesSection.saveCurrencyRates}}" stepKey="clickSaveCurrencyRates"/>
21+
<waitForPageLoad stepKey="waitForSave"/>
22+
<see selector="{{AdminMessagesSection.success}}" userInput="All valid rates have been saved." stepKey="seeSuccessMessage"/>
23+
</actionGroup>
24+
<actionGroup name="AdminSetCurrencyRatesActionGroup">
25+
<arguments>
26+
<argument name="firstCurrency" type="string" defaultValue="USD"/>
27+
<argument name="secondCurrency" type="string" defaultValue="EUR"/>
28+
<argument name="rate" type="string" defaultValue="0.5"/>
29+
</arguments>
30+
<fillField selector="{{AdminCurrencyRatesSection.currencyRate(firstCurrency, secondCurrency)}}" userInput="{{rate}}" stepKey="setCurrencyRate"/>
31+
<click selector="{{AdminCurrencyRatesSection.saveCurrencyRates}}" stepKey="clickSaveCurrencyRates"/>
32+
<waitForPageLoad stepKey="waitForSave"/>
33+
<see selector="{{AdminMessagesSection.success}}" userInput="{{AdminSaveCurrencyRatesMessageData.success}}" stepKey="seeSuccessMessage"/>
34+
</actionGroup>
35+
</actionGroups>
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<!--
3+
/**
4+
* Copyright © Magento, Inc. All rights reserved.
5+
* See COPYING.txt for license details.
6+
*/
7+
-->
8+
9+
<actionGroups xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
10+
xsi:noNamespaceSchemaLocation="urn:magento:mftf:Test/etc/actionGroupSchema.xsd">
11+
<actionGroup name="StorefrontSwitchCurrencyActionGroup">
12+
<arguments>
13+
<argument name="currency" type="string" defaultValue="EUR"/>
14+
</arguments>
15+
<click selector="{{StorefrontSwitchCurrencyRatesSection.currencyToggle}}" stepKey="openToggle"/>
16+
<waitForElementVisible selector="{{StorefrontSwitchCurrencyRatesSection.currency(currency)}}" stepKey="waitForCurrency"/>
17+
<click selector="{{StorefrontSwitchCurrencyRatesSection.currency(currency)}}" stepKey="chooseCurrency"/>
18+
<see selector="{{StorefrontSwitchCurrencyRatesSection.selectedCurrency}}" userInput="{{currency}}" stepKey="seeSelectedCurrency"/>
19+
</actionGroup>
20+
<actionGroup name="StorefrontSwitchCurrency">
21+
<arguments>
22+
<argument name="currency" type="string" defaultValue="EUR"/>
23+
</arguments>
24+
<click selector="{{StorefrontSwitchCurrencyRatesSection.currencyTrigger}}" stepKey="openTrigger"/>
25+
<waitForElementVisible selector="{{StorefrontSwitchCurrencyRatesSection.currency(currency)}}" stepKey="waitForCurrency"/>
26+
<click selector="{{StorefrontSwitchCurrencyRatesSection.currency(currency)}}" stepKey="chooseCurrency"/>
27+
<see selector="{{StorefrontSwitchCurrencyRatesSection.selectedCurrency}}" userInput="{{currency}}" stepKey="seeSelectedCurrency"/>
28+
</actionGroup>
29+
</actionGroups>
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<!--
3+
/**
4+
* Copyright © Magento, Inc. All rights reserved.
5+
* See COPYING.txt for license details.
6+
*/
7+
-->
8+
9+
<entities xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
10+
xsi:noNamespaceSchemaLocation="urn:magento:mftf:DataGenerator/etc/dataProfileSchema.xsd">
11+
<entity name="AdminSaveCurrencyRatesMessageData">
12+
<data key="success">All valid rates have been saved.</data>
13+
</entity>
14+
</entities>
Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<!--
3+
/**
4+
* Copyright © Magento, Inc. All rights reserved.
5+
* See COPYING.txt for license details.
6+
*/
7+
-->
8+
9+
<entities xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
10+
xsi:noNamespaceSchemaLocation="urn:magento:mftf:DataGenerator/etc/dataProfileSchema.xsd">
11+
<entity name="SetCurrencyUSDBaseConfig">
12+
<data key="path">currency/options/base</data>
13+
<data key="value">USD</data>
14+
<data key="scope">websites</data>
15+
<data key="scope_code">base</data>
16+
</entity>
17+
<entity name="SetCurrencyEURBaseConfig">
18+
<data key="path">currency/options/base</data>
19+
<data key="value">EUR</data>
20+
<data key="scope">websites</data>
21+
<data key="scope_code">base</data>
22+
</entity>
23+
<entity name="SetAllowedCurrenciesConfigForUSD">
24+
<data key="path">currency/options/allow</data>
25+
<data key="value">USD</data>
26+
<data key="scope">websites</data>
27+
<data key="scope_code">base</data>
28+
</entity>
29+
<entity name="SetAllowedCurrenciesConfigForEUR">
30+
<data key="path">currency/options/allow</data>
31+
<data key="value">EUR</data>
32+
<data key="scope">websites</data>
33+
<data key="scope_code">base</data>
34+
</entity>
35+
<entity name="SetAllowedCurrenciesConfigForRUB">
36+
<data key="path">currency/options/allow</data>
37+
<data key="value">RUB</data>
38+
<data key="scope">websites</data>
39+
<data key="scope_code">base</data>
40+
</entity>
41+
<entity name="SetDefaultCurrencyEURConfig">
42+
<data key="path">currency/options/default</data>
43+
<data key="value">EUR</data>
44+
<data key="scope">websites</data>
45+
<data key="scope_code">base</data>
46+
</entity>
47+
<entity name="SetDefaultCurrencyUSDConfig">
48+
<data key="path">currency/options/default</data>
49+
<data key="value">USD</data>
50+
<data key="scope">websites</data>
51+
<data key="scope_code">base</data>
52+
</entity>
53+
</entities>
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<!--
3+
/**
4+
* Copyright © Magento, Inc. All rights reserved.
5+
* See COPYING.txt for license details.
6+
*/
7+
-->
8+
9+
<pages xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
10+
xsi:noNamespaceSchemaLocation="urn:magento:mftf:Page/etc/PageObject.xsd">
11+
<page name="AdminCurrencyRatesPage" url="admin/system_currency/" area="admin" module="CurrencySymbol">
12+
<section name="AdminCurrencyRatesSection"/>
13+
</page>
14+
</pages>
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<!--
3+
/**
4+
* Copyright © Magento, Inc. All rights reserved.
5+
* See COPYING.txt for license details.
6+
*/
7+
-->
8+
9+
<sections xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
10+
xsi:noNamespaceSchemaLocation="urn:magento:mftf:Page/etc/SectionObject.xsd">
11+
<section name="AdminCurrencyRatesSection">
12+
<element name="import" type="button" selector="//button[@title='Import']"/>
13+
<element name="saveCurrencyRates" type="button" selector="//button[@title='Save Currency Rates']"/>
14+
<element name="oldRate" type="text" selector="//div[contains(@class, 'admin__field-note') and contains(text(), 'Old rate:')]/strong"/>
15+
<element name="rateService" type="select" selector="#rate_services"/>
16+
<element name="currencyRate" type="input" selector="input[name='rate[{{fistCurrency}}][{{secondCurrency}}]']" parameterized="true"/>
17+
</section>
18+
</sections>
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<!--
3+
/**
4+
* Copyright © Magento, Inc. All rights reserved.
5+
* See COPYING.txt for license details.
6+
*/
7+
-->
8+
9+
<sections xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
10+
xsi:noNamespaceSchemaLocation="urn:magento:mftf:Page/etc/SectionObject.xsd">
11+
<section name="StorefrontSwitchCurrencyRatesSection">
12+
<element name="currencyToggle" type="select" selector="#switcher-currency-trigger" timeout="30"/>
13+
<element name="currencyTrigger" type="select" selector="#switcher-currency-trigger" timeout="30"/>
14+
<element name="currency" type="button" selector="//div[@id='switcher-currency-trigger']/following-sibling::ul//a[contains(text(), '{{currency}}')]" parameterized="true" timeout="10"/>
15+
<element name="selectedCurrency" type="text" selector="#switcher-currency-trigger span"/>
16+
</section>
17+
</sections>

0 commit comments

Comments
 (0)