/** * @magentoDbIsolation enabled */ public function testGetTaxClassId() { $taxClassName = 'Get Me'; $taxClassDataObject = $this->taxClassFactory->create(); $taxClassDataObject->setClassName($taxClassName)->setClassType(TaxClassManagementInterface::TYPE_CUSTOMER); $taxClassId = $this->taxClassRepository->save($taxClassDataObject); /** @var \Magento\Tax\Api\Data\TaxClassKeyInterfaceFactory $taxClassKeyFactory */ $taxClassKeyFactory = $this->objectManager->create('Magento\\Tax\\Api\\Data\\TaxClassKeyInterfaceFactory'); $taxClassKeyTypeId = $taxClassKeyFactory->create(); $this->dataObjectHelper->populateWithArray($taxClassKeyTypeId, [TaxClassKeyInterface::KEY_TYPE => TaxClassKeyInterface::TYPE_ID, TaxClassKeyInterface::KEY_VALUE => $taxClassId], '\\Magento\\Tax\\Api\\Data\\TaxClassKeyInterface'); $this->assertEquals($taxClassId, $this->taxClassManagement->getTaxClassId($taxClassKeyTypeId, TaxClassManagementInterface::TYPE_CUSTOMER)); $taxClassKeyTypeName = $taxClassKeyFactory->create(); $this->dataObjectHelper->populateWithArray($taxClassKeyTypeName, [TaxClassKeyInterface::KEY_TYPE => TaxClassKeyInterface::TYPE_NAME, TaxClassKeyInterface::KEY_VALUE => $taxClassName], '\\Magento\\Tax\\Api\\Data\\TaxClassKeyInterface'); $this->assertEquals($taxClassId, $this->taxClassManagement->getTaxClassId($taxClassKeyTypeId, TaxClassManagementInterface::TYPE_CUSTOMER)); $this->assertNull($this->taxClassManagement->getTaxClassId(null)); $this->assertEquals(null, $this->taxClassManagement->getTaxClassId($taxClassKeyTypeName, TaxClassManagementInterface::TYPE_PRODUCT)); }
public function testGetTaxClassIdByNameType() { $taxClassKey = $this->getMock('\\Magento\\Tax\\Api\\Data\\TaxClassKeyInterface'); $taxClassKey->expects($this->once())->method('getType')->willReturn(\Magento\Tax\Api\Data\TaxClassKeyInterface::TYPE_NAME); $taxClassKey->expects($this->once())->method('getValue')->willReturn('value'); $this->filterBuilder->expects($this->exactly(2))->method('setField')->with($this->logicalOr(\Magento\Tax\Model\ClassModel::KEY_TYPE, \Magento\Tax\Model\ClassModel::KEY_NAME))->willReturnSelf(); $this->filterBuilder->expects($this->exactly(2))->method('setValue')->with($this->logicalOr('PRODUCT', 'value'))->willReturnSelf(); $filter = $this->getMock('\\Magento\\Framework\\Api\\Filter', [], [], '', false); $this->filterBuilder->expects($this->exactly(2))->method('create')->willReturn($filter); $this->searchCriteriaBuilder->expects($this->exactly(2))->method('addFilter')->with([$filter])->willReturnSelf(); $searchCriteria = $this->getMock('\\Magento\\Framework\\Api\\SearchCriteriaInterface'); $this->searchCriteriaBuilder->expects($this->once())->method('create')->willReturn($searchCriteria); $result = $this->getMock('\\Magento\\Tax\\Api\\Data\\TaxRateSearchResultsInterface'); $result->expects($this->once())->method('getItems')->willReturn([]); $this->classRepository->expects($this->once())->method('getList')->with($searchCriteria)->willReturn($result); $this->assertNull($this->model->getTaxClassId($taxClassKey), 'PRODUCT'); }