1313 * source code.
1414 */
1515
16+ use Flowpack \ElasticSearch \ContentRepositoryAdaptor \Driver \NodeTypeMappingBuilderInterface ;
17+ use Flowpack \ElasticSearch \ContentRepositoryAdaptor \Driver \QueryInterface ;
18+ use Flowpack \ElasticSearch \ContentRepositoryAdaptor \Driver \Version6 \Mapping \NodeTypeMappingBuilder ;
19+ use Flowpack \ElasticSearch \ContentRepositoryAdaptor \Driver \Version6 \Query \FilteredQuery ;
1620use Flowpack \ElasticSearch \ContentRepositoryAdaptor \ElasticSearchClient ;
1721use Flowpack \ElasticSearch \ContentRepositoryAdaptor \Exception \ConfigurationException ;
1822use Flowpack \ElasticSearch \ContentRepositoryAdaptor \Indexer \NodeIndexer ;
1923use Flowpack \ElasticSearch \ContentRepositoryAdaptor \Service \DimensionsService ;
24+ use Flowpack \ElasticSearch \ContentRepositoryAdaptor \Tests \Functional \TRaits \ContentRepositoryNodeCreationTrait ;
25+ use Flowpack \ElasticSearch \Domain \Model \Mapping ;
2026use Flowpack \ElasticSearch \Exception ;
2127use Flowpack \ElasticSearch \Transfer \Exception \ApiException ;
28+ use Neos \ContentRepository \Domain \Model \NodeInterface ;
2229use Neos \Flow \Tests \FunctionalTestCase ;
30+ use Neos \Utility \Arrays ;
2331
2432class NodeIndexerTest extends FunctionalTestCase
2533{
34+ use ContentRepositoryNodeCreationTrait;
35+
2636 const TESTING_INDEX_PREFIX = 'neoscr_testing ' ;
2737
38+ /**
39+ * @var boolean
40+ */
41+ protected static $ testablePersistenceEnabled = true ;
42+
2843 /**
2944 * @var NodeIndexer
3045 */
@@ -40,12 +55,18 @@ class NodeIndexerTest extends FunctionalTestCase
4055 */
4156 protected $ searchClient ;
4257
58+ /**
59+ * @var NodeTypeMappingBuilder
60+ */
61+ protected $ nodeTypeMappingBuilder ;
62+
4363 public function setUp (): void
4464 {
4565 parent ::setUp ();
4666 $ this ->searchClient = $ this ->objectManager ->get (ElasticSearchClient::class);
4767 $ this ->nodeIndexer = $ this ->objectManager ->get (NodeIndexer::class);
4868 $ this ->dimensionService = $ this ->objectManager ->get (DimensionsService::class);
69+ $ this ->nodeTypeMappingBuilder = $ this ->objectManager ->get (NodeTypeMappingBuilderInterface::class);
4970 }
5071
5172 protected function tearDown (): void
@@ -61,7 +82,7 @@ public function getIndexWithoutDimensionConfigured(): void
6182 {
6283 $ this ->nodeIndexer ->setDimensions ([]);
6384 $ index = $ this ->nodeIndexer ->getIndex ();
64- static ::assertEquals (self ::TESTING_INDEX_PREFIX . '-default-functionaltest ' , $ index ->getName ());
85+ static ::assertEquals (self ::TESTING_INDEX_PREFIX . '-default ' , $ index ->getName ());
6586 }
6687
6788 /**
@@ -78,7 +99,7 @@ public function getIndexForDimensionConfiguration(): void
7899 $ index = $ this ->nodeIndexer ->getIndex ();
79100 $ dimesionHash = $ this ->dimensionService ->hash ($ dimensionValues );
80101
81- static ::assertEquals (self ::TESTING_INDEX_PREFIX . '- ' . $ dimesionHash . ' -functionaltest ' , $ index ->getName ());
102+ static ::assertEquals (self ::TESTING_INDEX_PREFIX . '- ' . $ dimesionHash , $ index ->getName ());
82103 }
83104
84105 /**
@@ -97,6 +118,36 @@ public function updateIndexAlias(): void
97118 $ this ->assertAliasesEquals (self ::TESTING_INDEX_PREFIX , [$ this ->nodeIndexer ->getIndexName ()]);
98119 }
99120
121+ /**
122+ * @test
123+ */
124+ public function indexAndDeleteNode (): void
125+ {
126+ $ this ->setupContentRepository ();
127+ $ this ->createNodesForNodeSearchTest ();
128+ /** @var NodeInterface $testNode */
129+ $ testNode = current ($ this ->siteNode ->getChildNodes ('Neos.NodeTypes:Page ' , 1 ));
130+
131+ $ dimensionValues = ['language ' => ['en_US ' ]];
132+ $ this ->nodeIndexer ->setDimensions ($ dimensionValues );
133+ $ this ->nodeIndexer ->getIndex ()->create ();
134+
135+ $ nodeTypeMappingCollection = $ this ->nodeTypeMappingBuilder ->buildMappingInformation ($ this ->nodeIndexer ->getIndex ());
136+ foreach ($ nodeTypeMappingCollection as $ mapping ) {
137+ /** @var Mapping $mapping */
138+ $ mapping ->apply ();
139+ }
140+
141+ $ this ->nodeIndexer ->indexNode ($ testNode );
142+ $ this ->nodeIndexer ->flush ();
143+ $ this ->assertTrue ($ this ->nodeExistsInIndex ($ testNode ), 'Node was not successfully indexed. ' );
144+
145+ $ this ->nodeIndexer ->removeNode ($ testNode );
146+ $ this ->nodeIndexer ->flush ();
147+ usleep (500000 );
148+ $ this ->assertFalse ($ this ->nodeExistsInIndex ($ testNode ), 'Node still exists after delete ' );
149+ }
150+
100151
101152 /**
102153 * @param string $indexName
@@ -115,4 +166,24 @@ protected function assertAliasesEquals(string $aliasPrefix, array $expectdAliase
115166 $ content = $ this ->searchClient ->request ('GET ' , '/_alias/ ' . $ aliasPrefix . '* ' )->getTreatedContent ();
116167 static ::assertEquals ($ expectdAliases , array_keys ($ content ));
117168 }
169+
170+ /**
171+ * @param NodeInterface $testNode
172+ * @return bool
173+ * @throws ConfigurationException
174+ * @throws Exception
175+ * @throws \Flowpack\ElasticSearch\ContentRepositoryAdaptor\Exception
176+ * @throws \Flowpack\ElasticSearch\ContentRepositoryAdaptor\Exception\QueryBuildingException
177+ * @throws \Neos\Flow\Http\Exception
178+ */
179+ private function nodeExistsInIndex (NodeInterface $ testNode ): bool
180+ {
181+ $ this ->searchClient ->setContextNode ($ this ->siteNode );
182+ /** @var FilteredQuery $query */
183+ $ query = $ this ->objectManager ->get (QueryInterface::class);
184+ $ query ->queryFilter ('term ' , ['neos_node_identifier ' => $ testNode ->getIdentifier ()]);
185+
186+ $ result = $ this ->nodeIndexer ->getIndex ()->request ('GET ' , '/_search ' , [], $ query ->toArray ())->getTreatedContent ();
187+ return count (Arrays::getValueByPath ($ result , 'hits.hits ' )) === 1 ;
188+ }
118189}
0 commit comments