1515
1616namespace Functional \SearchIndex ;
1717
18+ use Codeception \Test \Unit ;
19+ use Exception ;
1820use OpenSearch \Common \Exceptions \Missing404Exception ;
1921use Pimcore \Bundle \GenericDataIndexBundle \Enum \SearchIndex \ElementType ;
2022use Pimcore \Bundle \GenericDataIndexBundle \Enum \SearchIndex \IndexName ;
2123use Pimcore \Bundle \GenericDataIndexBundle \Enum \SearchIndex \IndexQueueOperation ;
2224use Pimcore \Bundle \GenericDataIndexBundle \Repository \IndexQueueRepository ;
2325use Pimcore \Bundle \GenericDataIndexBundle \Service \SearchIndex \SearchIndexConfigServiceInterface ;
26+ use Pimcore \Bundle \GenericDataIndexBundle \Tests \IndexTester ;
2427use Pimcore \Db ;
28+ use Pimcore \Model \Element \ElementInterface ;
2529use Pimcore \Tests \Support \Util \TestHelper ;
2630
27- class IndexQueueTest extends \ Codeception \ Test \ Unit
31+ class IndexQueueTest extends Unit
2832{
29- /**
30- * @var \Pimcore\Bundle\GenericDataIndexBundle\Tests\IndexTester
31- */
32- protected $ tester ;
33+ protected IndexTester $ tester ;
34+
35+ private SearchIndexConfigServiceInterface $ searchIndexConfigService ;
36+
37+ private const ASSET_INDEX_NAME = 'asset ' ;
38+
39+ private const DOCUMENT_INDEX_NAME = 'document ' ;
3340
3441 protected function _before ()
3542 {
43+ $ this ->searchIndexConfigService = $ this ->tester ->grabService (
44+ SearchIndexConfigServiceInterface::class
45+ );
3646 $ this ->tester ->disableSynchronousProcessing ();
3747 $ this ->tester ->clearQueue ();
3848 }
@@ -94,11 +104,7 @@ public function testIndexQueueRepository(): void
94104
95105 public function testAssetSaveNotEnqueued (): void
96106 {
97- /**
98- * @var SearchIndexConfigServiceInterface $searchIndexConfigService
99- */
100- $ searchIndexConfigService = $ this ->tester ->grabService (SearchIndexConfigServiceInterface::class);
101- $ indexName = $ searchIndexConfigService ->getIndexName ('asset ' );
107+ $ indexName = $ this ->searchIndexConfigService ->getIndexName (self ::ASSET_INDEX_NAME );
102108
103109 $ asset = TestHelper::createImageAsset ();
104110
@@ -112,7 +118,7 @@ public function testAssetSaveProcessQueue(): void
112118 * @var SearchIndexConfigServiceInterface $searchIndexConfigService
113119 */
114120 $ searchIndexConfigService = $ this ->tester ->grabService (SearchIndexConfigServiceInterface::class);
115- $ indexName = $ searchIndexConfigService ->getIndexName (' asset ' );
121+ $ indexName = $ searchIndexConfigService ->getIndexName (self :: ASSET_INDEX_NAME );
116122
117123 $ asset = TestHelper::createImageAsset ();
118124
@@ -123,8 +129,46 @@ public function testAssetSaveProcessQueue(): void
123129 )
124130 );
125131
126- $ this ->tester -> runCommand ( ' messenger: consume' , [ ' --limit ' => 2 ], [ ' pimcore_generic_data_index_queue ' ] );
132+ $ this ->consume ( );
127133 $ result = $ this ->tester ->checkIndexEntry ($ asset ->getId (), $ indexName );
128134 $ this ->assertEquals ($ asset ->getId (), $ result ['_source ' ]['system_fields ' ]['id ' ]);
129135 }
136+
137+ /**
138+ * @throws Exception
139+ */
140+ public function testElementDeleteWithQueue (): void
141+ {
142+ $ this ->checkAndDeleteElement (
143+ TestHelper::createImageAsset (),
144+ $ this ->searchIndexConfigService ->getIndexName (self ::ASSET_INDEX_NAME )
145+ );
146+
147+ $ this ->checkAndDeleteElement (
148+ TestHelper::createEmptyDocument (),
149+ $ this ->searchIndexConfigService ->getIndexName (self ::DOCUMENT_INDEX_NAME )
150+ );
151+
152+ $ object = TestHelper::createEmptyObject ('' , false );
153+ $ this ->checkAndDeleteElement (
154+ $ object ,
155+ $ this ->searchIndexConfigService ->getIndexName ($ object ->getClassName ())
156+ );
157+ }
158+
159+ private function checkAndDeleteElement (ElementInterface $ element , string $ indexName ): void
160+ {
161+ $ this ->consume ();
162+ $ this ->tester ->checkIndexEntry ($ element ->getId (), $ indexName );
163+
164+ $ element ->delete ();
165+ $ this ->consume ();
166+ $ this ->expectException (Missing404Exception::class);
167+ $ this ->tester ->checkIndexEntry ($ element ->getId (), $ indexName );
168+ }
169+
170+ private function consume (): void
171+ {
172+ $ this ->tester ->runCommand ('messenger:consume ' , ['--limit ' =>2 ], ['pimcore_generic_data_index_queue ' ]);
173+ }
130174}
0 commit comments