7
7
8
8
namespace Magento \MediaContentSynchronizationCms \Test \Integration \Model \Synchronizer ;
9
9
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 ;
10
15
use Magento \Framework \Exception \IntegrationException ;
11
- use Magento \MediaContentApi \ Api \ Data \ ContentIdentityInterface ;
16
+ use Magento \Framework \ Exception \ LocalizedException ;
12
17
use Magento \MediaContentApi \Api \Data \ContentIdentityInterfaceFactory ;
13
18
use Magento \MediaContentApi \Api \GetAssetIdsByContentIdentityInterface ;
14
19
use Magento \MediaContentApi \Api \GetContentByAssetIdsInterface ;
@@ -54,16 +59,29 @@ protected function setUp(): void
54
59
}
55
60
56
61
/**
57
- * @dataProvider filesProvider
58
62
* @magentoDataFixture Magento/MediaContentCms/_files/page_with_asset.php
59
63
* @magentoDataFixture Magento/MediaContentCms/_files/block_with_asset.php
60
64
* @magentoDataFixture Magento/MediaGallery/_files/media_asset.php
61
- * @param ContentIdentityInterface[] $mediaContentIdentities
62
65
* @throws IntegrationException
66
+ * @throws LocalizedException
63
67
*/
64
- public function testExecute (array $ mediaContentIdentities ): void
68
+ public function testExecute (): void
65
69
{
66
70
$ 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
+ ];
67
85
68
86
$ contentIdentities = [];
69
87
foreach ($ mediaContentIdentities as $ mediaContentIdentity ) {
@@ -82,6 +100,7 @@ public function testExecute(array $mediaContentIdentities): void
82
100
83
101
$ entityIds = [];
84
102
foreach ($ contentIdentities as $ contentIdentity ) {
103
+ $ this ->assertEquals ([$ assetId ], $ this ->getAssetIds ->execute ($ contentIdentity ));
85
104
$ entityIds [] = $ contentIdentity ->getEntityId ();
86
105
}
87
106
@@ -94,27 +113,46 @@ public function testExecute(array $mediaContentIdentities): void
94
113
}
95
114
96
115
/**
97
- * Data provider
116
+ * Get fixture block
98
117
*
99
- * @return array
118
+ * @param string $identifier
119
+ * @return BlockInterface
120
+ * @throws LocalizedException
100
121
*/
101
- public function filesProvider ( ): array
122
+ private function getBlock ( string $ identifier ): BlockInterface
102
123
{
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 ());
119
157
}
120
158
}
0 commit comments