Skip to content

Commit ce5acea

Browse files
committed
Merge pull request #101 from daniellienert/improve-test-coverage
Improve test coverage
2 parents 474ddce + 898a75d commit ce5acea

2 files changed

Lines changed: 36 additions & 16 deletions

File tree

Configuration/Testing/WithoutLanguageFallback/Settings.yaml

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,7 @@ TYPO3:
1111
values: ['en_US']
1212
uriSegment: 'en'
1313
'en_UK': ~
14-
'de':
15-
label: 'German'
16-
values: ['de']
17-
uriSegment: 'de'
14+
'de': ~
1815
'fr': ~
1916
'nl': ~
2017
'dk': ~

Tests/Functional/Eel/ElasticSearchQueryTest.php

Lines changed: 35 additions & 12 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,29 +59,28 @@ 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');
6974
$this->contextFactory = $this->objectManager->get('TYPO3\TYPO3CR\Domain\Service\ContextFactoryInterface');
70-
$this->context = $this->contextFactory->create(array('workspaceName' => 'live', 'dimensions' => array('language' => array('de'))));
75+
$this->context = $this->contextFactory->create(array('workspaceName' => 'live', 'dimensions' => array('language' => array('en_US'))));
7176

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

@@ -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
/**
@@ -173,7 +179,24 @@ protected function createNodesForNodeSearchTest()
173179
$newNode3 = $rootNode->createNode('test-node-3', $this->nodeTypeManager->getNodeType('TYPO3.Neos.NodeTypes:Page'));
174180
$newNode3->setProperty('title', 'egg');
175181

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

0 commit comments

Comments
 (0)