Skip to content

Commit 9c37388

Browse files
Peter Rauberdaniellienert
authored andcommitted
Add trait to create nodes for the test
1 parent 2e9d82c commit 9c37388

2 files changed

Lines changed: 138 additions & 1 deletion

File tree

Classes/Command/NodeIndexCommandController.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -385,7 +385,8 @@ public function buildWorkspaceInternalCommand(string $workspace, string $dimensi
385385
$this->outputLine($message);
386386
};
387387

388-
$this->workspaceIndexer->indexWithDimensions($workspace, $dimensionsValuesArray, $limit, $workspaceLogger);
388+
//$this->workspaceIndexer->indexWithDimensions($workspace, $dimensionsValuesArray, $limit, $workspaceLogger);
389+
$this->workspaceIndexer->index($workspace, $limit, $workspaceLogger);
389390

390391
$this->outputErrorHandling();
391392
}
Lines changed: 136 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,136 @@
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 ContentRepositoryMultiDimensionNodeCreationTrait
30+
{
31+
/**
32+
* @var WorkspaceRepository
33+
*/
34+
protected $workspaceRepository;
35+
36+
/**
37+
* @var NodeInterface
38+
*/
39+
protected $siteNode;
40+
41+
/**
42+
* @var ContextFactoryInterface
43+
*/
44+
protected $contextFactory;
45+
46+
/**
47+
* @var NodeTypeManager
48+
*/
49+
protected $nodeTypeManager;
50+
51+
/**
52+
* @var NodeDataRepository
53+
*/
54+
protected $nodeDataRepository;
55+
56+
private function setupContentRepository():void
57+
{
58+
$this->workspaceRepository = $this->objectManager->get(WorkspaceRepository::class);
59+
$liveWorkspace = new Workspace('live');
60+
$this->workspaceRepository->add($liveWorkspace);
61+
62+
$this->nodeTypeManager = $this->objectManager->get(NodeTypeManager::class);
63+
$this->contextFactory = $this->objectManager->get(ContextFactoryInterface::class);
64+
$this->nodeDataRepository = $this->objectManager->get(NodeDataRepository::class);
65+
}
66+
67+
/**
68+
* Creates some sample nodes to run tests against
69+
*
70+
* @throws NodeExistsException
71+
* @throws NodeTypeNotFoundException
72+
* @throws StopActionException
73+
* @throws \Flowpack\ElasticSearch\ContentRepositoryAdaptor\Exception
74+
* @throws ApiException
75+
* @throws StopCommandException
76+
*/
77+
protected function createNodesForNodeSearchTest(): void
78+
{
79+
$defaultLanguageDimensionContext = $this->contextFactory->create([
80+
'workspaceName' => 'live',
81+
'dimensions' => ['language' => ['en_US']],
82+
'targetDimensions' => ['language' => 'en_US']
83+
]);
84+
$deLanguageDimensionContext = $this->contextFactory->create([
85+
'workspaceName' => 'live',
86+
'dimensions' => ['language' => ['de']],
87+
'targetDimensions' => ['language' => 'de']
88+
]);
89+
$dkLanguageDimensionContext = $this->contextFactory->create([
90+
'workspaceName' => 'live',
91+
'dimensions' => ['language' => ['dk']],
92+
'targetDimensions' => ['language' => 'dk']
93+
]);
94+
95+
$rootNode = $defaultLanguageDimensionContext->getRootNode();
96+
$this->siteNodeDefault = $rootNode->createNode('root', $this->nodeTypeManager->getNodeType('Flowpack.ElasticSearch.ContentRepositoryAdaptor:Document'));
97+
$this->siteNodeDefault->setProperty('title', 'root-default');
98+
$this->siteNodeDe = $deLanguageDimensionContext->adoptNode($this->siteNodeDefault, true);
99+
$this->siteNodeDe->setProperty('title', 'root-de');
100+
$this->siteNodeDk = $dkLanguageDimensionContext->adoptNode($this->siteNodeDefault, true);
101+
$this->siteNodeDk->setProperty('title', 'root-dk');
102+
103+
// add a document node that is translated in two languages
104+
$newDocumentNode1 = $this->siteNodeDefault->createNode('document1-default', $this->nodeTypeManager->getNodeType('Flowpack.ElasticSearch.ContentRepositoryAdaptor:Document'));
105+
$newDocumentNode1->setProperty('title', 'document1-default');
106+
107+
$translatedDocumentNode1De = $deLanguageDimensionContext->adoptNode($newDocumentNode1, true);
108+
$translatedDocumentNode1De->setProperty('title', 'document1-de');
109+
$translatedDocumentNode1Dk = $dkLanguageDimensionContext->adoptNode($newDocumentNode1, true);
110+
$translatedDocumentNode1Dk->setProperty('title', 'document1-dk');
111+
112+
// add a document node that is not translated
113+
$newDocumentNode_untranslated = $this->siteNodeDefault->createNode('document-untranslated', $this->nodeTypeManager->getNodeType('Flowpack.ElasticSearch.ContentRepositoryAdaptor:Document'));
114+
$newDocumentNode_untranslated->setProperty('title', 'document-untranslated');
115+
116+
// add additional, but separate nodes here
117+
$standaloneDocumentNode2De = $this->siteNodeDe->createNode('document2-de', $this->nodeTypeManager->getNodeType('Flowpack.ElasticSearch.ContentRepositoryAdaptor:Document'));
118+
$standaloneDocumentNode2De->setProperty('title', 'document2-de');
119+
120+
$standaloneDocumentNode2Dk = $this->siteNodeDk->createNode('document2-dk', $this->nodeTypeManager->getNodeType('Flowpack.ElasticSearch.ContentRepositoryAdaptor:Document'));
121+
$standaloneDocumentNode2Dk->setProperty('title', 'document2-dk');
122+
123+
// add an additional german node
124+
$documentNodeDe3 = $standaloneDocumentNode2De->createNode('document3-de', $this->nodeTypeManager->getNodeType('Flowpack.ElasticSearch.ContentRepositoryAdaptor:Document'));
125+
$documentNodeDe3->setProperty('title', 'document3-de');
126+
127+
// add another german node, but translate it to danish
128+
$documentNodeDe4 = $standaloneDocumentNode2De->createNode('document4-de', $this->nodeTypeManager->getNodeType('Flowpack.ElasticSearch.ContentRepositoryAdaptor:Document'));
129+
$documentNodeDe4->setProperty('title', 'document4-de');
130+
131+
$translatedDocumentNode4Dk = $dkLanguageDimensionContext->adoptNode($documentNodeDe4, true);
132+
$translatedDocumentNode4Dk->setProperty('title', 'document4-dk');
133+
134+
$this->persistenceManager->persistAll();
135+
}
136+
}

0 commit comments

Comments
 (0)