1414use Flowpack \ElasticSearch \ContentRepositoryAdaptor \Command \NodeIndexCommandController ;
1515use Flowpack \ElasticSearch \ContentRepositoryAdaptor \Eel \ElasticSearchQueryBuilder ;
1616use Flowpack \ElasticSearch \ContentRepositoryAdaptor \Eel \ElasticSearchQueryResult ;
17+ use Flowpack \ElasticSearch \ContentRepositoryAdaptor \Exception \QueryBuildingException ;
18+ use Neos \ContentRepository \Exception \NodeExistsException ;
19+ use Neos \ContentRepository \Exception \NodeTypeNotFoundException ;
20+ use Neos \Flow \Mvc \Exception \StopActionException ;
1721use Neos \Flow \Persistence \QueryResultInterface ;
1822use Neos \Flow \Tests \FunctionalTestCase ;
1923use Neos \ContentRepository \Domain \Model \NodeInterface ;
@@ -339,6 +343,22 @@ public function sortValuesAreReturned()
339343 }
340344 }
341345
346+ /**
347+ * @test
348+ * @throws QueryBuildingException
349+ * @throws \Flowpack\ElasticSearch\Exception
350+ */
351+ public function cacheLifetimeIsCalculatedCorrectly ()
352+ {
353+ $ cacheLifetime = $ this ->getQueryBuilder ()
354+ ->log ($ this ->getLogMessagePrefix (__METHOD__ ))
355+ ->nodeType ('Neos.NodeTypes:Text ' )
356+ ->sortAsc ('title ' )
357+ ->cacheLifetime ();
358+
359+ $ this ->assertEquals (3600 , $ cacheLifetime );
360+ }
361+
342362 /**
343363 * @return string
344364 */
@@ -349,24 +369,36 @@ protected function getLogMessagePrefix($method)
349369
350370 /**
351371 * Creates some sample nodes to run tests against
372+ * @throws NodeExistsException
373+ * @throws NodeTypeNotFoundException
374+ * @throws StopActionException
352375 */
353376 protected function createNodesForNodeSearchTest ()
354377 {
355378 $ newDocumentNode1 = $ this ->siteNode ->createNode ('test-node-1 ' , $ this ->nodeTypeManager ->getNodeType ('Neos.NodeTypes:Page ' ));
356379 $ newDocumentNode1 ->setProperty ('title ' , 'chicken ' );
357380 $ newDocumentNode1 ->setProperty ('title_analyzed ' , 'chicken ' );
358381
359- $ newContentNode = $ newDocumentNode1 ->getNode ('main ' )->createNode ('document-1-text-1 ' , $ this ->nodeTypeManager ->getNodeType ('Neos.NodeTypes:Text ' ));
360- $ newContentNode ->setProperty ('text ' , 'A Scout smiles and whistles under all circumstances. ' );
382+ $ newContentNode1 = $ newDocumentNode1 ->getNode ('main ' )->createNode ('document-1-text-1 ' , $ this ->nodeTypeManager ->getNodeType ('Neos.NodeTypes:Text ' ));
383+ $ newContentNode1 ->setProperty ('text ' , 'A Scout smiles and whistles under all circumstances. ' );
361384
362385 $ newDocumentNode2 = $ this ->siteNode ->createNode ('test-node-2 ' , $ this ->nodeTypeManager ->getNodeType ('Neos.NodeTypes:Page ' ));
363386 $ newDocumentNode2 ->setProperty ('title ' , 'chicken ' );
364387 $ newDocumentNode2 ->setProperty ('title_analyzed ' , 'chicken ' );
365388
389+ // Nodes for cacheLifetime test
390+ $ newContentNode2 = $ newDocumentNode2 ->getNode ('main ' )->createNode ('document-2-text-1 ' , $ this ->nodeTypeManager ->getNodeType ('Neos.NodeTypes:Text ' ));
391+ $ newContentNode2 ->setProperty ('text ' , 'Hidden after 2030-01-01 ' );
392+ $ newContentNode2 ->setHiddenAfterDateTime (new \DateTime ('@1532635200 ' ));
393+ $ newContentNode3 = $ newDocumentNode2 ->getNode ('main ' )->createNode ('document-2-text-2 ' , $ this ->nodeTypeManager ->getNodeType ('Neos.NodeTypes:Text ' ));
394+ $ newContentNode3 ->setProperty ('text ' , 'Hidden before 2018-07-18 ' );
395+ $ newContentNode3 ->setHiddenBeforeDateTime (new \DateTime ('@1532631600 ' ));
396+
366397 $ newDocumentNode3 = $ this ->siteNode ->createNode ('test-node-3 ' , $ this ->nodeTypeManager ->getNodeType ('Neos.NodeTypes:Page ' ));
367398 $ newDocumentNode3 ->setProperty ('title ' , 'egg ' );
368399 $ newDocumentNode3 ->setProperty ('title_analyzed ' , 'egg ' );
369400
401+
370402 $ dimensionContext = $ this ->contextFactory ->create ([
371403 'workspaceName ' => 'live ' ,
372404 'dimensions ' => ['language ' => ['de ' ]]
@@ -387,13 +419,15 @@ protected function createNodesForNodeSearchTest()
387419 }
388420
389421 /**
390- * @return QueryBuilderInterface
422+ * @return ElasticSearchQueryBuilder
423+ * @throws QueryBuildingException
424+ * @throws \Exception
391425 */
392- protected function getQueryBuilder ()
426+ protected function getQueryBuilder (): ElasticSearchQueryBuilder
393427 {
394- /** @var ElasticSearchQueryBuilder $query */
395- $ query = $ this ->objectManager -> get (ElasticSearchQueryBuilder::class );
428+ $ elasticSearchQueryBuilder = $ this -> objectManager -> get (ElasticSearchQueryBuilder::class);
429+ $ this ->inject ( $ elasticSearchQueryBuilder , ' now ' , new \ DateTimeImmutable ( ' @1532628000 ' ) );
396430
397- return $ query ->query ($ this ->siteNode );
431+ return $ elasticSearchQueryBuilder ->query ($ this ->siteNode );
398432 }
399433}
0 commit comments