Skip to content

Commit 93e3b9a

Browse files
authored
Merge pull request #1831 from konarshankar07/integration-test-coverage--task-1786
#1786 :- Replace DocumentToAssetTest unit test with an integration test
2 parents 12442e6 + fa85c2b commit 93e3b9a

File tree

2 files changed

+114
-171
lines changed

2 files changed

+114
-171
lines changed
Lines changed: 114 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,114 @@
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\AdobeStockImage\Test\Integration\Model\Extract;
9+
10+
use Magento\AdobeStockAssetApi\Api\Data\AssetInterface;
11+
use Magento\AdobeStockAssetApi\Api\Data\CategoryInterface;
12+
use Magento\AdobeStockAssetApi\Api\Data\CreatorInterface;
13+
use Magento\AdobeStockImage\Model\Extract\AdobeStockAsset;
14+
use Magento\Framework\Reflection\DataObjectProcessor;
15+
use Magento\Framework\Api\AttributeInterface;
16+
use Magento\Framework\Api\Search\Document;
17+
use Magento\TestFramework\Helper\Bootstrap;
18+
use PHPUnit\Framework\TestCase;
19+
20+
/**
21+
* Test converting a Document from the search result to Adobe Stock asset
22+
*/
23+
class DocumentToAssetTest extends TestCase
24+
{
25+
/**
26+
* @var AdobeStockAsset
27+
*/
28+
private $documentToAsset;
29+
30+
/**
31+
* @var mixed
32+
*/
33+
private $dataObjectProcessor;
34+
35+
/**
36+
* Prepare test objects.
37+
*/
38+
protected function setUp(): void
39+
{
40+
$this->documentToAsset = Bootstrap::getObjectManager()->get(
41+
AdobeStockAsset::class
42+
);
43+
$this->dataObjectProcessor = Bootstrap::getObjectManager()->get(
44+
DataObjectProcessor::class
45+
);
46+
}
47+
48+
/**
49+
* @dataProvider documentProvider
50+
* @param array $data
51+
* @param array $additionalData
52+
*/
53+
public function testConvert(
54+
array $data,
55+
array $additionalData
56+
): void {
57+
$document = $this->getDocument($data);
58+
$asset = $this->documentToAsset->convert($document, $additionalData);
59+
$getCategory = $this->dataObjectProcessor
60+
->buildOutputDataArray($asset->getCategory(), CategoryInterface::class);
61+
$this->assertEquals($data['creator_id'], $asset->getCreator()->getId());
62+
$this->assertEquals($data['creator_name'], $asset->getCreator()->getName());
63+
$this->assertEquals($data['category'], $getCategory);
64+
$this->assertEquals($data['id'], $asset->getId());
65+
$this->assertEquals($data['is_licensed'], $asset->getIsLicensed());
66+
$this->assertEquals($additionalData['media_gallery_id'], $asset->getMediaGalleryId());
67+
$this->assertInstanceOf(CategoryInterface::class, $asset['category']);
68+
$this->assertInstanceOf(CreatorInterface::class, $asset['creator']);
69+
$this->assertInstanceOf(AssetInterface::class, $asset);
70+
}
71+
72+
/**
73+
* @return array
74+
*/
75+
public function documentProvider(): array
76+
{
77+
return [
78+
'case1' => [
79+
'data' => [
80+
'id' => 1,
81+
'category' => [
82+
'id' => 2,
83+
'name' => 'The Category'
84+
],
85+
'creator_name' => 'Creator',
86+
'creator_id' => 3,
87+
'is_licensed' => 1
88+
],
89+
'additionaData' => [
90+
'media_gallery_id' => 5
91+
]
92+
]
93+
];
94+
}
95+
96+
/**
97+
* @param array $attributes
98+
* @return Document
99+
*/
100+
private function getDocument(array $attributes): Document
101+
{
102+
$document = Bootstrap::getObjectManager()->get(Document::class);
103+
$customAttributes = [];
104+
105+
foreach ($attributes as $key => $value) {
106+
$attribute = Bootstrap::getObjectManager()->create(AttributeInterface::class);
107+
$attribute->setAttributeCode($key)->setValue($value);
108+
$customAttributes[] = $attribute;
109+
}
110+
$document->setCustomAttributes($customAttributes);
111+
112+
return $document;
113+
}
114+
}

AdobeStockImage/Test/Unit/Model/Extract/DocumentToAssetTest.php

Lines changed: 0 additions & 171 deletions
This file was deleted.

0 commit comments

Comments
 (0)