Skip to content

Commit

Permalink
ENGCOM-3080: Added unit test for CRON converter plugin #18344
Browse files Browse the repository at this point in the history
  • Loading branch information
Stanislav Idolov authored Oct 3, 2018
2 parents 50ae37e + 9efad29 commit 3d850f3
Show file tree
Hide file tree
Showing 9 changed files with 245 additions and 4 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
<?php
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
declare(strict_types=1);

namespace Magento\Cron\Test\Unit\Model\System\Config\Initial;

use Magento\Cron\Model\Groups\Config\Data as GroupsConfigModel;
use Magento\Cron\Model\System\Config\Initial\Converter as ConverterPlugin;
use Magento\Framework\App\Config\Initial\Converter;

/**
* Class ConverterTest
*
* Unit test for \Magento\Cron\Model\System\Config\Initial\Converter
*/
class ConverterTest extends \PHPUnit\Framework\TestCase
{
/**
* @var GroupsConfigModel|\PHPUnit_Framework_MockObject_MockObject
*/
private $groupsConfigMock;

/**
* @var Converter|\PHPUnit_Framework_MockObject_MockObject
*/
private $converterMock;

/**
* @var ConverterPlugin
*/
private $converterPlugin;

/**
* @inheritdoc
*/
protected function setUp()
{
$this->groupsConfigMock = $this->getMockBuilder(
GroupsConfigModel::class
)->disableOriginalConstructor()->getMock();
$this->converterMock = $this->getMockBuilder(Converter::class)->getMock();
$this->converterPlugin = new ConverterPlugin($this->groupsConfigMock);
}

/**
* Tests afterConvert method with no $result['data']['default']['system'] set
*/
public function testAfterConvertWithNoData()
{
$expectedResult = ['test'];
$this->groupsConfigMock->expects($this->never())
->method('get');

$result = $this->converterPlugin->afterConvert($this->converterMock, $expectedResult);

self::assertSame($expectedResult, $result);
}

/**
* Tests afterConvert method with $result['data']['default']['system'] set
*/
public function testAfterConvertWithData()
{
$groups = [
'group1' => ['val1' => ['value' => '1']],
'group2' => ['val2' => ['value' => '2']]
];
$expectedResult['data']['default']['system']['cron'] = [
'group1' => [
'val1' => '1'
],
'group2' => [
'val2' => '2'
]
];
$result['data']['default']['system']['cron'] = '1';

$this->groupsConfigMock->expects($this->once())
->method('get')
->willReturn($groups);

$result = $this->converterPlugin->afterConvert($this->converterMock, $result);

self::assertEquals($expectedResult, $result);
}
}
13 changes: 13 additions & 0 deletions app/code/Magento/Customer/Test/Mftf/Data/CustomerData.xml
Original file line number Diff line number Diff line change
Expand Up @@ -89,4 +89,17 @@
<var key="id" entityKey="id" entityType="customer"/>
<data key="firstname">Jane</data>
</entity>
<entity name="Simple_US_CA_Customer" type="customer">
<data key="group_id">1</data>
<data key="default_billing">true</data>
<data key="default_shipping">true</data>
<data key="email" unique="prefix">John.Doe@example.com</data>
<data key="firstname">John</data>
<data key="lastname">Doe</data>
<data key="fullname">John Doe</data>
<data key="password">pwdTest123!</data>
<data key="store_id">0</data>
<data key="website_id">0</data>
<requiredEntity type="address">US_Address_CA</requiredEntity>
</entity>
</entities>
2 changes: 1 addition & 1 deletion app/code/Magento/Customer/Test/Mftf/Data/RegionData.xml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
<entity name="RegionTX" type="region">
<data key="region">Texas</data>
<data key="region_code">TX</data>
<data key="region_id">1</data>
<data key="region_id">57</data>
</entity>
<entity name="RegionCA" type="region">
<data key="region">California</data>
Expand Down
9 changes: 8 additions & 1 deletion app/code/Magento/Paypal/Model/Api/PayflowNvp.php
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,9 @@ class PayflowNvp extends \Magento\Paypal\Model\Api\Nvp
'CVV2MATCH' => 'cvv2_check_result',

'USERSELECTEDFUNDINGSOURCE' => 'funding_source',

'NOSHIPPING' => 'suppress_shipping',
'REQBILLINGADDRESS' => 'require_billing_address',
];

/**
Expand Down Expand Up @@ -248,6 +251,8 @@ class PayflowNvp extends \Magento\Paypal\Model\Api\Nvp
'PAYFLOWCOLOR',
'LOCALECODE',
'USERSELECTEDFUNDINGSOURCE',
'NOSHIPPING',
'REQBILLINGADDRESS',
];

/**
Expand Down Expand Up @@ -727,6 +732,7 @@ protected function _prepareExpressCheckoutCallRequest(&$requestFields)

/**
* Additional response processing.
*
* Hack to cut off length from API type response params.
*
* @param array $response
Expand Down Expand Up @@ -784,7 +790,8 @@ protected function _exportLineItems(array &$request, $i = 0)
}

/**
* Set specific data when negative line item case
* Set specific data when negative line item case.
*
* @return void
*/
protected function _setSpecificForNegativeLineItems()
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
<?php
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
declare(strict_types=1);

namespace Magento\Weee\Plugin\Catalog\Controller\Adminhtml\Product\Initialization\Helper;

use Magento\Catalog\Model\Product;
use Magento\Catalog\Controller\Adminhtml\Product\Initialization\Helper;
use Magento\Framework\App\RequestInterface;

/**
* Handles product tax attributes data initialization.
*/
class ProcessTaxAttribute
{
/**
* @var RequestInterface
*/
private $request;

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

/**
* Handles product tax attributes data initialization.
*
* @param Helper $subject
* @param Product $result
* @param Product $product
* @param array $productData
* @return Product
*
* @SuppressWarnings(PHPMD.UnusedFormalParameter)
*/
public function afterInitializeFromData(
Helper $subject,
Product $result,
Product $product,
array $productData
): Product {
$attributes = $result->getAttributes();
if (!empty($attributes)) {
foreach ($attributes as $attribute) {
if ($attribute->getFrontendInput() == 'weee' && !isset($productData[$attribute->getAttributeCode()])) {
$result->setData($attribute->getAttributeCode(), []);
}
}
}

return $result;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
xsi:noNamespaceSchemaLocation="urn:magento:mftf:Page/etc/SectionObject.xsd">
<section name="AdminProductAddFPTValueSection">
<element name="addFPT" type="button" selector="[data-index='{{FPTAttributeCode}}'] [data-action='add_new_row']" parameterized="true"/>
<element name="removeRowByIndex" type="button" selector="[data-index='{{FPTAttributeCode}}'] [data-action='remove_row']:nth-of-type({{rowIndex}})" parameterized="true"/>
<element name="selectCountryForFPT" type="select" selector="(//select[contains(@name, 'product[{{FPTAttributeCode}}]') and contains(@name, '[country]')])[last()]" parameterized="true"/>
<element name="selectStateForFPT" type="select" selector="(//select[contains(@name, 'product[{{FPTAttributeCode}}]') and contains(@name, '[state]')])[last()]" parameterized="true"/>
<element name="setTaxValueForFPT" type="text" selector="(//input[contains(@name, 'product[{{FPTAttributeCode}}]') and contains(@name, '[value]')])[last()]" parameterized="true"/>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
-->
<tests xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="../../../../../../../dev/tests/acceptance/vendor/magento/magento2-functional-testing-framework/src/Magento/FunctionalTestingFramework/Test/etc/testSchema.xsd">
<test name="AdminRemoveProductWeeeAttributeOptionTest">
<annotations>
<features value="Weee attribute options can be removed in product page"/>
<title value="Weee attribute options can be removed in product page"/>
<description value="Weee attribute options can be removed in product page"/>
<severity value="CRITICAL"/>
<testCaseId value="MAGETWO-95033"/>
<group value="weee"/>
</annotations>
<before>
<createData entity="productFPTAttribute" stepKey="createProductFPTAttribute"/>
<createData entity="AddToDefaultSet" stepKey="addFPTToAttributeSet">
<requiredEntity createDataKey="createProductFPTAttribute"/>
</createData>
<createData entity="SimpleProduct2" stepKey="createSimpleProduct"/>
<actionGroup ref="LoginAsAdmin" stepKey="loginAsAdmin"/>
<actionGroup ref="SearchForProductOnBackendActionGroup" stepKey="searchForSimpleProductInitial">
<argument name="product" value="$$createSimpleProduct$$"/>
</actionGroup>
<actionGroup ref="OpenEditProductOnBackendActionGroup" stepKey="openEditProductInitial">
<argument name="product" value="$$createSimpleProduct$$"/>
</actionGroup>
<actionGroup ref="AdminProductAddFPTValueActionGroup" stepKey="addWeeeAttributeValue">
<argument name="FPTAttributeCode" value="$$createProductFPTAttribute.attribute_code$$"/>
<argument name="stateForFPT" value="California"/>
<argument name="valueForFPT" value="10"/>
</actionGroup>
<actionGroup ref="saveProductForm" stepKey="saveProductInitial"/>
</before>
<after>
<amOnPage url="{{AdminProductIndexPage.url}}" stepKey="navigateToProductListing"/>
<waitForPageLoad stepKey="waitForProductListingPageLoad"/>
<actionGroup ref="resetProductGridToDefaultView" stepKey="resetGridToDefaultKeywordSearch"/>
<actionGroup ref="logout" stepKey="logout"/>
<deleteData createDataKey="createProductFPTAttribute" stepKey="deleteProductFPTAttribute"/>
<deleteData createDataKey="createSimpleProduct" stepKey="deleteSimpleProduct"/>
</after>
<!-- Test Steps -->
<!-- Step 1: Open created product edit page -->
<actionGroup ref="SearchForProductOnBackendActionGroup" stepKey="searchForSimpleProduct">
<argument name="product" value="$$createSimpleProduct$$"/>
</actionGroup>
<actionGroup ref="OpenEditProductOnBackendActionGroup" stepKey="openEditProduct">
<argument name="product" value="$$createSimpleProduct$$"/>
</actionGroup>
<!-- Step 2: Remove weee attribute options -->
<click selector="{{AdminProductAddFPTValueSection.removeRowByIndex('$$createProductFPTAttribute.attribute_code$$','1')}}" stepKey="removeAttributeOption"/>
<actionGroup ref="saveProductForm" stepKey="saveProduct"/>
<!-- Assert weee attribute options are empty -->
<dontSeeElement selector="{{AdminProductAddFPTValueSection.removeRowByIndex('$$createProductFPTAttribute.attribute_code$$','1')}}" stepKey="dontSeeOptions"/>
</test>
</tests>
Original file line number Diff line number Diff line change
Expand Up @@ -85,15 +85,15 @@ public function __construct(
}

/**
* {@inheritdoc}
* @inheritdoc
*/
public function modifyData(array $data)
{
return $data;
}

/**
* {@inheritdoc}
* @inheritdoc
*/
public function modifyMeta(array $meta)
{
Expand Down Expand Up @@ -155,6 +155,7 @@ protected function modifyAttributeConfig($attributeCode, array $attributeConfig)
'dndConfig' => [
'enabled' => false,
],
'required' => (bool)$attributeConfig['arguments']['data']['config']['required'],
],
],
],
Expand All @@ -180,6 +181,7 @@ protected function modifyAttributeConfig($attributeCode, array $attributeConfig)
'component' => 'Magento_Weee/js/fpt-group',
'visible' => true,
'label' => __('Country/State'),
'showLabel' => false,
],
],
],
Expand All @@ -197,6 +199,7 @@ protected function modifyAttributeConfig($attributeCode, array $attributeConfig)
'validation' => [
'required-entry' => true,
],
'showLabel' => false,
],
],
],
Expand All @@ -216,6 +219,7 @@ protected function modifyAttributeConfig($attributeCode, array $attributeConfig)
],
'caption' => '*',
'visible' => true,
'showLabel' => false,
],
],
],
Expand All @@ -233,6 +237,7 @@ protected function modifyAttributeConfig($attributeCode, array $attributeConfig)
'validation' => [
'validate-fpt-group' => true
],
'showLabel' => false,
],
],
],
Expand All @@ -252,6 +257,7 @@ protected function modifyAttributeConfig($attributeCode, array $attributeConfig)
'validation' => [
'required-entry' => true
],
'showLabel' => false,
],
],
],
Expand All @@ -267,6 +273,7 @@ protected function modifyAttributeConfig($attributeCode, array $attributeConfig)
'label' => __('Website'),
'visible' => $this->websiteManager->isMultiWebsites(),
'options' => $this->websiteManager->getWebsites($product, $eavAttribute),
'showLabel' => false,
],
],
],
Expand Down
3 changes: 3 additions & 0 deletions app/code/Magento/Weee/etc/di.xml
Original file line number Diff line number Diff line change
Expand Up @@ -78,4 +78,7 @@
</argument>
</arguments>
</type>
<type name="Magento\Catalog\Controller\Adminhtml\Product\Initialization\Helper">
<plugin name="weeeAttributeOptionsProcess" type="Magento\Weee\Plugin\Catalog\Controller\Adminhtml\Product\Initialization\Helper\ProcessTaxAttribute"/>
</type>
</config>

0 comments on commit 3d850f3

Please sign in to comment.