Skip to content

Commit 6343478

Browse files
committed
Merge remote-tracking branch 'origin/MC-19046' into 2.2-develop-pr108
2 parents 9679c05 + 0cffc58 commit 6343478

File tree

10 files changed

+257
-46
lines changed

10 files changed

+257
-46
lines changed
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
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="AdminClickSaveAndContinueButtonActionGroup">
12+
<annotations>
13+
<description>Click "Save and Continue" button and assert message</description>
14+
</annotations>
15+
<arguments>
16+
<argument name="message" type="string"/>
17+
</arguments>
18+
<scrollToTopOfPage stepKey="scrollToPageTop"/>
19+
<click selector="{{AdminMainActionsSection.saveAndContinue}}" stepKey="clickSaveAndContinue"/>
20+
<waitForElementVisible time="30" selector="{{AdminMessagesSection.success}}" stepKey="waitMessage"/>
21+
<see selector="{{AdminMessagesSection.success}}" userInput="{{message}}" stepKey="verifyMessage"/>
22+
</actionGroup>
23+
</actionGroups>

app/code/Magento/Catalog/Test/Mftf/ActionGroup/StorefrontCategoryActionGroup.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@
6060
</arguments>
6161
<!-- Go to storefront category page -->
6262
<amOnPage url="{{StorefrontCategoryPage.url(category)}}?product_list_mode={{mode}}&amp;product_list_order={{sortBy}}&amp;product_list_dir={{sort}}" stepKey="onCategoryPage"/>
63+
<waitForPageLoad time="30" stepKey="waitCategoryPageLoaded"/>
6364
</actionGroup>
6465

6566
<actionGroup name="VerifyCategoryPageParameters">
@@ -69,7 +70,6 @@
6970
<argument name="numOfProductsPerPage" type="string"/>
7071
<argument name="sortBy" type="string" defaultValue="position"/>
7172
</arguments>
72-
<amOnPage url="{{StorefrontCategoryPage.url(categoryName)}}" stepKey="navigateToCategoryPage"/>
7373
<seeInTitle userInput="{{categoryName}}" stepKey="assertCategoryNameInTitle"/>
7474
<see userInput="{{categoryName}}" selector="{{StorefrontCategoryMainSection.categoryTitle}}" stepKey="assertCategoryName"/>
7575
<see userInput="{{mode}}" selector="{{StorefrontCategoryPagerSection.modeGridIsActive}}" stepKey="assertViewMode"/>
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+
<actionGroups xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:mftf:Test/etc/actionGroupSchema.xsd">
9+
<actionGroup name="StorefrontNavigateCategoryPageActionGroup">
10+
<annotations>
11+
<description>Navigates storefront category page by url key</description>
12+
</annotations>
13+
<arguments>
14+
<argument name="categoryUrlKey"/>
15+
</arguments>
16+
<amOnPage url="{{StorefrontCategoryPage.url(categoryUrlKey)}}" stepKey="navigateStorefrontCategoryPage"/>
17+
<waitForPageLoad time="30" stepKey="waitCategoryPageLoaded"/>
18+
</actionGroup>
19+
</actionGroups>

app/code/Magento/Catalog/Test/Mftf/Test/StorefrontRememberCategoryPaginationTest.xml

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,6 @@
3030
</createData>
3131

3232
<createData entity="RememberPaginationCatalogStorefrontConfig" stepKey="setRememberPaginationCatalogStorefrontConfig"/>
33-
<magentoCLI command="cache:flush" stepKey="clearCache"/>
3433
</before>
3534

3635
<after>
@@ -40,26 +39,29 @@
4039
<deleteData createDataKey="createCategory" stepKey="deleteCategory"/>
4140
<deleteData createDataKey="createProduct1" stepKey="deleteProduct1"/>
4241
<deleteData createDataKey="createCategory1" stepKey="deleteCategory1"/>
43-
44-
<magentoCLI command="cache:flush" stepKey="flushCache"/>
4542
</after>
4643

47-
<actionGroup ref="GoToStorefrontCategoryPageByParameters" stepKey="goToStorefrontCategory1Page">
48-
<argument name="category" value="$$createCategory.name$$"/>
44+
<actionGroup ref="GoToStorefrontCategoryPageByParameters" stepKey="goToStorefrontCategoryPage">
45+
<argument name="category" value="$$createCategory.custom_attributes[url_key]$$"/>
4946
<argument name="mode" value="grid"/>
5047
</actionGroup>
5148

5249
<selectOption selector="{{StorefrontCategoryPagerSection.perPage}}" userInput="12" stepKey="setPerPage" />
53-
<waitForPageLoad stepKey="waitForPageLoad"/>
50+
<waitForPageLoad time="30" stepKey="waitForPageLoad"/>
51+
52+
<actionGroup ref="StorefrontNavigateCategoryPageActionGroup" stepKey="navigateToCategoryPage">
53+
<argument name="categoryUrlKey" value="$$createCategory.custom_attributes[url_key]$$"/>
54+
</actionGroup>
5455

5556
<actionGroup ref="VerifyCategoryPageParameters" stepKey="verifyCategoryPageParameters">
5657
<argument name="categoryName" value="$$createCategory.name$$"/>
5758
<argument name="mode" value="grid"/>
5859
<argument name="numOfProductsPerPage" value="12"/>
5960
</actionGroup>
6061

61-
<amOnPage url="{{StorefrontCategoryPage.url($$createCategory1.name$$)}}" stepKey="navigateToCategory1Page"/>
62-
<waitForPageLoad stepKey="waitForCategory1PageToLoad"/>
62+
<actionGroup ref="StorefrontNavigateCategoryPageActionGroup" stepKey="navigateToCategory1Page">
63+
<argument name="categoryUrlKey" value="$$createCategory1.custom_attributes[url_key]$$"/>
64+
</actionGroup>
6365

6466
<actionGroup ref="VerifyCategoryPageParameters" stepKey="verifyCategory1PageParameters">
6567
<argument name="categoryName" value="$$createCategory1.name$$"/>

app/code/Magento/CatalogRule/Controller/Adminhtml/Promo/Catalog/Save.php

Lines changed: 67 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,14 @@
77
namespace Magento\CatalogRule\Controller\Adminhtml\Promo\Catalog;
88

99
use Magento\Backend\App\Action\Context;
10+
use Magento\Framework\App\Request\DataPersistorInterface;
1011
use Magento\Framework\Exception\LocalizedException;
12+
use Magento\Framework\Filter\LocalizedToNormalizedFactory;
13+
use Magento\Framework\Filter\NormalizedToLocalizedFactory;
1114
use Magento\Framework\Registry;
15+
use Magento\Framework\Stdlib\DateTime;
1216
use Magento\Framework\Stdlib\DateTime\Filter\Date;
13-
use Magento\Framework\App\Request\DataPersistorInterface;
17+
use Magento\Framework\Stdlib\DateTime\TimezoneInterface;
1418

1519
/**
1620
* @SuppressWarnings(PHPMD.CouplingBetweenObjects)
@@ -22,20 +26,44 @@ class Save extends \Magento\CatalogRule\Controller\Adminhtml\Promo\Catalog
2226
*/
2327
protected $dataPersistor;
2428

29+
/**
30+
* @var TimezoneInterface
31+
*/
32+
private $localeDate;
33+
34+
/**
35+
* @var LocalizedToNormalizedFactory
36+
*/
37+
private $localizedToNormalizedFactory;
38+
39+
/**
40+
* @var NormalizedToLocalizedFactory
41+
*/
42+
private $normalizedToLocalizedFactory;
43+
2544
/**
2645
* @param Context $context
2746
* @param Registry $coreRegistry
2847
* @param Date $dateFilter
2948
* @param DataPersistorInterface $dataPersistor
49+
* @param TimezoneInterface $localeDate
50+
* @param LocalizedToNormalizedFactory $localizedToNormalizedFactory
51+
* @param NormalizedToLocalizedFactory $normalizedToLocalizedFactory
3052
*/
3153
public function __construct(
3254
Context $context,
3355
Registry $coreRegistry,
3456
Date $dateFilter,
35-
DataPersistorInterface $dataPersistor
57+
DataPersistorInterface $dataPersistor,
58+
TimezoneInterface $localeDate,
59+
LocalizedToNormalizedFactory $localizedToNormalizedFactory,
60+
NormalizedToLocalizedFactory $normalizedToLocalizedFactory
3661
) {
37-
$this->dataPersistor = $dataPersistor;
3862
parent::__construct($context, $coreRegistry, $dateFilter);
63+
$this->dataPersistor = $dataPersistor;
64+
$this->localeDate = $localeDate;
65+
$this->localizedToNormalizedFactory = $localizedToNormalizedFactory;
66+
$this->normalizedToLocalizedFactory = $normalizedToLocalizedFactory;
3967
}
4068

4169
/**
@@ -61,16 +89,7 @@ public function execute()
6189
);
6290
$data = $this->getRequest()->getPostValue();
6391

64-
$filterValues = ['from_date' => $this->_dateFilter];
65-
if ($this->getRequest()->getParam('to_date')) {
66-
$filterValues['to_date'] = $this->_dateFilter;
67-
}
68-
$inputFilter = new \Zend_Filter_Input(
69-
$filterValues,
70-
[],
71-
$data
72-
);
73-
$data = $inputFilter->getUnescaped();
92+
$data = $this->formatDateFields($data);
7493
$id = $this->getRequest()->getParam('rule_id');
7594
if ($id) {
7695
$model = $ruleRepository->get($id);
@@ -139,4 +158,39 @@ public function execute()
139158
}
140159
$this->_redirect('catalog_rule/*/');
141160
}
161+
162+
/**
163+
* Format date fields from localized to internal format.
164+
*
165+
* @param array $data
166+
* @return array
167+
*/
168+
private function formatDateFields(array $data): array
169+
{
170+
$filterInput = $this->localizedToNormalizedFactory->create(
171+
[
172+
'options' => [
173+
'locale' => $this->_localeResolver->getLocale(),
174+
'date_format' => $this->localeDate->getDateFormat(\IntlDateFormatter::SHORT),
175+
],
176+
]
177+
);
178+
$filterInternal = $this->normalizedToLocalizedFactory->create(
179+
[
180+
'options' => [
181+
'date_format' => DateTime::DATE_INTERNAL_FORMAT,
182+
],
183+
]
184+
);
185+
186+
foreach ($data as $fieldName => $fieldValue) {
187+
if (in_array($fieldName, ['from_date', 'to_date']) && !empty($fieldValue)) {
188+
$fieldValue = $filterInput->filter($fieldValue);
189+
$fieldValue = $filterInternal->filter($fieldValue);
190+
$data[$fieldName] = $fieldValue;
191+
}
192+
}
193+
194+
return $data;
195+
}
142196
}

0 commit comments

Comments
 (0)