Skip to content

Commit 39e1bc6

Browse files
author
Dmitry Kologrivov
committed
MAGNIMEX-156: Fix unit tests for export advanced prices
1 parent 002ac9d commit 39e1bc6

File tree

1 file changed

+20
-49
lines changed

1 file changed

+20
-49
lines changed

app/code/Magento/AdvancedPricingImportExport/Test/Unit/Model/Export/AdvancedPricingTest.php

Lines changed: 20 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,6 @@ protected function setUp()
129129
'',
130130
false
131131
);
132-
133132
$this->config = $this->getMock(
134133
'Magento\Eav\Model\Config',
135134
['getEntityType'],
@@ -145,15 +144,13 @@ protected function setUp()
145144
false
146145
);
147146
$this->config->expects($this->once())->method('getEntityType')->willReturn($type);
148-
149147
$this->resource = $this->getMock(
150148
'Magento\Framework\App\Resource',
151149
[],
152150
[],
153151
'',
154152
false
155153
);
156-
157154
$this->storeManager = $this->getMock(
158155
'Magento\Store\Model\StoreManager',
159156
[],
@@ -168,7 +165,6 @@ protected function setUp()
168165
'',
169166
false
170167
);
171-
172168
$this->collection = $this->getMock(
173169
'\Magento\Catalog\Model\Resource\Product\CollectionFactory',
174170
[],
@@ -198,7 +194,6 @@ protected function setUp()
198194
'',
199195
false
200196
);
201-
202197
$this->productFactory = $this->getMock(
203198
'Magento\Catalog\Model\Resource\ProductFactory',
204199
[
@@ -209,18 +204,13 @@ protected function setUp()
209204
'',
210205
false
211206
);
212-
213-
$this->attrSetColFactory = $this->getMock(
214-
'Magento\Eav\Model\Resource\Entity\Attribute\Set\CollectionFactory',
215-
[
216-
'create',
217-
'setEntityTypeFilter',
218-
],
207+
$this->_setColFactory = $this->getMock(
208+
'\Magento\Eav\Model\Resource\Entity\Attribute\Set\CollectionFactory',
209+
['create'],
219210
[],
220211
'',
221212
false
222213
);
223-
224214
$this->categoryColFactory = $this->getMock(
225215
'Magento\Catalog\Model\Resource\Category\CollectionFactory',
226216
[
@@ -231,7 +221,6 @@ protected function setUp()
231221
'',
232222
false
233223
);
234-
235224
$this->itemFactory = $this->getMock(
236225
'Magento\CatalogInventory\Model\Resource\Stock\ItemFactory',
237226
[],
@@ -246,7 +235,6 @@ protected function setUp()
246235
'',
247236
false
248237
);
249-
250238
$this->attributeColFactory = $this->getMock(
251239
'Magento\Catalog\Model\Resource\Product\Attribute\CollectionFactory',
252240
[],
@@ -261,7 +249,6 @@ protected function setUp()
261249
'',
262250
false
263251
);
264-
265252
$this->linkTypeProvider = $this->getMock(
266253
'Magento\Catalog\Model\Product\LinkTypeProvider',
267254
[],
@@ -290,7 +277,6 @@ protected function setUp()
290277
'',
291278
false
292279
);
293-
294280
$this->writer = $this->getMock(
295281
'Magento\ImportExport\Model\Export\Adapter\AbstractAdapter',
296282
[
@@ -302,7 +288,6 @@ protected function setUp()
302288
'',
303289
false
304290
);
305-
306291
$constructorMethods = [
307292
'initTypeModels',
308293
'initAttributes',
@@ -311,7 +296,6 @@ protected function setUp()
311296
'initWebsites',
312297
'initCategories'
313298
];
314-
315299
$mockMethods = array_merge($constructorMethods, [
316300
'_customHeadersMapping',
317301
'_prepareEntityCollection',
@@ -331,11 +315,9 @@ protected function setUp()
331315
'',
332316
false
333317
);
334-
335318
foreach ($constructorMethods as $method) {
336319
$this->advancedPricing->expects($this->once())->method($method)->will($this->returnSelf());
337320
}
338-
339321
$this->advancedPricing->__construct(
340322
$this->localeDate,
341323
$this->config,
@@ -345,7 +327,7 @@ protected function setUp()
345327
$this->collection,
346328
$this->exportConfig,
347329
$this->productFactory,
348-
$this->attrSetColFactory,
330+
$this->_setColFactory,
349331
$this->categoryColFactory,
350332
$this->itemFactory,
351333
$this->optionColFactory,
@@ -370,71 +352,62 @@ public function testExportCountZeroBreakInternalCalls()
370352
$this->advancedPricing->expects($this->once())->method('paginateCollection')->with($page, $itemsPerPage);
371353
$this->abstractCollection->expects($this->once())->method('setOrder')->with('has_options', 'asc');
372354
$this->abstractCollection->expects($this->once())->method('setStoreId')->with(Store::DEFAULT_STORE_ID);
373-
374355
$this->abstractCollection->expects($this->once())->method('count')->willReturn(0);
375-
376356
$this->abstractCollection->expects($this->never())->method('getCurPage');
377357
$this->abstractCollection->expects($this->never())->method('getLastPageNumber');
378358
$this->advancedPricing->expects($this->never())->method('_getHeaderColumns');
379359
$this->writer->expects($this->never())->method('setHeaderCols');
380360
$this->writer->expects($this->never())->method('writeRow');
381361
$this->advancedPricing->expects($this->never())->method('getExportData');
382362
$this->advancedPricing->expects($this->never())->method('_customFieldsMapping');
383-
384363
$this->writer->expects($this->once())->method('getContents');
385-
386364
$this->advancedPricing->export();
387365
}
388366

389367
public function testExportCurPageEqualToLastBreakInternalCalls()
390368
{
391369
$curPage = $lastPage = $page = 1;
392370
$itemsPerPage = 10;
393-
394371
$this->advancedPricing->expects($this->once())->method('getWriter')->willReturn($this->writer);
395372
$this->advancedPricing->expects($this->exactly(1))->method('_getEntityCollection')->willReturn($this->abstractCollection);
396373
$this->advancedPricing->expects($this->once())->method('_prepareEntityCollection')->with($this->abstractCollection);
397374
$this->advancedPricing->expects($this->once())->method('getItemsPerPage')->willReturn($itemsPerPage);
398375
$this->advancedPricing->expects($this->once())->method('paginateCollection')->with($page, $itemsPerPage);
399376
$this->abstractCollection->expects($this->once())->method('setOrder')->with('has_options', 'asc');
400377
$this->abstractCollection->expects($this->once())->method('setStoreId')->with(Store::DEFAULT_STORE_ID);
401-
402378
$this->abstractCollection->expects($this->once())->method('count')->willReturn(1);
403-
404379
$this->abstractCollection->expects($this->once())->method('getCurPage')->willReturn($curPage);
405380
$this->abstractCollection->expects($this->once())->method('getLastPageNumber')->willReturn($lastPage);
406381
$headers = ['headers'];
407382
$this->advancedPricing->expects($this->once())->method('_getHeaderColumns')->willReturn($headers);
408383
$this->writer->expects($this->once())->method('setHeaderCols')->with($headers);
409384
$data = [
410-
ImportAdvancedPricing::COL_SKU => 'simpletest',
411-
ImportAdvancedPricing::COL_GROUP_PRICE_WEBSITE => '0',
412-
ImportAdvancedPricing::COL_GROUP_PRICE_CUSTOMER_GROUP => '1',
413-
ImportAdvancedPricing::COL_GROUP_PRICE => '100',
414-
ImportAdvancedPricing::COL_TIER_PRICE_WEBSITE => '0',
415-
ImportAdvancedPricing::COL_TIER_PRICE_CUSTOMER_GROUP => '2',
416-
ImportAdvancedPricing::COL_TIER_PRICE_QTY => '2',
417-
ImportAdvancedPricing::COL_TIER_PRICE => '23',
385+
'sku' => 'simpletest',
386+
'group_price_website' => '0',
387+
'group_price_customer_group' => '1',
388+
'group_price' => '100',
389+
'tier_price_website' => '0',
390+
'tier_price_customer_group' => '2',
391+
'tier_price_qty' => '2',
392+
'tier_price' => '23',
418393
];
419394
$this->advancedPricing->expects($this->once())->method('getExportData')->willReturn($data);
420395
$webSite = 'All Websites [USD]';
421396
$userGroup = 'General';
422397
$this->advancedPricing->expects($this->once())->method('_getWebsiteCode')->willReturn($webSite);
423398
$this->advancedPricing->expects($this->once())->method('_getCustomerGroupById')->willReturn($userGroup);
424399
$exportData = [
425-
ImportAdvancedPricing::COL_SKU => 'simpletest',
426-
ImportAdvancedPricing::COL_GROUP_PRICE_WEBSITE => $webSite,
427-
ImportAdvancedPricing::COL_GROUP_PRICE_CUSTOMER_GROUP => $userGroup,
428-
ImportAdvancedPricing::COL_GROUP_PRICE => '100',
429-
ImportAdvancedPricing::COL_TIER_PRICE_WEBSITE => $webSite,
430-
ImportAdvancedPricing::COL_TIER_PRICE_CUSTOMER_GROUP => $userGroup,
431-
ImportAdvancedPricing::COL_TIER_PRICE_QTY => '2',
432-
ImportAdvancedPricing::COL_TIER_PRICE => '23',
400+
'sku' => 'simpletest',
401+
'group_price_website' => $webSite,
402+
'group_price_customer_group' => $userGroup,
403+
'group_price' => '100',
404+
'tier_price_website' => $webSite,
405+
'tier_price_customer_group' => $userGroup,
406+
'tier_price_qty' => '2',
407+
'tier_price' => '23',
433408
];
434409
$this->writer->expects($this->once())->method('writeRow')->with($exportData);
435-
436410
$this->writer->expects($this->once())->method('getContents');
437-
438411
$this->advancedPricing->export();
439412
}
440413

@@ -455,7 +428,6 @@ protected function getPropertyValue($object, $property)
455428
$reflection = new \ReflectionClass(get_class($object));
456429
$reflectionProperty = $reflection->getProperty($property);
457430
$reflectionProperty->setAccessible(true);
458-
459431
return $reflectionProperty->getValue($object);
460432
}
461433

@@ -472,7 +444,6 @@ protected function setPropertyValue(&$object, $property, $value)
472444
$reflectionProperty = $reflection->getProperty($property);
473445
$reflectionProperty->setAccessible(true);
474446
$reflectionProperty->setValue($object, $value);
475-
476447
return $object;
477448
}
478449
}

0 commit comments

Comments
 (0)