Skip to content

Commit 6b6169f

Browse files
authored
Merge branch '2.4-develop' into eav-graphql
2 parents 50df6e9 + 9649f62 commit 6b6169f

File tree

30 files changed

+1168
-186
lines changed

30 files changed

+1168
-186
lines changed

app/code/Magento/Backend/Block/Widget/Grid/Column/Filter/Date.php

Lines changed: 7 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -109,25 +109,16 @@ public function getHtml()
109109
' value="' .
110110
$this->localeResolver->getLocale() .
111111
'"/>';
112-
$scriptString = '
113-
require(["jquery", "mage/calendar"], function($){
114-
$("#' .
115-
$htmlId .
116-
'_range").dateRange({
117-
dateFormat: "' .
118-
$format .
119-
'",
120-
buttonText: "' . $this->escapeHtml(__('Date selector')) .
121-
'",
112+
$scriptString = 'require(["jquery", "mage/calendar"], function($){
113+
$("#' . $htmlId . '_range").dateRange({
114+
dateFormat: "' . $format . '",
115+
buttonText: "' . $this->escapeHtml(__('Date selector')) . '",
116+
buttonImage: "' . $this->getViewFileUrl('Magento_Theme::calendar.png') . '",
122117
from: {
123-
id: "' .
124-
$htmlId .
125-
'_from"
118+
id: "' . $htmlId . '_from"
126119
},
127120
to: {
128-
id: "' .
129-
$htmlId .
130-
'_to"
121+
id: "' . $htmlId . '_to"
131122
}
132123
})
133124
});';

app/code/Magento/Backend/Block/Widget/Grid/Column/Filter/Datetime.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ class Datetime extends \Magento\Backend\Block\Widget\Grid\Column\Filter\Date
1717
/**
1818
* full day is 86400, we need 23 hours:59 minutes:59 seconds = 86399
1919
*/
20-
const END_OF_DAY_IN_SECONDS = 86399;
20+
public const END_OF_DAY_IN_SECONDS = 86399;
2121

2222
/**
2323
* @inheritdoc
@@ -123,6 +123,7 @@ public function getHtml()
123123
timeFormat: "' . $timeFormat . '",
124124
showsTime: ' . ($this->getColumn()->getFilterTime() ? 'true' : 'false') . ',
125125
buttonText: "' . $this->escapeHtml(__('Date selector')) . '",
126+
buttonImage: "' . $this->getViewFileUrl('Magento_Theme::calendar.png') . '",
126127
from: {
127128
id: "' . $htmlId . '_from"
128129
},

app/code/Magento/Backend/Test/Unit/Block/Widget/Grid/Column/Filter/DateTest.php

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,18 +10,21 @@
1010
use Magento\Backend\Block\Context;
1111
use Magento\Backend\Block\Widget\Grid\Column;
1212
use Magento\Backend\Block\Widget\Grid\Column\Filter\Date;
13+
use Magento\Framework\App\Request\Http;
1314
use Magento\Framework\Escaper;
1415
use Magento\Framework\Locale\ResolverInterface;
1516
use Magento\Framework\Math\Random;
1617
use Magento\Framework\Stdlib\DateTime\DateTimeFormatterInterface;
1718
use Magento\Framework\Stdlib\DateTime\TimezoneInterface;
1819
use Magento\Framework\TestFramework\Unit\Helper\ObjectManager;
20+
use Magento\Framework\View\Asset\Repository;
1921
use PHPUnit\Framework\MockObject\MockObject;
2022
use PHPUnit\Framework\TestCase;
2123

2224
/**
2325
* Class DateTest to test Magento\Backend\Block\Widget\Grid\Column\Filter\Date
2426
*
27+
* @SuppressWarnings(PHPMD.CouplingBetweenObjects)
2528
*/
2629
class DateTest extends TestCase
2730
{
@@ -49,6 +52,16 @@ class DateTest extends TestCase
4952
/** @var Context|MockObject */
5053
private $contextMock;
5154

55+
/**
56+
* @var Http|MockObject
57+
*/
58+
private $request;
59+
60+
/**
61+
* @var Repository|MockObject
62+
*/
63+
private $repositoryMock;
64+
5265
protected function setUp(): void
5366
{
5467
$this->mathRandomMock = $this->getMockBuilder(Random::class)
@@ -88,6 +101,23 @@ protected function setUp(): void
88101
$this->contextMock->expects($this->once())->method('getEscaper')->willReturn($this->escaperMock);
89102
$this->contextMock->expects($this->once())->method('getLocaleDate')->willReturn($this->localeDateMock);
90103

104+
$this->request = $this->getMockBuilder(Http::class)
105+
->disableOriginalConstructor()
106+
->getMock();
107+
108+
$this->contextMock->expects($this->once())
109+
->method('getRequest')
110+
->willReturn($this->request);
111+
112+
$this->repositoryMock = $this->getMockBuilder(Repository::class)
113+
->disableOriginalConstructor()
114+
->setMethods(['getUrlWithParams'])
115+
->getMock();
116+
117+
$this->contextMock->expects($this->once())
118+
->method('getAssetRepository')
119+
->willReturn($this->repositoryMock);
120+
91121
$objectManagerHelper = new ObjectManager($this);
92122
$this->model = $objectManagerHelper->getObject(
93123
Date::class,
@@ -116,6 +146,14 @@ public function testGetHtmlSuccessfulTimestamp()
116146
'from' => $yesterday->getTimestamp(),
117147
'to' => $tomorrow->getTimestamp()
118148
];
149+
$params = ['_secure' => false];
150+
$fileId = 'Magento_Theme::calendar.png';
151+
$fileUrl = 'file url';
152+
153+
$this->repositoryMock->expects($this->once())
154+
->method('getUrlWithParams')
155+
->with($fileId, $params)
156+
->willReturn($fileUrl);
119157

120158
$this->mathRandomMock->expects($this->any())->method('getUniqueHash')->willReturn($uniqueHash);
121159
$this->columnMock->expects($this->once())->method('getHtmlId')->willReturn($id);

app/code/Magento/Backend/Test/Unit/Block/Widget/Grid/Column/Filter/DatetimeTest.php

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,17 +10,21 @@
1010
use Magento\Backend\Block\Context;
1111
use Magento\Backend\Block\Widget\Grid\Column;
1212
use Magento\Backend\Block\Widget\Grid\Column\Filter\Datetime;
13+
use Magento\Framework\App\Request\Http;
1314
use Magento\Framework\Escaper;
1415
use Magento\Framework\Locale\ResolverInterface;
1516
use Magento\Framework\Math\Random;
1617
use Magento\Framework\Stdlib\DateTime\DateTimeFormatterInterface;
1718
use Magento\Framework\Stdlib\DateTime\TimezoneInterface;
1819
use Magento\Framework\TestFramework\Unit\Helper\ObjectManager;
20+
use Magento\Framework\View\Asset\Repository;
1921
use PHPUnit\Framework\MockObject\MockObject;
2022
use PHPUnit\Framework\TestCase;
2123

2224
/**
2325
* Class DateTimeTest to test Magento\Backend\Block\Widget\Grid\Column\Filter\Date
26+
*
27+
* @SuppressWarnings(PHPMD.CouplingBetweenObjects)
2428
*/
2529
class DatetimeTest extends TestCase
2630
{
@@ -48,6 +52,16 @@ class DatetimeTest extends TestCase
4852
/** @var Context|MockObject */
4953
private $contextMock;
5054

55+
/**
56+
* @var Http|MockObject
57+
*/
58+
private $request;
59+
60+
/**
61+
* @var Repository|MockObject
62+
*/
63+
private $repositoryMock;
64+
5165
protected function setUp(): void
5266
{
5367
$this->mathRandomMock = $this->getMockBuilder(Random::class)
@@ -87,6 +101,23 @@ protected function setUp(): void
87101
$this->contextMock->expects($this->once())->method('getEscaper')->willReturn($this->escaperMock);
88102
$this->contextMock->expects($this->once())->method('getLocaleDate')->willReturn($this->localeDateMock);
89103

104+
$this->request = $this->getMockBuilder(Http::class)
105+
->disableOriginalConstructor()
106+
->getMock();
107+
108+
$this->contextMock->expects($this->once())
109+
->method('getRequest')
110+
->willReturn($this->request);
111+
112+
$this->repositoryMock = $this->getMockBuilder(Repository::class)
113+
->disableOriginalConstructor()
114+
->setMethods(['getUrlWithParams'])
115+
->getMock();
116+
117+
$this->contextMock->expects($this->once())
118+
->method('getAssetRepository')
119+
->willReturn($this->repositoryMock);
120+
90121
$objectManagerHelper = new ObjectManager($this);
91122
$this->model = $objectManagerHelper->getObject(
92123
Datetime::class,
@@ -115,6 +146,14 @@ public function testGetHtmlSuccessfulTimestamp()
115146
'from' => $yesterday->getTimestamp(),
116147
'to' => $tomorrow->getTimestamp()
117148
];
149+
$params = ['_secure' => false];
150+
$fileId = 'Magento_Theme::calendar.png';
151+
$fileUrl = 'file url';
152+
153+
$this->repositoryMock->expects($this->once())
154+
->method('getUrlWithParams')
155+
->with($fileId, $params)
156+
->willReturn($fileUrl);
118157

119158
$this->mathRandomMock->expects($this->any())->method('getUniqueHash')->willReturn($uniqueHash);
120159
$this->columnMock->expects($this->once())->method('getHtmlId')->willReturn($id);
Lines changed: 86 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,86 @@
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+
<tests xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:mftf:Test/etc/testSchema.xsd">
10+
<test name="AdminSaveProductByCustomDateWithCustomDateAttributeTest">
11+
<annotations>
12+
<features value="Catalog"/>
13+
<stories value="Adding Custom Date Attribute To Products"/>
14+
<title value="Issue while saving the date type product attribute"/>
15+
<description value="When we add the 01/01/1970 to the product attribute of the custom date type, it is throwing an error."/>
16+
<severity value="AVERAGE"/>
17+
<testCaseId value="AC-8290"/>
18+
<useCaseId value="ACP2E-1749"/>
19+
<group value="catalog"/>
20+
</annotations>
21+
22+
<before>
23+
<createData entity="_defaultCategory" stepKey="createCategory"/>
24+
<createData entity="SimpleProduct" stepKey="createProduct">
25+
<requiredEntity createDataKey="createCategory"/>
26+
</createData>
27+
<actionGroup ref="AdminLoginActionGroup" stepKey="adminLogin"/>
28+
</before>
29+
<after>
30+
<deleteData createDataKey="createCategory" stepKey="deleteCategory"/>
31+
<deleteData createDataKey="createProduct" stepKey="deleteProduct"/>
32+
<actionGroup ref="DeleteProductAttributeActionGroup" stepKey="deleteAttribute">
33+
<argument name="ProductAttribute" value="dateProductAttribute"/>
34+
</actionGroup>
35+
<actionGroup ref="CliIndexerReindexActionGroup" stepKey="reindex">
36+
<argument name="indices" value=""/>
37+
</actionGroup>
38+
<actionGroup ref="AdminGridFilterResetActionGroup" stepKey="resetGridFilter"/>
39+
<actionGroup ref="AdminLogoutActionGroup" stepKey="logout"/>
40+
</after>
41+
42+
<!-- Generate date for use as default value, needs to be MM/d/YYYY and mm/d/yy -->
43+
<generateDate date="now" format="m/j/Y" stepKey="generateDefaultDate"/>
44+
45+
<!-- Navigate to Stores > Attributes > Product. -->
46+
<actionGroup ref="AdminOpenProductAttributePageActionGroup" stepKey="goToProductAttributes"/>
47+
48+
<!-- Create new Product Attribute as Date, with code and default value. -->
49+
<actionGroup ref="CreateProductAttributeWithDateFieldActionGroup" stepKey="createAttribute">
50+
<argument name="attribute" value="dateProductAttribute"/>
51+
<argument name="date" value="{$generateDefaultDate}"/>
52+
</actionGroup>
53+
54+
<!-- Go to default attribute set edit page -->
55+
<amOnPage url="{{AdminProductAttributeSetEditPage.url}}/{{AddToDefaultSet.attributeSetId}}/" stepKey="onAttributeSetEdit"/>
56+
<!-- Assert created attribute in unassigned section -->
57+
<see userInput="{{dateProductAttribute.attribute_code}}" selector="{{AdminProductAttributeSetEditSection.unassignedAttributesTree}}" stepKey="seeAttributeInUnassigned"/>
58+
<!-- Assign attribute to product group -->
59+
<actionGroup ref="AssignAttributeToGroupActionGroup" stepKey="assignAttributeToGroup">
60+
<argument name="group" value="Product Details"/>
61+
<argument name="attribute" value="{{dateProductAttribute.attribute_code}}"/>
62+
</actionGroup>
63+
<!-- Assert attribute in a group -->
64+
<see userInput="{{dateProductAttribute.attribute_code}}" selector="{{AdminProductAttributeSetEditSection.groupTree}}" stepKey="seeAttributeInGroup"/>
65+
<!-- Save attribute set -->
66+
<actionGroup ref="SaveAttributeSetActionGroup" stepKey="SaveAttributeSet"/>
67+
68+
<!-- Open Product Edit Page and set custom attribute value 01/01/1970 and save the product-->
69+
<actionGroup ref="SearchForProductOnBackendActionGroup" stepKey="searchForProduct">
70+
<argument name="product" value="$createProduct$"/>
71+
</actionGroup>
72+
<actionGroup ref="OpenEditProductOnBackendActionGroup" stepKey="openEditProduct">
73+
<argument name="product" value="$createProduct$"/>
74+
</actionGroup>
75+
<fillField selector="{{AdminProductFormSection.newAddedAttributeInput(dateProductAttribute.attribute_code)}}" userInput="01/01/1970" stepKey="fillCustomDateValue"/>
76+
<actionGroup ref="SaveProductFormActionGroup" stepKey="saveProduct"/>
77+
<!-- Open Product Index Page and filter the product by date 01/01/1970 -->
78+
<actionGroup ref="AdminOpenProductIndexPageActionGroup" stepKey="navigateToProductIndex2"/>
79+
<actionGroup ref="FilterProductGridByCustomDateRangeActionGroup" stepKey="filterProductGridByCustomDateRange">
80+
<argument name="code" value="{{dateProductAttribute.attribute_code}}"/>
81+
<argument name="date" value="1/01/1970"/>
82+
</actionGroup>
83+
<!-- Check products filtering and see the product custom date 01/01/1970 successfully appeared -->
84+
<see selector="{{AdminProductGridSection.productGridNameProduct($createProduct.name$)}}" userInput="$createProduct.name$" stepKey="seeProductName"/>
85+
</test>
86+
</tests>

app/code/Magento/CatalogImportExport/Model/Import/Product/CategoryProcessor.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@
55
*/
66
namespace Magento\CatalogImportExport\Model\Import\Product;
77

8+
use Magento\Store\Model\Store;
9+
810
/**
911
* @api
1012
* @since 100.0.2
@@ -119,6 +121,7 @@ protected function createCategory($name, $parentId)
119121
$category->setIsActive(true);
120122
$category->setIncludeInMenu(true);
121123
$category->setAttributeSetId($category->getDefaultAttributeSetId());
124+
$category->setStoreId(Store::DEFAULT_STORE_ID);
122125
$category->save();
123126
$this->categoriesCache[$category->getId()] = $category;
124127
return $category->getId();

app/code/Magento/CatalogImportExport/Test/Unit/Model/Import/Product/CategoryProcessorTest.php

Lines changed: 20 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,16 +13,17 @@
1313
use Magento\CatalogImportExport\Model\Import\Product\Type\AbstractType;
1414
use Magento\Framework\Exception\AlreadyExistsException;
1515
use Magento\Framework\TestFramework\Unit\Helper\ObjectManager as ObjectManagerHelper;
16+
use Magento\Store\Model\Store;
1617
use PHPUnit\Framework\MockObject\MockObject;
1718
use PHPUnit\Framework\TestCase;
1819

1920
class CategoryProcessorTest extends TestCase
2021
{
21-
const PARENT_CATEGORY_ID = 1;
22+
public const PARENT_CATEGORY_ID = 1;
2223

23-
const CHILD_CATEGORY_ID = 2;
24+
public const CHILD_CATEGORY_ID = 2;
2425

25-
const CHILD_CATEGORY_NAME = 'Child';
26+
public const CHILD_CATEGORY_NAME = 'Child';
2627

2728
/**
2829
* @var \Magento\Framework\TestFramework\Unit\Helper\ObjectManager
@@ -48,7 +49,7 @@ class CategoryProcessorTest extends TestCase
4849
private $childCategory;
4950

5051
/**
51-
* \Magento\Catalog\Model\Category
52+
* @var \Magento\Catalog\Model\Category
5253
*/
5354
private $parentCategory;
5455

@@ -200,4 +201,19 @@ protected function setPropertyValue(&$object, $property, $value)
200201
$reflectionProperty->setValue($object, $value);
201202
return $object;
202203
}
204+
205+
/**
206+
* @throws \ReflectionException
207+
*/
208+
public function testCategoriesCreatedForGlobalScope()
209+
{
210+
$this->childCategory->expects($this->once())
211+
->method('setStoreId')
212+
->with(Store::DEFAULT_STORE_ID);
213+
214+
$reflection = new \ReflectionClass($this->categoryProcessor);
215+
$createCategoryReflection = $reflection->getMethod('createCategory');
216+
$createCategoryReflection->setAccessible(true);
217+
$createCategoryReflection->invokeArgs($this->categoryProcessor, ['testCategory', 2]);
218+
}
203219
}

app/code/Magento/CatalogRule/Model/Rule.php

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -405,9 +405,16 @@ public function callbackValidateProduct($args)
405405
$product->setData($args['row']);
406406

407407
$websites = $this->_getWebsitesMap();
408+
$websiteIds = $this->getWebsiteIds();
409+
if (!is_array($websiteIds)) {
410+
$websiteIds = explode(',', $websiteIds);
411+
}
408412
$results = [];
409413

410414
foreach ($websites as $websiteId => $defaultStoreId) {
415+
if (!in_array($websiteId, $websiteIds)) {
416+
continue;
417+
}
411418
$product->setStoreId($defaultStoreId);
412419
$results[$websiteId] = $this->getConditions()->validate($product);
413420
}

0 commit comments

Comments
 (0)