Skip to content

Commit 7755eef

Browse files
authored
Merge pull request #3480 from magento-tango/PR-2311
[tango] PR
2 parents 48f8e0a + 89bd63a commit 7755eef

File tree

11 files changed

+307
-54
lines changed

11 files changed

+307
-54
lines changed

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

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -213,4 +213,28 @@
213213
<conditionalClick selector="{{AdminProductGridTableHeaderSection.id('descend')}}" dependentSelector="{{AdminProductGridTableHeaderSection.id('ascend')}}" visible="false" stepKey="sortById"/>
214214
<waitForPageLoad stepKey="waitForPageLoad"/>
215215
</actionGroup>
216+
217+
<!--Disabled a product by filtering grid and using change status action-->
218+
<actionGroup name="ChangeStatusProductUsingProductGridActionGroup">
219+
<arguments>
220+
<argument name="product"/>
221+
<argument name="status" defaultValue="Enable" type="string" />
222+
</arguments>
223+
<amOnPage url="{{AdminProductIndexPage.url}}" stepKey="visitAdminProductPage"/>
224+
<waitForPageLoad time="60" stepKey="waitForPageLoadInitial"/>
225+
<conditionalClick selector="{{AdminProductGridFilterSection.clearFilters}}" dependentSelector="{{AdminProductGridFilterSection.clearFilters}}" visible="true" stepKey="clickClearFiltersInitial"/>
226+
<click selector="{{AdminProductGridFilterSection.filters}}" stepKey="openProductFilters"/>
227+
<fillField selector="{{AdminProductGridFilterSection.skuFilter}}" userInput="{{product.sku}}" stepKey="fillProductSkuFilter"/>
228+
<click selector="{{AdminProductGridFilterSection.applyFilters}}" stepKey="clickApplyFilters"/>
229+
<see selector="{{AdminProductGridSection.productGridCell('1', 'SKU')}}" userInput="{{product.sku}}" stepKey="seeProductSkuInGrid"/>
230+
<click selector="{{AdminProductGridSection.multicheckDropdown}}" stepKey="openMulticheckDropdown"/>
231+
<click selector="{{AdminProductGridSection.multicheckOption('Select All')}}" stepKey="selectAllProductInFilteredGrid"/>
232+
233+
<click selector="{{AdminProductGridSection.bulkActionDropdown}}" stepKey="clickActionDropdown"/>
234+
<click selector="{{AdminProductGridSection.bulkActionOption('Change status')}}" stepKey="clickChangeStatusAction"/>
235+
<click selector="{{AdminProductGridSection.changeStatus('status')}}" stepKey="clickChangeStatusDisabled" parameterized="true"/>
236+
<see selector="{{AdminMessagesSection.success}}" userInput="A total of 1 record(s) have been updated." stepKey="seeSuccessMessage"/>
237+
<waitForLoadingMaskToDisappear stepKey="waitForMaskToDisappear"/>
238+
<conditionalClick selector="{{AdminProductGridFilterSection.clearFilters}}" dependentSelector="{{AdminProductGridFilterSection.clearFilters}}" visible="true" stepKey="clickClearFiltersInitial2"/>
239+
</actionGroup>
216240
</actionGroups>

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,5 +30,6 @@
3030
<element name="productGridNameProduct" type="input" selector="//tbody//tr//td//div[contains(., '{{var1}}')]" parameterized="true" timeout="30"/>
3131
<element name="productGridContentsOnRow" type="checkbox" selector="//*[@id='container']//tr[{{row}}]/td" parameterized="true"/>
3232
<element name="selectRowBasedOnName" type="input" selector="//td/div[text()='{{var1}}']" parameterized="true"/>
33+
<element name="changeStatus" type="button" selector="//div[contains(@class,'admin__data-grid-header-row') and contains(@class, 'row')]//div[contains(@class, 'action-menu-item')]//ul/li/span[text() = '{{status}}']" parameterized="true"/>
3334
</section>
3435
</sections>

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@
5959

6060
<!--Step5. Open *Advanced Inventory* pop-up. Set *Enable Qty Increments* to *Yes*. Fill *.5* in *Qty Increments*-->
6161
<click selector="{{AdminProductFormSection.advancedInventoryLink}}" stepKey="clickOnAdvancedInventoryLink2"/>
62+
<waitForPageLoad stepKey="waitForPageLoad"/>
6263
<scrollTo selector="{{AdminProductFormAdvancedInventorySection.enableQtyIncrements}}" stepKey="scrollToEnableQtyIncrements"/>
6364
<click selector="{{AdminProductFormAdvancedInventorySection.enableQtyIncrementsUseConfigSettings}}" stepKey="clickOnEnableQtyIncrementsUseConfigSettingsCheckbox"/>
6465
<click selector="{{AdminProductFormAdvancedInventorySection.enableQtyIncrements}}" stepKey="clickOnEnableQtyIncrements"/>
Lines changed: 88 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,88 @@
1+
<?php
2+
/**
3+
* Copyright © Magento, Inc. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
7+
declare(strict_types=1);
8+
9+
namespace Magento\CatalogUrlRewrite\Plugin\Webapi\Controller\Rest;
10+
11+
use Magento\Catalog\Api\ProductRepositoryInterface;
12+
use Magento\Framework\Webapi\Rest\Request as RestRequest;
13+
14+
/**
15+
* Plugin for InputParamsResolver
16+
*
17+
* Used to modify product data with save_rewrites_history flag
18+
*/
19+
class InputParamsResolver
20+
{
21+
/**
22+
* @var RestRequest
23+
*/
24+
private $request;
25+
26+
/**
27+
* @param RestRequest $request
28+
*/
29+
public function __construct(RestRequest $request)
30+
{
31+
$this->request = $request;
32+
}
33+
34+
/**
35+
* Add 'save_rewrites_history' param to the product data
36+
*
37+
* @see \Magento\CatalogUrlRewrite\Plugin\Catalog\Controller\Adminhtml\Product\Initialization\Helper
38+
* @param \Magento\Webapi\Controller\Rest\InputParamsResolver $subject
39+
* @param array $result
40+
* @return array
41+
*/
42+
public function afterResolve(\Magento\Webapi\Controller\Rest\InputParamsResolver $subject, array $result): array
43+
{
44+
$route = $subject->getRoute();
45+
$serviceMethodName = $route->getServiceMethod();
46+
$serviceClassName = $route->getServiceClass();
47+
$requestBodyParams = $this->request->getBodyParams();
48+
49+
if ($this->isProductSaveCalled($serviceClassName, $serviceMethodName)
50+
&& $this->isCustomAttributesExists($requestBodyParams)) {
51+
foreach ($requestBodyParams['product']['custom_attributes'] as $attribute) {
52+
if ($attribute['attribute_code'] === 'save_rewrites_history') {
53+
foreach ($result as $resultItem) {
54+
if ($resultItem instanceof \Magento\Catalog\Model\Product) {
55+
$resultItem->setData('save_rewrites_history', (bool)$attribute['value']);
56+
break 2;
57+
}
58+
}
59+
break;
60+
}
61+
}
62+
}
63+
return $result;
64+
}
65+
66+
/**
67+
* Check that product save method called
68+
*
69+
* @param string $serviceClassName
70+
* @param string $serviceMethodName
71+
* @return bool
72+
*/
73+
private function isProductSaveCalled(string $serviceClassName, string $serviceMethodName): bool
74+
{
75+
return $serviceClassName === ProductRepositoryInterface::class && $serviceMethodName === 'save';
76+
}
77+
78+
/**
79+
* Check is any custom options exists in product data
80+
*
81+
* @param array $requestBodyParams
82+
* @return bool
83+
*/
84+
private function isCustomAttributesExists(array $requestBodyParams): bool
85+
{
86+
return !empty($requestBodyParams['product']['custom_attributes']);
87+
}
88+
}
Lines changed: 116 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,116 @@
1+
<?php
2+
/**
3+
* Copyright © Magento, Inc. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
7+
declare(strict_types=1);
8+
9+
namespace Magento\CatalogUrlRewrite\Test\Unit\Plugin\Webapi\Controller\Rest;
10+
11+
use Magento\Framework\TestFramework\Unit\Helper\ObjectManager;
12+
use Magento\Webapi\Controller\Rest\InputParamsResolver;
13+
use Magento\CatalogUrlRewrite\Plugin\Webapi\Controller\Rest\InputParamsResolver as InputParamsResolverPlugin;
14+
use Magento\Framework\Webapi\Rest\Request as RestRequest;
15+
use Magento\Catalog\Model\Product;
16+
use Magento\Webapi\Controller\Rest\Router\Route;
17+
use Magento\Catalog\Api\ProductRepositoryInterface;
18+
19+
/**
20+
* Unit test for InputParamsResolver plugin
21+
*/
22+
class InputParamsResolverTest extends \PHPUnit\Framework\TestCase
23+
{
24+
/**
25+
* @var string
26+
*/
27+
private $saveRewritesHistory;
28+
29+
/**
30+
* @var array
31+
*/
32+
private $requestBodyParams;
33+
34+
/**
35+
* @var array
36+
*/
37+
private $result;
38+
39+
/**
40+
* @var ObjectManager
41+
*/
42+
private $objectManager;
43+
44+
/**
45+
* @var InputParamsResolver|\PHPUnit_Framework_MockObject_MockObject
46+
*/
47+
private $subject;
48+
49+
/**
50+
* @var RestRequest|\PHPUnit_Framework_MockObject_MockObject
51+
*/
52+
private $request;
53+
54+
/**
55+
* @var Product|\PHPUnit_Framework_MockObject_MockObject
56+
*/
57+
private $product;
58+
59+
/**
60+
* @var Route|\PHPUnit_Framework_MockObject_MockObject
61+
*/
62+
private $route;
63+
64+
/**
65+
* @var InputParamsResolverPlugin
66+
*/
67+
private $plugin;
68+
69+
/**
70+
* @inheritdoc
71+
*/
72+
protected function setUp()
73+
{
74+
$this->saveRewritesHistory = 'save_rewrites_history';
75+
$this->requestBodyParams = [
76+
'product' => [
77+
'sku' => 'test',
78+
'custom_attributes' => [
79+
['attribute_code' => $this->saveRewritesHistory, 'value' => 1]
80+
]
81+
]
82+
];
83+
84+
$this->route = $this->createPartialMock(Route::class, ['getServiceMethod', 'getServiceClass']);
85+
$this->request = $this->createPartialMock(RestRequest::class, ['getBodyParams']);
86+
$this->request->expects($this->any())->method('getBodyParams')->willReturn($this->requestBodyParams);
87+
$this->subject = $this->createPartialMock(InputParamsResolver::class, ['getRoute']);
88+
$this->subject->expects($this->any())->method('getRoute')->willReturn($this->route);
89+
$this->product = $this->createPartialMock(Product::class, ['setData']);
90+
91+
$this->result = [false, $this->product, 'test'];
92+
93+
$this->objectManager = new ObjectManager($this);
94+
$this->plugin = $this->objectManager->getObject(
95+
InputParamsResolverPlugin::class,
96+
[
97+
'request' => $this->request
98+
]
99+
);
100+
}
101+
102+
public function testAfterResolve()
103+
{
104+
$this->route->expects($this->once())
105+
->method('getServiceClass')
106+
->willReturn(ProductRepositoryInterface::class);
107+
$this->route->expects($this->once())
108+
->method('getServiceMethod')
109+
->willReturn('save');
110+
$this->product->expects($this->once())
111+
->method('setData')
112+
->with($this->saveRewritesHistory, true);
113+
114+
$this->plugin->afterResolve($this->subject, $this->result);
115+
}
116+
}

app/code/Magento/CatalogUrlRewrite/composer.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,9 @@
1616
"magento/module-ui": "*",
1717
"magento/module-url-rewrite": "*"
1818
},
19+
"suggest": {
20+
"magento/module-webapi": "*"
21+
},
1922
"type": "magento2-module",
2023
"license": [
2124
"OSL-3.0",

app/code/Magento/CatalogUrlRewrite/etc/webapi_rest/di.xml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,4 +7,7 @@
77
-->
88
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:ObjectManager/etc/config.xsd">
99
<preference for="Magento\CatalogUrlRewrite\Model\ProductUrlPathGenerator" type="Magento\CatalogUrlRewrite\Model\WebapiProductUrlPathGenerator"/>
10+
<type name="Magento\Webapi\Controller\Rest\InputParamsResolver">
11+
<plugin name="product_save_rewrites_history_rest_plugin" type="Magento\CatalogUrlRewrite\Plugin\Webapi\Controller\Rest\InputParamsResolver" sortOrder="1" disabled="false" />
12+
</type>
1013
</config>

app/code/Magento/Quote/Test/Mftf/ActionGroup/ChangeStatusProductUsingProductGridActionGroup.xml

Lines changed: 0 additions & 33 deletions
This file was deleted.

app/code/Magento/Quote/Test/Mftf/Section/AdminProductGridSection.xml

Lines changed: 0 additions & 14 deletions
This file was deleted.

0 commit comments

Comments
 (0)