Magento Extensions Rating 2024
EXTENSIONS BY CATEGORY
B2B (Business-To-Business)
Blog
Customer
ERP (Enterprise Resource Planning)
Mega Menu
One Step Checkout
Order
POS (Point Of Sale)
Search
Shopping Cart
Sitemap
SEO
Social
Stock & Inventory Management
EXTENSIONS BY DEVELOPER
aheadWorks
Amasty
Boost My Shop
BSS Commerce
Magestore
MageWorx
Mirasvit
Templates Master
Wyomind
XTENTO
Magento 2 Documentation
Magento 2 Documentation
2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
vendor
magento
magento2-base
dev
tests
integration
testsuite
Magento
Swatches
Model
SwatchAttributeOptionAddTest.php
Go to the documentation of this file.
1
<?php
6
namespace
Magento\Swatches\Model
;
7
8
use
Magento\Catalog\Api\ProductAttributeOptionManagementInterface
;
9
use
Magento\Eav\Api\Data\AttributeOptionInterface
;
10
use Magento\Eav\Api\Data\AttributeOptionInterfaceFactory;
11
16
class
SwatchAttributeOptionAddTest
extends
\PHPUnit\Framework\TestCase
17
{
21
private
$objectManager;
22
23
protected
function
setUp
()
24
{
25
$this->objectManager =
\Magento\TestFramework\Helper\Bootstrap::getObjectManager
();
26
}
27
33
public
function
testSwatchOptionAdd()
34
{
36
$attribute
= $this->objectManager
37
->create(\
Magento
\Catalog\Model\
ResourceModel
\Eav\Attribute::class)
38
->load(
'color_swatch'
,
'attribute_code'
);
39
$optionsPerAttribute
= 3;
40
41
$data
[
'options'
][
'option'
] = array_reduce(
42
range(10,
$optionsPerAttribute
),
43
function
(
$values
,
$index
) use (
$optionsPerAttribute
) {
44
$values
[] = [
45
'label'
=>
'option '
.
$index
,
46
'value'
=>
'option_'
.
$index
47
];
48
return
$values
;
49
},
50
[]
51
);
52
54
$options
= [];
55
foreach
(
$data
[
'options'
][
'option'
] as
$optionData
) {
56
$options
[] = $this->objectManager
57
->get(AttributeOptionInterfaceFactory::class)
58
->create([
'data'
=>
$optionData
]);
59
}
60
62
$optionManagement = $this->objectManager->get(ProductAttributeOptionManagementInterface::class);
63
foreach
(
$options
as
$option
) {
64
$optionManagement->add(
65
$attribute
->getAttributeCode(),
66
$option
67
);
68
}
69
70
$items
= $optionManagement->getItems(
$attribute
->getAttributeCode());
71
array_walk(
72
$items
,
73
function
(&
$item
) {
75
$item
=
$item
->getLabel();
76
}
77
);
78
foreach
(
$options
as
$option
) {
79
$this->assertTrue(in_array(
$option
->getLabel(),
$items
));
80
}
81
}
82
}
Magento\Catalog\Model\ResourceModel\Product
Definition:
CollectionTest.php:6
$optionData
$optionData
Definition:
select_attribute.php:21
$attribute
$attribute
Definition:
attribute_set_with_image_attribute.php:41
$values
$values
Definition:
options.phtml:88
$item
$item
Definition:
partial_invoice.php:27
Magento\Catalog\Api\ProductAttributeOptionManagementInterface
Definition:
ProductAttributeOptionManagementInterface.php:13
$data
$data
Definition:
attribute_set_with_image_attribute.php:16
$optionsPerAttribute
$optionsPerAttribute
Definition:
products_with_layered_navigation_swatch.php:39
Magento\Eav\Api\Data\AttributeOptionInterface
Definition:
AttributeOptionInterface.php:15
Magento\Swatches\Model\SwatchAttributeOptionAddTest
Definition:
SwatchAttributeOptionAddTest.php:16
Magento
Magento\Swatches\Model
Definition:
AttributeCreateTest.php:6
Magento\Swatches\Model\SwatchAttributeOptionAddTest\setUp
setUp()
Definition:
SwatchAttributeOptionAddTest.php:23
$index
$index
Definition:
list.phtml:44
$option
$option
Definition:
product_configurable_with_single_child.php:38
$options
$options
Definition:
multiple_mixed_products.php:29
Magento\TestFramework\Helper\Bootstrap\getObjectManager
static getObjectManager()
Definition:
Bootstrap.php:125
$items
$items
Definition:
order_rollback.php:21