19 private $tierPriceValidator;
24 private $productIdLocator;
29 private $searchCriteriaBuilder;
34 private $filterBuilder;
39 private $customerGroupRepository;
44 private $websiteRepository;
49 private $validationResult;
55 private $invalidSkuProcessor;
67 $this->productIdLocator = $this->getMockBuilder(\
Magento\Catalog\Model\ProductIdLocatorInterface::class)
68 ->disableOriginalConstructor()->getMockForAbstractClass();
69 $this->searchCriteriaBuilder = $this->getMockBuilder(\
Magento\Framework\Api\SearchCriteriaBuilder::class)
70 ->disableOriginalConstructor()->getMock();
71 $this->filterBuilder = $this->getMockBuilder(\
Magento\Framework\Api\FilterBuilder::class)
72 ->disableOriginalConstructor()->getMock();
73 $this->customerGroupRepository = $this->getMockBuilder(\
Magento\Customer\Api\GroupRepositoryInterface::class)
74 ->disableOriginalConstructor()->getMockForAbstractClass();
75 $this->websiteRepository = $this->getMockBuilder(\
Magento\
Store\Api\WebsiteRepositoryInterface::class)
76 ->disableOriginalConstructor()->getMockForAbstractClass();
77 $this->validationResult = $this->getMockBuilder(\
Magento\Catalog\Model\
Product\
Price\Validation\Result::class)
78 ->disableOriginalConstructor()->getMock();
79 $this->invalidSkuProcessor = $this
80 ->getMockBuilder(\
Magento\Catalog\Model\
Product\
Price\Validation\InvalidSkuProcessor::class)
81 ->disableOriginalConstructor()->getMock();
82 $this->tierPrice = $this->getMockBuilder(\
Magento\Catalog\Api\Data\TierPriceInterface::class)
83 ->disableOriginalConstructor()->getMockForAbstractClass();
85 $objectManagerHelper = new \Magento\Framework\TestFramework\Unit\Helper\ObjectManager($this);
86 $this->tierPriceValidator = $objectManagerHelper->getObject(
89 'productIdLocator' => $this->productIdLocator,
90 'searchCriteriaBuilder' => $this->searchCriteriaBuilder,
91 'filterBuilder' => $this->filterBuilder,
92 'customerGroupRepository' => $this->customerGroupRepository,
93 'websiteRepository' => $this->websiteRepository,
94 'validationResult' => $this->validationResult,
95 'invalidSkuProcessor' => $this->invalidSkuProcessor
106 private function prepareCustomerGroupRepositoryMock(array $returned)
109 ->getMockBuilder(\
Magento\Framework\Api\Search\SearchCriteriaInterface::class)
110 ->disableOriginalConstructor()->getMock();
111 $filter = $this->getMockBuilder(\
Magento\Framework\Api\AbstractSimpleObject::class)
112 ->disableOriginalConstructor()->getMockForAbstractClass();
113 $this->filterBuilder->expects($this->atLeastOnce())->method(
'setField')->willReturnSelf();
114 $this->filterBuilder->expects($this->atLeastOnce())->method(
'setValue')->willReturnSelf();
115 $this->filterBuilder->expects($this->atLeastOnce())->method(
'create')->willReturn($filter);
116 $this->searchCriteriaBuilder->expects($this->atLeastOnce())->method(
'addFilters')->willReturnSelf();
117 $this->searchCriteriaBuilder->expects($this->atLeastOnce())->method(
'create')->willReturn(
$searchCriteria);
118 $customerGroupSearchResults = $this
119 ->getMockBuilder(\
Magento\Customer\Api\Data\GroupSearchResultsInterface::class)
120 ->disableOriginalConstructor()->getMock();
121 $customerGroupSearchResults->expects($this->once())->method(
'getItems')
122 ->willReturn($returned[
'customerGroupSearchResults_getItems']);
123 $this->customerGroupRepository->expects($this->atLeastOnce())->method(
'getList')
124 ->willReturn($customerGroupSearchResults);
134 private function prepareRetrieveValidationResultMethod($sku, array $returned)
136 $this->tierPrice->expects($this->atLeastOnce())->method(
'getSku')->willReturn($sku);
137 $tierPriceValue = 104;
138 $this->tierPrice->expects($this->atLeastOnce())->method(
'getPrice')->willReturn($tierPriceValue);
139 $this->tierPrice->expects($this->atLeastOnce())->method(
'getPriceType')
140 ->willReturn($returned[
'tierPrice_getPriceType']);
142 $this->tierPrice->expects($this->atLeastOnce())->method(
'getQuantity')->willReturn($qty);
144 $invalidWebsiteId = 4;
145 $this->tierPrice->expects($this->atLeastOnce())->method(
'getWebsiteId')
147 $this->tierPrice->expects($this->atLeastOnce())->method(
'getCustomerGroup')
148 ->willReturn($returned[
'tierPrice_getCustomerGroup']);
150 $this->invalidSkuProcessor->expects($this->atLeastOnce())->method(
'retrieveInvalidSkuList')
151 ->willReturn($skuDiff);
153 $productType = \Magento\Catalog\Model\Product\Type::TYPE_BUNDLE;
157 $this->productIdLocator->expects($this->atLeastOnce())->method(
'retrieveProductIdsBySkus')
158 ->willReturn($idsBySku);
168 $skus = [
'SDFS234234'];
169 $this->invalidSkuProcessor->expects($this->atLeastOnce())
170 ->method(
'filterSkuList')
174 $this->assertEquals(
$skus, $this->tierPriceValidator->validateSkus(
$skus));
188 $existingPrices = [$this->tierPrice];
189 $this->prepareRetrieveValidationResultMethod($sku, $returned);
191 ->disableOriginalConstructor()->getMockForAbstractClass();
192 $this->websiteRepository->expects($this->atLeastOnce())->method(
'getById')->willReturn(
$website);
193 $this->prepareCustomerGroupRepositoryMock($returned);
196 $this->validationResult,
197 $this->tierPriceValidator->retrieveValidationResult(
$prices, $existingPrices)
208 $customerGroupName =
'test_Group';
209 $customerGroup = $this->getMockBuilder(\
Magento\Customer\Api\Data\GroupInterface::class)
210 ->setMethods([
'getCode',
'getId'])
211 ->disableOriginalConstructor()->getMockForAbstractClass();
212 $customerGroup->expects($this->atLeastOnce())->method(
'getCode')->willReturn($customerGroupName);
213 $customerGroupId = 23;
214 $customerGroup->expects($this->atLeastOnce())->method(
'getId')->willReturn($customerGroupId);
219 'tierPrice_getCustomerGroup' => $customerGroupName,
221 'customerGroupSearchResults_getItems' => [$customerGroup]
226 'tierPrice_getCustomerGroup' => $customerGroupName,
228 'customerGroupSearchResults_getItems' => []
242 $customerGroupName =
'test_Group';
244 $existingPrices = [$this->tierPrice];
247 'customerGroupSearchResults_getItems' => [],
248 'tierPrice_getCustomerGroup' => $customerGroupName,
250 $this->prepareRetrieveValidationResultMethod($sku, $returned);
251 $exception = new \Magento\Framework\Exception\NoSuchEntityException();
252 $this->websiteRepository->expects($this->atLeastOnce())->method(
'getById')->willThrowException($exception);
253 $this->prepareCustomerGroupRepositoryMock($returned);
256 $this->validationResult,
257 $this->tierPriceValidator->retrieveValidationResult(
$prices, $existingPrices)
testRetrieveValidationResult(array $returned)
testRetrieveValidationResultWithException()
const PRICE_TYPE_DISCOUNT
foreach($websiteCodes as $websiteCode) $skus
retrieveValidationResultDataProvider()