15
15
16
16
namespace Functional \SearchIndex ;
17
17
18
+ use Codeception \Test \Unit ;
19
+ use Exception ;
18
20
use OpenSearch \Common \Exceptions \Missing404Exception ;
19
21
use Pimcore \Bundle \GenericDataIndexBundle \Enum \SearchIndex \ElementType ;
20
22
use Pimcore \Bundle \GenericDataIndexBundle \Enum \SearchIndex \IndexName ;
21
23
use Pimcore \Bundle \GenericDataIndexBundle \Enum \SearchIndex \IndexQueueOperation ;
22
24
use Pimcore \Bundle \GenericDataIndexBundle \Repository \IndexQueueRepository ;
23
25
use Pimcore \Bundle \GenericDataIndexBundle \Service \SearchIndex \SearchIndexConfigServiceInterface ;
26
+ use Pimcore \Bundle \GenericDataIndexBundle \Tests \IndexTester ;
24
27
use Pimcore \Db ;
28
+ use Pimcore \Model \Element \ElementInterface ;
25
29
use Pimcore \Tests \Support \Util \TestHelper ;
26
30
27
- class IndexQueueTest extends \ Codeception \ Test \ Unit
31
+ class IndexQueueTest extends Unit
28
32
{
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 ' ;
33
40
34
41
protected function _before ()
35
42
{
43
+ $ this ->searchIndexConfigService = $ this ->tester ->grabService (
44
+ SearchIndexConfigServiceInterface::class
45
+ );
36
46
$ this ->tester ->disableSynchronousProcessing ();
37
47
$ this ->tester ->clearQueue ();
38
48
}
@@ -94,11 +104,7 @@ public function testIndexQueueRepository(): void
94
104
95
105
public function testAssetSaveNotEnqueued (): void
96
106
{
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 );
102
108
103
109
$ asset = TestHelper::createImageAsset ();
104
110
@@ -112,7 +118,7 @@ public function testAssetSaveProcessQueue(): void
112
118
* @var SearchIndexConfigServiceInterface $searchIndexConfigService
113
119
*/
114
120
$ searchIndexConfigService = $ this ->tester ->grabService (SearchIndexConfigServiceInterface::class);
115
- $ indexName = $ searchIndexConfigService ->getIndexName (' asset ' );
121
+ $ indexName = $ searchIndexConfigService ->getIndexName (self :: ASSET_INDEX_NAME );
116
122
117
123
$ asset = TestHelper::createImageAsset ();
118
124
@@ -123,8 +129,46 @@ public function testAssetSaveProcessQueue(): void
123
129
)
124
130
);
125
131
126
- $ this ->tester -> runCommand ( ' messenger: consume' , [ ' --limit ' => 2 ], [ ' pimcore_generic_data_index_queue ' ] );
132
+ $ this ->consume ( );
127
133
$ result = $ this ->tester ->checkIndexEntry ($ asset ->getId (), $ indexName );
128
134
$ this ->assertEquals ($ asset ->getId (), $ result ['_source ' ]['system_fields ' ]['id ' ]);
129
135
}
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
+ }
130
174
}
0 commit comments