123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148 |
- <?php
- /**
- * Copyright © Magento, Inc. All rights reserved.
- * See COPYING.txt for license details.
- */
- namespace Magento\Tax\Test\Unit\Model;
- use \Magento\Tax\Model\TaxRateCollection;
-
- class TaxRateCollectionTest extends \PHPUnit\Framework\TestCase
- {
- /**
- * @var TaxRateCollection
- */
- protected $model;
-
- /**
- * @var \PHPUnit_Framework_MockObject_MockObject
- */
- protected $entityFactoryMock;
- /**
- * @var \PHPUnit_Framework_MockObject_MockObject
- */
- protected $filterBuilderMock;
- /**
- * @var \PHPUnit_Framework_MockObject_MockObject
- */
- protected $searchCriteriaBuilderMock;
- /**
- * @var \PHPUnit_Framework_MockObject_MockObject
- */
- protected $sortOrderBuilderMock;
- /**
- * @var \PHPUnit_Framework_MockObject_MockObject
- */
- protected $rateServiceMock;
- /**
- * @var \PHPUnit_Framework_MockObject_MockObject
- */
- protected $rateConverterMock;
- /**
- * @var \PHPUnit_Framework_MockObject_MockObject
- */
- protected $searchCriteriaMock;
- /**
- * @var \PHPUnit_Framework_MockObject_MockObject
- */
- protected $searchResultsMock;
- /**
- * @var \PHPUnit_Framework_MockObject_MockObject
- */
- protected $taxRateMock;
- protected function setUp()
- {
- $this->entityFactoryMock = $this->createMock(\Magento\Framework\Data\Collection\EntityFactory::class);
- $this->filterBuilderMock = $this->createMock(\Magento\Framework\Api\FilterBuilder::class);
- $this->searchCriteriaBuilderMock =
- $this->createMock(\Magento\Framework\Api\SearchCriteriaBuilder::class);
- $this->sortOrderBuilderMock = $this->createMock(\Magento\Framework\Api\SortOrderBuilder::class);
- $this->rateServiceMock = $this->createPartialMock(\Magento\Tax\Api\TaxRateRepositoryInterface::class, [
- 'save',
- 'get',
- 'deleteById',
- 'getList',
- 'delete',
- '__wakeup'
- ]);
- $this->rateConverterMock = $this->createMock(\Magento\Tax\Model\Calculation\Rate\Converter::class);
- $this->searchCriteriaMock = $this->createMock(\Magento\Framework\Api\SearchCriteriaInterface::class);
- $this->searchResultsMock = $this->createMock(\Magento\Tax\Api\Data\TaxRateSearchResultsInterface::class);
- $this->taxRateMock = $this->createMock(\Magento\Tax\Model\Calculation\Rate::class);
- $this->searchCriteriaBuilderMock->expects($this->any())
- ->method('create')
- ->willReturn($this->searchCriteriaMock);
- $this->model = new TaxRateCollection(
- $this->entityFactoryMock,
- $this->filterBuilderMock,
- $this->searchCriteriaBuilderMock,
- $this->sortOrderBuilderMock,
- $this->rateServiceMock,
- $this->rateConverterMock
- );
- }
- public function testLoadData()
- {
- $this->rateServiceMock->expects($this->once())
- ->method('getList')
- ->with($this->searchCriteriaMock)
- ->willReturn($this->searchResultsMock);
- $this->searchResultsMock->expects($this->once())->method('getTotalCount')->willReturn(123);
- $this->searchResultsMock->expects($this->once())->method('getItems')->willReturn([$this->taxRateMock]);
- $this->taxRateMock->expects($this->once())->method('getId')->willReturn(33);
- $this->taxRateMock->expects($this->once())->method('getCode')->willReturn(44);
- $this->taxRateMock->expects($this->once())->method('getTaxCountryId')->willReturn('CountryId');
- $this->taxRateMock->expects($this->once())->method('getTaxRegionId')->willReturn(55);
- $this->taxRateMock->expects($this->once())->method('getRegionName')->willReturn('Region Name');
- $this->taxRateMock->expects($this->once())->method('getTaxPostcode')->willReturn('Post Code');
- $this->taxRateMock->expects($this->once())->method('getRate')->willReturn(1.85);
- $this->rateConverterMock->expects($this->once())
- ->method('createTitleArrayFromServiceObject')
- ->with($this->taxRateMock)
- ->willReturn([]);
- $this->taxRateMock->expects($this->once())->method('getZipTo')->willReturn(null);
- $this->taxRateMock->expects($this->never())->method('getZipFrom');
- $this->model->loadData();
- }
- public function testCreateTaxRateCollectionItem()
- {
- $this->rateServiceMock->expects($this->once())
- ->method('getList')
- ->with($this->searchCriteriaMock)
- ->willReturn($this->searchResultsMock);
- $this->searchResultsMock->expects($this->once())->method('getTotalCount')->willReturn(123);
- $this->searchResultsMock->expects($this->once())->method('getItems')->willReturn([$this->taxRateMock]);
- $this->taxRateMock->expects($this->once())->method('getId')->willReturn(33);
- $this->taxRateMock->expects($this->once())->method('getCode')->willReturn(44);
- $this->taxRateMock->expects($this->once())->method('getTaxCountryId')->willReturn('CountryId');
- $this->taxRateMock->expects($this->once())->method('getTaxRegionId')->willReturn(55);
- $this->taxRateMock->expects($this->once())->method('getRegionName')->willReturn('Region Name');
- $this->taxRateMock->expects($this->once())->method('getTaxPostcode')->willReturn('Post Code');
- $this->taxRateMock->expects($this->once())->method('getRate')->willReturn(1.85);
- $this->rateConverterMock->expects($this->once())
- ->method('createTitleArrayFromServiceObject')
- ->with($this->taxRateMock)
- ->willReturn([]);
- $this->taxRateMock->expects($this->exactly(2))->method('getZipTo')->willReturn(1);
- $this->taxRateMock->expects($this->exactly(2))->method('getZipFrom')->willReturn(200);
- $this->model->loadData();
- }
- }
|