TaxRateCollectionTest.php 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  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\TestFramework\Helper\Bootstrap;
  8. class TaxRateCollectionTest extends \PHPUnit\Framework\TestCase
  9. {
  10. public function testCreateTaxRateCollectionItem()
  11. {
  12. /** @var \Magento\Tax\Model\ResourceModel\Calculation\Rate\Collection $collection */
  13. $collection = Bootstrap::getObjectManager()->get(
  14. \Magento\Tax\Model\ResourceModel\Calculation\Rate\Collection::class
  15. );
  16. $dbTaxRatesQty = $collection->count();
  17. if (($dbTaxRatesQty == 0) || ($collection->getFirstItem()->getId() != 1)) {
  18. $this->fail("Preconditions failed.");
  19. }
  20. /** @var \Magento\Tax\Model\TaxRateCollection $taxRatesCollection */
  21. $taxRatesCollection = Bootstrap::getObjectManager()
  22. ->create(\Magento\Tax\Model\TaxRateCollection::class);
  23. $collectionTaxRatesQty = $taxRatesCollection->count();
  24. $this->assertEquals($dbTaxRatesQty, $collectionTaxRatesQty, 'Tax rates quantity is invalid.');
  25. $taxRate = $taxRatesCollection->getFirstItem()->getData();
  26. $expectedTaxRateData = [
  27. 'code' => 'US-CA-*-Rate 1',
  28. 'tax_calculation_rate_id' => '1',
  29. 'rate' => 8.25,
  30. 'region_name' => 'CA',
  31. 'tax_country_id' => 'US',
  32. 'tax_postcode' => '*',
  33. 'tax_region_id' => '12',
  34. 'titles' => [],
  35. 'zip_is_range' => null,
  36. 'zip_from' => null,
  37. 'zip_to' => null,
  38. ];
  39. $this->assertEquals($expectedTaxRateData, $taxRate, 'Tax rate data is invalid.');
  40. }
  41. }