Skip to content

Commit a729054

Browse files
committed
Merge branch '2.1-develop' of github.com:magento/adobe-stock-integration into 1823-cover-getassetbyidinterface-with-integration-test
2 parents ada4bfb + c68f8a2 commit a729054

File tree

3 files changed

+274
-0
lines changed

3 files changed

+274
-0
lines changed
Lines changed: 128 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,128 @@
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(3);
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+
'id' => 2,
70+
'custom_attributes' => [
71+
'id_field_name' => 'id',
72+
'id' => 2,
73+
'thumbnail_240_url' => 'https://test.url/2',
74+
'width' => 120,
75+
'height' => 220,
76+
'comp_url' => 'https://test.url/2',
77+
'category' => [
78+
'id' => 1,
79+
'name' => 'Test',
80+
'link' => null
81+
],
82+
'category_id' => 1
83+
]
84+
],
85+
[
86+
'id' => 3,
87+
'custom_attributes' => [
88+
'id_field_name' => 'id',
89+
'id' => 3,
90+
'thumbnail_240_url' => 'https://test.url/3',
91+
'width' => 130,
92+
'height' => 230,
93+
'comp_url' => 'https://test.url/3',
94+
'category' => [
95+
'id' => 1,
96+
'name' => 'Test',
97+
'link' => null
98+
],
99+
'category_id' => 1
100+
],
101+
]
102+
];
103+
104+
return $stockFilesData;
105+
}
106+
107+
/**
108+
* @param array $stockFiles
109+
* @return Document
110+
*/
111+
private function getStockFileDocument(array $stockFiles): Document
112+
{
113+
$item = new Document();
114+
$item->setId($stockFiles[self::ID]);
115+
116+
$attributes = [];
117+
foreach ($stockFiles[self::CUSTOM_ATTRIBUTES] as $attributeCode => $value) {
118+
$attribute = new AttributeValue();
119+
$attribute->setAttributeCode($attributeCode);
120+
$attribute->setValue($value);
121+
$attributes[$attributeCode] = $attribute;
122+
}
123+
124+
$item->setCustomAttributes($attributes);
125+
126+
return $item;
127+
}
128+
}
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(3, $searchResults->getTotalCount());
67+
$this->assertCount(3, array_values($searchResults->getItems()));
68+
}
69+
}
Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<!--
3+
/**
4+
* Copyright © Magento, Inc. All rights reserved.
5+
* See COPYING.txt for license details.
6+
*/
7+
-->
8+
9+
<tests xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
10+
xsi:noNamespaceSchemaLocation="urn:magento:mftf:Test/etc/testSchema.xsd">
11+
<test name="AdminStandaloneMediaGalleryUnsuccessfulLicensingTest">
12+
<annotations>
13+
<skip>
14+
<issueId value="https://github.com/magento/adobe-stock-integration/issues/1170"/>
15+
</skip>
16+
<features value="AdobeStockMediaGallery"/>
17+
<useCaseId value="https://github.com/magento/adobe-stock-integration/issues/1802"/>
18+
<stories value="User checks if the context menu (three dots) is closed after unsuccessful licensing"/>
19+
<testCaseId value="https://studio.cucumber.io/projects/131313/test-plan/folders/1337102/scenarios/5199875"/>
20+
<title value="User checks if the context menu (three dots) is closed after unsuccessful licensing"/>
21+
<description value="User checks if the context menu (three dots) is closed after unsuccessful licensing"/>
22+
<severity value="CRITICAL"/>
23+
<group value="adobe_stock_media_gallery"/>
24+
</annotations>
25+
<before>
26+
<actionGroup ref="AdminLoginActionGroup" stepKey="loginAsAdmin"/>
27+
<actionGroup ref="AdminAdobeStockSetConfigActionGroup" stepKey="setIncorrectAdobeSecret">
28+
<argument name="privateKey" value=""/>
29+
</actionGroup>
30+
<actionGroup ref="AdminOpenStandaloneMediaGalleryActionGroup" stepKey="openMediaGallery"/>
31+
<actionGroup ref="ResetAdminDataGridToDefaultViewActionGroup" stepKey="resetAdminDataGridToDefaultView"/>
32+
<actionGroup ref="AdminMediaGalleryOpenNewFolderFormActionGroup" stepKey="openNewFolderForm"/>
33+
<actionGroup ref="AdminMediaGalleryCreateNewFolderActionGroup" stepKey="createTestFolder">
34+
<argument name="name" value="testFolder"/>
35+
</actionGroup>
36+
<actionGroup ref="AdminMediaGalleryAssertFolderNameActionGroup" stepKey="assertTestFolderCreated">
37+
<argument name="name" value="testFolder"/>
38+
</actionGroup>
39+
<waitForPageLoad stepKey="waitForGridToLoadAfterTestFolderCreated"/>
40+
<actionGroup ref="AdminEnhancedMediaGallerySearchAdobeStockActionGroup" stepKey="openAdobeStockGrid"/>
41+
<actionGroup ref="AdminSearchImagesOnModalActionGroup" stepKey="searchForUnlicensedImage">
42+
<argument name="query" value="{{AdobeStockUnlicensedImage.id}}"/>
43+
</actionGroup>
44+
<actionGroup ref="AdminAdobeStockExpandImagePreviewActionGroup" stepKey="expandImagePreview"/>
45+
<actionGroup ref="AdminAdobeStockSavePreviewActionGroup" stepKey="saveImagePreview"/>
46+
<actionGroup ref="AdminSaveAdobeStockImagePreviewActionGroup" stepKey="confirmSaveImagePreview"/>
47+
</before>
48+
<after>
49+
<actionGroup ref="AdminOpenStandaloneMediaGalleryActionGroup" stepKey="openMediaGallery"/>
50+
<actionGroup ref="AdminEnhancedMediaGallerySearchAdobeStockActionGroup" stepKey="openAdobeStockGrid"/>
51+
<actionGroup ref="ResetAdminDataGridToDefaultViewActionGroup" stepKey="resetAdobeStockGridToDefaultView"/>
52+
<actionGroup ref="AdminAdobeStockCloseSearchModalActionGroup" stepKey="closeAdobeStockPanel"/>
53+
<actionGroup ref="ResetAdminDataGridToDefaultViewActionGroup" stepKey="resetMediaGalleryGridToDefaultView"/>
54+
<actionGroup ref="AdminMediaGalleryFolderSelectActionGroup" stepKey="selectTestFolderToDelete">
55+
<argument name="name" value="testFolder"/>
56+
</actionGroup>
57+
<actionGroup ref="AdminMediaGalleryFolderDeleteActionGroup" stepKey="deleteTestFolder"/>
58+
<actionGroup ref="AdminMediaGalleryAssertFolderDoesNotExistActionGroup" stepKey="assertTestFolderWasDeleted">
59+
<argument name="name" value="testFolder"/>
60+
</actionGroup>
61+
<actionGroup ref="AdminAdobeStockSetConfigActionGroup" stepKey="setCorrectModuleConfig"/>
62+
<actionGroup ref="AdminLogoutActionGroup" stepKey="logout"/>
63+
</after>
64+
<actionGroup ref="AdminOpenStandaloneMediaGalleryActionGroup" stepKey="openMediaGallery"/>
65+
<actionGroup ref="ResetAdminDataGridToDefaultViewActionGroup" stepKey="resetAdminDataGridToDefaultView"/>
66+
<actionGroup ref="AdminMediaGalleryFolderSelectActionGroup" stepKey="selectTestFolderToOpen">
67+
<argument name="name" value="testFolder"/>
68+
</actionGroup>
69+
<click selector="{{AdminEnhancedMediaGalleryImageActionsSection.openContextMenu}}" stepKey="openContextMenu"/>
70+
<click selector="{{AdminEnhancedMediaGalleryImageActionsSection.license}}" stepKey="licenseImage"/>
71+
<waitForLoadingMaskToDisappear stepKey="waitForLoadingMaskToDisappear"/>
72+
<actionGroup ref="AdminAdobeStockImsPopupSignInFillUserDataActionGroup" stepKey="fillUserCredentials"/>
73+
<actionGroup ref="AdminAdobeStockImsPopupClickSignInActionGroup" stepKey="clickSignInImsPopup"/>
74+
<waitForElementVisible selector="{{AdminMessagesSection.errorMessage}}" stepKey="waitErrorMessage"/>
75+
<actionGroup ref="AssertAdminMediaGalleryContextMenuOpenedActionGroup" stepKey="assertContextMenuIsClosed"/>
76+
</test>
77+
</tests>

0 commit comments

Comments
 (0)