diff -r 02f113d43f18 -r 52169c718513 server/src/tests/Controllers/LanguageControllerTest.php --- a/server/src/tests/Controllers/LanguageControllerTest.php Thu Oct 20 15:09:31 2016 +0200 +++ b/server/src/tests/Controllers/LanguageControllerTest.php Thu Oct 20 17:27:36 2016 +0200 @@ -11,16 +11,21 @@ */ class LanguageControllerTest extends TestCase { - private $sparqlClient; + const ES_QUERY = [ + 'index' => 'corpus', + 'body' => [ + "size" => 0, + "query" => [ "match_all" => [] ], + "aggs" => [ + "languages" => [ + "terms" => [ "field" => "language", "order" => [ "_count" => "desc" ], "size" => 0 ] + ] + ] + ] + ]; public function setUp() { - parent::setup(); - - // create a mock of the post repository interface and inject it into the - // IoC container - $this->sparqlClient = m::mock('CorpusParole\Libraries\Sparql\SparqlClient'); - $this->app->instance('CorpusParole\Libraries\Sparql\SparqlClient', $this->sparqlClient); } public function tearDown() { @@ -29,27 +34,46 @@ } public function testIndex() { - $query = "select ?lang (count(?lang) as ?count) where { - ?s a . - ?s ?lang - } - GROUP BY ?lang - ORDER BY DESC(?count)"; - $this->sparqlClient - ->shouldReceive('query') - ->with($query) - ->once() - ->andReturn(new \ArrayIterator([ - (object)['lang'=>new Resource('http://lexvo.org/id/iso639-3/gsw'), 'count' => Literal::create(44)], - (object)['lang'=>new Resource('http://lexvo.org/id/iso639-3/fra'), 'count' => Literal::create(33)], - (object)['lang'=>new Resource('http://lexvo.org/id/iso639-3/bre'), 'count' => Literal::create(22)], - ])); - $response = $this->get('/api/v1/stats/languages/')-> - seeJsonEquals(['languages' => [ - 'http://lexvo.org/id/iso639-3/gsw' => 44, - 'http://lexvo.org/id/iso639-3/fra' => 33, - 'http://lexvo.org/id/iso639-3/bre' => 22, + Es::shouldReceive('search') + ->once() + ->with(self::ES_QUERY) + ->andReturn(json_decode('{ + "took": 92, + "timed_out": false, + "_shards": { + "total": 1, + "successful": 1, + "failed": 0 + }, + "hits": { + "total": 3373, + "max_score": 0.0, + "hits": [] + }, + "aggregations": { + "languages": { + "doc_count_error_upper_bound": 0, + "sum_other_doc_count": 0, + "buckets": [{ + "key": "http://lexvo.org/id/iso639-3/fra", + "doc_count": 1669 + }, { + "key": "http://lexvo.org/id/iso639-3/gsw", + "doc_count": 851 + }, { + "key": "http://lexvo.org/id/iso639-3/bre", + "doc_count": 403 + }] + } + } +}', true)); + + $response = $this->get('/api/v1/stats/languages/')->assertTrue($this->response->isOk(), $this->response->content()); + $this->seeJsonEquals(['languages' => [ + 'http://lexvo.org/id/iso639-3/fra' => 1669, + 'http://lexvo.org/id/iso639-3/gsw' => 851, + 'http://lexvo.org/id/iso639-3/bre' => 403, ]]); } }