TaxRuleCollectionTest.php 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125
  1. <?php
  2. /**
  3. * Copyright © Magento, Inc. All rights reserved.
  4. * See COPYING.txt for license details.
  5. */
  6. namespace Magento\Tax\Test\Unit\Model;
  7. use Magento\Framework\Api\FilterBuilder;
  8. use Magento\Framework\Api\SearchCriteria;
  9. use Magento\Framework\Api\SearchCriteriaBuilder;
  10. use Magento\Framework\Api\SortOrderBuilder;
  11. use Magento\Framework\Data\Collection\EntityFactory;
  12. use Magento\Tax\Api\Data\TaxRateSearchResultsInterface;
  13. use Magento\Tax\Api\TaxRuleRepositoryInterface;
  14. use Magento\Tax\Model\Calculation\Rule;
  15. use \Magento\Tax\Model\TaxRuleCollection;
  16. use PHPUnit_Framework_MockObject_MockObject as MockObject;
  17. class TaxRuleCollectionTest extends \PHPUnit\Framework\TestCase
  18. {
  19. /**
  20. * @var TaxRuleCollection
  21. */
  22. protected $model;
  23. /**
  24. * @var TaxRuleRepositoryInterface | MockObject
  25. */
  26. protected $ruleServiceMock;
  27. /**
  28. * @var EntityFactory | MockObject
  29. */
  30. protected $entityFactoryMock;
  31. /**
  32. * @var FilterBuilder | MockObject
  33. */
  34. protected $filterBuilderMock;
  35. /**
  36. * @var SearchCriteriaBuilder | MockObject
  37. */
  38. protected $searchCriteriaBuilderMock;
  39. /**
  40. * @var SortOrderBuilder | MockObject
  41. */
  42. protected $sortOrderBuilderMock;
  43. /**
  44. * @var SearchCriteria | MockObject
  45. */
  46. protected $searchCriteriaMock;
  47. /**
  48. * @var TaxRateSearchResultsInterface | MockObject
  49. */
  50. protected $searchResultsMock;
  51. /**
  52. * @var Rule | MockObject
  53. */
  54. protected $taxRuleMock;
  55. protected function setUp()
  56. {
  57. $this->entityFactoryMock = $this->createMock(\Magento\Framework\Data\Collection\EntityFactory::class);
  58. $this->filterBuilderMock = $this->createMock(\Magento\Framework\Api\FilterBuilder::class);
  59. $this->searchCriteriaBuilderMock =
  60. $this->createMock(\Magento\Framework\Api\SearchCriteriaBuilder::class);
  61. $this->sortOrderBuilderMock = $this->createMock(\Magento\Framework\Api\SortOrderBuilder::class);
  62. $this->ruleServiceMock = $this->createMock(\Magento\Tax\Api\TaxRuleRepositoryInterface::class);
  63. $this->searchCriteriaMock = $this->createMock(\Magento\Framework\Api\SearchCriteria::class);
  64. $this->searchResultsMock = $this->createMock(\Magento\Tax\Api\Data\TaxRateSearchResultsInterface::class);
  65. $this->taxRuleMock = $this->getMockBuilder(Rule::class)
  66. ->disableOriginalConstructor()
  67. ->setMethods([
  68. 'getId',
  69. 'getCode',
  70. 'getPriority',
  71. 'getPosition',
  72. 'getCalculateSubtotal',
  73. 'getCustomerTaxClassIds',
  74. 'getProductTaxClassIds',
  75. 'getTaxRateIds',
  76. 'getTaxRatesCodes'
  77. ])
  78. ->getMock();
  79. $this->searchCriteriaBuilderMock->expects($this->any())
  80. ->method('create')
  81. ->willReturn($this->searchCriteriaMock);
  82. $this->model = new TaxRuleCollection(
  83. $this->entityFactoryMock,
  84. $this->filterBuilderMock,
  85. $this->searchCriteriaBuilderMock,
  86. $this->sortOrderBuilderMock,
  87. $this->ruleServiceMock
  88. );
  89. }
  90. public function testLoadData()
  91. {
  92. $this->ruleServiceMock->expects($this->once())
  93. ->method('getList')
  94. ->with($this->searchCriteriaMock)
  95. ->willReturn($this->searchResultsMock);
  96. $this->searchResultsMock->expects($this->once())->method('getTotalCount')->willReturn(568);
  97. $this->searchResultsMock->expects($this->once())->method('getItems')->willReturn([$this->taxRuleMock]);
  98. $this->taxRuleMock->expects($this->once())->method('getId')->willReturn(33);
  99. $this->taxRuleMock->expects($this->once())->method('getCode')->willReturn(44);
  100. $this->taxRuleMock->expects($this->once())->method('getPriority')->willReturn('some priority');
  101. $this->taxRuleMock->expects($this->once())->method('getPosition')->willReturn('position');
  102. $this->taxRuleMock->expects($this->once())->method('getCalculateSubtotal')->willReturn(null);
  103. $this->taxRuleMock->expects($this->once())->method('getCustomerTaxClassIds')->willReturn('Post Code');
  104. $this->taxRuleMock->expects($this->once())->method('getProductTaxClassIds')->willReturn([12]);
  105. $this->taxRuleMock->expects($this->once())->method('getTaxRateIds')->willReturn([66]);
  106. $this->taxRuleMock->expects($this->once())->method('getTaxRatesCodes')->willReturn(['some_code']);
  107. $this->model->loadData();
  108. }
  109. }