77namespace Magento \Rule \Model \Condition \Sql ;
88
99use Magento \Catalog \Model \ResourceModel \Eav \Attribute ;
10+ use Magento \Catalog \Model \ResourceModel \Product \Collection \ProductLimitation ;
1011use Magento \Catalog \Setup \CategorySetup ;
1112use Magento \Eav \Model \Entity \Attribute \Backend \ArrayBackend ;
12- use Magento \Eav \Model \Entity \Attribute \Source \Table ;
1313use Magento \Eav \Test \Fixture \AttributeOption as AttributeOptionFixture ;
14+ use Magento \Framework \DB \Select ;
1415use Magento \Framework \Exception \LocalizedException ;
1516use Magento \TestFramework \Helper \Bootstrap ;
1617use Magento \TestFramework \Fixture \DataFixture ;
1920use Magento \CatalogWidget \Model \RuleFactory ;
2021use Magento \CatalogWidget \Model \Rule \Condition \Combine as CombineCondition ;
2122use Magento \CatalogWidget \Model \Rule \Condition \Product as ProductCondition ;
23+ use Magento \Catalog \Model \ResourceModel \Product \Collection ;
2224use PHPUnit \Framework \TestCase ;
2325
2426/**
@@ -52,12 +54,13 @@ protected function setUp(): void
5254 MultiselectAttribute::class,
5355 [
5456 'entity_type_id ' => CategorySetup::CATALOG_PRODUCT_ENTITY_TYPE_ID ,
55- 'source_model ' => Table::class ,
56- // 'backend_model' => ArrayBackend::class,
57+ 'source_model ' => null ,
58+ 'backend_model ' => ArrayBackend::class,
5759 'attribute_code ' => 'multi_select_attr ' ,
5860 'is_visible_on_front ' => true ,
5961 'frontend_input ' => 'multiselect ' ,
60- 'backend_type ' => 'static ' //nu asa ?!
62+ 'backend_type ' => 'text ' ,
63+ 'attribute_model ' => Attribute::class,
6164 ],
6265 'multiselect '
6366 ),
@@ -115,6 +118,21 @@ public function testAttachConditionToCollection(
115118 ];
116119
117120 $ rule ->loadPost ($ ruleConditionArray );
121+ foreach ($ rule ->getConditions ()->getConditions () as $ condition ) {
122+ if ($ condition ->getAttribute () === 'multi_select_attr ' ) {
123+ $ productCollection = $ this ->createMock (Collection::class);
124+ $ limitationFilters = $ this ->createMock (ProductLimitation::class);
125+ $ limitationFilters ->expects ($ this ->any ())->method ('isUsingPriceIndex ' )->willReturn (false );
126+ $ productCollection ->expects ($ this ->any ())
127+ ->method ('getLimitationFilters ' )
128+ ->willReturn ($ limitationFilters );
129+ $ productCollection ->expects ($ this ->any ())->method ('isEnabledFlat ' )->willReturn (true );
130+ $ select = $ this ->createMock (Select::class);
131+ $ select ->expects ($ this ->any ())->method ('getPart ' )->willReturn ([]);
132+ $ productCollection ->expects ($ this ->any ())->method ('getSelect ' )->willReturn ($ select );
133+ $ condition ->addToCollection ($ productCollection );
134+ }
135+ }
118136 $ this ->model ->attachConditionToCollection ($ collection , $ rule ->getConditions ());
119137
120138 $ this ->assertStringContainsString ($ expectedWhere , $ collection ->getSelectSql (true ));
@@ -127,7 +145,7 @@ public function testAttachConditionToCollection(
127145 public static function attachConditionToCollectionDataProvider (): array
128146 {
129147 return [
130- /* [
148+ [
131149 [
132150 '1 ' => [
133151 'type ' => CombineCondition::class,
@@ -159,7 +177,7 @@ public static function attachConditionToCollectionDataProvider(): array
159177 "AND(`e`.`entity_id` = '2017-09-15 00:00:00') AND(`e`.`sku` IN " .
160178 "('sku1', 'sku2', 'sku3', 'sku4', 'sku5')) ))) AND (e.created_in <= 1) AND (e.updated_in > 1) " ,
161179 "ORDER BY (FIELD(`e`.`sku`, 'sku1', 'sku2', 'sku3', 'sku4', 'sku5')) "
162- ],*/
180+ ],
163181 [
164182 [
165183 '1 ' => [
@@ -184,12 +202,15 @@ public static function attachConditionToCollectionDataProvider(): array
184202 'type ' => ProductCondition::class,
185203 'attribute ' => 'multi_select_attr ' ,
186204 'operator ' => '{} ' ,
205+ 'collected_attributes ' => ['multiselect_attribute ' => true ],
187206 ]
188207 ],
189208 "WHERE ((((`e`.`entity_id` IN (SELECT `catalog_category_product`.`product_id` FROM " .
190- "`catalog_category_product` WHERE (category_id IN ('3')))) AND(`e`.`sku` IN " .
191- "('sku1', 'sku2', 'sku3')) AND(`multiselect_attribute` LIKE '%%') ))) AND " .
192- "(e.created_in <= 1) AND (e.updated_in > 1) " ,
209+ "`catalog_category_product` WHERE (category_id IN ('3')))) AND(`e`.`sku` IN ('sku1', 'sku2', 'sku3')) " .
210+ " AND(`at_multi_select_attr`.`value` IN ('13', '14') OR " .
211+ "(FIND_IN_SET ('13', `at_multi_select_attr`.`value`) > 0) OR " .
212+ "(FIND_IN_SET ('14', `at_multi_select_attr`.`value`) > 0)) ))) AND " .
213+ "(e.created_in <= 1) AND (e.updated_in > 1) " ,
193214 "ORDER BY (FIELD(`e`.`sku`, 'sku1', 'sku2', 'sku3')) "
194215 ]
195216 ];
0 commit comments