Skip to content

Commit bb4b489

Browse files
committed
Merge branch 'MC-37933' of https://github.com/magento-chaika/magento2ce into TANGO-PR-11-05-2020_24
2 parents f8dd0b5 + 3afc813 commit bb4b489

File tree

3 files changed

+116
-86
lines changed

3 files changed

+116
-86
lines changed

app/code/Magento/DownloadableImportExport/Model/Export/RowCustomizer.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,9 @@ public function prepareData($collection, $productIds): void
8282
->addAttributeToSelect('samples_title');
8383
// set global scope during export
8484
$this->storeManager->setCurrentStore(Store::DEFAULT_STORE_ID);
85-
foreach ($productCollection as $product) {
85+
86+
while ($product = $productCollection->fetchItem()) {
87+
/** @var $product \Magento\Catalog\Api\Data\ProductInterface */
8688
$productLinks = $this->linkRepository->getLinksByProduct($product);
8789
$productSamples = $this->sampleRepository->getSamplesByProduct($product);
8890
$this->downloadableData[$product->getId()] = [];

app/code/Magento/DownloadableImportExport/Test/Unit/Model/Export/Product/RowCustomizerTest.php

Lines changed: 0 additions & 85 deletions
This file was deleted.
Lines changed: 113 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,113 @@
1+
<?php
2+
/**
3+
* Copyright © Magento, Inc. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
declare(strict_types=1);
7+
8+
namespace Magento\DownloadableImportExport\Test\Unit\Model\Export;
9+
10+
use Magento\Catalog\Api\Data\ProductInterface;
11+
use Magento\Catalog\Model\ResourceModel\Product\Collection;
12+
use Magento\Downloadable\Model\LinkRepository;
13+
use Magento\Downloadable\Model\SampleRepository;
14+
use Magento\Framework\TestFramework\Unit\Helper\ObjectManager as ObjectManagerHelper;
15+
use Magento\Store\Model\StoreManagerInterface;
16+
use PHPUnit\Framework\MockObject\MockObject;
17+
use PHPUnit\Framework\TestCase;
18+
19+
/**
20+
* Class RowCustomizerTest for export RowCustomizer
21+
*/
22+
class RowCustomizerTest extends TestCase
23+
{
24+
/**
25+
* @var StoreManagerInterface|MockObject
26+
*/
27+
private $storeManagerMock;
28+
29+
/**
30+
* @var LinkRepository|MockObject
31+
*/
32+
private $linkRepositoryMock;
33+
34+
/**
35+
* @var SampleRepository|MockObject
36+
*/
37+
private $sampleRepositoryMock;
38+
39+
/**
40+
* @var \Magento\DownloadableImportExport\Model\Export\RowCustomizer
41+
*/
42+
private $model;
43+
44+
/**
45+
* Setup
46+
*
47+
* @return void
48+
*/
49+
protected function setUp(): void
50+
{
51+
$this->storeManagerMock = $this->getMockBuilder(StoreManagerInterface::class)
52+
->disableOriginalConstructor()
53+
->getMock();
54+
55+
$this->linkRepositoryMock = $this->getMockBuilder(LinkRepository::class)
56+
->disableOriginalConstructor()
57+
->getMock();
58+
59+
$this->sampleRepositoryMock = $this->getMockBuilder(SampleRepository::class)
60+
->disableOriginalConstructor()
61+
->getMock();
62+
63+
$objectManagerHelper = new ObjectManagerHelper($this);
64+
$this->model = $objectManagerHelper->getObject(
65+
\Magento\DownloadableImportExport\Model\Export\RowCustomizer::class,
66+
[
67+
'storeManager' => $this->storeManagerMock,
68+
'linkRepository' => $this->linkRepositoryMock,
69+
'sampleRepository' => $this->sampleRepositoryMock,
70+
]
71+
);
72+
}
73+
74+
/**
75+
* Test Prepare configurable data for export
76+
*/
77+
public function testPrepareData()
78+
{
79+
$product1 = $this->getMockBuilder(ProductInterface::class)
80+
->disableOriginalConstructor()
81+
->getMock();
82+
$product1->expects($this->any())
83+
->method('getId')
84+
->willReturn(1);
85+
$product2 = $this->getMockBuilder(ProductInterface::class)
86+
->disableOriginalConstructor()
87+
->getMock();
88+
$product2->expects($this->any())
89+
->method('getId')
90+
->willReturn(2);
91+
$collection = $this->getMockBuilder(Collection::class)
92+
->disableOriginalConstructor()
93+
->getMock();
94+
$collection->expects($this->atLeastOnce())
95+
->method('fetchItem')
96+
->willReturn($product1, $product2);
97+
98+
$collection->expects($this->exactly(2))
99+
->method('addAttributeToFilter')
100+
->willReturnSelf();
101+
$collection->expects($this->exactly(2))
102+
->method('addAttributeToSelect')
103+
->willReturnSelf();
104+
$this->linkRepositoryMock->expects($this->exactly(2))
105+
->method('getLinksByProduct')
106+
->will($this->returnValue([]));
107+
$this->sampleRepositoryMock->expects($this->exactly(2))
108+
->method('getSamplesByProduct')
109+
->will($this->returnValue([]));
110+
111+
$this->model->prepareData($collection, []);
112+
}
113+
}

0 commit comments

Comments
 (0)