|
11 | 11 | * The TYPO3 project - inspiring people to share! * |
12 | 12 | * */ |
13 | 13 |
|
| 14 | +use TYPO3\TYPO3CR\Domain\Model\Workspace; |
14 | 15 | use TYPO3\TYPO3CR\Domain\Repository\WorkspaceRepository; |
15 | 16 |
|
16 | 17 | /** |
@@ -58,29 +59,28 @@ class ElasticSearchQueryTest extends \TYPO3\Flow\Tests\FunctionalTestCase |
58 | 59 | */ |
59 | 60 | protected $queryBuilder; |
60 | 61 |
|
| 62 | + |
| 63 | + protected static $indexInitialized = false; |
| 64 | + |
| 65 | + |
61 | 66 | public function setUp() |
62 | 67 | { |
63 | 68 | parent::setUp(); |
64 | 69 | $this->workspaceRepository = $this->objectManager->get('TYPO3\TYPO3CR\Domain\Repository\WorkspaceRepository'); |
65 | | - $liveWorkspace = new \TYPO3\TYPO3CR\Domain\Model\Workspace("live"); |
| 70 | + $liveWorkspace = new Workspace("live"); |
66 | 71 | $this->workspaceRepository->add($liveWorkspace); |
67 | 72 |
|
68 | 73 | $this->nodeTypeManager = $this->objectManager->get('TYPO3\TYPO3CR\Domain\Service\NodeTypeManager'); |
69 | 74 | $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')))); |
71 | 76 |
|
72 | 77 | $this->nodeDataRepository = $this->objectManager->get('TYPO3\TYPO3CR\Domain\Repository\NodeDataRepository'); |
73 | 78 | $this->queryBuilder = $this->objectManager->get('Flowpack\ElasticSearch\ContentRepositoryAdaptor\Eel\ElasticSearchQueryBuilder'); |
74 | 79 |
|
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 | | - |
81 | 80 | $this->nodeIndexCommandController = $this->objectManager->get('Flowpack\ElasticSearch\ContentRepositoryAdaptor\Command\NodeIndexCommandController'); |
82 | | - $this->nodeIndexCommandController->buildCommand(); |
83 | 81 |
|
| 82 | + $this->queryBuilder->log(); |
| 83 | + $this->initializeIndex(); |
84 | 84 | $this->createNodesForNodeSearchTest(); |
85 | 85 | } |
86 | 86 |
|
@@ -126,15 +126,21 @@ public function filterLimitQuery() |
126 | 126 | /** |
127 | 127 | * @test |
128 | 128 | */ |
129 | | - public function aggregationsCanAdded() |
| 129 | + public function fieldBasedAggregations() |
130 | 130 | { |
131 | 131 | $aggregationTitle = "titleagg"; |
132 | 132 | $result = $this->queryBuilder->query($this->context->getRootNode())->fieldBasedAggregation($aggregationTitle, "title")->execute()->getAggregations(); |
133 | 133 |
|
134 | 134 | $this->assertArrayHasKey($aggregationTitle, $result); |
135 | 135 |
|
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]); |
138 | 144 | } |
139 | 145 |
|
140 | 146 | /** |
@@ -173,7 +179,24 @@ protected function createNodesForNodeSearchTest() |
173 | 179 | $newNode3 = $rootNode->createNode('test-node-3', $this->nodeTypeManager->getNodeType('TYPO3.Neos.NodeTypes:Page')); |
174 | 180 | $newNode3->setProperty('title', 'egg'); |
175 | 181 |
|
| 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 | + |
176 | 187 | $this->persistenceManager->persistAll(); |
177 | 188 | $this->nodeIndexCommandController->buildCommand(); |
178 | 189 | } |
| 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 | + } |
179 | 202 | } |
0 commit comments