10
10
use Magento \Catalog \Model \ResourceModel \Product \Collection \ProductLimitation ;
11
11
use Magento \Catalog \Setup \CategorySetup ;
12
12
use Magento \Eav \Model \Entity \Attribute \Backend \ArrayBackend ;
13
- use Magento \Eav \Test \Fixture \AttributeOption as AttributeOptionFixture ;
14
13
use Magento \Framework \DB \Select ;
15
14
use Magento \Framework \Exception \LocalizedException ;
15
+ use Magento \TestFramework \Fixture \DataFixtureStorage ;
16
+ use Magento \TestFramework \Fixture \DataFixtureStorageManager ;
16
17
use Magento \TestFramework \Helper \Bootstrap ;
17
18
use Magento \TestFramework \Fixture \DataFixture ;
18
19
use Magento \Catalog \Test \Fixture \MultiselectAttribute ;
21
22
use Magento \CatalogWidget \Model \Rule \Condition \Combine as CombineCondition ;
22
23
use Magento \CatalogWidget \Model \Rule \Condition \Product as ProductCondition ;
23
24
use Magento \Catalog \Model \ResourceModel \Product \Collection ;
25
+ use Magento \TestFramework \Helper \Bootstrap as BootstrapHelper ;
24
26
use PHPUnit \Framework \TestCase ;
25
27
26
28
/**
@@ -33,20 +35,26 @@ class BuilderTest extends TestCase
33
35
*/
34
36
private Builder $ model ;
35
37
38
+ /**
39
+ * @var DataFixtureStorage
40
+ */
41
+ private DataFixtureStorage $ fixtures ;
42
+
36
43
/**
37
44
* @inheritDoc
38
45
*/
39
46
protected function setUp (): void
40
47
{
41
48
$ this ->model = Bootstrap::getObjectManager ()->create (Builder::class);
49
+ $ this ->fixtures = BootstrapHelper::getObjectManager ()->get (DataFixtureStorageManager::class)->getStorage ();
42
50
}
43
51
44
52
/**
45
53
* @param array $conditions
46
54
* @param string $expectedWhere
47
55
* @param string $expectedOrder
48
56
* @return void
49
- * @throws LocalizedException
57
+ * @throws LocalizedException|\PHPUnit\Framework\MockObject\Exception
50
58
* @dataProvider attachConditionToCollectionDataProvider
51
59
*/
52
60
#[
@@ -61,27 +69,9 @@ protected function setUp(): void
61
69
'frontend_input ' => 'multiselect ' ,
62
70
'backend_type ' => 'text ' ,
63
71
'attribute_model ' => Attribute::class,
72
+ 'options ' => ['red ' , 'white ' ]
64
73
],
65
74
'multiselect '
66
- ),
67
- DataFixture(
68
- AttributeOptionFixture::class,
69
- [
70
- 'attribute_code ' => 'multiselect.attribute_code$ ' ,
71
- 'label ' => 'red ' ,
72
- 'sort_order ' => 20
73
- ],
74
- 'multiselect_custom_attribute_option_1 '
75
- ),
76
- DataFixture(
77
- AttributeOptionFixture::class,
78
- [
79
- 'attribute_code ' => 'multiselect.attribute_code$ ' ,
80
- 'sort_order ' => 10 ,
81
- 'label ' => 'white ' ,
82
- 'is_default ' => true
83
- ],
84
- 'multiselect_custom_attribute_option_2 '
85
75
)
86
76
]
87
77
public function testAttachConditionToCollection (
@@ -94,23 +84,11 @@ public function testAttachConditionToCollection(
94
84
$ collection = $ collectionFactory ->create ();
95
85
foreach ($ conditions as $ key => $ condition ) {
96
86
if (isset ($ condition ['attribute ' ]) && $ condition ['attribute ' ] === 'multi_select_attr ' ) {
97
- $ multiselect = Bootstrap::getObjectManager ()->create (
98
- Attribute::class
99
- );
100
- $ multiselect ->load ('multi_select_attr ' , 'attribute_code ' );
101
- $ multiselectAttributeOptionIds = [];
102
- $ optionIndex = 1 ;
103
- foreach ($ multiselect ->getOptions () as $ option ) {
104
- if ($ option ->getValue ()) {
105
- $ multiselectAttributeOptionIds [] = $ option ->getValue ();
106
- $ expectedWhere = str_replace (
107
- "#optionAtrId $ optionIndex# " ,
108
- $ option ->getValue (),
109
- $ expectedWhere
110
- );
111
- $ optionIndex ++;
112
- }
113
- }
87
+ $ multiselectAttributeOptionIds = [
88
+ $ this ->fixtures ->get ('multiselect ' )->getData ('red ' ),
89
+ $ this ->fixtures ->get ('multiselect ' )->getData ('white ' )
90
+ ];
91
+ $ expectedWhere = str_replace (["red " , "white " ], $ multiselectAttributeOptionIds , $ expectedWhere );
114
92
115
93
$ conditions [$ key ]['value ' ] = $ multiselectAttributeOptionIds ;
116
94
}
@@ -215,9 +193,9 @@ public static function attachConditionToCollectionDataProvider(): array
215
193
"(((`e`.`entity_id` IN (SELECT `catalog_category_product`.`product_id` FROM " .
216
194
"`catalog_category_product` WHERE (category_id IN ('3')))) " .
217
195
"AND(`e`.`sku` IN ('sku1', 'sku2', 'sku3')) AND(`at_multi_select_attr`.`value` IN " .
218
- "('#optionAtrId1# ', '#optionAtrId2# ') OR " .
219
- "(FIND_IN_SET ('#optionAtrId1# ', `at_multi_select_attr`.`value`) > 0) OR " .
220
- "(FIND_IN_SET ('#optionAtrId2# ', `at_multi_select_attr`.`value`) > 0)) " ,
196
+ "('red ', 'white ') OR " .
197
+ "(FIND_IN_SET ('red ', `at_multi_select_attr`.`value`) > 0) OR " .
198
+ "(FIND_IN_SET ('white ', `at_multi_select_attr`.`value`) > 0)) " ,
221
199
"ORDER BY (FIELD(`e`.`sku`, 'sku1', 'sku2', 'sku3')) "
222
200
]
223
201
];
0 commit comments