TaxRuleCollectionTest.php 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  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 TaxRuleCollectionTest extends \PHPUnit\Framework\TestCase
  9. {
  10. /**
  11. * @magentoAppIsolation enabled
  12. * @magentoDataFixture Magento/Tax/_files/tax_classes.php
  13. */
  14. public function testCreateTaxRuleCollectionItem()
  15. {
  16. /** @var \Magento\Tax\Model\ResourceModel\Calculation\Rule\Collection $collection */
  17. $collection = Bootstrap::getObjectManager()->get(
  18. \Magento\Tax\Model\ResourceModel\Calculation\Rule\Collection::class
  19. );
  20. $dbTaxRulesQty = $collection->count();
  21. /** @var \Magento\Tax\Model\Calculation\Rule $firstTaxRuleFixture */
  22. $firstTaxRuleFixture = Bootstrap::getObjectManager()->get(\Magento\Framework\Registry::class)
  23. ->registry('_fixture/Magento_Tax_Model_Calculation_Rule');
  24. $expectedFirstTaxRuleId = $firstTaxRuleFixture->getId();
  25. if (($dbTaxRulesQty == 0) || ($collection->getFirstItem()->getId() != $expectedFirstTaxRuleId)) {
  26. $this->fail("Preconditions failed.");
  27. }
  28. /** @var \Magento\Tax\Model\TaxRuleCollection $taxRulesCollection */
  29. $taxRulesCollection = Bootstrap::getObjectManager()
  30. ->create(\Magento\Tax\Model\TaxRuleCollection::class);
  31. $collectionTaxRulesQty = $taxRulesCollection->count();
  32. $this->assertEquals($dbTaxRulesQty, $collectionTaxRulesQty, 'Tax rules quantity is invalid.');
  33. $taxRule = $taxRulesCollection->getFirstItem()->getData();
  34. $expectedTaxRuleData = [
  35. 'tax_calculation_rule_id' => $expectedFirstTaxRuleId,
  36. 'code' => 'Test Rule',
  37. 'priority' => '0',
  38. 'position' => '0',
  39. 'calculate_subtotal' => '0',
  40. 'customer_tax_classes' => $firstTaxRuleFixture->getCustomerTaxClassIds(),
  41. 'product_tax_classes' => $firstTaxRuleFixture->getProductTaxClassIds(),
  42. 'tax_rates' => $firstTaxRuleFixture->getTaxRateIds(),
  43. 'tax_rates_codes' => $firstTaxRuleFixture->getTaxRatesCodes()
  44. ];
  45. $this->assertEquals($expectedTaxRuleData, $taxRule, 'Tax rule data is invalid.');
  46. }
  47. }