72 $this->repositoryMock = $this->createMock(\
Magento\Catalog\Model\ProductRepository::class);
73 $this->priceFactoryMock = $this->createPartialMock(
74 \
Magento\Catalog\Api\Data\ProductTierPriceInterfaceFactory::class,
77 $this->storeManagerMock = $this->createMock(\
Magento\
Store\Model\StoreManagerInterface::class);
79 $this->createPartialMock(\
Magento\
Store\Model\Website::class, [
'getId',
'__wakeup']);
80 $this->productMock = $this->createPartialMock(
81 \
Magento\Catalog\Model\Product::class,
82 [
'getData',
'getIdBySku',
'load',
'__wakeup',
'save',
'validate',
'setData']
84 $this->configMock = $this->createMock(\
Magento\Framework\
App\
Config\ScopeConfigInterface::class);
85 $this->priceModifierMock =
86 $this->createMock(\
Magento\Catalog\Model\
Product\PriceModifier::class);
87 $this->repositoryMock->expects($this->any())->method(
'get')->with(
'product_sku')
88 ->will($this->returnValue($this->productMock));
89 $this->groupManagementMock =
90 $this->createMock(\
Magento\Customer\Api\GroupManagementInterface::class);
91 $this->groupRepositoryMock =
92 $this->createMock(\
Magento\Customer\Api\GroupRepositoryInterface::class);
95 $this->repositoryMock,
96 $this->priceFactoryMock,
97 $this->storeManagerMock,
98 $this->priceModifierMock,
100 $this->groupManagementMock,
101 $this->groupRepositoryMock
112 public function testGetList($configValue, $customerGroupId, $groupData, $expected)
114 $group = $this->createMock(\
Magento\Customer\Model\Data\Group::class);
116 $this->groupManagementMock->expects($this->any())->method(
'getAllCustomersGroup')
117 ->will($this->returnValue(
$group));
118 $this->repositoryMock->expects($this->once())->method(
'get')->with(
'product_sku')
119 ->will($this->returnValue($this->productMock));
121 ->expects($this->once())
124 ->will($this->returnValue([$groupData]));
126 ->expects($this->once())
129 ->will($this->returnValue($configValue));
131 $priceMock = $this->createMock(\
Magento\Catalog\Api\Data\ProductTierPriceInterface::class);
132 $priceMock->expects($this->once())
134 ->with($expected[
'value'])
136 $priceMock->expects($this->once())
138 ->with($expected[
'qty'])
140 $this->priceFactoryMock
141 ->expects($this->once())
143 ->will($this->returnValue($priceMock));
145 $this->priceFactoryMock->expects($this->never())->method(
'create');
147 $prices = $this->service->getList(
'product_sku', $customerGroupId);
148 $this->assertCount($expected ? 1 : 0,
$prices);
150 $this->assertEquals($priceMock,
$prices[0]);
163 [
'website_price' => 10,
'price' => 5,
'all_groups' => 1,
'price_qty' => 5],
164 [
'value' => 10,
'qty' => 5],
169 [
'website_price' => 10,
'price' => 5,
'all_groups' => 0,
'cust_group' => 1,
'price_qty' => 5],
170 [
'value' => 5,
'qty' => 5]
175 [
'website_price' => 10,
'price' => 5,
'all_groups' => 0,
'cust_group' => 1,
'price_qty' => 5],
183 $this->storeManagerMock
184 ->expects($this->never())
185 ->method(
'getWebsite');
187 ->expects($this->once())
190 ->will($this->returnValue(0));
191 $this->priceModifierMock->expects($this->once())->method(
'removeTierPrice')->with($this->productMock, 4, 5, 0);
193 $this->assertEquals(
true, $this->service->remove(
'product_sku', 4, 5, 0));
202 $this->repositoryMock->expects($this->once())->method(
'get')
204 $this->priceModifierMock->expects($this->never())->method(
'removeTierPrice');
205 $this->storeManagerMock
206 ->expects($this->never())
207 ->method(
'getWebsite');
208 $this->service->remove(
'product_sku',
null, 10, 5);
213 $this->storeManagerMock
214 ->expects($this->once())
215 ->method(
'getWebsite')
216 ->will($this->returnValue($this->websiteMock));
217 $this->websiteMock->expects($this->once())->method(
'getId')->will($this->returnValue(1));
219 ->expects($this->once())
222 ->will($this->returnValue(1));
223 $this->priceModifierMock->expects($this->once())->method(
'removeTierPrice')->with($this->productMock, 4, 5, 1);
225 $this->assertEquals(
true, $this->service->remove(
'product_sku', 4, 5, 6));
231 ->setMethods([
'getId',
'__wakeup'])
232 ->disableOriginalConstructor()
234 $websiteMock->expects($this->once())->method(
'getId')->will($this->returnValue(0));
236 $this->storeManagerMock->expects($this->once())->method(
'getWebsite')->will($this->returnValue(
$websiteMock));
239 ->expects($this->once())
244 [[
'all_groups' => 0,
'website_id' => 0,
'price_qty' => 4,
'price' => 50]]
248 ->expects($this->once())
251 ->will($this->returnValue(1));
253 $this->productMock->expects($this->once())->method(
'setData')->with(
256 [
'all_groups' => 0,
'website_id' => 0,
'price_qty' => 4,
'price' => 50],
258 'cust_group' => 32000,
260 'website_price' => 100,
266 $this->repositoryMock->expects($this->once())->method(
'save')->with($this->productMock);
267 $group = $this->createMock(\
Magento\Customer\Model\Data\Group::class);
269 $this->groupManagementMock->expects($this->once())->method(
'getAllCustomersGroup')
270 ->will($this->returnValue(
$group));
271 $this->service->add(
'product_sku',
'all', 100, 3);
276 $group = $this->createMock(\
Magento\Customer\Model\Data\Group::class);
277 $group->expects($this->once())->method(
'getId')->will($this->returnValue(1));
278 $this->groupRepositoryMock->expects($this->once())->method(
'getById')->will($this->returnValue(
$group));
280 ->expects($this->once())
285 [[
'cust_group' => 1,
'website_id' => 0,
'price_qty' => 4,
'price' => 50]]
289 ->expects($this->once())
292 ->will($this->returnValue(0));
294 $this->productMock->expects($this->once())->method(
'setData')->with(
297 [
'cust_group' => 1,
'website_id' => 0,
'price_qty' => 4,
'price' => 50],
298 [
'cust_group' => 1,
'website_id' => 0,
'price_qty' => 3,
'price' => 100,
'website_price' => 100]
301 $this->repositoryMock->expects($this->once())->method(
'save')->with($this->productMock);
302 $this->service->add(
'product_sku', 1, 100, 3);
308 ->expects($this->once())
313 [[
'cust_group' => 1,
'website_id' => 0,
'price_qty' => 3,
'price' => 50]]
317 ->expects($this->once())
320 ->will($this->returnValue(0));
322 $this->productMock->expects($this->once())->method(
'setData')->with(
325 [
'cust_group' => 1,
'website_id' => 0,
'price_qty' => 3,
'price' => 100]
328 $this->repositoryMock->expects($this->once())->method(
'save')->with($this->productMock);
329 $this->service->add(
'product_sku', 1, 100, 3);
338 $group = $this->createMock(\
Magento\Customer\Model\Data\Group::class);
339 $group->expects($this->once())->method(
'getId')->will($this->returnValue(1));
341 ->expects($this->once())
344 ->will($this->returnValue([]));
346 $this->groupRepositoryMock->expects($this->once())->method(
'getById')->will($this->returnValue(
$group));
347 $this->productMock->expects($this->once())->method(
'validate')->will(
349 [
'attr1' =>
'',
'attr2' =>
'']
352 $this->repositoryMock->expects($this->never())->method(
'save');
353 $this->service->add(
'product_sku', 1, 100, 2);
361 $group = $this->createMock(\
Magento\Customer\Model\Data\Group::class);
362 $group->expects($this->once())->method(
'getId')->will($this->returnValue(1));
364 ->expects($this->once())
367 ->will($this->returnValue([]));
369 $this->groupRepositoryMock->expects($this->once())->method(
'getById')->will($this->returnValue(
$group));
370 $this->repositoryMock->expects($this->once())->method(
'save')->will($this->throwException(
new \
Exception()));
371 $this->service->add(
'product_sku', 1, 100, 2);
379 $group = $this->createMock(\
Magento\Customer\Model\Data\Group::class);
380 $group->expects($this->once())
384 ->expects($this->once())
387 ->will($this->returnValue([]));
388 $this->groupRepositoryMock->expects($this->once())
391 $this->repositoryMock->expects($this->once())
395 $this->service->add(
'product_sku', 1, 100, 2);
406 $this->service->add(
'product_sku', 1,
$price, $qty);
testAddRethrowsTemporaryStateExceptionIfRecoverableErrorOccurred()
testSetNewPriceWithGlobalPriceScopeAll()
testGetList($configValue, $customerGroupId, $groupData, $expected)
testSetUpdatedPriceWithGlobalPriceScope()
testSuccessDeleteTierPriceFromWebsiteLevel()
testDeleteTierPriceFromNonExistingProduct()
testSuccessDeleteTierPrice()
testSetThrowsExceptionIfCantSave()
testSetThrowsExceptionIfDoesntValidate()
testAddWithInvalidData($price, $qty)
testSetNewPriceWithGlobalPriceScope()