Skip to content

Commit 23ce613

Browse files
committed
Merge remote-tracking branch 'origin/MC-37816' into 2.4-develop-pr45
2 parents ec232e8 + 304e5a1 commit 23ce613

File tree

2 files changed

+86
-1
lines changed

2 files changed

+86
-1
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ 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 ($collection as $product) {
85+
foreach ($productCollection as $product) {
8686
$productLinks = $this->linkRepository->getLinksByProduct($product);
8787
$productSamples = $this->sampleRepository->getSamplesByProduct($product);
8888
$this->downloadableData[$product->getId()] = [];
Lines changed: 85 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,85 @@
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\Product;
9+
10+
use Magento\Catalog\Model\ResourceModel\Product\Collection as ProductCollection;
11+
use Magento\Downloadable\Model\LinkRepository;
12+
use Magento\Downloadable\Model\Product\Type as Type;
13+
use Magento\Downloadable\Model\SampleRepository;
14+
use Magento\DownloadableImportExport\Model\Export\RowCustomizer;
15+
use Magento\Store\Model\Store;
16+
use Magento\Store\Model\StoreManagerInterface;
17+
use PHPUnit\Framework\MockObject\MockObject;
18+
use PHPUnit\Framework\TestCase;
19+
20+
/**
21+
* Class to test Customizes output during export
22+
*/
23+
class RowCustomizerTest extends TestCase
24+
{
25+
/**
26+
* @var LinkRepository|MockObject
27+
*/
28+
private $linkRepository;
29+
30+
/**
31+
* @var SampleRepository|MockObject
32+
*/
33+
private $sampleRepository;
34+
35+
/**
36+
* @var StoreManagerInterface|MockObject
37+
*/
38+
private $storeManager;
39+
40+
/**
41+
* @var RowCustomizer
42+
*/
43+
private $rowCustomizer;
44+
45+
/**
46+
* @inheritdoc
47+
*/
48+
protected function setUp(): void
49+
{
50+
$this->linkRepository = $this->createMock(LinkRepository::class);
51+
$this->sampleRepository = $this->createMock(SampleRepository::class);
52+
$this->storeManager = $this->createMock(StoreManagerInterface::class);
53+
54+
$this->rowCustomizer = new RowCustomizer(
55+
$this->storeManager,
56+
$this->linkRepository,
57+
$this->sampleRepository
58+
);
59+
}
60+
61+
/**
62+
* Test to Prepare downloadable data for export
63+
*/
64+
public function testPrepareData()
65+
{
66+
$productIds = [1, 2, 3];
67+
$collection = $this->createMock(ProductCollection::class);
68+
$collection->expects($this->at(0))
69+
->method('addAttributeToFilter')
70+
->with('entity_id', ['in' => $productIds])
71+
->willReturnSelf();
72+
$collection->expects($this->at(1))
73+
->method('addAttributeToFilter')
74+
->with('type_id', ['eq' => Type::TYPE_DOWNLOADABLE])
75+
->willReturnSelf();
76+
$collection->method('addAttributeToSelect')->willReturnSelf();
77+
$collection->method('getIterator')->willReturn(new \ArrayIterator([]));
78+
79+
$this->storeManager->expects($this->once())
80+
->method('setCurrentStore')
81+
->with(Store::DEFAULT_STORE_ID);
82+
83+
$this->rowCustomizer->prepareData($collection, $productIds);
84+
}
85+
}

0 commit comments

Comments
 (0)