Skip to content

Commit 4935874

Browse files
🔃 Update 2.1-master from 2.1-develop
Accepted Community Pull Requests:
2 parents 740340b + bfad7fd commit 4935874

File tree

14 files changed

+462
-54
lines changed

14 files changed

+462
-54
lines changed

AdobeStockAsset/Model/Asset.php

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -56,9 +56,11 @@ public function getId(): ?int
5656
/**
5757
* @inheritdoc
5858
*/
59-
public function getCategoryId(): int
59+
public function getCategoryId(): ?int
6060
{
61-
return (int) $this->getData(self::CATEGORY_ID);
61+
$categoryId = $this->getData(self::CATEGORY_ID);
62+
63+
return $categoryId !== null ? (int) $categoryId : null;
6264
}
6365

6466
/**
@@ -112,7 +114,7 @@ public function getCreationDate(): string
112114
/**
113115
* @inheritdoc
114116
*/
115-
public function getExtensionAttributes(): AssetExtensionInterface
117+
public function getExtensionAttributes(): ?AssetExtensionInterface
116118
{
117119
return $this->_getExtensionAttributes();
118120
}

AdobeStockAsset/Model/SaveAsset.php

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -80,11 +80,13 @@ public function execute(AssetInterface $asset): void
8080

8181
$category = $asset->getCategory();
8282
if ($category !== null) {
83-
$category = $this->categoryRepository->save($category);
83+
$categoryId = $category->getId();
84+
if ($categoryId !== null) {
85+
$category = $this->categoryRepository->save($category);
86+
}
87+
$data[self::CATEGORY_ID] = $categoryId;
88+
$data[self::CATEGORY] = $category;
8489
}
85-
$data[self::CATEGORY_ID] = $category->getId();
86-
$data[self::CATEGORY] = $category;
87-
8890
$creator = $asset->getCreator();
8991
if ($creator !== null) {
9092
$creator = $this->creatorRepository->save($creator);

AdobeStockAsset/Test/Api/AssetRepository/DeleteByIdTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ private function verifyAssetDeleted(): void
7373
$e,
7474
$expectedMessage,
7575
'env:Sender',
76-
[1 => self::FIXTURE_ASSET_ID]
76+
['id' => self::FIXTURE_ASSET_ID]
7777
);
7878
} else {
7979
throw $e;

AdobeStockAsset/Test/Api/AssetRepository/GetByIdTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ public function testGetNoSuchEntityException(): void
5858
self::assertEquals(Exception::HTTP_NOT_FOUND, $e->getCode());
5959
} elseif (constant('TESTS_WEB_API_ADAPTER') === self::ADAPTER_SOAP) {
6060
$this->assertInstanceOf('SoapFault', $e);
61-
$this->checkSoapFault($e, $expectedMessage, 'env:Sender', [1 => $notExistedAssetId]);
61+
$this->checkSoapFault($e, $expectedMessage, 'env:Sender', ['id' => $notExistedAssetId]);
6262
} else {
6363
throw $e;
6464
}

AdobeStockAsset/Test/Api/AssetRepository/GetListTest.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
class GetListTest extends WebapiAbstract
2323
{
2424
private const RESOURCE_PATH = '/V1/adobestock/asset/search';
25-
private const SERVICE_NAME = 'adobeStockAssetApiGetAssetListV1';
25+
private const SERVICE_NAME = 'adobeStockAssetApiAssetRepositoryV1';
2626

2727
/**
2828
* Test getting the Adobe Stock image by search criteria.
@@ -74,7 +74,7 @@ public function testGetList(): void
7474
],
7575
];
7676

77-
$response = $this->_webApiCall($serviceInfo, $searchCriteria);
77+
$response = $this->_webApiCall($serviceInfo, $requestData);
7878

7979
$this->assertArrayHasKey('search_criteria', $response);
8080
$this->assertArrayHasKey('total_count', $response);

AdobeStockAsset/Test/Api/SearchAdobeStockTest.php

Lines changed: 21 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -25,18 +25,26 @@ class SearchAdobeStockTest extends WebapiAbstract
2525
private const SERVICE_NAME = 'adobeStockAssetApiGetAssetListV1';
2626
private const REQUEST_NAME = 'search_adobe_stock_content';
2727

28+
/**
29+
* @inheridoc
30+
*/
31+
protected function setUp(): void
32+
{
33+
$this->markTestSkipped("The test requires adobe stock credentials and cannot be currently executed on CICD");
34+
}
35+
2836
/**
2937
* Test get list WEB API method.
3038
*
3139
* @return void
3240
*/
3341
public function testGetList(): void
3442
{
35-
/** @var SearchCriteriaBuilder $searchCriteriaBuilder */
36-
$searchCriteriaBuilder = Bootstrap::getObjectManager()->create(SearchCriteriaBuilder::class);
43+
/** @var SearchCriteriaBuilder $criteriaBuilder */
44+
$criteriaBuilder = Bootstrap::getObjectManager()->create(SearchCriteriaBuilder::class);
3745

38-
$searchCriteriaBuilder->setPageSize(32);
39-
$searchCriteriaBuilder->setCurrentPage(1);
46+
$criteriaBuilder->setPageSize(32);
47+
$criteriaBuilder->setCurrentPage(1);
4048

4149
/** @var FilterBuilder $filterBuilder */
4250
$filterBuilder = Bootstrap::getObjectManager()->create(FilterBuilder::class);
@@ -60,22 +68,22 @@ public function testGetList(): void
6068
->setConditionType('eq')
6169
->create();
6270

63-
/** @var FilterGroupBuilder $filterGroupBuilder */
64-
$filterGroupBuilder = Bootstrap::getObjectManager()->create(FilterGroupBuilder::class);
65-
$wordsFilterGroup = $filterGroupBuilder->setFilters([$wordsFilter])->create();
66-
$contentTypeFilterGroup = $filterGroupBuilder->setFilters([$illustrationFilter, $photoFilter])->create();
67-
$premiumPriceFilterGroup = $filterGroupBuilder->setFilters([$premiumPriceFilter])->create();
71+
/** @var FilterGroupBuilder $groupBuilder */
72+
$groupBuilder = Bootstrap::getObjectManager()->create(FilterGroupBuilder::class);
73+
$wordsFilterGroup = $groupBuilder->setFilters([$wordsFilter])->create();
74+
$contentFilterGroup = $groupBuilder->setFilters([$illustrationFilter, $photoFilter])->create();
75+
$priceFilterGroup = $groupBuilder->setFilters([$premiumPriceFilter])->create();
6876

6977
/** @var SortOrderBuilder $sortOrderBuilder */
7078
$sortOrderBuilder = Bootstrap::getObjectManager()->create(SortOrderBuilder::class);
7179
$sortOrder = $sortOrderBuilder->setField('id')
7280
->setDirection(SortOrder::SORT_DESC)
7381
->create();
7482

75-
$searchCriteria = $searchCriteriaBuilder->create();
83+
$searchCriteria = $criteriaBuilder->create();
7684
$searchCriteria->setSortOrders([$sortOrder]);
7785
$searchCriteria->setRequestName(self::REQUEST_NAME);
78-
$searchCriteria->setFilterGroups([$wordsFilterGroup, $contentTypeFilterGroup, $premiumPriceFilterGroup]);
86+
$searchCriteria->setFilterGroups([$wordsFilterGroup, $contentFilterGroup, $priceFilterGroup]);
7987

8088
$requestData = ['search_criteria' => $searchCriteria->__toArray()];
8189

@@ -86,11 +94,11 @@ public function testGetList(): void
8694
],
8795
'soap' => [
8896
'service' => self::SERVICE_NAME,
89-
'operation' => self::SERVICE_NAME . 'GetList',
97+
'operation' => self::SERVICE_NAME . 'Execute',
9098
],
9199
];
92100

93-
$response = $this->_webApiCall($serviceInfo, $searchCriteria);
101+
$response = $this->_webApiCall($serviceInfo, $requestData);
94102

95103
$this->assertArrayHasKey('search_criteria', $response);
96104
$this->assertArrayHasKey('total_count', $response);

AdobeStockAsset/Test/Integration/Model/SaveAssetTest.php

Lines changed: 86 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
use Magento\AdobeStockAssetApi\Api\CreatorRepositoryInterface;
1414
use Magento\AdobeStockAssetApi\Api\Data\AssetInterface;
1515
use Magento\AdobeStockAssetApi\Api\Data\AssetInterfaceFactory;
16+
use Magento\AdobeStockAssetApi\Api\Data\CategoryInterfaceFactory;
1617
use Magento\AdobeStockAssetApi\Api\SaveAssetInterface;
1718
use Magento\MediaGalleryApi\Api\GetAssetsByPathsInterface;
1819
use Magento\MediaGalleryApi\Api\SaveAssetsInterface;
@@ -35,6 +36,29 @@ class SaveAssetTest extends TestCase
3536
*/
3637
private $saveAsset;
3738

39+
/**
40+
* @return array
41+
*/
42+
public function getAssetData(): array
43+
{
44+
return [
45+
'asset_save' => [
46+
'data' => [
47+
'media_gallery_path' => ['some/path.jpg'],
48+
'category_id' => 42,
49+
'creator_id' => 42,
50+
]
51+
],
52+
'without_category' => [
53+
'data' => [
54+
'media_gallery_path' => ['some/path.jpg'],
55+
'category_id' => null,
56+
'creator_id' => 42,
57+
]
58+
]
59+
];
60+
}
61+
3862
/**
3963
* @inheritdoc
4064
*/
@@ -46,13 +70,17 @@ protected function setUp(): void
4670

4771
/**
4872
* Test save an Adobe Stock asset.
73+
*
74+
* @param array $caseData
75+
*
76+
* @dataProvider getAssetData
4977
* @magentoDataFixture ../../../../app/code/Magento/AdobeStockAsset/Test/_files/media_asset.php
5078
* @magentoDataFixture ../../../../app/code/Magento/AdobeStockAsset/Test/_files/category.php
5179
* @magentoDataFixture ../../../../app/code/Magento/AdobeStockAsset/Test/_files/creator.php
5280
*/
53-
public function testExecute(): void
81+
public function testExecute(array $caseData): void
5482
{
55-
$asset = $this->prepareAsset();
83+
$asset = $this->prepareAsset($caseData);
5684
$this->saveAsset->execute($asset);
5785
$expectedAsset = $this->assetRepository->getById($asset->getId());
5886

@@ -66,35 +94,24 @@ public function testExecute(): void
6694

6795
/**
6896
* Prepare an Adobe Stock asset test object.
97+
*
98+
* @param array $caseData
99+
* @return AssetInterface
100+
* @throws \Magento\Framework\Exception\LocalizedException
69101
*/
70-
public function prepareAsset(): AssetInterface
102+
public function prepareAsset(array $caseData): AssetInterface
71103
{
72-
/** @var GetAssetsByPathsInterface $mediaGetByPath */
73-
$mediaGetByPath = Bootstrap::getObjectManager()->get(GetAssetsByPathsInterface::class);
74-
$mediaAssetId = $mediaGetByPath->execute(['some/path.jpg'])[0]->getId();
75-
76-
/** @var CategoryRepositoryInterface $categoryRepository */
77-
$categoryRepository = Bootstrap::getObjectManager()->get(CategoryRepositoryInterface::class);
78-
$category= $categoryRepository->getById(42);
79-
80-
/** @var CreatorRepositoryInterface $creatorRepository */
81-
$creatorRepository = Bootstrap::getObjectManager()->get(CreatorRepositoryInterface::class);
82-
$creator = $creatorRepository->getById(42);
83-
104+
$assetData['data'] = [
105+
'id' => 1,
106+
'is_licensed' => 1,
107+
];
108+
$assetData['data']['media_gallery_id'] = $this->getMediaAssetId($caseData['media_gallery_path']);
109+
$assetData['data']['category'] = $this->getCategory($caseData['category_id']);
110+
$assetData['data']['creator'] = $this->getCreator($caseData['creator_id']);
84111
/** @var AssetInterfaceFactory $assetFactory */
85112
$assetFactory = Bootstrap::getObjectManager()->get(AssetInterfaceFactory::class);
86113
/** @var AssetInterface $asset */
87-
$asset = $assetFactory->create(
88-
[
89-
'data' => [
90-
'id' => 1,
91-
'is_licensed' => 1,
92-
'media_gallery_id' => $mediaAssetId,
93-
'category' => $category,
94-
'creator' => $creator
95-
]
96-
]
97-
);
114+
$asset = $assetFactory->create($assetData);
98115

99116
return $asset;
100117
}
@@ -109,4 +126,47 @@ private function cleanUpEntries(AssetInterface $asset): void
109126
{
110127
$this->assetRepository->deleteById($asset->getId());
111128
}
129+
130+
/**
131+
* @param $paths
132+
* @return int|null
133+
* @throws \Magento\Framework\Exception\LocalizedException
134+
*/
135+
protected function getMediaAssetId($paths): int
136+
{
137+
/** @var GetAssetsByPathsInterface $mediaGetByPath */
138+
$mediaGetByPath = Bootstrap::getObjectManager()->get(GetAssetsByPathsInterface::class);
139+
$mediaAssetId = $mediaGetByPath->execute($paths)[0]->getId();
140+
141+
return $mediaAssetId;
142+
}
143+
144+
/**
145+
* @param int|null $categoryId
146+
* @return \Magento\AdobeStockAssetApi\Api\Data\CategoryInterface|null
147+
* @throws \Magento\Framework\Exception\NoSuchEntityException
148+
*/
149+
protected function getCategory(?int $categoryId): ?\Magento\AdobeStockAssetApi\Api\Data\CategoryInterface
150+
{
151+
/** @var CategoryRepositoryInterface $categoryRepository */
152+
$categoryRepository = Bootstrap::getObjectManager()->get(CategoryRepositoryInterface::class);
153+
/** @var CategoryInterfaceFactory $categoryRepository */
154+
$categoryFactory = Bootstrap::getObjectManager()->get(CategoryInterfaceFactory::class);
155+
156+
return $categoryId !== null ? $categoryRepository->getById($categoryId) : $categoryFactory->create();
157+
}
158+
159+
/**
160+
* @param int $creatorId
161+
* @return \Magento\AdobeStockAssetApi\Api\Data\CreatorInterface
162+
* @throws \Magento\Framework\Exception\NoSuchEntityException
163+
*/
164+
protected function getCreator(int $creatorId): \Magento\AdobeStockAssetApi\Api\Data\CreatorInterface
165+
{
166+
/** @var CreatorRepositoryInterface $creatorRepository */
167+
$creatorRepository = Bootstrap::getObjectManager()->get(CreatorRepositoryInterface::class);
168+
$creator = $creatorRepository->getById($creatorId);
169+
170+
return $creator;
171+
}
112172
}

AdobeStockAssetApi/Api/Data/AssetInterface.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -75,9 +75,9 @@ public function getCreationDate(): string;
7575
/**
7676
* Retrieve existing extension attributes object or create a new one.
7777
*
78-
* @return \Magento\AdobeStockAssetApi\Api\Data\AssetExtensionInterface
78+
* @return \Magento\AdobeStockAssetApi\Api\Data\AssetExtensionInterface|null
7979
*/
80-
public function getExtensionAttributes(): AssetExtensionInterface;
80+
public function getExtensionAttributes(): ?AssetExtensionInterface;
8181

8282
/**
8383
* Set an extension attributes object.

AdobeStockImage/Test/Api/SearchExecuteTest.php

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,19 @@ class SearchExecuteTest extends WebapiAbstract
2424
private const RESOURCE_PATH = '/V1/adobestock/search';
2525
private const SERVICE_NAME = 'adobeStockImageApiGetImageListV1';
2626

27+
/**
28+
* @inheridoc
29+
*/
30+
protected function setUp(): void
31+
{
32+
$this->markTestSkipped("The test requires adobe stock credentials and cannot be currently executed on CICD");
33+
}
34+
35+
/**
36+
* Test search WEB API method.
37+
*
38+
* @return void
39+
*/
2740
public function testSearchExecute(): void
2841
{
2942
/** @var SearchCriteriaBuilder $searchCriteriaBuilder */
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
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\AdobeStockImage\Test\Integration\Model;
10+
11+
use Magento\Framework\Filesystem\Driver\Https;
12+
13+
/**
14+
* Class DriverMock represents overwritten methods
15+
*/
16+
class HttpsDriverMock extends Https
17+
{
18+
/**
19+
* Retrieve file contents from given path
20+
*
21+
* @param string $path
22+
* @param string|null $flags
23+
* @param resource|null $context
24+
* @return string
25+
*/
26+
public function fileGetContents($path, $flags = null, $context = null)
27+
{
28+
return file_get_contents($path, (bool)$flags, $context);
29+
}
30+
}

0 commit comments

Comments
 (0)