SourceTest.php 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. <?php
  2. /**
  3. * Copyright © Magento, Inc. All rights reserved.
  4. * See COPYING.txt for license details.
  5. */
  6. namespace Magento\Tax\Model\Rate;
  7. use Magento\TestFramework\Helper\Bootstrap;
  8. use Magento\Tax\Model\Rate\Provider;
  9. class SourceTest extends \Magento\TestFramework\Indexer\TestCase
  10. {
  11. public static function setUpBeforeClass()
  12. {
  13. $db = Bootstrap::getInstance()->getBootstrap()
  14. ->getApplication()
  15. ->getDbInstance();
  16. if (!$db->isDbDumpExists()) {
  17. throw new \LogicException('DB dump does not exist.');
  18. }
  19. $db->restoreFromDbDump();
  20. parent::setUpBeforeClass();
  21. }
  22. /**
  23. * @magentoDbIsolation disabled
  24. */
  25. public function testToOptionArray()
  26. {
  27. /** @var \Magento\Tax\Model\ResourceModel\Calculation\Rate\Collection $collection */
  28. $collection = Bootstrap::getObjectManager()->get(
  29. \Magento\Tax\Model\ResourceModel\Calculation\Rate\Collection::class
  30. );
  31. $taxRateProvider = Bootstrap::getObjectManager()->get(Provider::class);
  32. $expectedResult = [];
  33. /** @var $taxRate \Magento\Tax\Model\Calculation\Rate */
  34. foreach ($collection as $taxRate) {
  35. $expectedResult[] = ['value' => $taxRate->getId(), 'label' => $taxRate->getCode()];
  36. if (count($expectedResult) >= $taxRateProvider->getPageSize()) {
  37. break;
  38. }
  39. }
  40. /** @var \Magento\Tax\Model\Rate\Source $source */
  41. if (empty($expectedResult)) {
  42. $this->fail('Preconditions failed: At least one tax rate should be available.');
  43. }
  44. $source = Bootstrap::getObjectManager()->get(\Magento\Tax\Model\Rate\Source::class);
  45. $this->assertEquals(
  46. $expectedResult,
  47. $source->toOptionArray(),
  48. 'Tax rate options are invalid.'
  49. );
  50. }
  51. /**
  52. * teardown
  53. */
  54. public function tearDown()
  55. {
  56. parent::tearDown();
  57. }
  58. }