Skip to content

Commit 474ddce

Browse files
committed
Merge pull request #98 from johannessteu/feature/sort-fixes
This change fixes the return value for getFirst() according to the api to the first object instead of an sliced array. After this change not an array but a single node will be returned.
2 parents 888c962 + 4592e81 commit 474ddce

2 files changed

Lines changed: 23 additions & 3 deletions

File tree

Classes/Flowpack/ElasticSearch/ContentRepositoryAdaptor/Eel/ElasticSearchQueryResult.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -151,7 +151,7 @@ public function getFirst()
151151
{
152152
$this->initialize();
153153
if (count($this->nodes) > 0) {
154-
return array_slice($this->nodes, 0, 1);
154+
return array_values($this->nodes)[0];
155155
}
156156
}
157157

Tests/Functional/Eel/ElasticSearchQueryTest.php

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -137,6 +137,26 @@ public function aggregationsCanAdded()
137137
$this->assertCount(3, $result[$aggregationTitle]);
138138
}
139139

140+
/**
141+
* @test
142+
*/
143+
public function nodesWillBeSortedDesc()
144+
{
145+
$descendingResult = $this->queryBuilder->query($this->context->getRootNode())->sortDesc("title")->execute();
146+
$node = $descendingResult->getFirst();
147+
$this->assertEquals("egg", $node->getProperty("title"), "Asserting a desc sort order by property title");
148+
}
149+
150+
/**
151+
* @test
152+
*/
153+
public function nodesWillBeSortedAsc()
154+
{
155+
$ascendingResult = $this->queryBuilder->query($this->context->getRootNode())->sortAsc("title")->execute();
156+
$node = $ascendingResult->getFirst();
157+
$this->assertEquals("chicken", $node->getProperty("title"), "Asserting a asc sort order by property title");
158+
}
159+
140160
/**
141161
* Creates some sample nodes to run tests against
142162
*/
@@ -150,8 +170,8 @@ protected function createNodesForNodeSearchTest()
150170
$newNode2 = $rootNode->createNode('test-node-2', $this->nodeTypeManager->getNodeType('TYPO3.Neos.NodeTypes:Page'));
151171
$newNode2->setProperty('title', 'chicken');
152172

153-
$newNode2 = $rootNode->createNode('test-node-3', $this->nodeTypeManager->getNodeType('TYPO3.Neos.NodeTypes:Page'));
154-
$newNode2->setProperty('title', 'egg');
173+
$newNode3 = $rootNode->createNode('test-node-3', $this->nodeTypeManager->getNodeType('TYPO3.Neos.NodeTypes:Page'));
174+
$newNode3->setProperty('title', 'egg');
155175

156176
$this->persistenceManager->persistAll();
157177
$this->nodeIndexCommandController->buildCommand();

0 commit comments

Comments
 (0)