Пример #1
0
 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));
 }
Пример #2
0
 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');
     }
 }
Пример #3
0
 /**
  * @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));
 }