Skip to content

Commit 740340b

Browse files
authored
Merge pull request magento#1834 from magento/2.1-develop
Update 2.1-master from 2.1-develop
2 parents 3e4f056 + 59873a2 commit 740340b

File tree

16 files changed

+598
-236
lines changed

16 files changed

+598
-236
lines changed
Lines changed: 94 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,94 @@
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\AdobeStockAsset\Test\Integration\Model;
9+
10+
use Magento\AdobeStockClient\Model\Client;
11+
use Magento\Framework\Api\AttributeValue;
12+
use Magento\Framework\Api\Search\Document;
13+
use Magento\Framework\Api\Search\SearchCriteriaInterface;
14+
use Magento\Framework\Api\Search\SearchResult;
15+
use Magento\Framework\Api\Search\SearchResultInterface;
16+
17+
class ClientMock extends Client
18+
{
19+
private const ID = 'id';
20+
private const CUSTOM_ATTRIBUTES = 'custom_attributes';
21+
22+
/**
23+
* Search for assets
24+
*
25+
* @param SearchCriteriaInterface $searchCriteria
26+
* @return SearchResultInterface
27+
*/
28+
public function search(SearchCriteriaInterface $searchCriteria): SearchResultInterface
29+
{
30+
$items = [];
31+
foreach ($this->getStockFiles() as $file) {
32+
$items[] = $this->getStockFileDocument($file);
33+
}
34+
35+
$searchResult = new SearchResult();
36+
$searchResult->setSearchCriteria($searchCriteria);
37+
$searchResult->setItems($items);
38+
$searchResult->setTotalCount(1);
39+
40+
return $searchResult;
41+
}
42+
43+
/**
44+
* Get array of stock files data.
45+
*
46+
* @return array
47+
*/
48+
private function getStockFiles(): array
49+
{
50+
$stockFilesData = [
51+
[
52+
'id' => 1,
53+
'custom_attributes' => [
54+
'id_field_name' => 'id',
55+
'id' => 1,
56+
'thumbnail_240_url' => 'https://test.url/1',
57+
'width' => 110,
58+
'height' => 210,
59+
'comp_url' => 'https://test.url/1',
60+
'category' => [
61+
'id' => 1,
62+
'name' => 'Test',
63+
'link' => null
64+
],
65+
'category_id' => 1
66+
]
67+
]
68+
];
69+
70+
return $stockFilesData;
71+
}
72+
73+
/**
74+
* @param array $stockFiles
75+
* @return Document
76+
*/
77+
private function getStockFileDocument(array $stockFiles): Document
78+
{
79+
$item = new Document();
80+
$item->setId($stockFiles[self::ID]);
81+
82+
$attributes = [];
83+
foreach ($stockFiles[self::CUSTOM_ATTRIBUTES] as $attributeCode => $value) {
84+
$attribute = new AttributeValue();
85+
$attribute->setAttributeCode($attributeCode);
86+
$attribute->setValue($value);
87+
$attributes[$attributeCode] = $attribute;
88+
}
89+
90+
$item->setCustomAttributes($attributes);
91+
92+
return $item;
93+
}
94+
}
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
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\AdobeStockAsset\Test\Integration\Model;
9+
10+
use Magento\AdobeStockAssetApi\Api\GetAssetByIdInterface;
11+
use Magento\AdobeStockClientApi\Api\ClientInterface;
12+
use Magento\Framework\Api\Search\DocumentInterface;
13+
use Magento\TestFramework\Helper\Bootstrap;
14+
use PHPUnit\Framework\TestCase;
15+
16+
class GetAssetByIdTest extends TestCase
17+
{
18+
/**
19+
* @var GetAssetByIdInterface
20+
*/
21+
private $getAssetById;
22+
23+
protected function setUp(): void
24+
{
25+
Bootstrap::getObjectManager()->configure([
26+
'preferences' => [
27+
ClientInterface::class => ClientMock::class
28+
]
29+
]);
30+
31+
$this->getAssetById = Bootstrap::getObjectManager()->get(GetAssetByIdInterface::class);
32+
}
33+
34+
public function testExecute(): void
35+
{
36+
/** @var DocumentInterface $searchResults */
37+
$searchResults = $this->getAssetById->execute(1);
38+
39+
$this->assertInstanceOf(DocumentInterface::class, $searchResults);
40+
$this->assertNotEmpty($searchResults);
41+
$this->assertEquals(1, $searchResults->getId());
42+
}
43+
}
Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
<?php
2+
/**
3+
* Copyright © Magento, Inc. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
7+
declare(strict_types=1);
8+
9+
namespace Magento\AdobeStockAsset\Test\Integration\Model;
10+
11+
use Magento\AdobeStockAssetApi\Api\GetAssetListInterface;
12+
use Magento\AdobeStockClientApi\Api\ClientInterface;
13+
use Magento\Framework\Api\FilterBuilder;
14+
use Magento\Framework\Api\Search\SearchCriteriaBuilder;
15+
use Magento\Framework\Api\Search\SearchResultInterface;
16+
use Magento\Framework\Exception\LocalizedException;
17+
use Magento\TestFramework\Helper\Bootstrap;
18+
use PHPUnit\Framework\TestCase;
19+
20+
/**
21+
* Provides integration test for the Adobe Stock GetAssetListInterface functionality.
22+
*/
23+
class GetAssetListTest extends TestCase
24+
{
25+
/**
26+
* @var GetAssetListInterface
27+
*/
28+
private $getAssetList;
29+
30+
/**
31+
* @inheritDoc
32+
*/
33+
protected function setUp(): void
34+
{
35+
Bootstrap::getObjectManager()->configure([
36+
'preferences' => [
37+
ClientInterface::class => ClientMock::class
38+
]
39+
]);
40+
41+
$this->getAssetList = Bootstrap::getObjectManager()->get(GetAssetListInterface::class);
42+
}
43+
44+
/**
45+
* Test 'execute' method of GetAssetListInterface class
46+
*
47+
* @throws LocalizedException
48+
*/
49+
public function testExecute(): void
50+
{
51+
$words = 'test';
52+
53+
$filter = Bootstrap::getObjectManager()->get(FilterBuilder::class)
54+
->setConditionType('fulltext')
55+
->setField('words')
56+
->setValue($words)
57+
->create();
58+
$searchCriteria = Bootstrap::getObjectManager()->get(SearchCriteriaBuilder::class)
59+
->addFilter($filter)
60+
->create();
61+
62+
/** @var SearchResultInterface $searchResults */
63+
$searchResults = $this->getAssetList->execute($searchCriteria);
64+
65+
$this->assertInstanceOf(SearchResultInterface::class, $searchResults);
66+
$this->assertEquals(1, $searchResults->getTotalCount());
67+
$this->assertCount(1, array_values($searchResults->getItems()));
68+
}
69+
}

AdobeStockAsset/etc/acl.xml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,8 @@
1010
<resources>
1111
<resource id="Magento_Backend::admin">
1212
<resource id="Magento_Backend::system">
13-
<resource id="Magento_AdobeStockAsset::adobe_stock_asset" title="Adobe Stock" translate="title" sortOrder="5">
14-
<resource id="Magento_AdobeStockAsset::actions" title="Actions" translate="title">
13+
<resource id="Magento_AdobeStockAsset::adobe_stock_asset" title="Adobe Stock WebAPI" translate="title" sortOrder="5">
14+
<resource id="Magento_AdobeStockAsset::actions" title="WebAPI Actions" translate="title">
1515
<resource id="Magento_AdobeStockAsset::actions_delete" title="Delete" translate="title"/>
1616
<resource id="Magento_AdobeStockAsset::actions_save" title="Save" translate="title"/>
1717
<resource id="Magento_AdobeStockAsset::actions_view" title="View" translate="title"/>
Lines changed: 135 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,135 @@
1+
<?php
2+
/**
3+
* Copyright © Magento, Inc. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
7+
declare(strict_types=1);
8+
9+
namespace Magento\AdobeStockClient\Test\Integration\Model\Client;
10+
11+
use AdobeStock\Api\Client\AdobeStock;
12+
use AdobeStock\Api\Models\StockFile;
13+
use AdobeStock\Api\Response\Files as FilesResponse;
14+
use Magento\AdobeStockClient\Model\Client\Files;
15+
use Magento\AdobeStockClient\Model\ConnectionFactory;
16+
use Magento\Framework\Exception\IntegrationException;
17+
use Magento\TestFramework\Helper\Bootstrap;
18+
use PHPUnit\Framework\MockObject\MockObject;
19+
use PHPUnit\Framework\TestCase;
20+
21+
/**
22+
* Test client files for communication to Adobe Stock API.
23+
*/
24+
class FilesTest extends TestCase
25+
{
26+
/**
27+
* @var Files
28+
*/
29+
private $files;
30+
31+
/**
32+
* @var AdobeStock|MockObject
33+
*/
34+
private $connection;
35+
36+
/**
37+
* Prepare objects.
38+
*/
39+
protected function setUp(): void
40+
{
41+
$this->connection = $this->createMock(AdobeStock::class);
42+
$response = $this->createMock(FilesResponse::class);
43+
$response->expects($this->once())
44+
->method('getFiles')
45+
->willReturn($this->getStockFiles());
46+
$this->connection->expects($this->once())
47+
->method('getFiles')
48+
->willReturn($response);
49+
/** @var ConnectionFactory|MockObject $connectionFactory */
50+
$connectionFactory = $this->createMock(ConnectionFactory::class);
51+
$connectionFactory->expects($this->once())
52+
->method('create')
53+
->willReturn($this->connection);
54+
$this->files = Bootstrap::getObjectManager()->create(
55+
Files::class,
56+
[
57+
'connectionFactory' => $connectionFactory
58+
]
59+
);
60+
}
61+
62+
/**
63+
* Test execute method return data.
64+
*
65+
* @throws IntegrationException
66+
*/
67+
public function testExecute(): void
68+
{
69+
$files = $this->files->execute(['1', '2', '3'], []);
70+
71+
$this->assertIsArray($files);
72+
$this->assertCount(3, $files);
73+
$this->assertEquals(
74+
'https://test.url/2',
75+
$files[1]['comp_url']
76+
);
77+
}
78+
79+
/**
80+
* Result files.
81+
*
82+
* @return StockFile[]
83+
*/
84+
private function getStockFiles(): array
85+
{
86+
$stockFilesData = [
87+
[
88+
'id' => 1,
89+
'comp_url' => 'https://test.url/1',
90+
'thumbnail_240_url' => 'https://test.url/1',
91+
'width' => 110,
92+
'height' => 210,
93+
'some_bool_param' => false,
94+
'some_nullable_param' => null,
95+
'category' => [
96+
'id' => 1,
97+
'name' => 'Test'
98+
]
99+
],
100+
[
101+
'id' => 2,
102+
'comp_url' => 'https://test.url/2',
103+
'thumbnail_240_url' => 'https://test.url/2',
104+
'width' => 120,
105+
'height' => 220,
106+
'some_bool_params' => false,
107+
'some_nullable_param' => 1,
108+
'category' => [
109+
'id' => 1,
110+
'name' => 'Test'
111+
]
112+
],
113+
[
114+
'id' => 3,
115+
'comp_url' => 'https://test.url/3',
116+
'thumbnail_240_url' => 'https://test.url/3',
117+
'width' => 130,
118+
'height' => 230,
119+
'some_bool_params' => true,
120+
'some_nullable_param' => 2,
121+
'category' => [
122+
'id' => 1,
123+
'name' => 'Test'
124+
]
125+
],
126+
];
127+
128+
$stockFiles = [];
129+
foreach ($stockFilesData as $stockFileData) {
130+
$stockFiles[] = new StockFile($stockFileData);
131+
}
132+
133+
return $stockFiles;
134+
}
135+
}

0 commit comments

Comments
 (0)