public function testAddValueSortToCollection() { $attributeCode = 'attribute_code'; $dir = \Magento\Framework\DB\Select::SQL_ASC; $collection = $this->getMockBuilder('Magento\\Eav\\Model\\Entity\\Collection\\AbstractCollection')->setMethods(['getSelect', 'getStoreId'])->disableOriginalConstructor()->getMockForAbstractClass(); $attribute = $this->getMockBuilder('Magento\\Eav\\Model\\Entity\\Attribute\\AbstractAttribute')->setMethods(['getAttributeCode', 'getEntity', 'getBackend', 'getId'])->disableOriginalConstructor()->getMockForAbstractClass(); $attribute->expects($this->any())->method('getAttributeCode')->willReturn($attributeCode); $entity = $this->getMockBuilder('Magento\\Eav\\Model\\Entity\\AbstractEntity')->setMethods(['getLinkField'])->disableOriginalConstructor()->getMockForAbstractClass(); $attribute->expects($this->once())->method('getEntity')->willReturn($entity); $entity->expects($this->once())->method('getLinkField')->willReturn('entity_id'); $select = $this->getMockBuilder('Magento\\Framework\\DB\\Select')->setMethods(['joinLeft', 'getConnection', 'order'])->disableOriginalConstructor()->getMock(); $collection->expects($this->any())->method('getSelect')->willReturn($select); $select->expects($this->any())->method('joinLeft')->willReturnSelf(); $backend = $this->getMockBuilder('Magento\\Eav\\Model\\Entity\\Attribute\\Backend\\AbstractBackend')->setMethods(['getTable'])->disableOriginalConstructor()->getMockForAbstractClass(); $attribute->expects($this->any())->method('getBackend')->willReturn($backend); $backend->expects($this->any())->method('getTable')->willReturn('table_name'); $attribute->expects($this->any())->method('getId')->willReturn(1); $collection->expects($this->once())->method('getStoreId')->willReturn(1); $connection = $this->getMockBuilder('Magento\\Framework\\DB\\Adapter\\AdapterInterface')->disableOriginalConstructor()->getMock(); $expr = $this->getMockBuilder('Zend_Db_Expr')->disableOriginalConstructor()->getMock(); $connection->expects($this->once())->method('getCheckSql')->willReturn($expr); $select->expects($this->once())->method('getConnection')->willReturn($connection); $attrOption = $this->getMockBuilder('Magento\\Eav\\Model\\ResourceModel\\Entity\\Attribute\\Option')->disableOriginalConstructor()->getMock(); $this->attrOptionFactory->expects($this->once())->method('create')->willReturn($attrOption); $attrOption->expects($this->once())->method('addOptionValueToCollection')->with($collection, $attribute, $expr)->willReturnSelf(); $select->expects($this->once())->method('order')->with("{$attributeCode} {$dir}"); $this->model->setAttribute($attribute); $this->assertEquals($this->model, $this->model->addValueSortToCollection($collection, $dir)); }
public function testGetFlatColums() { $abstractFrontendMock = $this->getMock('Magento\\Eav\\Model\\Entity\\Attribute\\Frontend\\AbstractFrontend', array(), array(), '', false); $abstractAttributeMock = $this->getMock('\\Magento\\Eav\\Model\\Entity\\Attribute\\AbstractAttribute', array('getFrontend', 'getAttributeCode', '__wakeup'), array(), '', false); $abstractAttributeMock->expects($this->any())->method('getFrontend')->will($this->returnValue($abstractFrontendMock)); $abstractAttributeMock->expects($this->any())->method('getAttributeCode')->will($this->returnValue('code')); $this->_model->setAttribute($abstractAttributeMock); $flatColums = $this->_model->getFlatColums(); $this->assertTrue(is_array($flatColums), 'FlatColums must be an array value'); $this->assertTrue(!empty($flatColums), 'FlatColums must be not empty'); foreach ($flatColums as $result) { $this->assertArrayHasKey('unsigned', $result, 'FlatColums must have "unsigned" column'); $this->assertArrayHasKey('default', $result, 'FlatColums must have "default" column'); $this->assertArrayHasKey('extra', $result, 'FlatColums must have "extra" column'); $this->assertArrayHasKey('type', $result, 'FlatColums must have "type" column'); $this->assertArrayHasKey('nullable', $result, 'FlatColums must have "nullable" column'); $this->assertArrayHasKey('comment', $result, 'FlatColums must have "comment" column'); $this->assertArrayHasKey('length', $result, 'FlatColums must have "length" column'); } }
/** * @dataProvider getOptionTextProvider * @param array $optionsIds * @param array|string $value * @param array $options * @param array|string $expectedResult */ public function testGetOptionText($optionsIds, $value, $options, $expectedResult) { $attributeId = 1; $storeId = 5; $attribute = $this->getMock('Magento\\Eav\\Model\\Entity\\Attribute\\AbstractAttribute', ['getId', 'getStoreId', '__wakeup'], [], '', false); $attribute->expects($this->once())->method('getId')->willReturn($attributeId); $attribute->expects($this->once())->method('getStoreId')->willReturn($storeId); $this->_model->setAttribute($attribute); $this->collectionFactory->expects($this->once())->method('create')->willReturnSelf(); $this->collectionFactory->expects($this->once())->method('setPositionOrder')->willReturnSelf(); $this->collectionFactory->expects($this->once())->method('setAttributeFilter')->with($attributeId)->willReturnSelf(); $this->collectionFactory->expects($this->once())->method('addFieldToFilter')->with('main_table.option_id', ['in' => $optionsIds])->willReturnSelf(); $this->collectionFactory->expects($this->once())->method('setStoreFilter')->with($storeId)->willReturnSelf(); $this->collectionFactory->expects($this->once())->method('load')->willReturnSelf(); $this->collectionFactory->expects($this->once())->method('toOptionArray')->willReturn($options); $this->assertEquals($expectedResult, $this->_model->getOptionText($value)); }
/** * @param \Magento\Eav\Model\Resource\Entity\Attribute\Option\CollectionFactory $attrOptionCollectionFactory * @param \Magento\Eav\Model\Resource\Entity\Attribute\OptionFactory $attrOptionFactory * @param \Magento\Directory\Model\Resource\Region\CollectionFactory $regionsFactory */ public function __construct(\Magento\Eav\Model\Resource\Entity\Attribute\Option\CollectionFactory $attrOptionCollectionFactory, \Magento\Eav\Model\Resource\Entity\Attribute\OptionFactory $attrOptionFactory, \Magento\Directory\Model\Resource\Region\CollectionFactory $regionsFactory) { $this->_regionsFactory = $regionsFactory; parent::__construct($attrOptionCollectionFactory, $attrOptionFactory); }
/** * @param \Magento\Eav\Model\ResourceModel\Entity\Attribute\Option\CollectionFactory $attrOptionCollectionFactory * @param \Magento\Eav\Model\ResourceModel\Entity\Attribute\OptionFactory $attrOptionFactory * @param \Magento\Store\Model\System\Store $store * @param \Magento\Store\Model\ResourceModel\Store\CollectionFactory $storesFactory */ public function __construct(\Magento\Eav\Model\ResourceModel\Entity\Attribute\Option\CollectionFactory $attrOptionCollectionFactory, \Magento\Eav\Model\ResourceModel\Entity\Attribute\OptionFactory $attrOptionFactory, \Magento\Store\Model\System\Store $store, \Magento\Store\Model\ResourceModel\Store\CollectionFactory $storesFactory) { parent::__construct($attrOptionCollectionFactory, $attrOptionFactory); $this->_store = $store; $this->_storesFactory = $storesFactory; }
/** * @param \Magento\Eav\Model\Resource\Entity\Attribute\Option\CollectionFactory $attrOptionCollectionFactory * @param \Magento\Eav\Model\Resource\Entity\Attribute\OptionFactory $attrOptionFactory * @param GroupManagementInterface $groupManagement * @param \Magento\Framework\Convert\Object $converter */ public function __construct(\Magento\Eav\Model\Resource\Entity\Attribute\Option\CollectionFactory $attrOptionCollectionFactory, \Magento\Eav\Model\Resource\Entity\Attribute\OptionFactory $attrOptionFactory, GroupManagementInterface $groupManagement, \Magento\Framework\Convert\Object $converter) { $this->_groupManagement = $groupManagement; $this->_converter = $converter; parent::__construct($attrOptionCollectionFactory, $attrOptionFactory); }
/** * @param \Magento\Core\Helper\Data $coreData * @param \Magento\Eav\Model\Resource\Entity\Attribute\Option\CollectionFactory $attrOptionCollectionFactory * @param \Magento\Eav\Model\Resource\Entity\Attribute\OptionFactory $attrOptionFactory * @param \Magento\Directory\Model\Resource\Country\CollectionFactory $countriesFactory */ public function __construct(\Magento\Core\Helper\Data $coreData, \Magento\Eav\Model\Resource\Entity\Attribute\Option\CollectionFactory $attrOptionCollectionFactory, \Magento\Eav\Model\Resource\Entity\Attribute\OptionFactory $attrOptionFactory, \Magento\Directory\Model\Resource\Country\CollectionFactory $countriesFactory) { $this->_countriesFactory = $countriesFactory; parent::__construct($coreData, $attrOptionCollectionFactory, $attrOptionFactory); }
/** * @param \Magento\Core\Helper\Data $coreData * @param \Magento\Eav\Model\Resource\Entity\Attribute\Option\CollectionFactory $attrOptionCollectionFactory * @param \Magento\Eav\Model\Resource\Entity\Attribute\OptionFactory $attrOptionFactory * @param \Magento\Customer\Service\V1\CustomerGroupServiceInterface $groupService * @param \Magento\Framework\Convert\Object $converter */ public function __construct(\Magento\Core\Helper\Data $coreData, \Magento\Eav\Model\Resource\Entity\Attribute\Option\CollectionFactory $attrOptionCollectionFactory, \Magento\Eav\Model\Resource\Entity\Attribute\OptionFactory $attrOptionFactory, \Magento\Customer\Service\V1\CustomerGroupServiceInterface $groupService, \Magento\Framework\Convert\Object $converter) { $this->_groupService = $groupService; $this->_converter = $converter; parent::__construct($coreData, $attrOptionCollectionFactory, $attrOptionFactory); }
/** * @param \Magento\Core\Helper\Data $coreData * @param \Magento\Eav\Model\Resource\Entity\Attribute\Option\CollectionFactory $attrOptionCollectionFactory * @param \Magento\Eav\Model\Resource\Entity\Attribute\OptionFactory $attrOptionFactory * @param \Magento\Store\Model\System\Store $store */ public function __construct(\Magento\Core\Helper\Data $coreData, \Magento\Eav\Model\Resource\Entity\Attribute\Option\CollectionFactory $attrOptionCollectionFactory, \Magento\Eav\Model\Resource\Entity\Attribute\OptionFactory $attrOptionFactory, \Magento\Store\Model\System\Store $store) { parent::__construct($coreData, $attrOptionCollectionFactory, $attrOptionFactory); $this->_store = $store; }