Skip to content

Commit a1df0d6

Browse files
remuslazardaniellienert
authored andcommitted
Implement nodeMoveIsHandledCorrectly test method
This adds the missing implementation for the existing nodeMoveIsHandledCorrectly method. Additionally this also add a new private method to get the node path as stored in ES.
1 parent 15bc258 commit a1df0d6

1 file changed

Lines changed: 38 additions & 1 deletion

File tree

Tests/Functional/Indexer/NodeIndexerTest.php

Lines changed: 38 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,44 @@ public function nodeMoveIsHandledCorrectly(): void
125125
$testNode = $this->setupCrAndIndexTestNode();
126126
self::assertTrue($this->nodeExistsInIndex($testNode), 'Node was not successfully indexed.');
127127

128-
// $testNode->moveInto();
128+
$testNode2 = $this->siteNode->getNode('test-node-2');
129+
130+
// move this node (test-node-1) into test-node-2
131+
$testNode->setProperty('title', 'changed');
132+
$testNode->moveInto($testNode2);
133+
134+
// re-index
135+
$this->nodeIndexer->indexNode($testNode);
136+
$this->nodeIndexer->flush();
137+
sleep(1);
138+
139+
// check if we do have more than one single occurrence (nodeExistsInIndex will check that indirectly)
140+
self::assertTrue($this->nodeExistsInIndex($testNode), 'Node was not successfully indexed.');
141+
142+
// check the node path in es after indexing
143+
$pathInEs = $this->getNeosPathOfNodeInIndex($testNode);
144+
self::assertNotNull($pathInEs, 'Node does not exist after indexing');
145+
self::assertEquals($pathInEs, $testNode->getPath(), 'Wrong node path in elasticsearch after indexing');
146+
}
147+
148+
/**
149+
* Fetch the node path (stored in elasticsearch) of the given node
150+
*/
151+
private function getNeosPathOfNodeInIndex(NodeInterface $node): ?string {
152+
$this->searchClient->setContextNode($this->siteNode);
153+
/** @var FilteredQuery $query */
154+
$query = $this->objectManager->get(QueryInterface::class);
155+
$query->queryFilter('term', ['neos_node_identifier' => $node->getIdentifier()]);
156+
157+
$result = $this->nodeIndexer->getIndex()->request('GET', '/_search', [], $query->toArray())->getTreatedContent();
158+
159+
$firstHit = current(Arrays::getValueByPath($result, 'hits.hits'));
160+
161+
if ($firstHit === false) {
162+
return null;
163+
}
164+
165+
return Arrays::getValueByPath($firstHit, '_source.neos_path');
129166
}
130167

131168
/**

0 commit comments

Comments
 (0)