6 declare(strict_types=1);
17 private $objectManager;
19 private $productCollectionFactory;
21 private $conditionsToCollectionApplier;
23 private $combinedConditionFactory;
25 private $simpleConditionFactory;
27 private $categoryCollectionFactory;
35 $this->productCollectionFactory = $this->objectManager
38 $this->conditionsToCollectionApplier = $this->objectManager
41 $this->combinedConditionFactory = $this->objectManager
44 $this->simpleConditionFactory = $this->objectManager
47 $this->categoryCollectionFactory = $this->objectManager
50 $this->setFactory = $this->objectManager
63 foreach ($this->conditionProvider() as $variationName => $variationData) {
64 $condition = $variationData[
'condition'];
65 $expectedSkuList = $variationData[
'expected-sku'];
68 $resultCollection = $this->conditionsToCollectionApplier
71 $resultSkuList = array_map(
75 array_values($resultCollection->getItems())
78 asort($expectedSkuList);
79 asort($resultSkuList);
81 $this->assertEquals($expectedSkuList, $resultSkuList, sprintf(
'%s failed', $variationName));
94 'type' => \Magento\CatalogRule\Model\Rule\Condition\Combine::class,
95 'aggregator' =>
'all',
99 'type' => \Magento\CatalogRule\Model\Rule\Condition\Product::class,
100 'operator' =>
'====',
102 'attribute' =>
'attribute_set_id' 107 $combineCondition = $this->getCombineConditionFromArray($conditions);
110 $this->conditionsToCollectionApplier
123 'type' => \Magento\CatalogRule\Model\Rule\Condition\Combine::class,
124 'aggregator' =>
'olo-lo',
128 'type' => \Magento\CatalogRule\Model\Rule\Condition\Product::class,
131 'attribute' =>
'attribute_set_id' 136 $combineCondition = $this->getCombineConditionFromArray($conditions);
139 $this->conditionsToCollectionApplier
147 private function conditionProvider()
152 'condition' => $this->getConditionsForVariation1(),
163 'condition' => $this->getConditionsForVariation2(),
182 'condition' => $this->getConditionsForVariation3(),
199 'condition' => $this->getConditionsForVariation4(),
205 'condition' => $this->getConditionsForVariation5(),
206 'expected-sku' => [
'simple-product-2']
211 'condition' => $this->getConditionsForVariation6(),
222 'condition' => $this->getConditionsForVariation7(),
232 'condition' => $this->getConditionsForVariation8(),
251 'condition' => $this->getConditionsForVariation9(),
257 'condition' => $this->getConditionsForVariation10(),
276 'condition' => $this->getConditionsForVariation11(),
282 'condition' => $this->getConditionsForVariation12(),
299 'condition' => $this->getConditionsForVariation13(),
308 'condition' => $this->getConditionsForVariation14(),
321 'condition' => $this->getConditionsForVariation15(),
334 'condition' => $this->getConditionsForVariation16(),
344 'condition' => $this->getConditionsForVariation17(),
356 'condition' => $this->getConditionsForVariation18(),
371 'condition' => $this->getConditionsForVariation19(),
390 'condition' => $this->getConditionsForVariation20(),
401 'condition' => $this->getConditionsForVariation21(),
420 private function getConditionsForVariation1()
422 $category2Name =
'Category 2';
424 $category2Id = $this->categoryCollectionFactory
426 ->addAttributeToFilter(
'name', $category2Name)
430 'type' => \Magento\CatalogRule\Model\Rule\Condition\Combine::class,
431 'aggregator' =>
'any',
435 'type' => \Magento\CatalogRule\Model\Rule\Condition\Product::class,
437 'value' => implode(
',', $category2Id),
438 'attribute' =>
'category_ids' 443 return $this->getCombineConditionFromArray($conditions);
446 private function getConditionsForVariation2()
448 $categoryName =
'Default Category';
450 $categoryId = $this->categoryCollectionFactory
452 ->addAttributeToFilter(
'name', $categoryName)
456 'type' => \Magento\CatalogRule\Model\Rule\Condition\Combine::class,
457 'aggregator' =>
'any',
461 'type' => \Magento\CatalogRule\Model\Rule\Condition\Product::class,
463 'value' => implode(
',', $categoryId),
464 'attribute' =>
'category_ids' 469 return $this->getCombineConditionFromArray($conditions);
472 private function getConditionsForVariation3()
474 $category1Name =
'Category 1';
476 $category1Id = $this->categoryCollectionFactory
478 ->addAttributeToFilter(
'name', $category1Name)
482 'type' => \Magento\CatalogRule\Model\Rule\Condition\Combine::class,
483 'aggregator' =>
'any',
487 'type' => \Magento\CatalogRule\Model\Rule\Condition\Product::class,
489 'value' => implode(
',', $category1Id),
490 'attribute' =>
'category_ids' 495 return $this->getCombineConditionFromArray($conditions);
498 private function getConditionsForVariation4()
501 'type' => \Magento\CatalogRule\Model\Rule\Condition\Combine::class,
502 'aggregator' =>
'any',
506 'type' => \Magento\CatalogRule\Model\Rule\Condition\Product::class,
508 'value' => implode(
',', [308567758103]),
509 'attribute' =>
'category_ids' 514 return $this->getCombineConditionFromArray($conditions);
517 private function getConditionsForVariation5()
520 'type' => \Magento\CatalogRule\Model\Rule\Condition\Combine::class,
521 'aggregator' =>
'any',
525 'type' => \Magento\CatalogRule\Model\Rule\Condition\Product::class,
527 'value' =>
'product-2',
533 return $this->getCombineConditionFromArray($conditions);
536 private function getConditionsForVariation6()
538 $attrSet = $this->setFactory->create()
539 ->load(
'Super Powerful Muffins',
'attribute_set_name');
542 'type' => \Magento\CatalogRule\Model\Rule\Condition\Combine::class,
543 'aggregator' =>
'any',
547 'type' => \Magento\CatalogRule\Model\Rule\Condition\Product::class,
549 'value' => $attrSet->getId(),
550 'attribute' =>
'attribute_set_id' 555 return $this->getCombineConditionFromArray($conditions);
558 private function getConditionsForVariation7()
561 'type' => \Magento\CatalogRule\Model\Rule\Condition\Combine::class,
562 'aggregator' =>
'any',
566 'type' => \Magento\CatalogRule\Model\Rule\Condition\Product::class,
569 'attribute' =>
'name' 574 return $this->getCombineConditionFromArray($conditions);
577 private function getConditionsForVariation8()
580 'type' => \Magento\CatalogRule\Model\Rule\Condition\Combine::class,
581 'aggregator' =>
'any',
585 'type' => \Magento\CatalogRule\Model\Rule\Condition\Product::class,
588 'attribute' =>
'absolutely_random_attribute_name' 593 return $this->getCombineConditionFromArray($conditions);
596 private function getConditionsForVariation9()
599 'type' => \Magento\CatalogRule\Model\Rule\Condition\Combine::class,
600 'aggregator' =>
'any',
604 'type' => \Magento\CatalogRule\Model\Rule\Condition\Product::class,
607 'attribute' =>
'category_ids' 612 return $this->getCombineConditionFromArray($conditions);
615 private function getConditionsForVariation10()
618 'type' => \Magento\CatalogRule\Model\Rule\Condition\Combine::class,
619 'aggregator' =>
'any',
623 'type' => \Magento\CatalogRule\Model\Rule\Condition\Product::class,
631 return $this->getCombineConditionFromArray($conditions);
634 private function getConditionsForVariation11()
637 'type' => \Magento\CatalogRule\Model\Rule\Condition\Combine::class,
638 'aggregator' =>
'any',
642 'type' => \Magento\CatalogRule\Model\Rule\Condition\Product::class,
645 'attribute' =>
'name' 650 return $this->getCombineConditionFromArray($conditions);
653 private function getConditionsForVariation12()
655 $category1Name =
'Category 1';
657 $category1Id = $this->categoryCollectionFactory
659 ->addAttributeToFilter(
'name', $category1Name)
663 'type' => \Magento\CatalogRule\Model\Rule\Condition\Combine::class,
664 'aggregator' =>
'any',
668 'type' => \Magento\CatalogRule\Model\Rule\Condition\Product::class,
670 'value' => implode(
',', $category1Id),
671 'attribute' =>
'category_ids' 676 return $this->getCombineConditionFromArray($conditions);
679 private function getConditionsForVariation13()
681 $category3Name =
'Category 3';
683 $category3Id = $this->categoryCollectionFactory
685 ->addAttributeToFilter(
'name', $category3Name)
688 $category2Name =
'Category 2';
690 $category2Id = $this->categoryCollectionFactory
692 ->addAttributeToFilter(
'name', $category2Name)
696 'type' => \Magento\CatalogRule\Model\Rule\Condition\Combine::class,
697 'aggregator' =>
'all',
701 'type' => \Magento\CatalogRule\Model\Rule\Condition\Product::class,
703 'value' => implode(
',', $category3Id),
704 'attribute' =>
'category_ids' 707 'type' => \Magento\CatalogRule\Model\Rule\Condition\Product::class,
709 'value' => implode(
',', $category2Id),
710 'attribute' =>
'category_ids' 715 return $this->getCombineConditionFromArray($conditions);
718 private function getConditionsForVariation14()
720 $category3Name =
'Category 3';
722 $category3Id = $this->categoryCollectionFactory
724 ->addAttributeToFilter(
'name', $category3Name)
727 $category2Name =
'Category 2';
729 $category2Id = $this->categoryCollectionFactory
731 ->addAttributeToFilter(
'name', $category2Name)
735 'type' => \Magento\CatalogRule\Model\Rule\Condition\Combine::class,
736 'aggregator' =>
'any',
740 'type' => \Magento\CatalogRule\Model\Rule\Condition\Product::class,
742 'value' => implode(
',', $category3Id),
743 'attribute' =>
'category_ids' 746 'type' => \Magento\CatalogRule\Model\Rule\Condition\Product::class,
748 'value' => implode(
',', $category2Id),
749 'attribute' =>
'category_ids' 754 return $this->getCombineConditionFromArray($conditions);
757 private function getConditionsForVariation15()
759 $category3Name =
'Category 3';
761 $category3Id = $this->categoryCollectionFactory
763 ->addAttributeToFilter(
'name', $category3Name)
766 $category2Name =
'Category 2';
768 $category2Id = $this->categoryCollectionFactory
770 ->addAttributeToFilter(
'name', $category2Name)
774 'type' => \Magento\CatalogRule\Model\Rule\Condition\Combine::class,
775 'aggregator' =>
'all',
779 'type' => \Magento\CatalogRule\Model\Rule\Condition\Product::class,
781 'value' => [$category3Id[0], $category2Id[0]],
782 'attribute' =>
'category_ids' 787 return $this->getCombineConditionFromArray($conditions);
790 private function getConditionsForVariation16()
793 'type' => \Magento\CatalogRule\Model\Rule\Condition\Combine::class,
794 'aggregator' =>
'any',
798 'type' => \Magento\CatalogRule\Model\Rule\Condition\Product::class,
800 'value' =>
'simple-product-1,simple-product-5,simple-product-11',
806 return $this->getCombineConditionFromArray($conditions);
809 private function getConditionsForVariation17()
811 $category1Name =
'Category 1';
813 $category1Id = $this->categoryCollectionFactory
815 ->addAttributeToFilter(
'name', $category1Name)
818 $category2Name =
'Category 2';
820 $category2Id = $this->categoryCollectionFactory
822 ->addAttributeToFilter(
'name', $category2Name)
826 ->load(
'Super Powerful Muffins',
'attribute_set_name');
829 ->load(
'Banana Rangers',
'attribute_set_name');
832 'type' => \Magento\CatalogRule\Model\Rule\Condition\Combine::class,
833 'aggregator' =>
'any',
837 'type' => \Magento\CatalogRule\Model\Rule\Condition\Combine::class,
838 'aggregator' =>
'all',
842 'type' => \Magento\CatalogRule\Model\Rule\Condition\Product::class,
844 'value' => implode(
',', $category1Id),
845 'attribute' =>
'category_ids' 848 'type' => \Magento\CatalogRule\Model\Rule\Condition\Product::class,
851 'attribute' =>
'attribute_set_id' 856 'type' => \Magento\CatalogRule\Model\Rule\Condition\Combine::class,
857 'aggregator' =>
'all',
861 'type' => \Magento\CatalogRule\Model\Rule\Condition\Product::class,
863 'value' => implode(
',', $category2Id),
864 'attribute' =>
'category_ids' 867 'type' => \Magento\CatalogRule\Model\Rule\Condition\Product::class,
870 'attribute' =>
'attribute_set_id' 877 return $this->getCombineConditionFromArray($conditions);
880 private function getConditionsForVariation18()
882 $category1Name =
'Category 1';
884 $category1Id = $this->categoryCollectionFactory
886 ->addAttributeToFilter(
'name', $category1Name)
890 ->load(
'Super Powerful Muffins',
'attribute_set_name');
893 'type' => \Magento\CatalogRule\Model\Rule\Condition\Combine::class,
894 'aggregator' =>
'any',
898 'type' => \Magento\CatalogRule\Model\Rule\Condition\Combine::class,
899 'aggregator' =>
'all',
903 'type' => \Magento\CatalogRule\Model\Rule\Condition\Product::class,
905 'value' => implode(
',', $category1Id),
906 'attribute' =>
'category_ids' 909 'type' => \Magento\CatalogRule\Model\Rule\Condition\Combine::class,
910 'aggregator' =>
'any',
914 'type' => \Magento\CatalogRule\Model\Rule\Condition\Product::class,
917 'attribute' =>
'name' 920 'type' => \Magento\CatalogRule\Model\Rule\Condition\Product::class,
923 'attribute' =>
'attribute_set_id' 932 return $this->getCombineConditionFromArray($conditions);
935 private function getConditionsForVariation19()
938 'type' => \Magento\CatalogRule\Model\Rule\Condition\Combine::class,
939 'aggregator' =>
'all',
944 return $this->getCombineConditionFromArray($conditions);
947 private function getConditionsForVariation20()
950 ->load(
'Super Powerful Muffins',
'attribute_set_name');
953 ->load(
'Guardians of the Refrigerator',
'attribute_set_name');
956 'type' => \Magento\CatalogRule\Model\Rule\Condition\Combine::class,
957 'aggregator' =>
'all',
961 'type' => \Magento\CatalogRule\Model\Rule\Condition\Product::class,
964 'attribute' =>
'attribute_set_id' 967 'type' => \Magento\CatalogRule\Model\Rule\Condition\Product::class,
970 'attribute' =>
'attribute_set_id' 975 return $this->getCombineConditionFromArray($conditions);
978 private function getConditionsForVariation21()
981 ->load(
'Super Powerful Muffins',
'attribute_set_name');
984 ->load(
'Guardians of the Refrigerator',
'attribute_set_name');
987 'type' => \Magento\CatalogRule\Model\Rule\Condition\Combine::class,
988 'aggregator' =>
'any',
992 'type' => \Magento\CatalogRule\Model\Rule\Condition\Product::class,
995 'attribute' =>
'attribute_set_id' 998 'type' => \Magento\CatalogRule\Model\Rule\Condition\Product::class,
1001 'attribute' =>
'attribute_set_id' 1006 return $this->getCombineConditionFromArray($conditions);
1009 private function getCombineConditionFromArray(array
$data)
1011 $combinedCondition = $this->combinedConditionFactory->create();
1012 $combinedCondition->setPrefix(
'conditions');
1013 $combinedCondition->loadArray(
$data);
1015 return $combinedCondition;
testExceptionUndefinedRuleAggregator()
testExceptionUndefinedRuleOperator()
static getObjectManager()