Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
ClassTest.php
Go to the documentation of this file.
1 <?php
6 namespace Magento\Tax\Model;
7 
8 class ClassTest extends \PHPUnit\Framework\TestCase
9 {
13  protected $_objectManager;
14 
15  protected function setUp()
16  {
19  }
20 
24  public function testCheckClassCanBeDeletedCustomerClassAssertException()
25  {
27  $model = $this->_objectManager->create(
28  \Magento\Tax\Model\ClassModel::class
29  )->getCollection()->setClassTypeFilter(
31  )->getFirstItem();
32 
33  $this->expectException(\Magento\Framework\Exception\CouldNotDeleteException::class);
34  $model->delete();
35  }
36 
40  public function testCheckClassCanBeDeletedProductClassAssertException()
41  {
43  $model = $this->_objectManager->create(
44  \Magento\Tax\Model\ClassModel::class
45  )->getCollection()->setClassTypeFilter(
47  )->getFirstItem();
48 
49  $this->_objectManager->create(
50  \Magento\Catalog\Model\Product::class
51  )->setTypeId(
52  'simple'
53  )->setAttributeSetId(
54  4
55  )->setName(
56  'Simple Product'
57  )->setSku(
58  uniqid()
59  )->setPrice(
60  10
61  )->setMetaTitle(
62  'meta title'
63  )->setMetaKeyword(
64  'meta keyword'
65  )->setMetaDescription(
66  'meta description'
67  )->setVisibility(
68  \Magento\Catalog\Model\Product\Visibility::VISIBILITY_BOTH
69  )->setStatus(
70  \Magento\Catalog\Model\Product\Attribute\Source\Status::STATUS_ENABLED
71  )->setTaxClassId(
72  $model->getId()
73  )->save();
74 
75  $this->expectException(\Magento\Framework\Exception\CouldNotDeleteException::class);
76  $model->delete();
77  }
78 
83  public function testCheckClassCanBeDeletedPositiveResult($classType)
84  {
86  $model = $this->_objectManager->create(\Magento\Tax\Model\ClassModel::class);
87  $model->setClassName('TaxClass' . uniqid())->setClassType($classType)->isObjectNew(true);
88  $model->save();
89 
90  $model->delete();
91  }
92 
93  public function classesDataProvider()
94  {
95  return [
98  ];
99  }
100 
105  public function testCheckClassCanBeDeletedCustomerClassUsedInTaxRule()
106  {
108  $registry = $this->_objectManager->get(\Magento\Framework\Registry::class);
110  $taxRule = $registry->registry('_fixture/Magento_Tax_Model_Calculation_Rule');
111  $customerClasses = $taxRule->getCustomerTaxClasses();
112 
114  $model = $this->_objectManager->create(\Magento\Tax\Model\ClassModel::class)->load($customerClasses[0]);
115  $this->expectException(\Magento\Framework\Exception\CouldNotDeleteException::class);
116  $this->expectExceptionMessage('You cannot delete this tax class because it is used in' .
117  ' Tax Rules. You have to delete the rules it is used in first.');
118  $model->delete();
119  }
120 
125  public function testCheckClassCanBeDeletedProductClassUsedInTaxRule()
126  {
128  $registry = $this->_objectManager->get(\Magento\Framework\Registry::class);
130  $taxRule = $registry->registry('_fixture/Magento_Tax_Model_Calculation_Rule');
131  $productClasses = $taxRule->getProductTaxClasses();
132 
134  $model = $this->_objectManager->create(\Magento\Tax\Model\ClassModel::class)->load($productClasses[0]);
135  $this->expectException(\Magento\Framework\Exception\CouldNotDeleteException::class);
136  $this->expectExceptionMessage('You cannot delete this tax class because it is used in' .
137  ' Tax Rules. You have to delete the rules it is used in first.');
138  $model->delete();
139  }
140 }
$taxRule
Definition: tax_rule.php:35