public function testGetTaxClass() { $taxClassId = 1; $this->classModelMock->expects($this->exactly(2))->method('getId')->will($this->returnValue($taxClassId)); $this->classModelMock->expects($this->once())->method('load')->with($taxClassId)->will($this->returnValue($this->classModelMock)); $this->assertEquals($this->classModelMock, $this->taxRuleRegistry->retrieve($taxClassId)); }
/** * Create new config object * * @param \Magento\Tax\Model\ClassModel $taxClass * @return \Magento\Tax\Model\TaxClass\Type\TypeInterface * @throws \Magento\Framework\Exception\LocalizedException */ public function create(\Magento\Tax\Model\ClassModel $taxClass) { $taxClassType = $taxClass->getClassType(); if (!array_key_exists($taxClassType, $this->_types)) { throw new \Magento\Framework\Exception\LocalizedException(__('Invalid type of tax class "%1"', $taxClassType)); } return $this->_objectManager->create($this->_types[$taxClassType], ['data' => ['id' => $taxClass->getId()]]); }
/** * Create new config object * * @param \Magento\Tax\Model\ClassModel $taxClass * @return \Magento\Tax\Model\TaxClass\Type\TypeInterface * @throws \Magento\Framework\Model\Exception */ public function create(\Magento\Tax\Model\ClassModel $taxClass) { $taxClassType = $taxClass->getClassType(); if (!array_key_exists($taxClassType, $this->_types)) { throw new \Magento\Framework\Model\Exception(sprintf('Invalid type of tax class "%s"', $taxClassType)); } return $this->_objectManager->create($this->_types[$taxClassType], array('data' => array('id' => $taxClass->getId()))); }
/** * @magentoDbIsolation enabled * @expectedException \Magento\Framework\Exception\InputException * @expectedExceptionMessage Updating classType is not allowed. */ public function testUpdateTaxClassWithChangingClassType() { $taxClassName = 'New Class Name'; $taxClassDataObject = $this->taxClassBuilder->setClassName($taxClassName)->setClassType(TaxClassModel::TAX_CLASS_TYPE_CUSTOMER)->create(); $taxClassId = $this->taxClassService->createTaxClass($taxClassDataObject); $this->assertEquals($taxClassName, $this->taxClassModel->load($taxClassId)->getClassName()); $updatedTaxClassName = 'Updated Class Name'; $taxClassDataObject = $this->taxClassBuilder->setClassName($updatedTaxClassName)->setClassType(TaxClassModel::TAX_CLASS_TYPE_PRODUCT)->create(); $this->taxClassService->updateTaxClass($taxClassId, $taxClassDataObject); }
/** * @magentoDbIsolation enabled * @expectedException \Magento\Framework\Exception\InputException * @expectedExceptionMessage Updating classType is not allowed. */ public function testSaveThrowsExceptionIfTargetTaxClassHasDifferentClassType() { $taxClassName = 'New Class Name'; $taxClassDataObject = $this->taxClassFactory->create(); $taxClassDataObject->setClassName($taxClassName)->setClassType(TaxClassModel::TAX_CLASS_TYPE_CUSTOMER); $taxClassId = $this->taxClassRepository->save($taxClassDataObject); $this->assertEquals($taxClassName, $this->taxClassModel->load($taxClassId)->getClassName()); $updatedTaxClassName = 'Updated Class Name'; $taxClassDataObject = $this->taxClassFactory->create(); $taxClassDataObject->setClassName($updatedTaxClassName)->setClassId($taxClassId)->setClassType(TaxClassModel::TAX_CLASS_TYPE_PRODUCT); $this->taxClassRepository->save($taxClassDataObject); }
/** * Convert tax class model into tax class service data object. * * @param TaxClassModel $taxClassModel * @return TaxClass */ public function createTaxClassData(TaxClassModel $taxClassModel) { return $this->taxClassDataObjectFactory->create()->setClassId($taxClassModel->getId())->setClassName($taxClassModel->getClassName())->setClassType($taxClassModel->getClassType()); }
public function testDeleteModelDeleteSuccess() { $taxClassId = 1; $this->taxClassModelMock->expects($this->once())->method('delete'); $this->assertTrue($this->taxClassService->deleteTaxClass($taxClassId)); }
/** * Convert tax class model into tax class service data object. * * @param TaxClassModel $taxClassModel * @return TaxClass */ public function createTaxClassData(TaxClassModel $taxClassModel) { $this->taxClassBuilder->setClassId($taxClassModel->getId())->setClassName($taxClassModel->getClassName())->setClassType($taxClassModel->getClassType()); return $this->taxClassBuilder->create(); }
/** * Add tax class model to the registry * * @param TaxClassModel $taxClassModel * @return void */ public function registerTaxClass(TaxClassModel $taxClassModel) { $this->taxClassRegistryById[$taxClassModel->getId()] = $taxClassModel; }