Skip to content

Commit ff5ee48

Browse files
committed
TASK: Refactor test node types
1 parent fb87cf4 commit ff5ee48

4 files changed

Lines changed: 62 additions & 34 deletions

File tree

Tests/Functional/BaseElasticsearchContentRepositoryAdapterTest.php

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
use Flowpack\ElasticSearch\ContentRepositoryAdaptor\Command\NodeIndexCommandController;
1717
use Flowpack\ElasticSearch\ContentRepositoryAdaptor\Eel\ElasticSearchQueryBuilder;
1818
use Flowpack\ElasticSearch\ContentRepositoryAdaptor\ElasticSearchClient;
19+
use Neos\ContentRepository\Domain\Service\ContextFactory;
1920
use Neos\Flow\Tests\FunctionalTestCase;
2021

2122
abstract class BaseElasticsearchContentRepositoryAdapterTest extends FunctionalTestCase
@@ -51,7 +52,9 @@ public function tearDown(): void
5152
{
5253
parent::tearDown();
5354

54-
$this->inject($this->contextFactory, 'contextInstances', []);
55+
if (isset($this->contextFactory) && $this->contextFactory instanceof ContextFactory) {
56+
$this->inject($this->contextFactory, 'contextInstances', []);
57+
}
5558

5659
if (!$this->isIndexInitialized()) {
5760
// clean up any existing indices

Tests/Functional/Eel/ElasticSearchQueryTest.php

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ public function elasticSearchQueryBuilderStartsClean(): void
4444
/** @var ElasticSearchQueryBuilder $query */
4545
$query = $this->objectManager->get(ElasticSearchQueryBuilder::class);
4646
$cleanRequestArray = $query->getRequest()->toArray();
47-
$query->nodeType('Neos.NodeTypes:Page');
47+
$query->nodeType('Flowpack.ElasticSearch.ContentRepositoryAdaptor:Document');
4848

4949
$query2 = $this->objectManager->get(ElasticSearchQueryBuilder::class);
5050

@@ -66,7 +66,7 @@ public function fullTextSearchReturnsTheDocumentNode(): void
6666

6767
/** @var NodeInterface $node */
6868
$node = $result->current();
69-
static::assertEquals('Neos.NodeTypes:Page', $node->getNodeType()->getName());
69+
static::assertEquals('Flowpack.ElasticSearch.ContentRepositoryAdaptor:Document', $node->getNodeType()->getName());
7070
static::assertEquals('test-node-1', $node->getName());
7171
}
7272

@@ -97,7 +97,7 @@ public function filterByNodeType(): void
9797
{
9898
$resultCount = $this->getQueryBuilder()
9999
->log($this->getLogMessagePrefix(__METHOD__))
100-
->nodeType('Neos.NodeTypes:Page')
100+
->nodeType('Flowpack.ElasticSearch.ContentRepositoryAdaptor:Document')
101101
->count();
102102
static::assertEquals(4, $resultCount);
103103
}
@@ -138,7 +138,7 @@ public function limitDoesNotImpactCount(): void
138138
{
139139
$query = $this->getQueryBuilder()
140140
->log($this->getLogMessagePrefix(__METHOD__))
141-
->nodeType('Neos.NodeTypes:Page')
141+
->nodeType('Flowpack.ElasticSearch.ContentRepositoryAdaptor:Document')
142142
->limit(1);
143143

144144
$resultCount = $query->count();
@@ -240,7 +240,7 @@ public function nodesWillBeSortedDesc(): void
240240
{
241241
$result = $this->getQueryBuilder()
242242
->log($this->getLogMessagePrefix(__METHOD__))
243-
->nodeType('Neos.NodeTypes:Page')
243+
->nodeType('Flowpack.ElasticSearch.ContentRepositoryAdaptor:Document')
244244
->sortDesc('title')
245245
->execute();
246246

@@ -263,7 +263,7 @@ public function nodesWillBeSortedAsc(): void
263263
{
264264
$result = $this->getQueryBuilder()
265265
->log($this->getLogMessagePrefix(__METHOD__))
266-
->nodeType('Neos.NodeTypes:Page')
266+
->nodeType('Flowpack.ElasticSearch.ContentRepositoryAdaptor:Document')
267267
->sortAsc('title')
268268
->execute();
269269
/** @var ElasticSearchQueryResult $result */
@@ -280,7 +280,7 @@ public function sortValuesAreReturned(): void
280280
{
281281
$result = $this->getQueryBuilder()
282282
->log($this->getLogMessagePrefix(__METHOD__))
283-
->nodeType('Neos.NodeTypes:Page')
283+
->nodeType('Flowpack.ElasticSearch.ContentRepositoryAdaptor:Document')
284284
->sortAsc('title')
285285
->execute();
286286

@@ -300,7 +300,7 @@ public function cacheLifetimeIsCalculatedCorrectly(): void
300300
{
301301
$cacheLifetime = $this->getQueryBuilder()
302302
->log($this->getLogMessagePrefix(__METHOD__))
303-
->nodeType('Neos.NodeTypes:Text')
303+
->nodeType('Flowpack.ElasticSearch.ContentRepositoryAdaptor:Content')
304304
->sortAsc('title')
305305
->cacheLifetime();
306306

Tests/Functional/Indexer/NodeIndexerTest.php

Lines changed: 43 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
use Flowpack\ElasticSearch\ContentRepositoryAdaptor\Tests\Functional\BaseElasticsearchContentRepositoryAdapterTest;
2525
use Flowpack\ElasticSearch\ContentRepositoryAdaptor\Tests\Functional\Traits\Assertions;
2626
use Flowpack\ElasticSearch\ContentRepositoryAdaptor\Tests\Functional\Traits\ContentRepositoryNodeCreationTrait;
27+
use Flowpack\ElasticSearch\ContentRepositoryAdaptor\Tests\Functional\Traits\ContentRepositorySetupTrait;
2728
use Flowpack\ElasticSearch\Domain\Model\Mapping;
2829
use Flowpack\ElasticSearch\Exception;
2930
use Flowpack\ElasticSearch\Transfer\Exception\ApiException;
@@ -33,7 +34,7 @@
3334

3435
class NodeIndexerTest extends BaseElasticsearchContentRepositoryAdapterTest
3536
{
36-
use ContentRepositoryNodeCreationTrait, Assertions;
37+
use ContentRepositorySetupTrait, ContentRepositoryNodeCreationTrait, Assertions;
3738

3839
/**
3940
* @var NodeIndexer
@@ -107,23 +108,7 @@ public function updateIndexAlias(): void
107108
*/
108109
public function indexAndDeleteNode(): void
109110
{
110-
$this->setupContentRepository();
111-
$this->createNodesForNodeSearchTest();
112-
/** @var NodeInterface $testNode */
113-
$testNode = current($this->siteNode->getChildNodes('Neos.NodeTypes:Page', 1));
114-
115-
$this->nodeIndexer->setDimensions($testNode->getDimensions());
116-
$this->nodeIndexer->getIndex()->create();
117-
118-
$nodeTypeMappingCollection = $this->nodeTypeMappingBuilder->buildMappingInformation($this->nodeIndexer->getIndex());
119-
foreach ($nodeTypeMappingCollection as $mapping) {
120-
/** @var Mapping $mapping */
121-
$mapping->apply();
122-
}
123-
124-
$this->nodeIndexer->indexNode($testNode);
125-
$this->nodeIndexer->flush();
126-
sleep(1);
111+
$testNode = $this->setupCrAndIndexTestNode();
127112
self::assertTrue($this->nodeExistsInIndex($testNode), 'Node was not successfully indexed.');
128113

129114
$this->nodeIndexer->removeNode($testNode);
@@ -132,6 +117,17 @@ public function indexAndDeleteNode(): void
132117
self::assertFalse($this->nodeExistsInIndex($testNode), 'Node still exists after delete');
133118
}
134119

120+
/**
121+
* @test
122+
*/
123+
public function nodeMoveIsHandledCorrectly(): void
124+
{
125+
$testNode = $this->setupCrAndIndexTestNode();
126+
self::assertTrue($this->nodeExistsInIndex($testNode), 'Node was not successfully indexed.');
127+
128+
// $testNode->moveInto();
129+
}
130+
135131
/**
136132
* @param NodeInterface $testNode
137133
* @return bool
@@ -151,4 +147,33 @@ private function nodeExistsInIndex(NodeInterface $testNode): bool
151147
$result = $this->nodeIndexer->getIndex()->request('GET', '/_search', [], $query->toArray())->getTreatedContent();
152148
return count(Arrays::getValueByPath($result, 'hits.hits')) === 1;
153149
}
150+
151+
/**
152+
* @return NodeInterface
153+
* @throws ConfigurationException
154+
* @throws Exception
155+
* @throws \Flowpack\ElasticSearch\ContentRepositoryAdaptor\Exception
156+
* @throws \Neos\Flow\Http\Exception
157+
*/
158+
protected function setupCrAndIndexTestNode(): NodeInterface
159+
{
160+
$this->setupContentRepository();
161+
$this->createNodesForNodeSearchTest();
162+
/** @var NodeInterface $testNode */
163+
$testNode = current($this->siteNode->getChildNodes('Flowpack.ElasticSearch.ContentRepositoryAdaptor:Document', 1));
164+
165+
$this->nodeIndexer->setDimensions($testNode->getDimensions());
166+
$this->nodeIndexer->getIndex()->create();
167+
168+
$nodeTypeMappingCollection = $this->nodeTypeMappingBuilder->buildMappingInformation($this->nodeIndexer->getIndex());
169+
foreach ($nodeTypeMappingCollection as $mapping) {
170+
/** @var Mapping $mapping */
171+
$mapping->apply();
172+
}
173+
174+
$this->nodeIndexer->indexNode($testNode);
175+
$this->nodeIndexer->flush();
176+
sleep(1);
177+
return $testNode;
178+
}
154179
}

Tests/Functional/Traits/ContentRepositoryNodeCreationTrait.php

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -28,29 +28,29 @@ protected function createNodesForNodeSearchTest(): void
2828
]);
2929
$rootNode = $this->context->getRootNode();
3030

31-
$this->siteNode = $rootNode->createNode('welcome', $this->nodeTypeManager->getNodeType('Neos.NodeTypes:Page'));
31+
$this->siteNode = $rootNode->createNode('welcome', $this->nodeTypeManager->getNodeType('Flowpack.ElasticSearch.ContentRepositoryAdaptor:Document'));
3232
$this->siteNode->setProperty('title', 'welcome');
3333

34-
$newDocumentNode1 = $this->siteNode->createNode('test-node-1', $this->nodeTypeManager->getNodeType('Neos.NodeTypes:Page'));
34+
$newDocumentNode1 = $this->siteNode->createNode('test-node-1', $this->nodeTypeManager->getNodeType('Flowpack.ElasticSearch.ContentRepositoryAdaptor:Document'));
3535
$newDocumentNode1->setProperty('title', 'chicken');
3636
$newDocumentNode1->setProperty('title_analyzed', 'chicken');
3737

38-
$newContentNode1 = $newDocumentNode1->getNode('main')->createNode('document-1-text-1', $this->nodeTypeManager->getNodeType('Neos.NodeTypes:Text'));
38+
$newContentNode1 = $newDocumentNode1->getNode('main')->createNode('document-1-text-1', $this->nodeTypeManager->getNodeType('Flowpack.ElasticSearch.ContentRepositoryAdaptor:Content'));
3939
$newContentNode1->setProperty('text', 'A Scout smiles and whistles under all circumstances.');
4040

41-
$newDocumentNode2 = $this->siteNode->createNode('test-node-2', $this->nodeTypeManager->getNodeType('Neos.NodeTypes:Page'));
41+
$newDocumentNode2 = $this->siteNode->createNode('test-node-2', $this->nodeTypeManager->getNodeType('Flowpack.ElasticSearch.ContentRepositoryAdaptor:Document'));
4242
$newDocumentNode2->setProperty('title', 'chicken');
4343
$newDocumentNode2->setProperty('title_analyzed', 'chicken');
4444

4545
// Nodes for cacheLifetime test
46-
$newContentNode2 = $newDocumentNode2->getNode('main')->createNode('document-2-text-1', $this->nodeTypeManager->getNodeType('Neos.NodeTypes:Text'));
46+
$newContentNode2 = $newDocumentNode2->getNode('main')->createNode('document-2-text-1', $this->nodeTypeManager->getNodeType('Flowpack.ElasticSearch.ContentRepositoryAdaptor:Content'));
4747
$newContentNode2->setProperty('text', 'Hidden after 2025-01-01');
4848
$newContentNode2->setHiddenAfterDateTime(new \DateTime('@1735686000'));
49-
$newContentNode3 = $newDocumentNode2->getNode('main')->createNode('document-2-text-2', $this->nodeTypeManager->getNodeType('Neos.NodeTypes:Text'));
49+
$newContentNode3 = $newDocumentNode2->getNode('main')->createNode('document-2-text-2', $this->nodeTypeManager->getNodeType('Flowpack.ElasticSearch.ContentRepositoryAdaptor:Content'));
5050
$newContentNode3->setProperty('text', 'Hidden before 2018-07-18');
5151
$newContentNode3->setHiddenBeforeDateTime(new \DateTime('@1531864800'));
5252

53-
$newDocumentNode3 = $this->siteNode->createNode('test-node-3', $this->nodeTypeManager->getNodeType('Neos.NodeTypes:Page'));
53+
$newDocumentNode3 = $this->siteNode->createNode('test-node-3', $this->nodeTypeManager->getNodeType('Flowpack.ElasticSearch.ContentRepositoryAdaptor:Document'));
5454
$newDocumentNode3->setProperty('title', 'egg');
5555
$newDocumentNode3->setProperty('title_analyzed', 'egg');
5656

0 commit comments

Comments
 (0)