ProviderTest.php 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  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\Tax\Model\Calculation\Rate;
  8. use Magento\Tax\Model\Rate\Provider;
  9. use Magento\Tax\Model\ResourceModel\Calculation\Rate\Collection;
  10. use Magento\TestFramework\Helper\Bootstrap;
  11. use Magento\Framework\Api\SearchCriteriaBuilder;
  12. /**
  13. * Class ProviderTest provides coverage
  14. * of Tax Rate model options provider.
  15. */
  16. class ProviderTest extends \PHPUnit\Framework\TestCase
  17. {
  18. /**
  19. * Test of requesting tax rates by search criteria.
  20. */
  21. public function testToOptionArray()
  22. {
  23. $objectManager = Bootstrap::getObjectManager();
  24. $optionsCount = 1;
  25. /** @var Collection $collection */
  26. $collection = $objectManager->get(Collection::class);
  27. $expectedResult = [];
  28. /** @var $taxRate Rate */
  29. foreach ($collection as $taxRate) {
  30. $expectedResult[] = ['value' => $taxRate->getId(), 'label' => $taxRate->getCode()];
  31. if (count($expectedResult) >= $optionsCount) {
  32. break;
  33. }
  34. }
  35. /** @var Source $source */
  36. if (empty($expectedResult)) {
  37. $this->fail('Preconditions failed: At least one tax rate should be available.');
  38. }
  39. $provider = $objectManager->get(Provider::class);
  40. /** @var SearchCriteriaBuilder $searchCriteriaBuilder */
  41. $searchCriteriaBuilder = $objectManager->create(SearchCriteriaBuilder::class);
  42. $searchCriteriaBuilder->setPageSize($optionsCount);
  43. $searchCriteriaBuilder->setCurrentPage(1);
  44. $searchCriteria = $searchCriteriaBuilder->create();
  45. $this->assertEquals(
  46. $expectedResult,
  47. $provider->toOptionArray($searchCriteria),
  48. 'Tax rate options are invalid.'
  49. );
  50. }
  51. }