Skip to content

Commit

Permalink
Merge pull request #3480 from magento-tango/PR-2311
Browse files Browse the repository at this point in the history
[tango] PR
  • Loading branch information
dhorytskyi authored Nov 23, 2018

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
2 parents 48f8e0a + 89bd63a commit 7755eef
Showing 11 changed files with 307 additions and 54 deletions.
Original file line number Diff line number Diff line change
@@ -213,4 +213,28 @@
<conditionalClick selector="{{AdminProductGridTableHeaderSection.id('descend')}}" dependentSelector="{{AdminProductGridTableHeaderSection.id('ascend')}}" visible="false" stepKey="sortById"/>
<waitForPageLoad stepKey="waitForPageLoad"/>
</actionGroup>

<!--Disabled a product by filtering grid and using change status action-->
<actionGroup name="ChangeStatusProductUsingProductGridActionGroup">
<arguments>
<argument name="product"/>
<argument name="status" defaultValue="Enable" type="string" />
</arguments>
<amOnPage url="{{AdminProductIndexPage.url}}" stepKey="visitAdminProductPage"/>
<waitForPageLoad time="60" stepKey="waitForPageLoadInitial"/>
<conditionalClick selector="{{AdminProductGridFilterSection.clearFilters}}" dependentSelector="{{AdminProductGridFilterSection.clearFilters}}" visible="true" stepKey="clickClearFiltersInitial"/>
<click selector="{{AdminProductGridFilterSection.filters}}" stepKey="openProductFilters"/>
<fillField selector="{{AdminProductGridFilterSection.skuFilter}}" userInput="{{product.sku}}" stepKey="fillProductSkuFilter"/>
<click selector="{{AdminProductGridFilterSection.applyFilters}}" stepKey="clickApplyFilters"/>
<see selector="{{AdminProductGridSection.productGridCell('1', 'SKU')}}" userInput="{{product.sku}}" stepKey="seeProductSkuInGrid"/>
<click selector="{{AdminProductGridSection.multicheckDropdown}}" stepKey="openMulticheckDropdown"/>
<click selector="{{AdminProductGridSection.multicheckOption('Select All')}}" stepKey="selectAllProductInFilteredGrid"/>

<click selector="{{AdminProductGridSection.bulkActionDropdown}}" stepKey="clickActionDropdown"/>
<click selector="{{AdminProductGridSection.bulkActionOption('Change status')}}" stepKey="clickChangeStatusAction"/>
<click selector="{{AdminProductGridSection.changeStatus('status')}}" stepKey="clickChangeStatusDisabled" parameterized="true"/>
<see selector="{{AdminMessagesSection.success}}" userInput="A total of 1 record(s) have been updated." stepKey="seeSuccessMessage"/>
<waitForLoadingMaskToDisappear stepKey="waitForMaskToDisappear"/>
<conditionalClick selector="{{AdminProductGridFilterSection.clearFilters}}" dependentSelector="{{AdminProductGridFilterSection.clearFilters}}" visible="true" stepKey="clickClearFiltersInitial2"/>
</actionGroup>
</actionGroups>
Original file line number Diff line number Diff line change
@@ -30,5 +30,6 @@
<element name="productGridNameProduct" type="input" selector="//tbody//tr//td//div[contains(., '{{var1}}')]" parameterized="true" timeout="30"/>
<element name="productGridContentsOnRow" type="checkbox" selector="//*[@id='container']//tr[{{row}}]/td" parameterized="true"/>
<element name="selectRowBasedOnName" type="input" selector="//td/div[text()='{{var1}}']" parameterized="true"/>
<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"/>
</section>
</sections>
Original file line number Diff line number Diff line change
@@ -59,6 +59,7 @@

<!--Step5. Open *Advanced Inventory* pop-up. Set *Enable Qty Increments* to *Yes*. Fill *.5* in *Qty Increments*-->
<click selector="{{AdminProductFormSection.advancedInventoryLink}}" stepKey="clickOnAdvancedInventoryLink2"/>
<waitForPageLoad stepKey="waitForPageLoad"/>
<scrollTo selector="{{AdminProductFormAdvancedInventorySection.enableQtyIncrements}}" stepKey="scrollToEnableQtyIncrements"/>
<click selector="{{AdminProductFormAdvancedInventorySection.enableQtyIncrementsUseConfigSettings}}" stepKey="clickOnEnableQtyIncrementsUseConfigSettingsCheckbox"/>
<click selector="{{AdminProductFormAdvancedInventorySection.enableQtyIncrements}}" stepKey="clickOnEnableQtyIncrements"/>
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
<?php
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/

declare(strict_types=1);

namespace Magento\CatalogUrlRewrite\Plugin\Webapi\Controller\Rest;

use Magento\Catalog\Api\ProductRepositoryInterface;
use Magento\Framework\Webapi\Rest\Request as RestRequest;

/**
* Plugin for InputParamsResolver
*
* Used to modify product data with save_rewrites_history flag
*/
class InputParamsResolver
{
/**
* @var RestRequest
*/
private $request;

/**
* @param RestRequest $request
*/
public function __construct(RestRequest $request)
{
$this->request = $request;
}

/**
* Add 'save_rewrites_history' param to the product data
*
* @see \Magento\CatalogUrlRewrite\Plugin\Catalog\Controller\Adminhtml\Product\Initialization\Helper
* @param \Magento\Webapi\Controller\Rest\InputParamsResolver $subject
* @param array $result
* @return array
*/
public function afterResolve(\Magento\Webapi\Controller\Rest\InputParamsResolver $subject, array $result): array
{
$route = $subject->getRoute();
$serviceMethodName = $route->getServiceMethod();
$serviceClassName = $route->getServiceClass();
$requestBodyParams = $this->request->getBodyParams();

if ($this->isProductSaveCalled($serviceClassName, $serviceMethodName)
&& $this->isCustomAttributesExists($requestBodyParams)) {
foreach ($requestBodyParams['product']['custom_attributes'] as $attribute) {
if ($attribute['attribute_code'] === 'save_rewrites_history') {
foreach ($result as $resultItem) {
if ($resultItem instanceof \Magento\Catalog\Model\Product) {
$resultItem->setData('save_rewrites_history', (bool)$attribute['value']);
break 2;
}
}
break;
}
}
}
return $result;
}

/**
* Check that product save method called
*
* @param string $serviceClassName
* @param string $serviceMethodName
* @return bool
*/
private function isProductSaveCalled(string $serviceClassName, string $serviceMethodName): bool
{
return $serviceClassName === ProductRepositoryInterface::class && $serviceMethodName === 'save';
}

/**
* Check is any custom options exists in product data
*
* @param array $requestBodyParams
* @return bool
*/
private function isCustomAttributesExists(array $requestBodyParams): bool
{
return !empty($requestBodyParams['product']['custom_attributes']);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,116 @@
<?php
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/

declare(strict_types=1);

namespace Magento\CatalogUrlRewrite\Test\Unit\Plugin\Webapi\Controller\Rest;

use Magento\Framework\TestFramework\Unit\Helper\ObjectManager;
use Magento\Webapi\Controller\Rest\InputParamsResolver;
use Magento\CatalogUrlRewrite\Plugin\Webapi\Controller\Rest\InputParamsResolver as InputParamsResolverPlugin;
use Magento\Framework\Webapi\Rest\Request as RestRequest;
use Magento\Catalog\Model\Product;
use Magento\Webapi\Controller\Rest\Router\Route;
use Magento\Catalog\Api\ProductRepositoryInterface;

/**
* Unit test for InputParamsResolver plugin
*/
class InputParamsResolverTest extends \PHPUnit\Framework\TestCase
{
/**
* @var string
*/
private $saveRewritesHistory;

/**
* @var array
*/
private $requestBodyParams;

/**
* @var array
*/
private $result;

/**
* @var ObjectManager
*/
private $objectManager;

/**
* @var InputParamsResolver|\PHPUnit_Framework_MockObject_MockObject
*/
private $subject;

/**
* @var RestRequest|\PHPUnit_Framework_MockObject_MockObject
*/
private $request;

/**
* @var Product|\PHPUnit_Framework_MockObject_MockObject
*/
private $product;

/**
* @var Route|\PHPUnit_Framework_MockObject_MockObject
*/
private $route;

/**
* @var InputParamsResolverPlugin
*/
private $plugin;

/**
* @inheritdoc
*/
protected function setUp()
{
$this->saveRewritesHistory = 'save_rewrites_history';
$this->requestBodyParams = [
'product' => [
'sku' => 'test',
'custom_attributes' => [
['attribute_code' => $this->saveRewritesHistory, 'value' => 1]
]
]
];

$this->route = $this->createPartialMock(Route::class, ['getServiceMethod', 'getServiceClass']);
$this->request = $this->createPartialMock(RestRequest::class, ['getBodyParams']);
$this->request->expects($this->any())->method('getBodyParams')->willReturn($this->requestBodyParams);
$this->subject = $this->createPartialMock(InputParamsResolver::class, ['getRoute']);
$this->subject->expects($this->any())->method('getRoute')->willReturn($this->route);
$this->product = $this->createPartialMock(Product::class, ['setData']);

$this->result = [false, $this->product, 'test'];

$this->objectManager = new ObjectManager($this);
$this->plugin = $this->objectManager->getObject(
InputParamsResolverPlugin::class,
[
'request' => $this->request
]
);
}

public function testAfterResolve()
{
$this->route->expects($this->once())
->method('getServiceClass')
->willReturn(ProductRepositoryInterface::class);
$this->route->expects($this->once())
->method('getServiceMethod')
->willReturn('save');
$this->product->expects($this->once())
->method('setData')
->with($this->saveRewritesHistory, true);

$this->plugin->afterResolve($this->subject, $this->result);
}
}
3 changes: 3 additions & 0 deletions app/code/Magento/CatalogUrlRewrite/composer.json
Original file line number Diff line number Diff line change
@@ -16,6 +16,9 @@
"magento/module-ui": "*",
"magento/module-url-rewrite": "*"
},
"suggest": {
"magento/module-webapi": "*"
},
"type": "magento2-module",
"license": [
"OSL-3.0",
3 changes: 3 additions & 0 deletions app/code/Magento/CatalogUrlRewrite/etc/webapi_rest/di.xml
Original file line number Diff line number Diff line change
@@ -7,4 +7,7 @@
-->
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:ObjectManager/etc/config.xsd">
<preference for="Magento\CatalogUrlRewrite\Model\ProductUrlPathGenerator" type="Magento\CatalogUrlRewrite\Model\WebapiProductUrlPathGenerator"/>
<type name="Magento\Webapi\Controller\Rest\InputParamsResolver">
<plugin name="product_save_rewrites_history_rest_plugin" type="Magento\CatalogUrlRewrite\Plugin\Webapi\Controller\Rest\InputParamsResolver" sortOrder="1" disabled="false" />
</type>
</config>

This file was deleted.

This file was deleted.

Loading

0 comments on commit 7755eef

Please sign in to comment.