Skip to content

Commit 000120d

Browse files
committed
magento/adobe-stock-integration#1724: Support batches processing for synchronization queue messages - added integration test for publisher
1 parent 2fb949e commit 000120d

File tree

1 file changed

+141
-0
lines changed

1 file changed

+141
-0
lines changed
Lines changed: 141 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,141 @@
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\MediaContentSynchronization\Test\Integration\Model;
9+
10+
use Magento\Framework\Exception\IntegrationException;
11+
use Magento\Framework\Exception\LocalizedException;
12+
use Magento\Framework\MessageQueue\ConsumerInterface;
13+
use Magento\MediaContentApi\Api\Data\ContentIdentityInterfaceFactory;
14+
use Magento\MediaContentApi\Api\GetAssetIdsByContentIdentityInterface;
15+
use Magento\MediaContentApi\Api\GetContentByAssetIdsInterface;
16+
use Magento\MediaContentSynchronization\Model\Publish;
17+
use Magento\TestFramework\Helper\Bootstrap;
18+
use PHPUnit\Framework\TestCase;
19+
use Magento\Framework\MessageQueue\ConsumerFactory;
20+
21+
/**
22+
* Test for media content Publisher
23+
*/
24+
class PublisherTest extends TestCase
25+
{
26+
private const TOPIC_MEDIA_CONTENT_SYNCHRONIZATION = 'media.content.synchronization';
27+
28+
/**
29+
* @var ContentIdentityInterfaceFactory
30+
*/
31+
private $contentIdentityFactory;
32+
33+
/**
34+
* @var GetAssetIdsByContentIdentityInterface
35+
*/
36+
private $getAssetIds;
37+
38+
/**
39+
* @var GetContentByAssetIdsInterface
40+
*/
41+
private $getContentIdentities;
42+
43+
/**
44+
* @var Publish
45+
*/
46+
private $publish;
47+
48+
/**
49+
* @var ConsumerInterface
50+
*/
51+
private $consumer;
52+
53+
/**
54+
* @var ConsumerFactory
55+
*/
56+
private $consumerFactory;
57+
58+
protected function setUp(): void
59+
{
60+
$this->contentIdentityFactory = Bootstrap::getObjectManager()->get(ContentIdentityInterfaceFactory::class);
61+
$this->publish = Bootstrap::getObjectManager()->get(Publish::class);
62+
$this->getAssetIds = Bootstrap::getObjectManager()->get(GetAssetIdsByContentIdentityInterface::class);
63+
$this->getContentIdentities = Bootstrap::getObjectManager()->get(GetContentByAssetIdsInterface::class);
64+
$this->consumerFactory = Bootstrap::getObjectManager()->get(ConsumerFactory::class);
65+
$this->consumer = Bootstrap::getObjectManager()->get(ConsumerInterface::class);
66+
}
67+
68+
/**
69+
* @dataProvider filesProvider
70+
* @magentoDataFixture Magento/MediaContentCatalog/_files/category_with_asset.php
71+
* @magentoDataFixture Magento/MediaContentCatalog/_files/product_with_asset.php
72+
* @magentoDataFixture Magento/MediaContentCms/_files/page_with_asset.php
73+
* @magentoDataFixture Magento/MediaContentCms/_files/block_with_asset.php
74+
* @magentoDataFixture Magento/MediaGallery/_files/media_asset.php
75+
* @param array $contentIdentities
76+
* @throws IntegrationException
77+
* @throws LocalizedException
78+
*/
79+
public function testExecute(array $contentIdentities): void
80+
{
81+
// publish message to the queue
82+
$this->publish->execute($contentIdentities);
83+
84+
// run and process message
85+
$consumerName = self::TOPIC_MEDIA_CONTENT_SYNCHRONIZATION;
86+
$this->consumerFactory->get(self::TOPIC_MEDIA_CONTENT_SYNCHRONIZATION);
87+
$this->consumer->process();
88+
89+
// verify synchronized media content
90+
foreach ($contentIdentities as $contentIdentity) {
91+
$assetId = 2020;
92+
$contentIdentityObject = $this->contentIdentityFactory->create($contentIdentity);
93+
var_dump($this->getAssetIds->execute($contentIdentityObject));
94+
$this->assertEquals([$assetId], $this->getAssetIds->execute($contentIdentityObject));
95+
$synchronizedContentIdentities = $this->getContentIdentities->execute([$assetId]);
96+
var_dump(count($synchronizedContentIdentities));
97+
$this->assertEquals(4, count($synchronizedContentIdentities));
98+
99+
$syncedIds = [];
100+
foreach ($synchronizedContentIdentities as $syncedContentIdentity) {
101+
$syncedIds[] = $syncedContentIdentity->getEntityId();
102+
}
103+
$this->assertContains($contentIdentity->getEntityId(), $syncedIds);
104+
}
105+
}
106+
107+
/**
108+
* Data provider
109+
*
110+
* @return array
111+
*/
112+
public function filesProvider(): array
113+
{
114+
return [
115+
[
116+
[
117+
[
118+
'entityType' => 'catalog_category',
119+
'field' => 'description',
120+
'entityId' => 28767
121+
],
122+
[
123+
'entityType' => 'catalog_product',
124+
'field' => 'description',
125+
'entityId' => 1567
126+
],
127+
[
128+
'entityType' => 'cms_page',
129+
'field' => 'content',
130+
'entityId' => 5
131+
],
132+
[
133+
'entityType' => 'cms_block',
134+
'field' => 'content',
135+
'entityId' => 1
136+
]
137+
]
138+
]
139+
];
140+
}
141+
}

0 commit comments

Comments
 (0)