1111 * The TYPO3 project - inspiring people to share! *
1212 * */
1313
14- use Flowpack \ ElasticSearch \ ContentRepositoryAdaptor \ Eel \ ElasticSearchQuery ;
14+ use TYPO3 \ TYPO3CR \ Domain \ Repository \ WorkspaceRepository ;
1515
1616/**
1717 * Testcase for ElasticSearchQuery
1818 */
1919class ElasticSearchQueryTest extends \TYPO3 \Flow \Tests \FunctionalTestCase
2020{
21+ /**
22+ * @var WorkspaceRepository
23+ */
24+ protected $ workspaceRepository ;
25+
2126 /**
2227 * @var \Flowpack\ElasticSearch\ContentRepositoryAdaptor\Command\NodeIndexCommandController
2328 */
@@ -56,19 +61,28 @@ class ElasticSearchQueryTest extends \TYPO3\Flow\Tests\FunctionalTestCase
5661 public function setUp ()
5762 {
5863 parent ::setUp ();
64+ $ this ->workspaceRepository = $ this ->objectManager ->get ('TYPO3\TYPO3CR\Domain\Repository\WorkspaceRepository ' );
65+ $ liveWorkspace = new \TYPO3 \TYPO3CR \Domain \Model \Workspace ("live " );
66+ $ this ->workspaceRepository ->add ($ liveWorkspace );
67+
5968 $ this ->nodeTypeManager = $ this ->objectManager ->get ('TYPO3\TYPO3CR\Domain\Service\NodeTypeManager ' );
6069 $ this ->contextFactory = $ this ->objectManager ->get ('TYPO3\TYPO3CR\Domain\Service\ContextFactoryInterface ' );
6170 $ this ->context = $ this ->contextFactory ->create (array ('workspaceName ' => 'live ' , 'dimensions ' => array ('language ' => array ('de ' ))));
71+
6272 $ this ->nodeDataRepository = $ this ->objectManager ->get ('TYPO3\TYPO3CR\Domain\Repository\NodeDataRepository ' );
6373 $ this ->queryBuilder = $ this ->objectManager ->get ('Flowpack\ElasticSearch\ContentRepositoryAdaptor\Eel\ElasticSearchQueryBuilder ' );
6474
6575 $ this ->queryBuilder ->log ();
66- $ this ->createNodesForNodeSearchTest ();
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 );
6780
6881 $ this ->nodeIndexCommandController = $ this ->objectManager ->get ('Flowpack\ElasticSearch\ContentRepositoryAdaptor\Command\NodeIndexCommandController ' );
6982 $ this ->nodeIndexCommandController ->buildCommand ();
70- }
7183
84+ $ this ->createNodesForNodeSearchTest ();
85+ }
7286
7387 public function tearDown ()
7488 {
@@ -109,7 +123,23 @@ public function filterLimitQuery()
109123 $ this ->assertCount (1 , $ result ->toArray (), 'Asserting the executed query returns a valid number of items. ' );
110124 }
111125
126+ /**
127+ * @test
128+ */
129+ public function aggregationsCanAdded ()
130+ {
131+ $ aggregationTitle = "titleagg " ;
132+ $ result = $ this ->queryBuilder ->query ($ this ->context ->getRootNode ())->fieldBasedAggregation ($ aggregationTitle , "title " )->execute ()->getAggregations ();
133+
134+ $ this ->assertArrayHasKey ($ aggregationTitle , $ result );
112135
136+ // assume three results because there are three nodes created with an title set
137+ $ this ->assertCount (3 , $ result [$ aggregationTitle ]);
138+ }
139+
140+ /**
141+ * Creates some sample nodes to run tests against
142+ */
113143 protected function createNodesForNodeSearchTest ()
114144 {
115145 $ rootNode = $ this ->context ->getRootNode ();
@@ -124,5 +154,6 @@ protected function createNodesForNodeSearchTest()
124154 $ newNode2 ->setProperty ('title ' , 'egg ' );
125155
126156 $ this ->persistenceManager ->persistAll ();
157+ $ this ->nodeIndexCommandController ->buildCommand ();
127158 }
128159}
0 commit comments