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