--- a/server/src/tests/Controllers/DateStatsControllerTest.php Tue Nov 15 18:27:17 2016 +0100
+++ b/server/src/tests/Controllers/DateStatsControllerTest.php Tue Nov 15 23:35:59 2016 +0100
@@ -42,6 +42,29 @@
]
]
];
+
+ $this->ES_QUERY_MINMAX = [
+ 'index' => 'corpus',
+ 'body' => [
+ "size" => 0,
+ "query" => [ "match_all" => (object) null ],
+ "aggs" => [
+ "datestats" => [
+ "nested"=> [
+ "path" => "creation_years"
+ ],
+ "aggs" => [
+ "minyear" => [
+ "min" => [ "field"=> "creation_years.year" ]
+ ],
+ "maxyear" => [
+ "max" => [ "field"=> "creation_years.year" ]
+ ]
+ ]
+ ]
+ ]
+ ]
+ ];
}
public function tearDown() {
@@ -147,4 +170,73 @@
]]);
}
+
+ public function testMinMaxQuery() {
+
+ Es::shouldReceive('search')
+ ->once()
+ ->with($this->ES_QUERY_MINMAX)
+ ->andReturn(json_decode('{
+ "took" : 708,
+ "timed_out" : false,
+ "_shards" : {
+ "total" : 1,
+ "successful" : 1,
+ "failed" : 0
+ },
+ "hits" : {
+ "total" : 0,
+ "max_score" : 0.0,
+ "hits" : [ ]
+ },
+ "aggregations" : {
+ "datestats" : {
+ "doc_count" : 0,
+ "maxyear" : {
+ "value" : null
+ },
+ "minyear" : {
+ "value" : null
+ }
+ }
+ }
+ }', true));
+ $this->get('/api/v1/stats/dateminmax/')->assertTrue($this->response->isOk(), $this->response->content());
+ $this->seeJsonEquals(["dateminmax" => [0, 0]]);
+ }
+
+ public function testMinMaxResult() {
+
+ Es::shouldReceive('search')
+ ->once()
+ ->with($this->ES_QUERY_MINMAX)
+ ->andReturn(json_decode('{
+ "took" : 708,
+ "timed_out" : false,
+ "_shards" : {
+ "total" : 1,
+ "successful" : 1,
+ "failed" : 0
+ },
+ "hits" : {
+ "total" : 3375,
+ "max_score" : 0.0,
+ "hits" : [ ]
+ },
+ "aggregations" : {
+ "datestats" : {
+ "doc_count" : 3727,
+ "maxyear" : {
+ "value" : 2015.0
+ },
+ "minyear" : {
+ "value" : 1948.0
+ }
+ }
+ }
+ }', true));
+ $this->get('/api/v1/stats/dateminmax/')->assertTrue($this->response->isOk(), $this->response->content());
+ $this->seeJsonEquals(["dateminmax" => [ 1948, 2015 ]]);
+ }
+
}