/** * @covers \Magento\Eav\Model\Entity\Attribute\Source\Boolean::addValueSortToCollection * * @dataProvider addValueSortToCollectionDataProvider * @param string $direction * @param bool $isScopeGlobal * @param array $expectedJoinCondition * @param string $expectedOrder */ public function testAddValueSortToCollection($direction, $isScopeGlobal, $expectedJoinCondition, $expectedOrder) { $attributeMock = $this->getAttributeMock(); $attributeMock->expects($this->any())->method('isScopeGlobal')->will($this->returnValue($isScopeGlobal)); $selectMock = $this->getMock('\\Magento\\Framework\\DB\\Select', [], [], '', false); $collectionMock = $this->getCollectionMock(); $collectionMock->expects($this->any())->method('getSelect')->will($this->returnValue($selectMock)); foreach ($expectedJoinCondition as $step => $data) { $selectMock->expects($this->at($step))->method('joinLeft')->with($data['requisites'], $data['condition'], [])->will($this->returnSelf()); } $selectMock->expects($this->once())->method('order')->with($expectedOrder); $this->_model->setAttribute($attributeMock); $this->_model->addValueSortToCollection($collectionMock, $direction); }
/** * @covers \Magento\Eav\Model\Entity\Attribute\Source\Boolean::addValueSortToCollection * * @dataProvider addValueSortToCollectionDataProvider * @param string $direction * @param bool $isScopeGlobal * @param array $expectedJoinCondition * @param string $expectedOrder */ public function testAddValueSortToCollection($direction, $isScopeGlobal, $expectedJoinCondition, $expectedOrder) { $attributeMock = $this->getAttributeMock(); $attributeMock->expects($this->any())->method('isScopeGlobal')->will($this->returnValue($isScopeGlobal)); $entity = $this->getMockBuilder(AbstractEntity::class)->disableOriginalConstructor()->setMethods(['getLinkField'])->getMockForAbstractClass(); $entity->expects($this->once())->method('getLinkField')->willReturn('entity_id'); $attributeMock->expects($this->once())->method('getEntity')->willReturn($entity); $selectMock = $this->getMock('\\Magento\\Framework\\DB\\Select', [], [], '', false); $collectionMock = $this->getCollectionMock(); $collectionMock->expects($this->any())->method('getSelect')->will($this->returnValue($selectMock)); foreach ($expectedJoinCondition as $step => $data) { $selectMock->expects($this->at($step))->method('joinLeft')->with($data['requisites'], $data['condition'], [])->will($this->returnSelf()); } $selectMock->expects($this->once())->method('order')->with($expectedOrder); $this->_model->setAttribute($attributeMock); $this->_model->addValueSortToCollection($collectionMock, $direction); }
public function testGetFlatColums() { $abstractAttributeMock = $this->getMock('\\Magento\\Eav\\Model\\Entity\\Attribute\\AbstractAttribute', array('getAttributeCode', '__wakeup'), array(), '', false); $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'); } }