-
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.
- Loading branch information
1 parent
276c690
commit 59cedcd
Showing
4 changed files
with
196 additions
and
1 deletion.
There are no files selected for viewing
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
95 changes: 95 additions & 0 deletions
95
dev/tests/integration/testsuite/Magento/Rule/Model/Condition/Product/AbstractProductTest.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,95 @@ | ||
<?php | ||
/** | ||
* Copyright © Magento, Inc. All rights reserved. | ||
* See COPYING.txt for license details. | ||
*/ | ||
|
||
namespace Magento\Rule\Model\Condition\Product; | ||
|
||
use Magento\Backend\Helper\Data; | ||
use Magento\Catalog\Api\ProductRepositoryInterface; | ||
use Magento\Catalog\Model\ProductCategoryList; | ||
use Magento\Catalog\Model\ProductFactory; | ||
use Magento\Catalog\Model\ResourceModel\Product; | ||
use Magento\Eav\Model\Config; | ||
use Magento\Eav\Model\ResourceModel\Entity\Attribute\Set\Collection; | ||
use Magento\Framework\Locale\FormatInterface; | ||
use Magento\Rule\Model\Condition\Context; | ||
use Magento\TestFramework\Helper\Bootstrap; | ||
|
||
/** | ||
* Provide tests for Abstract Rule product condition data model. | ||
* @magentoAppArea adminhtml | ||
*/ | ||
class AbstractProductTest extends \PHPUnit\Framework\TestCase | ||
{ | ||
/** | ||
* Test subject. | ||
* | ||
* @var AbstractProduct|\PHPUnit_Framework_MockObject_MockObject | ||
*/ | ||
private $model; | ||
|
||
/** | ||
* @inheritdoc | ||
*/ | ||
protected function setUp() | ||
{ | ||
$objectManager = Bootstrap::getObjectManager(); | ||
$context = $objectManager->get(Context::class); | ||
$helperData = $objectManager->get(Data::class); | ||
$config = $objectManager->get(Config::class); | ||
$productFactory = $objectManager->get(ProductFactory::class); | ||
$productRepository = $objectManager->get(ProductRepositoryInterface::class); | ||
$productResource = $objectManager->get(Product::class); | ||
$attributeSetCollection = $objectManager->get(Collection::class); | ||
$localeFormat = $objectManager->get(FormatInterface::class); | ||
$data = []; | ||
$productCategoryList = $objectManager->get(ProductCategoryList::class); | ||
$this->model = $this->getMockBuilder(AbstractProduct::class) | ||
->setMethods(['getOperator', 'getFormName', 'setFormName']) | ||
->setConstructorArgs([ | ||
$context, | ||
$helperData, | ||
$config, | ||
$productFactory, | ||
$productRepository, | ||
$productResource, | ||
$attributeSetCollection, | ||
$localeFormat, | ||
$data, | ||
$productCategoryList | ||
]) | ||
->getMockForAbstractClass(); | ||
} | ||
|
||
/** | ||
* Test Abstract Rule product condition data model shows attribute labels in more readable view | ||
* (without html tags, if one presented). | ||
* | ||
* @magentoDataFixture Magento/Rule/_files/dropdown_attribute_with_html.php | ||
*/ | ||
public function test() | ||
{ | ||
$expectedOptions = [ | ||
[ | ||
'label' => ' ', | ||
'value' => '', | ||
], | ||
[ | ||
'value' => '4', | ||
'label' => 'Option 1', | ||
], | ||
[ | ||
'value' => '5', | ||
'label' => 'Option 2', | ||
], | ||
[ | ||
'value' => '6', | ||
'label' => 'Option 3', | ||
], | ||
]; | ||
$this->model->setAttribute('dropdown_attribute_with_html'); | ||
self::assertSame($expectedOptions, $this->model->getValueSelectOptions()); | ||
} | ||
} |
59 changes: 59 additions & 0 deletions
59
dev/tests/integration/testsuite/Magento/Rule/_files/dropdown_attribute_with_html.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,59 @@ | ||
<?php | ||
/** | ||
* Copyright © Magento, Inc. All rights reserved. | ||
* See COPYING.txt for license details. | ||
*/ | ||
|
||
/* Create attribute */ | ||
/** @var $attribute \Magento\Catalog\Model\ResourceModel\Eav\Attribute */ | ||
$attribute = \Magento\TestFramework\Helper\Bootstrap::getObjectManager()->create( | ||
\Magento\Catalog\Model\ResourceModel\Eav\Attribute::class | ||
); | ||
|
||
if (!$attribute->loadByCode(4, 'dropdown_attribute_with_html')->getId()) { | ||
/** @var $installer \Magento\Catalog\Setup\CategorySetup */ | ||
$installer = \Magento\TestFramework\Helper\Bootstrap::getObjectManager()->create( | ||
\Magento\Catalog\Setup\CategorySetup::class | ||
); | ||
|
||
$attribute->setData( | ||
[ | ||
'attribute_code' => 'dropdown_attribute_with_html', | ||
'entity_type_id' => $installer->getEntityTypeId('catalog_product'), | ||
'is_global' => 0, | ||
'is_user_defined' => 1, | ||
'frontend_input' => 'select', | ||
'is_unique' => 0, | ||
'is_required' => 0, | ||
'is_searchable' => 0, | ||
'is_visible_in_advanced_search' => 0, | ||
'is_comparable' => 0, | ||
'is_filterable' => 0, | ||
'is_filterable_in_search' => 0, | ||
'is_used_for_promo_rules' => 0, | ||
'is_html_allowed_on_front' => 1, | ||
'is_visible_on_front' => 0, | ||
'used_in_product_listing' => 0, | ||
'used_for_sort_by' => 0, | ||
'frontend_label' => ['Drop-Down Attribute'], | ||
'backend_type' => 'varchar', | ||
'backend_model' => \Magento\Eav\Model\Entity\Attribute\Backend\ArrayBackend::class, | ||
'option' => [ | ||
'value' => [ | ||
'option_1' => ['<a href="#">Option 1</a>'], | ||
'option_2' => ['<a href="#">Option 2</a>'], | ||
'option_3' => ['<a href="#">Option 3</a>'], | ||
], | ||
'order' => [ | ||
'option_1' => 1, | ||
'option_2' => 2, | ||
'option_3' => 3, | ||
], | ||
], | ||
] | ||
); | ||
$attribute->save(); | ||
|
||
/* Assign attribute to attribute set */ | ||
$installer->addAttributeToGroup('catalog_product', 'Default', 'Attributes', $attribute->getId()); | ||
} |
22 changes: 22 additions & 0 deletions
22
...tests/integration/testsuite/Magento/Rule/_files/dropdown_attribute_with_html_rollback.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,22 @@ | ||
<?php | ||
/** | ||
* Copyright © Magento, Inc. All rights reserved. | ||
* See COPYING.txt for license details. | ||
*/ | ||
/* Delete attribute with dropdown_attribute_with_html code */ | ||
|
||
use Magento\Catalog\Model\ResourceModel\Eav\Attribute; | ||
use Magento\TestFramework\Helper\Bootstrap; | ||
|
||
$registry = Bootstrap::getObjectManager()->get(\Magento\Framework\Registry::class); | ||
$registry->unregister('isSecureArea'); | ||
$registry->register('isSecureArea', true); | ||
/** @var $attribute Attribute */ | ||
$attribute = Bootstrap::getObjectManager()->create( | ||
Attribute::class | ||
); | ||
$attribute->load('dropdown_attribute_with_html', 'attribute_code'); | ||
$attribute->delete(); | ||
|
||
$registry->unregister('isSecureArea'); | ||
$registry->register('isSecureArea', false); |