77
88namespace Magento \MediaContentSynchronizationCms \Test \Integration \Model \Synchronizer ;
99
10+ use Magento \Cms \Api \BlockRepositoryInterface ;
11+ use Magento \Cms \Api \Data \BlockInterface ;
12+ use Magento \Cms \Api \Data \PageInterface ;
13+ use Magento \Cms \Api \PageRepositoryInterface ;
14+ use Magento \Framework \Api \SearchCriteriaBuilder ;
1015use Magento \Framework \Exception \IntegrationException ;
11- use Magento \MediaContentApi \ Api \ Data \ ContentIdentityInterface ;
16+ use Magento \Framework \ Exception \ LocalizedException ;
1217use Magento \MediaContentApi \Api \Data \ContentIdentityInterfaceFactory ;
1318use Magento \MediaContentApi \Api \GetAssetIdsByContentIdentityInterface ;
1419use Magento \MediaContentApi \Api \GetContentByAssetIdsInterface ;
@@ -54,16 +59,29 @@ protected function setUp(): void
5459 }
5560
5661 /**
57- * @dataProvider filesProvider
5862 * @magentoDataFixture Magento/MediaContentCms/_files/page_with_asset.php
5963 * @magentoDataFixture Magento/MediaContentCms/_files/block_with_asset.php
6064 * @magentoDataFixture Magento/MediaGallery/_files/media_asset.php
61- * @param ContentIdentityInterface[] $mediaContentIdentities
6265 * @throws IntegrationException
66+ * @throws LocalizedException
6367 */
64- public function testExecute (array $ mediaContentIdentities ): void
68+ public function testExecute (): void
6569 {
6670 $ assetId = 2020 ;
71+ $ pageId = $ this ->getPage ('fixture_page_with_asset ' )->getId ();
72+ $ blockId = $ this ->getBlock ('fixture_block_with_asset ' )->getId ();
73+ $ mediaContentIdentities = [
74+ [
75+ 'entityType ' => 'cms_page ' ,
76+ 'field ' => 'content ' ,
77+ 'entityId ' => $ pageId
78+ ],
79+ [
80+ 'entityType ' => 'cms_block ' ,
81+ 'field ' => 'content ' ,
82+ 'entityId ' => $ blockId
83+ ]
84+ ];
6785
6886 $ contentIdentities = [];
6987 foreach ($ mediaContentIdentities as $ mediaContentIdentity ) {
@@ -82,6 +100,7 @@ public function testExecute(array $mediaContentIdentities): void
82100
83101 $ entityIds = [];
84102 foreach ($ contentIdentities as $ contentIdentity ) {
103+ $ this ->assertEquals ([$ assetId ], $ this ->getAssetIds ->execute ($ contentIdentity ));
85104 $ entityIds [] = $ contentIdentity ->getEntityId ();
86105 }
87106
@@ -94,27 +113,46 @@ public function testExecute(array $mediaContentIdentities): void
94113 }
95114
96115 /**
97- * Data provider
116+ * Get fixture block
98117 *
99- * @return array
118+ * @param string $identifier
119+ * @return BlockInterface
120+ * @throws LocalizedException
100121 */
101- public function filesProvider ( ): array
122+ private function getBlock ( string $ identifier ): BlockInterface
102123 {
103- return [
104- [
105- [
106- [
107- 'entityType ' => 'cms_page ' ,
108- 'field ' => 'content ' ,
109- 'entityId ' => 5
110- ],
111- [
112- 'entityType ' => 'cms_block ' ,
113- 'field ' => 'content ' ,
114- 'entityId ' => 1
115- ]
116- ]
117- ]
118- ];
124+ $ objectManager = Bootstrap::getObjectManager ();
125+
126+ /** @var BlockRepositoryInterface $blockRepository */
127+ $ blockRepository = $ objectManager ->get (BlockRepositoryInterface::class);
128+
129+ /** @var SearchCriteriaBuilder $searchCriteriaBuilder */
130+ $ searchCriteriaBuilder = $ objectManager ->get (SearchCriteriaBuilder::class);
131+ $ searchCriteria = $ searchCriteriaBuilder ->addFilter (BlockInterface::IDENTIFIER , $ identifier )
132+ ->create ();
133+
134+ return current ($ blockRepository ->getList ($ searchCriteria )->getItems ());
135+ }
136+
137+ /**
138+ * Get fixture page
139+ *
140+ * @param string $identifier
141+ * @return PageInterface
142+ * @throws LocalizedException
143+ */
144+ private function getPage (string $ identifier ): PageInterface
145+ {
146+ $ objectManager = Bootstrap::getObjectManager ();
147+
148+ /** @var PageRepositoryInterface $repository */
149+ $ repository = $ objectManager ->get (PageRepositoryInterface::class);
150+
151+ /** @var SearchCriteriaBuilder $searchCriteriaBuilder */
152+ $ searchCriteriaBuilder = $ objectManager ->get (SearchCriteriaBuilder::class);
153+ $ searchCriteria = $ searchCriteriaBuilder ->addFilter (PageInterface::IDENTIFIER , $ identifier )
154+ ->create ();
155+
156+ return current ($ repository ->getList ($ searchCriteria )->getItems ());
119157 }
120158}
0 commit comments