-
Notifications
You must be signed in to change notification settings - Fork 9.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
ENGCOM-3080: Added unit test for CRON converter plugin #18344
- Loading branch information
Showing
9 changed files
with
245 additions
and
4 deletions.
There are no files selected for viewing
89 changes: 89 additions & 0 deletions
89
app/code/Magento/Cron/Test/Unit/Model/System/Config/Initial/ConverterTest.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
60 changes: 60 additions & 0 deletions
60
...Plugin/Catalog/Controller/Adminhtml/Product/Initialization/Helper/ProcessTaxAttribute.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
61 changes: 61 additions & 0 deletions
61
app/code/Magento/Weee/Test/Mftf/Test/AdminRemoveProductWeeeAttributeOptionTest.xml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters