public function testGetNewChildSelectOptions() { $expectedOptions = [['value' => '', 'label' => __('Please choose a condition to add.')], ['value' => 'Magento\\CatalogWidget\\Model\\Rule\\Condition\\Combine', 'label' => __('Conditions Combination')], ['label' => __('Product Attribute'), 'value' => [['value' => 'Magento\\CatalogWidget\\Model\\Rule\\Condition\\Product|sku', 'label' => 'SKU'], ['value' => 'Magento\\CatalogWidget\\Model\\Rule\\Condition\\Product|category', 'label' => 'Category']]]]; $attributeOptions = ['sku' => 'SKU', 'category' => 'Category']; $productCondition = $this->getMockBuilder('\\Magento\\CatalogWidget\\Model\\Rule\\Condition\\Product')->setMethods(['loadAttributeOptions', 'getAttributeOption'])->disableOriginalConstructor()->getMock(); $productCondition->expects($this->any())->method('loadAttributeOptions')->will($this->returnSelf()); $productCondition->expects($this->any())->method('getAttributeOption')->will($this->returnValue($attributeOptions)); $this->conditionFactory->expects($this->atLeastOnce())->method('create')->willReturn($productCondition); $this->assertEquals($expectedOptions, $this->condition->getNewChildSelectOptions()); }
/** * @return array */ public function getNewChildSelectOptions() { $productAttributes = $this->productFactory->create()->loadAttributeOptions()->getAttributeOption(); $attributes = []; foreach ($productAttributes as $code => $label) { $attributes[] = ['value' => 'Magento\\CatalogWidget\\Model\\Rule\\Condition\\Product|' . $code, 'label' => $label]; } $conditions = parent::getNewChildSelectOptions(); $conditions = array_merge_recursive($conditions, [['value' => 'Magento\\CatalogWidget\\Model\\Rule\\Condition\\Combine', 'label' => __('Conditions Combination')], ['label' => __('Product Attribute'), 'value' => $attributes]]); return $conditions; }