Skip to content

Commit 3a08af0

Browse files
committed
[TASK] Merge
1 parent 474ddce commit 3a08af0

1 file changed

Lines changed: 37 additions & 13 deletions

File tree

Tests/Functional/Eel/ElasticSearchQueryTest.php

Lines changed: 37 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
* The TYPO3 project - inspiring people to share! *
1212
* */
1313

14+
use TYPO3\TYPO3CR\Domain\Model\Workspace;
1415
use TYPO3\TYPO3CR\Domain\Repository\WorkspaceRepository;
1516

1617
/**
@@ -58,11 +59,15 @@ class ElasticSearchQueryTest extends \TYPO3\Flow\Tests\FunctionalTestCase
5859
*/
5960
protected $queryBuilder;
6061

62+
63+
protected static $indexInitialized = false;
64+
65+
6166
public function setUp()
6267
{
6368
parent::setUp();
6469
$this->workspaceRepository = $this->objectManager->get('TYPO3\TYPO3CR\Domain\Repository\WorkspaceRepository');
65-
$liveWorkspace = new \TYPO3\TYPO3CR\Domain\Model\Workspace("live");
70+
$liveWorkspace = new Workspace("live");
6671
$this->workspaceRepository->add($liveWorkspace);
6772

6873
$this->nodeTypeManager = $this->objectManager->get('TYPO3\TYPO3CR\Domain\Service\NodeTypeManager');
@@ -72,23 +77,18 @@ public function setUp()
7277
$this->nodeDataRepository = $this->objectManager->get('TYPO3\TYPO3CR\Domain\Repository\NodeDataRepository');
7378
$this->queryBuilder = $this->objectManager->get('Flowpack\ElasticSearch\ContentRepositoryAdaptor\Eel\ElasticSearchQueryBuilder');
7479

75-
$this->queryBuilder->log();
76-
77-
// we need to make sure that the index will be prefixed with an unique name. so we add a sleet as it is not
78-
// possible right now to set the index name
79-
sleep(4);
80-
8180
$this->nodeIndexCommandController = $this->objectManager->get('Flowpack\ElasticSearch\ContentRepositoryAdaptor\Command\NodeIndexCommandController');
82-
$this->nodeIndexCommandController->buildCommand();
8381

82+
$this->queryBuilder->log();
83+
$this->initializeIndex();
8484
$this->createNodesForNodeSearchTest();
8585
}
8686

8787
public function tearDown()
8888
{
8989
parent::tearDown();
9090
$this->inject($this->contextFactory, 'contextInstances', array());
91-
$this->nodeIndexCommandController->cleanupCommand();
91+
// $this->nodeIndexCommandController->cleanupCommand();
9292
}
9393

9494
/**
@@ -105,7 +105,7 @@ public function filterByNodeType()
105105
*/
106106
public function filterNodeByProperty()
107107
{
108-
$resultCount = $this->queryBuilder->query($this->context->getRootNode())->exactMatch('title', 'egg')->count();
108+
$resultCount = $this->queryBuilder->query($this->context->getRootNode())->exactMatch('title', 'ei')->count();
109109
$this->assertEquals(1, $resultCount);
110110
}
111111

@@ -126,15 +126,21 @@ public function filterLimitQuery()
126126
/**
127127
* @test
128128
*/
129-
public function aggregationsCanAdded()
129+
public function fieldBasedAggregations()
130130
{
131131
$aggregationTitle = "titleagg";
132132
$result = $this->queryBuilder->query($this->context->getRootNode())->fieldBasedAggregation($aggregationTitle, "title")->execute()->getAggregations();
133133

134134
$this->assertArrayHasKey($aggregationTitle, $result);
135135

136-
// assume three results because there are three nodes created with an title set
137-
$this->assertCount(3, $result[$aggregationTitle]);
136+
$this->assertCount(2, $result[$aggregationTitle]['buckets']);
137+
138+
$expectedChickenBucket = array(
139+
'key' => 'chicken',
140+
'doc_count' => 2
141+
);
142+
143+
$this->assertEquals($expectedChickenBucket, $result[$aggregationTitle]['buckets'][0]);
138144
}
139145

140146
/**
@@ -171,9 +177,27 @@ protected function createNodesForNodeSearchTest()
171177
$newNode2->setProperty('title', 'chicken');
172178

173179
$newNode3 = $rootNode->createNode('test-node-3', $this->nodeTypeManager->getNodeType('TYPO3.Neos.NodeTypes:Page'));
180+
174181
$newNode3->setProperty('title', 'egg');
175182

183+
$dimensionContext = $this->contextFactory->create(array('workspaceName' => 'live', 'dimensions' => array('language' => array('en_us'))));
184+
$translatedNode3 = $dimensionContext->adoptNode($newNode3, TRUE);
185+
$translatedNode3->setProperty('title', 'egg');
186+
187+
176188
$this->persistenceManager->persistAll();
177189
$this->nodeIndexCommandController->buildCommand();
178190
}
191+
192+
protected function initializeIndex()
193+
{
194+
if (self::$indexInitialized === false) {
195+
// we need to make sure that the index will be prefixed with an unique name. so we add a sleep as it is not
196+
// possible right now to set the index name
197+
sleep(2);
198+
$this->nodeIndexCommandController->buildCommand();
199+
200+
self::$indexInitialized = true;
201+
}
202+
}
179203
}

0 commit comments

Comments
 (0)