Skip to content

Commit 113c419

Browse files
committed
TASK: Extract creating of content repository nodes to a trait
1 parent 29b2e65 commit 113c419

2 files changed

Lines changed: 132 additions & 103 deletions

File tree

Tests/Functional/Eel/ElasticSearchQueryTest.php

Lines changed: 6 additions & 103 deletions
Original file line numberDiff line numberDiff line change
@@ -13,70 +13,31 @@
1313
* source code.
1414
*/
1515

16-
use DateTime;
1716
use DateTimeImmutable;
1817
use Exception;
1918
use Flowpack\ElasticSearch\ContentRepositoryAdaptor\Command\NodeIndexCommandController;
2019
use Flowpack\ElasticSearch\ContentRepositoryAdaptor\Eel\ElasticSearchQueryBuilder;
2120
use Flowpack\ElasticSearch\ContentRepositoryAdaptor\Eel\ElasticSearchQueryResult;
2221
use Flowpack\ElasticSearch\ContentRepositoryAdaptor\Exception\QueryBuildingException;
23-
use Flowpack\ElasticSearch\Transfer\Exception\ApiException;
22+
use Flowpack\ElasticSearch\ContentRepositoryAdaptor\Tests\Functional\TRaits\ContentRepositoryNodeCreationTrait;
2423
use Neos\ContentRepository\Domain\Model\NodeInterface;
25-
use Neos\ContentRepository\Domain\Model\Workspace;
26-
use Neos\ContentRepository\Domain\Repository\NodeDataRepository;
27-
use Neos\ContentRepository\Domain\Repository\WorkspaceRepository;
28-
use Neos\ContentRepository\Domain\Service\Context;
29-
use Neos\ContentRepository\Domain\Service\ContextFactoryInterface;
30-
use Neos\ContentRepository\Domain\Service\NodeTypeManager;
31-
use Neos\ContentRepository\Exception\NodeExistsException;
32-
use Neos\ContentRepository\Exception\NodeTypeNotFoundException;
33-
use Neos\Flow\Cli\Exception\StopCommandException;
34-
use Neos\Flow\Mvc\Exception\StopActionException;
3524
use Neos\Flow\Persistence\QueryResultInterface;
3625
use Neos\Flow\Tests\FunctionalTestCase;
3726

3827
class ElasticSearchQueryTest extends FunctionalTestCase
3928
{
40-
/**
41-
* @var WorkspaceRepository
42-
*/
43-
protected $workspaceRepository;
29+
use ContentRepositoryNodeCreationTrait;
4430

4531
/**
4632
* @var NodeIndexCommandController
4733
*/
4834
protected $nodeIndexCommandController;
4935

50-
/**
51-
* @var Context
52-
*/
53-
protected $context;
54-
55-
/**
56-
* @var NodeInterface
57-
*/
58-
protected $siteNode;
59-
6036
/**
6137
* @var boolean
6238
*/
6339
protected static $testablePersistenceEnabled = true;
6440

65-
/**
66-
* @var ContextFactoryInterface
67-
*/
68-
protected $contextFactory;
69-
70-
/**
71-
* @var NodeTypeManager
72-
*/
73-
protected $nodeTypeManager;
74-
75-
/**
76-
* @var NodeDataRepository
77-
*/
78-
protected $nodeDataRepository;
79-
8041
/**
8142
* @var boolean
8243
*/
@@ -85,27 +46,13 @@ class ElasticSearchQueryTest extends FunctionalTestCase
8546
public function setUp(): void
8647
{
8748
parent::setUp();
88-
$this->workspaceRepository = $this->objectManager->get(WorkspaceRepository::class);
89-
$liveWorkspace = new Workspace('live');
90-
$this->workspaceRepository->add($liveWorkspace);
91-
92-
$this->nodeTypeManager = $this->objectManager->get(NodeTypeManager::class);
93-
$this->contextFactory = $this->objectManager->get(ContextFactoryInterface::class);
94-
$this->context = $this->contextFactory->create([
95-
'workspaceName' => 'live',
96-
'dimensions' => ['language' => ['en_US']],
97-
'targetDimensions' => ['language' => 'en_US']
98-
]);
99-
$rootNode = $this->context->getRootNode();
100-
101-
$this->siteNode = $rootNode->createNode('welcome', $this->nodeTypeManager->getNodeType('Neos.NodeTypes:Page'));
102-
$this->siteNode->setProperty('title', 'welcome');
103-
104-
$this->nodeDataRepository = $this->objectManager->get(NodeDataRepository::class);
49+
$this->setupContentRepository();
10550

10651
$this->nodeIndexCommandController = $this->objectManager->get(NodeIndexCommandController::class);
10752

10853
$this->createNodesForNodeSearchTest();
54+
sleep(2);
55+
$this->indexNodes();
10956
}
11057

11158
public function tearDown(): void
@@ -394,52 +341,8 @@ protected function getLogMessagePrefix(string $method): string
394341
return substr(strrchr($method, '\\'), 1);
395342
}
396343

397-
/**
398-
* Creates some sample nodes to run tests against
399-
*
400-
* @throws NodeExistsException
401-
* @throws NodeTypeNotFoundException
402-
* @throws StopActionException
403-
* @throws \Flowpack\ElasticSearch\ContentRepositoryAdaptor\Exception
404-
* @throws ApiException
405-
* @throws StopCommandException
406-
*/
407-
protected function createNodesForNodeSearchTest(): void
344+
protected function indexNodes(): void
408345
{
409-
$newDocumentNode1 = $this->siteNode->createNode('test-node-1', $this->nodeTypeManager->getNodeType('Neos.NodeTypes:Page'));
410-
$newDocumentNode1->setProperty('title', 'chicken');
411-
$newDocumentNode1->setProperty('title_analyzed', 'chicken');
412-
413-
$newContentNode1 = $newDocumentNode1->getNode('main')->createNode('document-1-text-1', $this->nodeTypeManager->getNodeType('Neos.NodeTypes:Text'));
414-
$newContentNode1->setProperty('text', 'A Scout smiles and whistles under all circumstances.');
415-
416-
$newDocumentNode2 = $this->siteNode->createNode('test-node-2', $this->nodeTypeManager->getNodeType('Neos.NodeTypes:Page'));
417-
$newDocumentNode2->setProperty('title', 'chicken');
418-
$newDocumentNode2->setProperty('title_analyzed', 'chicken');
419-
420-
// Nodes for cacheLifetime test
421-
$newContentNode2 = $newDocumentNode2->getNode('main')->createNode('document-2-text-1', $this->nodeTypeManager->getNodeType('Neos.NodeTypes:Text'));
422-
$newContentNode2->setProperty('text', 'Hidden after 2025-01-01');
423-
$newContentNode2->setHiddenAfterDateTime(new DateTime('@1735686000'));
424-
$newContentNode3 = $newDocumentNode2->getNode('main')->createNode('document-2-text-2', $this->nodeTypeManager->getNodeType('Neos.NodeTypes:Text'));
425-
$newContentNode3->setProperty('text', 'Hidden before 2018-07-18');
426-
$newContentNode3->setHiddenBeforeDateTime(new DateTime('@1531864800'));
427-
428-
$newDocumentNode3 = $this->siteNode->createNode('test-node-3', $this->nodeTypeManager->getNodeType('Neos.NodeTypes:Page'));
429-
$newDocumentNode3->setProperty('title', 'egg');
430-
$newDocumentNode3->setProperty('title_analyzed', 'egg');
431-
432-
$dimensionContext = $this->contextFactory->create([
433-
'workspaceName' => 'live',
434-
'dimensions' => ['language' => ['de']]
435-
]);
436-
$translatedNode3 = $dimensionContext->adoptNode($newDocumentNode3, true);
437-
$translatedNode3->setProperty('title', 'De');
438-
439-
$this->persistenceManager->persistAll();
440-
441-
sleep(2);
442-
443346
if (self::$indexInitialized === true) {
444347
return;
445348
}
Lines changed: 126 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,126 @@
1+
<?php
2+
declare(strict_types=1);
3+
4+
namespace Flowpack\ElasticSearch\ContentRepositoryAdaptor\Tests\Functional\TRaits;
5+
6+
/*
7+
* This file is part of the Flowpack.ElasticSearch.ContentRepositoryAdaptor package.
8+
*
9+
* (c) Contributors of the Neos Project - www.neos.io
10+
*
11+
* This package is Open Source Software. For the full copyright and license
12+
* information, please view the LICENSE file which was distributed with this
13+
* source code.
14+
*/
15+
16+
use Flowpack\ElasticSearch\Transfer\Exception\ApiException;
17+
use Neos\ContentRepository\Domain\Model\NodeInterface;
18+
use Neos\ContentRepository\Domain\Model\Workspace;
19+
use Neos\ContentRepository\Domain\Repository\NodeDataRepository;
20+
use Neos\ContentRepository\Domain\Repository\WorkspaceRepository;
21+
use Neos\ContentRepository\Domain\Service\Context;
22+
use Neos\ContentRepository\Domain\Service\ContextFactoryInterface;
23+
use Neos\ContentRepository\Domain\Service\NodeTypeManager;
24+
use Neos\ContentRepository\Exception\NodeExistsException;
25+
use Neos\ContentRepository\Exception\NodeTypeNotFoundException;
26+
use Neos\Flow\Cli\Exception\StopCommandException;
27+
use Neos\Flow\Mvc\Exception\StopActionException;
28+
29+
trait ContentRepositoryNodeCreationTrait
30+
{
31+
/**
32+
* @var WorkspaceRepository
33+
*/
34+
protected $workspaceRepository;
35+
36+
/**
37+
* @var Context
38+
*/
39+
protected $context;
40+
41+
/**
42+
* @var NodeInterface
43+
*/
44+
protected $siteNode;
45+
46+
/**
47+
* @var ContextFactoryInterface
48+
*/
49+
protected $contextFactory;
50+
51+
/**
52+
* @var NodeTypeManager
53+
*/
54+
protected $nodeTypeManager;
55+
56+
/**
57+
* @var NodeDataRepository
58+
*/
59+
protected $nodeDataRepository;
60+
61+
private function setupContentRepository():void
62+
{
63+
$this->workspaceRepository = $this->objectManager->get(WorkspaceRepository::class);
64+
$liveWorkspace = new Workspace('live');
65+
$this->workspaceRepository->add($liveWorkspace);
66+
67+
$this->nodeTypeManager = $this->objectManager->get(NodeTypeManager::class);
68+
$this->contextFactory = $this->objectManager->get(ContextFactoryInterface::class);
69+
$this->context = $this->contextFactory->create([
70+
'workspaceName' => 'live',
71+
'dimensions' => ['language' => ['en_US']],
72+
'targetDimensions' => ['language' => 'en_US']
73+
]);
74+
$rootNode = $this->context->getRootNode();
75+
76+
$this->siteNode = $rootNode->createNode('welcome', $this->nodeTypeManager->getNodeType('Neos.NodeTypes:Page'));
77+
$this->siteNode->setProperty('title', 'welcome');
78+
79+
$this->nodeDataRepository = $this->objectManager->get(NodeDataRepository::class);
80+
}
81+
82+
/**
83+
* Creates some sample nodes to run tests against
84+
*
85+
* @throws NodeExistsException
86+
* @throws NodeTypeNotFoundException
87+
* @throws StopActionException
88+
* @throws \Flowpack\ElasticSearch\ContentRepositoryAdaptor\Exception
89+
* @throws ApiException
90+
* @throws StopCommandException
91+
*/
92+
protected function createNodesForNodeSearchTest(): void
93+
{
94+
$newDocumentNode1 = $this->siteNode->createNode('test-node-1', $this->nodeTypeManager->getNodeType('Neos.NodeTypes:Page'));
95+
$newDocumentNode1->setProperty('title', 'chicken');
96+
$newDocumentNode1->setProperty('title_analyzed', 'chicken');
97+
98+
$newContentNode1 = $newDocumentNode1->getNode('main')->createNode('document-1-text-1', $this->nodeTypeManager->getNodeType('Neos.NodeTypes:Text'));
99+
$newContentNode1->setProperty('text', 'A Scout smiles and whistles under all circumstances.');
100+
101+
$newDocumentNode2 = $this->siteNode->createNode('test-node-2', $this->nodeTypeManager->getNodeType('Neos.NodeTypes:Page'));
102+
$newDocumentNode2->setProperty('title', 'chicken');
103+
$newDocumentNode2->setProperty('title_analyzed', 'chicken');
104+
105+
// Nodes for cacheLifetime test
106+
$newContentNode2 = $newDocumentNode2->getNode('main')->createNode('document-2-text-1', $this->nodeTypeManager->getNodeType('Neos.NodeTypes:Text'));
107+
$newContentNode2->setProperty('text', 'Hidden after 2025-01-01');
108+
$newContentNode2->setHiddenAfterDateTime(new \DateTime('@1735686000'));
109+
$newContentNode3 = $newDocumentNode2->getNode('main')->createNode('document-2-text-2', $this->nodeTypeManager->getNodeType('Neos.NodeTypes:Text'));
110+
$newContentNode3->setProperty('text', 'Hidden before 2018-07-18');
111+
$newContentNode3->setHiddenBeforeDateTime(new \DateTime('@1531864800'));
112+
113+
$newDocumentNode3 = $this->siteNode->createNode('test-node-3', $this->nodeTypeManager->getNodeType('Neos.NodeTypes:Page'));
114+
$newDocumentNode3->setProperty('title', 'egg');
115+
$newDocumentNode3->setProperty('title_analyzed', 'egg');
116+
117+
$dimensionContext = $this->contextFactory->create([
118+
'workspaceName' => 'live',
119+
'dimensions' => ['language' => ['de']]
120+
]);
121+
$translatedNode3 = $dimensionContext->adoptNode($newDocumentNode3, true);
122+
$translatedNode3->setProperty('title', 'De');
123+
124+
$this->persistenceManager->persistAll();
125+
}
126+
}

0 commit comments

Comments
 (0)