|
| 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