/** * @param array $setData * @param string $attributeObjectFrontendInput * @param array $attrObjectSourceAllOptionsValue * @param array $attrSetCollectionOptionsArray * @param bool $expectedAttrObjSourceAllOptionsParam * @param array $expectedValueSelectOptions * @param array $expectedValueOption * @dataProvider prepareValueOptionsDataProvider * @SuppressWarnings(PHPMD.NPathComplexity) */ public function testPrepareValueOptions($setData, $attributeObjectFrontendInput, $attrObjectSourceAllOptionsValue, $attrSetCollectionOptionsArray, $expectedAttrObjSourceAllOptionsParam, $expectedValueSelectOptions, $expectedValueOption) { foreach ($setData as $key => $value) { $this->_condition->setData($key, $value); } $attrObjectSourceMock = $this->getMockBuilder('Magento\\Eav\\Model\\Entity\\Attribute\\Source\\AbstractSource')->setMethods(['getAllOptions'])->disableOriginalConstructor()->getMock(); $attrObjectSourceMock->expects(is_null($expectedAttrObjSourceAllOptionsParam) ? $this->never() : $this->once())->method('getAllOptions')->with($expectedAttrObjSourceAllOptionsParam)->willReturn($attrObjectSourceAllOptionsValue); $attributeObjectMock = $this->getMockBuilder('Magento\\Catalog\\Model\\Resource\\Eav\\Attribute')->setMethods(['usesSource', 'getFrontendInput', 'getSource', 'getAllOptions'])->disableOriginalConstructor()->getMock(); $attributeObjectMock->method('usesSource')->willReturn(true); $attributeObjectMock->expects(is_null($attributeObjectFrontendInput) ? $this->never() : $this->once())->method('getFrontendInput')->willReturn($attributeObjectFrontendInput); $attributeObjectMock->method('getSource')->willReturn($attrObjectSourceMock); $entityTypeMock = $this->getMockBuilder('Magento\\Framework\\Model\\AbstractModel\\Type')->setMethods(['getId'])->disableOriginalConstructor()->getMock(); $entityTypeMock->method('getId')->willReturn('SomeEntityType'); $configValueMock = $this->getMock('Magento\\Eav\\Model\\Config', ['getAttribute', 'getEntityType'], [], '', false); $configValueMock->method('getAttribute')->willReturn($attributeObjectMock); $configValueMock->method('getEntityType')->willReturn($entityTypeMock); $configProperty = new ReflectionProperty('Magento\\Rule\\Model\\Condition\\Product\\AbstractProduct', '_config'); $configProperty->setAccessible(true); $configProperty->setValue($this->_condition, $configValueMock); $attrSetCollectionValueMock = $this->getMockBuilder('Magento\\Eav\\Model\\Resource\\Entity\\Attribute\\Set\\Collection')->setMethods(['setEntityTypeFilter', 'load', 'toOptionArray'])->disableOriginalConstructor()->getMock(); $attrSetCollectionValueMock->method('setEntityTypeFilter')->will($this->returnSelf()); $attrSetCollectionValueMock->method('load')->will($this->returnSelf()); $attrSetCollectionValueMock->expects(is_null($attrSetCollectionOptionsArray) ? $this->never() : $this->once())->method('toOptionArray')->willReturn($attrSetCollectionOptionsArray); $attrSetCollectionProperty = new ReflectionProperty('Magento\\Rule\\Model\\Condition\\Product\\AbstractProduct', '_attrSetCollection'); $attrSetCollectionProperty->setAccessible(true); $attrSetCollectionProperty->setValue($this->_condition, $attrSetCollectionValueMock); $testedMethod = new ReflectionMethod('Magento\\Rule\\Model\\Condition\\Product\\AbstractProduct', '_prepareValueOptions'); $testedMethod->setAccessible(true); $testedMethod->invoke($this->_condition); $this->assertEquals($expectedValueSelectOptions, $this->_condition->getData('value_select_options')); $this->assertEquals($expectedValueOption, $this->_condition->getData('value_option')); }