コード例 #1
0
 /**
  * @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));
 }
コード例 #2
0
 /**
  * @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);
 }
コード例 #3
0
 /**
  * Test delete Tax class
  */
 public function testDeleteTaxClass()
 {
     $taxClassDataObject = $this->taxClassFactory->create();
     $taxClassDataObject->setClassName(self::SAMPLE_TAX_CLASS_NAME . uniqid())->setClassType(TaxClassManagementInterface::TYPE_CUSTOMER);
     $taxClassId = $this->taxClassRepository->save($taxClassDataObject);
     $this->assertNotNull($taxClassId);
     //Verify by getting the Data\TaxClassInterface
     $serviceInfo = ['rest' => ['resourcePath' => self::RESOURCE_PATH . '/' . $taxClassId, 'httpMethod' => \Magento\Framework\Webapi\Rest\Request::HTTP_METHOD_DELETE], 'soap' => ['service' => self::SERVICE_NAME, 'serviceVersion' => self::SERVICE_VERSION, 'operation' => self::SERVICE_NAME . 'DeleteById']];
     $requestData = ['taxClassId' => $taxClassId];
     $result = $this->_webApiCall($serviceInfo, $requestData);
     $this->assertTrue($result);
     try {
         $this->taxClassRegistry->remove($taxClassId);
         $this->taxClassRepository->get($taxClassId);
         $this->fail("Tax class was not expected to be returned after being deleted.");
     } catch (NoSuchEntityException $e) {
         $this->assertEquals('No such entity with class_id = ' . $taxClassId, $e->getMessage());
     }
 }
コード例 #4
0
 /**
  * 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());
 }