Skip to content

Commit c7c66ad

Browse files
authored
Merge pull request #4398 from magento-epam/EPAM-PR-59
- fixed "[GitHub] catalog:images:resize = getimagesize(): Read error! in vendor/magento/module-catalog/Model/Product/Image.php on line 410 if an image is 0 bytes #8204" - fixed "CMS page of the second website with same URL key as first website, show content of the First website instead of second website content." - fixed "Error appears when a restricted user tries to add a new category from the product page" - fixed "Product attribute cannot be edited if the attribute was created with 2 same values" - fixed "Invalid join condition in Product Flat Indexer" - fixed "Fatal error on Import/Export page if deleted category ids exist in category path"
2 parents 1e58f70 + f531148 commit c7c66ad

File tree

38 files changed

+1303
-225
lines changed

38 files changed

+1303
-225
lines changed

app/code/Magento/Braintree/Test/Mftf/ActionGroup/AdminUserActionGroup.xml

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -38,18 +38,4 @@
3838
<waitForPageLoad stepKey="waitForSaveUser" time="10"/>
3939
<see userInput="You saved the user." stepKey="seeSuccessMessage" />
4040
</actionGroup>
41-
42-
<!--Delete User-->
43-
<actionGroup name="AdminDeleteNewUserActionGroup">
44-
45-
<click stepKey="clickOnUser" selector="{{AdminDeleteUserSection.theUser}}"/>
46-
<fillField stepKey="TypeCurrentPassword" selector="{{AdminDeleteUserSection.password}}" userInput="{{_ENV.MAGENTO_ADMIN_PASSWORD}}"/>
47-
<scrollToTopOfPage stepKey="scrollToTop"/>
48-
<click stepKey="clickToDeleteUser" selector="{{AdminDeleteUserSection.delete}}"/>
49-
<waitForPageLoad stepKey="waitForDeletePopupOpen" time="5"/>
50-
<click stepKey="clickToConfirm" selector="{{AdminDeleteUserSection.confirm}}"/>
51-
<waitForPageLoad stepKey="waitForPageLoad" time="10"/>
52-
<see userInput="You deleted the user." stepKey="seeSuccessMessage" />
53-
</actionGroup>
54-
5541
</actionGroups>

app/code/Magento/Catalog/Model/Indexer/Product/Flat/AbstractAction.php

Lines changed: 17 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -169,8 +169,7 @@ protected function _reindex($storeId, array $changedIds = [])
169169
}
170170

171171
/**
172-
* Retrieve Product Type Instances
173-
* as key - type code, value - instance model
172+
* Retrieve Product Type Instances as key - type code, value - instance model
174173
*
175174
* @return array
176175
*/
@@ -213,17 +212,19 @@ protected function _updateRelationProducts($storeId, $productIds = null)
213212
) {
214213
$columns = $this->_productIndexerHelper->getFlatColumns();
215214
$fieldList = array_keys($columns);
216-
unset($columns['entity_id']);
217-
unset($columns['child_id']);
218-
unset($columns['is_child']);
215+
unset(
216+
$columns['entity_id'],
217+
$columns['child_id'],
218+
$columns['is_child']
219+
);
219220
/** @var $select \Magento\Framework\DB\Select */
220221
$select = $this->_connection->select()->from(
221222
['t' => $this->_productIndexerHelper->getTable($relation->getTable())],
222-
[$relation->getChildFieldName(), new \Zend_Db_Expr('1')]
223+
['entity_table.entity_id', $relation->getChildFieldName(), new \Zend_Db_Expr('1')]
223224
)->join(
224225
['entity_table' => $this->_connection->getTableName('catalog_product_entity')],
225-
'entity_table.' . $metadata->getLinkField() . 't.' . $relation->getParentFieldName(),
226-
[$relation->getParentFieldName() => 'entity_table.entity_id']
226+
"entity_table.{$metadata->getLinkField()} = t.{$relation->getParentFieldName()}",
227+
[]
227228
)->join(
228229
['e' => $this->_productIndexerHelper->getFlatTableName($storeId)],
229230
"e.entity_id = t.{$relation->getChildFieldName()}",
@@ -232,10 +233,10 @@ protected function _updateRelationProducts($storeId, $productIds = null)
232233
if ($relation->getWhere() !== null) {
233234
$select->where($relation->getWhere());
234235
}
235-
if ($productIds !== null) {
236+
if (!empty($productIds)) {
236237
$cond = [
237238
$this->_connection->quoteInto("{$relation->getChildFieldName()} IN(?)", $productIds),
238-
$this->_connection->quoteInto("entity_table.entity_id IN(?)", $productIds),
239+
$this->_connection->quoteInto('entity_table.entity_id IN(?)', $productIds),
239240
];
240241

241242
$select->where(implode(' OR ', $cond));
@@ -273,15 +274,11 @@ protected function _cleanRelationProducts($storeId)
273274
$select = $this->_connection->select()->distinct(
274275
true
275276
)->from(
276-
['t' => $this->_productIndexerHelper->getTable($relation->getTable())],
277-
[]
278-
)->join(
279-
['entity_table' => $this->_connection->getTableName('catalog_product_entity')],
280-
'entity_table.' . $metadata->getLinkField() . 't.' . $relation->getParentFieldName(),
281-
[$relation->getParentFieldName() => 'entity_table.entity_id']
277+
$this->_productIndexerHelper->getTable($relation->getTable()),
278+
$relation->getParentFieldName()
282279
);
283280
$joinLeftCond = [
284-
"e.entity_id = entity_table.entity_id",
281+
"e.{$metadata->getLinkField()} = t.{$relation->getParentFieldName()}",
285282
"e.child_id = t.{$relation->getChildFieldName()}",
286283
];
287284
if ($relation->getWhere() !== null) {
@@ -302,7 +299,7 @@ protected function _cleanRelationProducts($storeId)
302299
'e.is_child = ?',
303300
1
304301
)->where(
305-
'e.entity_id IN(?)',
302+
"e.{$metadata->getLinkField()} IN(?)",
306303
$entitySelect
307304
)->where(
308305
"t.{$relation->getChildFieldName()} IS NULL"
@@ -335,6 +332,8 @@ protected function _isFlatTableExists($storeId)
335332
}
336333

337334
/**
335+
* Get Metadata Pool
336+
*
338337
* @return \Magento\Framework\EntityManager\MetadataPool
339338
*/
340339
private function getMetadataPool()

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

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -441,6 +441,15 @@
441441
</arguments>
442442
<searchAndMultiSelectOption selector="{{AdminProductFormSection.categoriesDropdown}}" parameterArray="[{{categoryName}}]" stepKey="searchAndSelectCategory"/>
443443
</actionGroup>
444+
<!--Remove category from product in ProductFrom Page-->
445+
<actionGroup name="removeCategoryFromProduct">
446+
<arguments>
447+
<argument name="categoryName" type="string" defaultValue="{{_defaultCategory.name}}"/>
448+
</arguments>
449+
<click selector="{{AdminProductFormSection.categoriesDropdown}}" stepKey="clickCategoriesDropDown"/>
450+
<click selector="{{AdminProductFormSection.unselectCategories(categoryName)}}" stepKey="unselectCategories"/>
451+
<click selector="{{AdminProductFormSection.done}}" stepKey="clickOnDoneAdvancedCategory"/>
452+
</actionGroup>
444453

445454
<actionGroup name="expandAdminProductSection">
446455
<arguments>

app/code/Magento/Catalog/Test/Mftf/Section/AdminProductFormSection.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,7 @@
7272
<element name="selectMultipleCategories" type="input" selector="//*[@data-index='container_category_ids']//*[contains(@class, '_selected')]"/>
7373
<element name="countryOfManufacture" type="select" selector="select[name='product[country_of_manufacture]']"/>
7474
<element name="newAddedAttribute" type="text" selector="//fieldset[@class='admin__fieldset']//div[contains(@data-index,'{{attributeCode}}')]" parameterized="true"/>
75+
<element name="newCategoryButton" type="button" selector="button[data-index='create_category_button']" timeout="30"/>
7576
<element name="footerBlock" type="block" selector="//footer"/>
7677
</section>
7778
<section name="ProductInWebsitesSection">
Lines changed: 110 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,110 @@
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"
10+
xsi:noNamespaceSchemaLocation="urn:magento:mftf:Test/etc/testSchema.xsd">
11+
<test name="AdminRestrictedUserAddCategoryFromProductPageTest">
12+
<annotations>
13+
<features value="Catalog"/>
14+
<title value="Adding new category from product page by restricted user"/>
15+
<description value="Adding new category from product page by restricted user"/>
16+
<severity value="MAJOR"/>
17+
<testCaseId value="MC-17229"/>
18+
<useCaseId value="MAGETWO-69893"/>
19+
<group value="catalog"/>
20+
</annotations>
21+
<before>
22+
<actionGroup ref="LoginAsAdmin" stepKey="loginAsAdmin"/>
23+
<!--Create category-->
24+
<comment userInput="Create category" stepKey="commentCreateCategory"/>
25+
<createData entity="SimpleSubCategory" stepKey="createCategory"/>
26+
</before>
27+
<after>
28+
<!--Delete created product-->
29+
<comment userInput="Delete created product" stepKey="commentDeleteProduct"/>
30+
<actionGroup ref="deleteProductBySku" stepKey="deleteProduct">
31+
<argument name="sku" value="{{_defaultProduct.sku}}"/>
32+
</actionGroup>
33+
<actionGroup ref="resetProductGridToDefaultView" stepKey="resetFiltersIfExist"/>
34+
<actionGroup ref="logout" stepKey="logoutOfUser"/>
35+
<actionGroup ref="LoginAsAdmin" stepKey="loginAsAdmin"/>
36+
<!--Delete created data-->
37+
<comment userInput="Delete created data" stepKey="commentDeleteCreatedData"/>
38+
<amOnPage url="{{AdminRolesPage.url}}" stepKey="navigateToUserRoleGrid" />
39+
<waitForPageLoad stepKey="waitForRolesGridLoad" />
40+
<actionGroup ref="AdminDeleteRoleActionGroup" stepKey="deleteUserRole">
41+
<argument name="role" value="adminRole"/>
42+
</actionGroup>
43+
<amOnPage url="{{AdminUsersPage.url}}" stepKey="goToAllUsersPage"/>
44+
<waitForPageLoad stepKey="waitForUsersGridLoad" />
45+
<actionGroup ref="AdminDeleteNewUserActionGroup" stepKey="deleteUser">
46+
<argument name="userName" value="{{admin2.username}}"/>
47+
</actionGroup>
48+
<deleteData createDataKey="createCategory" stepKey="deleteCategory"/>
49+
<actionGroup ref="logout" stepKey="logoutOfAdmin"/>
50+
</after>
51+
<!--Create user role-->
52+
<comment userInput="Create user role" stepKey="commentCreateUserRole"/>
53+
<actionGroup ref="AdminFillUserRoleRequiredData" stepKey="fillUserRoleRequiredData">
54+
<argument name="User" value="adminRole"/>
55+
<argument name="restrictedRole" value="Stores"/>
56+
</actionGroup>
57+
<click selector="{{AdminEditRoleInfoSection.roleResourcesTab}}" stepKey="clickRoleResourcesTab" />
58+
<actionGroup ref="AdminAddRestrictedRole" stepKey="addRestrictedRoleStores">
59+
<argument name="User" value="adminRole"/>
60+
<argument name="restrictedRole" value="Stores"/>
61+
</actionGroup>
62+
<actionGroup ref="AdminAddRestrictedRole" stepKey="addRestrictedRoleProducts">
63+
<argument name="User" value="adminRole"/>
64+
<argument name="restrictedRole" value="Products"/>
65+
</actionGroup>
66+
<click selector="{{AdminEditRoleInfoSection.saveButton}}" stepKey="clickSaveRoleButton" />
67+
<see userInput="You saved the role." stepKey="seeUserRoleSavedMessage"/>
68+
<!--Create user and assign role to it-->
69+
<comment userInput="Create user and assign role to it" stepKey="commentCreateUser"/>
70+
<actionGroup ref="AdminCreateUserActionGroup" stepKey="createAdminUser">
71+
<argument name="role" value="adminRole"/>
72+
<argument name="User" value="admin2"/>
73+
</actionGroup>
74+
<!--Log out of admin and login with newly created user-->
75+
<comment userInput="Log out of admin and login with newly created user" stepKey="commentLoginWithNewUser"/>
76+
<actionGroup ref="logout" stepKey="logoutOfAdmin"/>
77+
<actionGroup ref="LoginAsAdmin" stepKey="loginAsNewUser">
78+
<argument name="adminUser" value="admin2"/>
79+
</actionGroup>
80+
<!--Go to create product page-->
81+
<comment userInput="Go to create product page" stepKey="commentGoCreateProductPage"/>
82+
<actionGroup ref="goToCreateProductPage" stepKey="goToCreateProductPage"/>
83+
<dontSeeElement selector="{{AdminProductFormSection.newCategoryButton}}" stepKey="dontSeeNewCategoryButton"/>
84+
<!--Fill product data and assign to category-->
85+
<comment userInput="Fill product data and assign to category" stepKey="commentFillProductData"/>
86+
<actionGroup ref="fillMainProductForm" stepKey="fillMainProductForm"/>
87+
<actionGroup ref="SetCategoryByName" stepKey="addCategoryToProduct">
88+
<argument name="categoryName" value="$$createCategory.name$$"/>
89+
</actionGroup>
90+
<actionGroup ref="saveProductForm" stepKey="saveProduct"/>
91+
<!--Assert that category exist in field-->
92+
<comment userInput="Assert that category exist in field" stepKey="commentAssertion"/>
93+
<grabTextFrom selector="{{AdminProductFormSection.categoriesDropdown}}" stepKey="grabCategoryName"/>
94+
<assertContains stepKey="assertThatCategory">
95+
<expectedResult type="variable">$$createCategory.name$$</expectedResult>
96+
<actualResult type="variable">$grabCategoryName</actualResult>
97+
</assertContains>
98+
<!--Remove the category from the product and assert that it removed-->
99+
<comment userInput="Remove the category from the product and assert that it removed" stepKey="assertCategoryRemoved"/>
100+
<actionGroup ref="removeCategoryFromProduct" stepKey="removeCategoryFromProduct">
101+
<argument name="categoryName" value="$$createCategory.name$$"/>
102+
</actionGroup>
103+
<actionGroup ref="saveProductForm" stepKey="saveProductAfterRemovingCategory"/>
104+
<grabTextFrom selector="{{AdminProductFormSection.categoriesDropdown}}" stepKey="grabCategoryFieldContent"/>
105+
<assertNotContains stepKey="assertThatCategoryRemoved">
106+
<expectedResult type="variable">$$createCategory.name$$</expectedResult>
107+
<actualResult type="variable">$grabCategoryFieldContent</actualResult>
108+
</assertNotContains>
109+
</test>
110+
</tests>

app/code/Magento/Catalog/Test/Unit/Ui/DataProvider/Product/Form/Modifier/CategoriesTest.php

Lines changed: 23 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33
* Copyright © Magento, Inc. All rights reserved.
44
* See COPYING.txt for license details.
55
*/
6+
declare(strict_types=1);
7+
68
namespace Magento\Catalog\Test\Unit\Ui\DataProvider\Product\Form\Modifier;
79

810
use Magento\Catalog\Ui\DataProvider\Product\Form\Modifier\Categories;
@@ -12,6 +14,7 @@
1214
use Magento\Framework\DB\Helper as DbHelper;
1315
use Magento\Framework\UrlInterface;
1416
use Magento\Store\Model\Store;
17+
use Magento\Framework\AuthorizationInterface;
1518

1619
/**
1720
* Class CategoriesTest
@@ -45,6 +48,11 @@ class CategoriesTest extends AbstractModifierTest
4548
*/
4649
protected $categoryCollectionMock;
4750

51+
/**
52+
* @var AuthorizationInterface|\PHPUnit_Framework_MockObject_MockObject
53+
*/
54+
private $authorizationMock;
55+
4856
protected function setUp()
4957
{
5058
parent::setUp();
@@ -63,6 +71,9 @@ protected function setUp()
6371
$this->categoryCollectionMock = $this->getMockBuilder(CategoryCollection::class)
6472
->disableOriginalConstructor()
6573
->getMock();
74+
$this->authorizationMock = $this->getMockBuilder(AuthorizationInterface::class)
75+
->disableOriginalConstructor()
76+
->getMock();
6677

6778
$this->categoryCollectionFactoryMock->expects($this->any())
6879
->method('create')
@@ -86,11 +97,15 @@ protected function setUp()
8697
*/
8798
protected function createModel()
8899
{
89-
return $this->objectManager->getObject(Categories::class, [
90-
'locator' => $this->locatorMock,
91-
'categoryCollectionFactory' => $this->categoryCollectionFactoryMock,
92-
'arrayManager' => $this->arrayManagerMock,
93-
]);
100+
return $this->objectManager->getObject(
101+
Categories::class,
102+
[
103+
'locator' => $this->locatorMock,
104+
'categoryCollectionFactory' => $this->categoryCollectionFactoryMock,
105+
'arrayManager' => $this->arrayManagerMock,
106+
'authorization' => $this->authorizationMock
107+
]
108+
);
94109
}
95110

96111
public function testModifyData()
@@ -130,7 +145,9 @@ public function testModifyMetaLocked($locked)
130145
],
131146
],
132147
];
133-
148+
$this->authorizationMock->expects($this->exactly(2))
149+
->method('isAllowed')
150+
->willReturn(true);
134151
$this->arrayManagerMock->expects($this->any())
135152
->method('findPath')
136153
->willReturn('path');

0 commit comments

Comments
 (0)