Skip to content

Commit 3d850f3

Browse files
author
Stanislav Idolov
authored
ENGCOM-3080: Added unit test for CRON converter plugin #18344
2 parents 50ae37e + 9efad29 commit 3d850f3

File tree

9 files changed

+245
-4
lines changed

9 files changed

+245
-4
lines changed
Lines changed: 89 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,89 @@
1+
<?php
2+
/**
3+
* Copyright © Magento, Inc. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
declare(strict_types=1);
7+
8+
namespace Magento\Cron\Test\Unit\Model\System\Config\Initial;
9+
10+
use Magento\Cron\Model\Groups\Config\Data as GroupsConfigModel;
11+
use Magento\Cron\Model\System\Config\Initial\Converter as ConverterPlugin;
12+
use Magento\Framework\App\Config\Initial\Converter;
13+
14+
/**
15+
* Class ConverterTest
16+
*
17+
* Unit test for \Magento\Cron\Model\System\Config\Initial\Converter
18+
*/
19+
class ConverterTest extends \PHPUnit\Framework\TestCase
20+
{
21+
/**
22+
* @var GroupsConfigModel|\PHPUnit_Framework_MockObject_MockObject
23+
*/
24+
private $groupsConfigMock;
25+
26+
/**
27+
* @var Converter|\PHPUnit_Framework_MockObject_MockObject
28+
*/
29+
private $converterMock;
30+
31+
/**
32+
* @var ConverterPlugin
33+
*/
34+
private $converterPlugin;
35+
36+
/**
37+
* @inheritdoc
38+
*/
39+
protected function setUp()
40+
{
41+
$this->groupsConfigMock = $this->getMockBuilder(
42+
GroupsConfigModel::class
43+
)->disableOriginalConstructor()->getMock();
44+
$this->converterMock = $this->getMockBuilder(Converter::class)->getMock();
45+
$this->converterPlugin = new ConverterPlugin($this->groupsConfigMock);
46+
}
47+
48+
/**
49+
* Tests afterConvert method with no $result['data']['default']['system'] set
50+
*/
51+
public function testAfterConvertWithNoData()
52+
{
53+
$expectedResult = ['test'];
54+
$this->groupsConfigMock->expects($this->never())
55+
->method('get');
56+
57+
$result = $this->converterPlugin->afterConvert($this->converterMock, $expectedResult);
58+
59+
self::assertSame($expectedResult, $result);
60+
}
61+
62+
/**
63+
* Tests afterConvert method with $result['data']['default']['system'] set
64+
*/
65+
public function testAfterConvertWithData()
66+
{
67+
$groups = [
68+
'group1' => ['val1' => ['value' => '1']],
69+
'group2' => ['val2' => ['value' => '2']]
70+
];
71+
$expectedResult['data']['default']['system']['cron'] = [
72+
'group1' => [
73+
'val1' => '1'
74+
],
75+
'group2' => [
76+
'val2' => '2'
77+
]
78+
];
79+
$result['data']['default']['system']['cron'] = '1';
80+
81+
$this->groupsConfigMock->expects($this->once())
82+
->method('get')
83+
->willReturn($groups);
84+
85+
$result = $this->converterPlugin->afterConvert($this->converterMock, $result);
86+
87+
self::assertEquals($expectedResult, $result);
88+
}
89+
}

app/code/Magento/Customer/Test/Mftf/Data/CustomerData.xml

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,4 +89,17 @@
8989
<var key="id" entityKey="id" entityType="customer"/>
9090
<data key="firstname">Jane</data>
9191
</entity>
92+
<entity name="Simple_US_CA_Customer" type="customer">
93+
<data key="group_id">1</data>
94+
<data key="default_billing">true</data>
95+
<data key="default_shipping">true</data>
96+
<data key="email" unique="prefix">[email protected]</data>
97+
<data key="firstname">John</data>
98+
<data key="lastname">Doe</data>
99+
<data key="fullname">John Doe</data>
100+
<data key="password">pwdTest123!</data>
101+
<data key="store_id">0</data>
102+
<data key="website_id">0</data>
103+
<requiredEntity type="address">US_Address_CA</requiredEntity>
104+
</entity>
92105
</entities>

app/code/Magento/Customer/Test/Mftf/Data/RegionData.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
<entity name="RegionTX" type="region">
1616
<data key="region">Texas</data>
1717
<data key="region_code">TX</data>
18-
<data key="region_id">1</data>
18+
<data key="region_id">57</data>
1919
</entity>
2020
<entity name="RegionCA" type="region">
2121
<data key="region">California</data>

app/code/Magento/Paypal/Model/Api/PayflowNvp.php

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -136,6 +136,9 @@ class PayflowNvp extends \Magento\Paypal\Model\Api\Nvp
136136
'CVV2MATCH' => 'cvv2_check_result',
137137

138138
'USERSELECTEDFUNDINGSOURCE' => 'funding_source',
139+
140+
'NOSHIPPING' => 'suppress_shipping',
141+
'REQBILLINGADDRESS' => 'require_billing_address',
139142
];
140143

141144
/**
@@ -248,6 +251,8 @@ class PayflowNvp extends \Magento\Paypal\Model\Api\Nvp
248251
'PAYFLOWCOLOR',
249252
'LOCALECODE',
250253
'USERSELECTEDFUNDINGSOURCE',
254+
'NOSHIPPING',
255+
'REQBILLINGADDRESS',
251256
];
252257

253258
/**
@@ -727,6 +732,7 @@ protected function _prepareExpressCheckoutCallRequest(&$requestFields)
727732

728733
/**
729734
* Additional response processing.
735+
*
730736
* Hack to cut off length from API type response params.
731737
*
732738
* @param array $response
@@ -784,7 +790,8 @@ protected function _exportLineItems(array &$request, $i = 0)
784790
}
785791

786792
/**
787-
* Set specific data when negative line item case
793+
* Set specific data when negative line item case.
794+
*
788795
* @return void
789796
*/
790797
protected function _setSpecificForNegativeLineItems()
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
<?php
2+
/**
3+
* Copyright © Magento, Inc. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
declare(strict_types=1);
7+
8+
namespace Magento\Weee\Plugin\Catalog\Controller\Adminhtml\Product\Initialization\Helper;
9+
10+
use Magento\Catalog\Model\Product;
11+
use Magento\Catalog\Controller\Adminhtml\Product\Initialization\Helper;
12+
use Magento\Framework\App\RequestInterface;
13+
14+
/**
15+
* Handles product tax attributes data initialization.
16+
*/
17+
class ProcessTaxAttribute
18+
{
19+
/**
20+
* @var RequestInterface
21+
*/
22+
private $request;
23+
24+
/**
25+
* @param RequestInterface $request
26+
*/
27+
public function __construct(RequestInterface $request)
28+
{
29+
$this->request = $request;
30+
}
31+
32+
/**
33+
* Handles product tax attributes data initialization.
34+
*
35+
* @param Helper $subject
36+
* @param Product $result
37+
* @param Product $product
38+
* @param array $productData
39+
* @return Product
40+
*
41+
* @SuppressWarnings(PHPMD.UnusedFormalParameter)
42+
*/
43+
public function afterInitializeFromData(
44+
Helper $subject,
45+
Product $result,
46+
Product $product,
47+
array $productData
48+
): Product {
49+
$attributes = $result->getAttributes();
50+
if (!empty($attributes)) {
51+
foreach ($attributes as $attribute) {
52+
if ($attribute->getFrontendInput() == 'weee' && !isset($productData[$attribute->getAttributeCode()])) {
53+
$result->setData($attribute->getAttributeCode(), []);
54+
}
55+
}
56+
}
57+
58+
return $result;
59+
}
60+
}

app/code/Magento/Weee/Test/Mftf/Section/AdminProductAddFPTValueSection.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
xsi:noNamespaceSchemaLocation="urn:magento:mftf:Page/etc/SectionObject.xsd">
1111
<section name="AdminProductAddFPTValueSection">
1212
<element name="addFPT" type="button" selector="[data-index='{{FPTAttributeCode}}'] [data-action='add_new_row']" parameterized="true"/>
13+
<element name="removeRowByIndex" type="button" selector="[data-index='{{FPTAttributeCode}}'] [data-action='remove_row']:nth-of-type({{rowIndex}})" parameterized="true"/>
1314
<element name="selectCountryForFPT" type="select" selector="(//select[contains(@name, 'product[{{FPTAttributeCode}}]') and contains(@name, '[country]')])[last()]" parameterized="true"/>
1415
<element name="selectStateForFPT" type="select" selector="(//select[contains(@name, 'product[{{FPTAttributeCode}}]') and contains(@name, '[state]')])[last()]" parameterized="true"/>
1516
<element name="setTaxValueForFPT" type="text" selector="(//input[contains(@name, 'product[{{FPTAttributeCode}}]') and contains(@name, '[value]')])[last()]" parameterized="true"/>
Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
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+
<tests xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
9+
xsi:noNamespaceSchemaLocation="../../../../../../../dev/tests/acceptance/vendor/magento/magento2-functional-testing-framework/src/Magento/FunctionalTestingFramework/Test/etc/testSchema.xsd">
10+
<test name="AdminRemoveProductWeeeAttributeOptionTest">
11+
<annotations>
12+
<features value="Weee attribute options can be removed in product page"/>
13+
<title value="Weee attribute options can be removed in product page"/>
14+
<description value="Weee attribute options can be removed in product page"/>
15+
<severity value="CRITICAL"/>
16+
<testCaseId value="MAGETWO-95033"/>
17+
<group value="weee"/>
18+
</annotations>
19+
<before>
20+
<createData entity="productFPTAttribute" stepKey="createProductFPTAttribute"/>
21+
<createData entity="AddToDefaultSet" stepKey="addFPTToAttributeSet">
22+
<requiredEntity createDataKey="createProductFPTAttribute"/>
23+
</createData>
24+
<createData entity="SimpleProduct2" stepKey="createSimpleProduct"/>
25+
<actionGroup ref="LoginAsAdmin" stepKey="loginAsAdmin"/>
26+
<actionGroup ref="SearchForProductOnBackendActionGroup" stepKey="searchForSimpleProductInitial">
27+
<argument name="product" value="$$createSimpleProduct$$"/>
28+
</actionGroup>
29+
<actionGroup ref="OpenEditProductOnBackendActionGroup" stepKey="openEditProductInitial">
30+
<argument name="product" value="$$createSimpleProduct$$"/>
31+
</actionGroup>
32+
<actionGroup ref="AdminProductAddFPTValueActionGroup" stepKey="addWeeeAttributeValue">
33+
<argument name="FPTAttributeCode" value="$$createProductFPTAttribute.attribute_code$$"/>
34+
<argument name="stateForFPT" value="California"/>
35+
<argument name="valueForFPT" value="10"/>
36+
</actionGroup>
37+
<actionGroup ref="saveProductForm" stepKey="saveProductInitial"/>
38+
</before>
39+
<after>
40+
<amOnPage url="{{AdminProductIndexPage.url}}" stepKey="navigateToProductListing"/>
41+
<waitForPageLoad stepKey="waitForProductListingPageLoad"/>
42+
<actionGroup ref="resetProductGridToDefaultView" stepKey="resetGridToDefaultKeywordSearch"/>
43+
<actionGroup ref="logout" stepKey="logout"/>
44+
<deleteData createDataKey="createProductFPTAttribute" stepKey="deleteProductFPTAttribute"/>
45+
<deleteData createDataKey="createSimpleProduct" stepKey="deleteSimpleProduct"/>
46+
</after>
47+
<!-- Test Steps -->
48+
<!-- Step 1: Open created product edit page -->
49+
<actionGroup ref="SearchForProductOnBackendActionGroup" stepKey="searchForSimpleProduct">
50+
<argument name="product" value="$$createSimpleProduct$$"/>
51+
</actionGroup>
52+
<actionGroup ref="OpenEditProductOnBackendActionGroup" stepKey="openEditProduct">
53+
<argument name="product" value="$$createSimpleProduct$$"/>
54+
</actionGroup>
55+
<!-- Step 2: Remove weee attribute options -->
56+
<click selector="{{AdminProductAddFPTValueSection.removeRowByIndex('$$createProductFPTAttribute.attribute_code$$','1')}}" stepKey="removeAttributeOption"/>
57+
<actionGroup ref="saveProductForm" stepKey="saveProduct"/>
58+
<!-- Assert weee attribute options are empty -->
59+
<dontSeeElement selector="{{AdminProductAddFPTValueSection.removeRowByIndex('$$createProductFPTAttribute.attribute_code$$','1')}}" stepKey="dontSeeOptions"/>
60+
</test>
61+
</tests>

app/code/Magento/Weee/Ui/DataProvider/Product/Form/Modifier/Weee.php

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -85,15 +85,15 @@ public function __construct(
8585
}
8686

8787
/**
88-
* {@inheritdoc}
88+
* @inheritdoc
8989
*/
9090
public function modifyData(array $data)
9191
{
9292
return $data;
9393
}
9494

9595
/**
96-
* {@inheritdoc}
96+
* @inheritdoc
9797
*/
9898
public function modifyMeta(array $meta)
9999
{
@@ -155,6 +155,7 @@ protected function modifyAttributeConfig($attributeCode, array $attributeConfig)
155155
'dndConfig' => [
156156
'enabled' => false,
157157
],
158+
'required' => (bool)$attributeConfig['arguments']['data']['config']['required'],
158159
],
159160
],
160161
],
@@ -180,6 +181,7 @@ protected function modifyAttributeConfig($attributeCode, array $attributeConfig)
180181
'component' => 'Magento_Weee/js/fpt-group',
181182
'visible' => true,
182183
'label' => __('Country/State'),
184+
'showLabel' => false,
183185
],
184186
],
185187
],
@@ -197,6 +199,7 @@ protected function modifyAttributeConfig($attributeCode, array $attributeConfig)
197199
'validation' => [
198200
'required-entry' => true,
199201
],
202+
'showLabel' => false,
200203
],
201204
],
202205
],
@@ -216,6 +219,7 @@ protected function modifyAttributeConfig($attributeCode, array $attributeConfig)
216219
],
217220
'caption' => '*',
218221
'visible' => true,
222+
'showLabel' => false,
219223
],
220224
],
221225
],
@@ -233,6 +237,7 @@ protected function modifyAttributeConfig($attributeCode, array $attributeConfig)
233237
'validation' => [
234238
'validate-fpt-group' => true
235239
],
240+
'showLabel' => false,
236241
],
237242
],
238243
],
@@ -252,6 +257,7 @@ protected function modifyAttributeConfig($attributeCode, array $attributeConfig)
252257
'validation' => [
253258
'required-entry' => true
254259
],
260+
'showLabel' => false,
255261
],
256262
],
257263
],
@@ -267,6 +273,7 @@ protected function modifyAttributeConfig($attributeCode, array $attributeConfig)
267273
'label' => __('Website'),
268274
'visible' => $this->websiteManager->isMultiWebsites(),
269275
'options' => $this->websiteManager->getWebsites($product, $eavAttribute),
276+
'showLabel' => false,
270277
],
271278
],
272279
],

app/code/Magento/Weee/etc/di.xml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,4 +78,7 @@
7878
</argument>
7979
</arguments>
8080
</type>
81+
<type name="Magento\Catalog\Controller\Adminhtml\Product\Initialization\Helper">
82+
<plugin name="weeeAttributeOptionsProcess" type="Magento\Weee\Plugin\Catalog\Controller\Adminhtml\Product\Initialization\Helper\ProcessTaxAttribute"/>
83+
</type>
8184
</config>

0 commit comments

Comments
 (0)