CalculationTest.php 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. <?php
  2. /**
  3. * Copyright © Magento, Inc. All rights reserved.
  4. * See COPYING.txt for license details.
  5. */
  6. namespace Magento\Tax\Model;
  7. use Magento\Customer\Api\AddressRepositoryInterface;
  8. use Magento\Customer\Api\GroupRepositoryInterface;
  9. use Magento\Customer\Api\CustomerRepositoryInterface;
  10. /**
  11. * Class CalculationTest
  12. *
  13. * @magentoDataFixture Magento/Customer/_files/customer.php
  14. * @magentoDataFixture Magento/Customer/_files/customer_address.php
  15. */
  16. class CalculationTest extends \PHPUnit\Framework\TestCase
  17. {
  18. /**
  19. * @var \Magento\TestFramework\ObjectManager
  20. */
  21. protected $_objectManager;
  22. /**
  23. * @var CustomerRepositoryInterface
  24. */
  25. protected $customerRepository;
  26. /**
  27. * @var AddressRepositoryInterface
  28. */
  29. protected $addressRepository;
  30. /**
  31. * @var GroupRepositoryInterface
  32. */
  33. protected $groupRepository;
  34. const FIXTURE_CUSTOMER_ID = 1;
  35. const FIXTURE_ADDRESS_ID = 1;
  36. /**
  37. * @var \Magento\Tax\Model\Calculation
  38. */
  39. protected $_model;
  40. protected function setUp()
  41. {
  42. /** @var $objectManager \Magento\TestFramework\ObjectManager */
  43. $this->_objectManager = \Magento\TestFramework\Helper\Bootstrap::getObjectManager();
  44. $this->_model = $this->_objectManager->create(\Magento\Tax\Model\Calculation::class);
  45. $this->customerRepository = $this->_objectManager->create(
  46. \Magento\Customer\Api\CustomerRepositoryInterface::class
  47. );
  48. $this->addressRepository = $this->_objectManager->create(
  49. \Magento\Customer\Api\AddressRepositoryInterface::class
  50. );
  51. $this->groupRepository = $this->_objectManager->create(\Magento\Customer\Api\GroupRepositoryInterface::class);
  52. }
  53. public function testDefaultCustomerTaxClass()
  54. {
  55. $defaultCustomerTaxClass = 3;
  56. $this->assertEquals($defaultCustomerTaxClass, $this->_model->getDefaultCustomerTaxClass(null));
  57. }
  58. public function testGetDefaultRateRequest()
  59. {
  60. $customerDataSet = $this->customerRepository->getById(self::FIXTURE_CUSTOMER_ID);
  61. $address = $this->addressRepository->getById(self::FIXTURE_ADDRESS_ID);
  62. $rateRequest = $this->_model->getRateRequest(null, null, null, null, $customerDataSet->getId());
  63. $this->assertNotNull($rateRequest);
  64. $this->assertEquals($address->getCountryId(), $rateRequest->getCountryId());
  65. $this->assertEquals($address->getRegion()->getRegionId(), $rateRequest->getRegionId());
  66. $this->assertEquals($address->getPostcode(), $rateRequest->getPostcode());
  67. $customerTaxClassId = $this->groupRepository->getById($customerDataSet->getGroupId())->getTaxClassId();
  68. $this->assertEquals($customerTaxClassId, $rateRequest->getCustomerClassId());
  69. }
  70. }