Skip to content

Commit ec4eebd

Browse files
Converted DocumentToAssetTest from Integration to Unit Test
1 parent c68f8a2 commit ec4eebd

File tree

2 files changed

+125
-171
lines changed

2 files changed

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

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

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

0 commit comments

Comments
 (0)