TaxClassTest.php 2.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. <?php
  2. /**
  3. * Copyright © Magento, Inc. All rights reserved.
  4. * See COPYING.txt for license details.
  5. */
  6. /**
  7. * Test class for \Magento\Tax\Model\Config\TaxClass
  8. */
  9. namespace Magento\Tax\Test\Unit\Model\Config;
  10. use Magento\Framework\TestFramework\Unit\Helper\ObjectManager;
  11. class TaxClassTest extends \PHPUnit\Framework\TestCase
  12. {
  13. /**
  14. * Tests the afterSave method indirectly
  15. */
  16. public function testAfterSave()
  17. {
  18. $attributeMock = $this->getMockBuilder(\Magento\Eav\Model\Entity\Attribute::class)
  19. ->disableOriginalConstructor()
  20. ->setMethods(['loadByCode', 'getId', 'setData', 'save', '__wakeup'])
  21. ->getMock();
  22. $attributeMock
  23. ->expects($this->any())
  24. ->method('getId')
  25. ->will($this->returnValue(1));
  26. $attributeFactoryMock = $this->getMockBuilder(\Magento\Eav\Model\Entity\AttributeFactory::class)
  27. ->disableOriginalConstructor()
  28. ->setMethods(['create', '__wakeup'])
  29. ->getMock();
  30. $attributeFactoryMock
  31. ->expects($this->any())
  32. ->method('create')
  33. ->will($this->returnValue($attributeMock));
  34. $resourceMock = $this->getMockBuilder(\Magento\Framework\Model\ResourceModel\Db\AbstractDb::class)
  35. ->disableOriginalConstructor()
  36. ->setMethods(['beginTransaction', '_construct', 'getIdFieldName', 'addCommitCallback', 'commit',
  37. 'save', '__wakeup', ])
  38. ->getMock();
  39. $resourceMock
  40. ->expects($this->any())
  41. ->method('beginTransaction')
  42. ->will($this->returnValue(null));
  43. $resourceMock
  44. ->expects($this->any())
  45. ->method('getIdFieldName')
  46. ->will($this->returnValue('tax'));
  47. $resourceMock
  48. ->expects($this->any())
  49. ->method('addCommitCallback')
  50. ->will($this->returnValue($resourceMock));
  51. $objectManager = new ObjectManager($this);
  52. $taxClass = $objectManager->getObject(
  53. \Magento\Tax\Model\Config\TaxClass::class,
  54. [
  55. 'resource' => $resourceMock,
  56. 'attributeFactory' => $attributeFactoryMock
  57. ]
  58. );
  59. $taxClass->setDataChanges(true);
  60. // Save the tax config data which will call _aftersave() in tax and update the default product tax class
  61. // No assertion should be thrown
  62. $result = $taxClass->save();
  63. $this->assertNotNull($result);
  64. }
  65. }