author | ymh <ymh.work@gmail.com> |
Wed, 09 Nov 2016 15:05:41 +0100 | |
changeset 406 | cf0f23803a53 |
parent 377 | 52169c718513 |
child 407 | 2dba812c7ef2 |
permissions | -rw-r--r-- |
160 | 1 |
<?php |
2 |
||
3 |
use Mockery as m; |
|
4 |
||
5 |
/** |
|
6 |
* |
|
7 |
*/ |
|
8 |
class DiscourseControllerTest extends TestCase { |
|
9 |
||
377
52169c718513
make all stats view use elasticsearch. Make sure that the document discourse types are taken form the predefined list
ymh <ymh.work@gmail.com>
parents:
319
diff
changeset
|
10 |
const ES_QUERY = [ |
52169c718513
make all stats view use elasticsearch. Make sure that the document discourse types are taken form the predefined list
ymh <ymh.work@gmail.com>
parents:
319
diff
changeset
|
11 |
'index' => 'corpus', |
52169c718513
make all stats view use elasticsearch. Make sure that the document discourse types are taken form the predefined list
ymh <ymh.work@gmail.com>
parents:
319
diff
changeset
|
12 |
'body' => [ |
52169c718513
make all stats view use elasticsearch. Make sure that the document discourse types are taken form the predefined list
ymh <ymh.work@gmail.com>
parents:
319
diff
changeset
|
13 |
"size" => 0, |
52169c718513
make all stats view use elasticsearch. Make sure that the document discourse types are taken form the predefined list
ymh <ymh.work@gmail.com>
parents:
319
diff
changeset
|
14 |
"query" => [ "match_all" => [] ], |
52169c718513
make all stats view use elasticsearch. Make sure that the document discourse types are taken form the predefined list
ymh <ymh.work@gmail.com>
parents:
319
diff
changeset
|
15 |
"aggs" => [ |
52169c718513
make all stats view use elasticsearch. Make sure that the document discourse types are taken form the predefined list
ymh <ymh.work@gmail.com>
parents:
319
diff
changeset
|
16 |
"discourses" => [ |
52169c718513
make all stats view use elasticsearch. Make sure that the document discourse types are taken form the predefined list
ymh <ymh.work@gmail.com>
parents:
319
diff
changeset
|
17 |
"terms" => [ "field" => "discourse_types", "order" => [ "_count" => "desc" ], "size" => 0 ] |
52169c718513
make all stats view use elasticsearch. Make sure that the document discourse types are taken form the predefined list
ymh <ymh.work@gmail.com>
parents:
319
diff
changeset
|
18 |
] |
52169c718513
make all stats view use elasticsearch. Make sure that the document discourse types are taken form the predefined list
ymh <ymh.work@gmail.com>
parents:
319
diff
changeset
|
19 |
] |
52169c718513
make all stats view use elasticsearch. Make sure that the document discourse types are taken form the predefined list
ymh <ymh.work@gmail.com>
parents:
319
diff
changeset
|
20 |
] |
52169c718513
make all stats view use elasticsearch. Make sure that the document discourse types are taken form the predefined list
ymh <ymh.work@gmail.com>
parents:
319
diff
changeset
|
21 |
]; |
160 | 22 |
|
23 |
public function setUp() { |
|
24 |
||
25 |
parent::setup(); |
|
26 |
||
27 |
} |
|
28 |
||
29 |
public function tearDown() { |
|
30 |
m::close(); |
|
31 |
parent::tearDown(); |
|
32 |
} |
|
33 |
||
34 |
public function testIndex() { |
|
35 |
||
377
52169c718513
make all stats view use elasticsearch. Make sure that the document discourse types are taken form the predefined list
ymh <ymh.work@gmail.com>
parents:
319
diff
changeset
|
36 |
Es::shouldReceive('search') |
52169c718513
make all stats view use elasticsearch. Make sure that the document discourse types are taken form the predefined list
ymh <ymh.work@gmail.com>
parents:
319
diff
changeset
|
37 |
->once() |
52169c718513
make all stats view use elasticsearch. Make sure that the document discourse types are taken form the predefined list
ymh <ymh.work@gmail.com>
parents:
319
diff
changeset
|
38 |
->with(self::ES_QUERY) |
52169c718513
make all stats view use elasticsearch. Make sure that the document discourse types are taken form the predefined list
ymh <ymh.work@gmail.com>
parents:
319
diff
changeset
|
39 |
->andReturn(json_decode('{ |
52169c718513
make all stats view use elasticsearch. Make sure that the document discourse types are taken form the predefined list
ymh <ymh.work@gmail.com>
parents:
319
diff
changeset
|
40 |
"took" : 116, |
52169c718513
make all stats view use elasticsearch. Make sure that the document discourse types are taken form the predefined list
ymh <ymh.work@gmail.com>
parents:
319
diff
changeset
|
41 |
"timed_out" : false, |
52169c718513
make all stats view use elasticsearch. Make sure that the document discourse types are taken form the predefined list
ymh <ymh.work@gmail.com>
parents:
319
diff
changeset
|
42 |
"_shards" : { |
52169c718513
make all stats view use elasticsearch. Make sure that the document discourse types are taken form the predefined list
ymh <ymh.work@gmail.com>
parents:
319
diff
changeset
|
43 |
"total" : 1, |
52169c718513
make all stats view use elasticsearch. Make sure that the document discourse types are taken form the predefined list
ymh <ymh.work@gmail.com>
parents:
319
diff
changeset
|
44 |
"successful" : 1, |
52169c718513
make all stats view use elasticsearch. Make sure that the document discourse types are taken form the predefined list
ymh <ymh.work@gmail.com>
parents:
319
diff
changeset
|
45 |
"failed" : 0 |
52169c718513
make all stats view use elasticsearch. Make sure that the document discourse types are taken form the predefined list
ymh <ymh.work@gmail.com>
parents:
319
diff
changeset
|
46 |
}, |
52169c718513
make all stats view use elasticsearch. Make sure that the document discourse types are taken form the predefined list
ymh <ymh.work@gmail.com>
parents:
319
diff
changeset
|
47 |
"hits" : { |
52169c718513
make all stats view use elasticsearch. Make sure that the document discourse types are taken form the predefined list
ymh <ymh.work@gmail.com>
parents:
319
diff
changeset
|
48 |
"total" : 3373, |
52169c718513
make all stats view use elasticsearch. Make sure that the document discourse types are taken form the predefined list
ymh <ymh.work@gmail.com>
parents:
319
diff
changeset
|
49 |
"max_score" : 0.0, |
52169c718513
make all stats view use elasticsearch. Make sure that the document discourse types are taken form the predefined list
ymh <ymh.work@gmail.com>
parents:
319
diff
changeset
|
50 |
"hits" : [ ] |
52169c718513
make all stats view use elasticsearch. Make sure that the document discourse types are taken form the predefined list
ymh <ymh.work@gmail.com>
parents:
319
diff
changeset
|
51 |
}, |
52169c718513
make all stats view use elasticsearch. Make sure that the document discourse types are taken form the predefined list
ymh <ymh.work@gmail.com>
parents:
319
diff
changeset
|
52 |
"aggregations" : { |
52169c718513
make all stats view use elasticsearch. Make sure that the document discourse types are taken form the predefined list
ymh <ymh.work@gmail.com>
parents:
319
diff
changeset
|
53 |
"discourses" : { |
52169c718513
make all stats view use elasticsearch. Make sure that the document discourse types are taken form the predefined list
ymh <ymh.work@gmail.com>
parents:
319
diff
changeset
|
54 |
"doc_count_error_upper_bound" : 0, |
52169c718513
make all stats view use elasticsearch. Make sure that the document discourse types are taken form the predefined list
ymh <ymh.work@gmail.com>
parents:
319
diff
changeset
|
55 |
"sum_other_doc_count" : 0, |
52169c718513
make all stats view use elasticsearch. Make sure that the document discourse types are taken form the predefined list
ymh <ymh.work@gmail.com>
parents:
319
diff
changeset
|
56 |
"buckets" : [ { |
52169c718513
make all stats view use elasticsearch. Make sure that the document discourse types are taken form the predefined list
ymh <ymh.work@gmail.com>
parents:
319
diff
changeset
|
57 |
"key" : "http://ark.bnf.fr/ark:/12148/cb12083158d", |
52169c718513
make all stats view use elasticsearch. Make sure that the document discourse types are taken form the predefined list
ymh <ymh.work@gmail.com>
parents:
319
diff
changeset
|
58 |
"doc_count" : 44 |
52169c718513
make all stats view use elasticsearch. Make sure that the document discourse types are taken form the predefined list
ymh <ymh.work@gmail.com>
parents:
319
diff
changeset
|
59 |
}, { |
52169c718513
make all stats view use elasticsearch. Make sure that the document discourse types are taken form the predefined list
ymh <ymh.work@gmail.com>
parents:
319
diff
changeset
|
60 |
"key" : "http://ark.bnf.fr/ark:/12148/cb119783362", |
52169c718513
make all stats view use elasticsearch. Make sure that the document discourse types are taken form the predefined list
ymh <ymh.work@gmail.com>
parents:
319
diff
changeset
|
61 |
"doc_count" : 33 |
52169c718513
make all stats view use elasticsearch. Make sure that the document discourse types are taken form the predefined list
ymh <ymh.work@gmail.com>
parents:
319
diff
changeset
|
62 |
}, { |
52169c718513
make all stats view use elasticsearch. Make sure that the document discourse types are taken form the predefined list
ymh <ymh.work@gmail.com>
parents:
319
diff
changeset
|
63 |
"key" : "http://ark.bnf.fr/ark:/12148/cb13319048g", |
52169c718513
make all stats view use elasticsearch. Make sure that the document discourse types are taken form the predefined list
ymh <ymh.work@gmail.com>
parents:
319
diff
changeset
|
64 |
"doc_count" : 22 |
52169c718513
make all stats view use elasticsearch. Make sure that the document discourse types are taken form the predefined list
ymh <ymh.work@gmail.com>
parents:
319
diff
changeset
|
65 |
} ] |
52169c718513
make all stats view use elasticsearch. Make sure that the document discourse types are taken form the predefined list
ymh <ymh.work@gmail.com>
parents:
319
diff
changeset
|
66 |
} |
52169c718513
make all stats view use elasticsearch. Make sure that the document discourse types are taken form the predefined list
ymh <ymh.work@gmail.com>
parents:
319
diff
changeset
|
67 |
} |
52169c718513
make all stats view use elasticsearch. Make sure that the document discourse types are taken form the predefined list
ymh <ymh.work@gmail.com>
parents:
319
diff
changeset
|
68 |
}', true)); |
52169c718513
make all stats view use elasticsearch. Make sure that the document discourse types are taken form the predefined list
ymh <ymh.work@gmail.com>
parents:
319
diff
changeset
|
69 |
|
306
3fccf43160a7
Some more changes linked to the change of api organization + some jshint error cleaning
ymh <ymh.work@gmail.com>
parents:
160
diff
changeset
|
70 |
$this->get('/api/v1/stats/discourses/')->assertTrue($this->response->isOk(), $this->response->content()); |
377
52169c718513
make all stats view use elasticsearch. Make sure that the document discourse types are taken form the predefined list
ymh <ymh.work@gmail.com>
parents:
319
diff
changeset
|
71 |
|
160 | 72 |
$this->seeJsonEquals(["discourses" => [ |
73 |
"http://ark.bnf.fr/ark:/12148/cb12083158d" => ["label" => "argumentation", "count" => 44], |
|
74 |
"http://ark.bnf.fr/ark:/12148/cb119783362" => ["label" => "bavardage", "count" => 33], |
|
75 |
"http://ark.bnf.fr/ark:/12148/cb13319048g" => ["label" => "chansons", "count" => 22], |
|
76 |
]]); |
|
377
52169c718513
make all stats view use elasticsearch. Make sure that the document discourse types are taken form the predefined list
ymh <ymh.work@gmail.com>
parents:
319
diff
changeset
|
77 |
|
52169c718513
make all stats view use elasticsearch. Make sure that the document discourse types are taken form the predefined list
ymh <ymh.work@gmail.com>
parents:
319
diff
changeset
|
78 |
} |
52169c718513
make all stats view use elasticsearch. Make sure that the document discourse types are taken form the predefined list
ymh <ymh.work@gmail.com>
parents:
319
diff
changeset
|
79 |
|
52169c718513
make all stats view use elasticsearch. Make sure that the document discourse types are taken form the predefined list
ymh <ymh.work@gmail.com>
parents:
319
diff
changeset
|
80 |
public function testIndexQuery() { |
52169c718513
make all stats view use elasticsearch. Make sure that the document discourse types are taken form the predefined list
ymh <ymh.work@gmail.com>
parents:
319
diff
changeset
|
81 |
Es::shouldReceive('search') |
52169c718513
make all stats view use elasticsearch. Make sure that the document discourse types are taken form the predefined list
ymh <ymh.work@gmail.com>
parents:
319
diff
changeset
|
82 |
->once() |
52169c718513
make all stats view use elasticsearch. Make sure that the document discourse types are taken form the predefined list
ymh <ymh.work@gmail.com>
parents:
319
diff
changeset
|
83 |
->with(self::ES_QUERY) |
52169c718513
make all stats view use elasticsearch. Make sure that the document discourse types are taken form the predefined list
ymh <ymh.work@gmail.com>
parents:
319
diff
changeset
|
84 |
->andReturn(json_decode('{ |
52169c718513
make all stats view use elasticsearch. Make sure that the document discourse types are taken form the predefined list
ymh <ymh.work@gmail.com>
parents:
319
diff
changeset
|
85 |
"took" : 116, |
52169c718513
make all stats view use elasticsearch. Make sure that the document discourse types are taken form the predefined list
ymh <ymh.work@gmail.com>
parents:
319
diff
changeset
|
86 |
"timed_out" : false, |
52169c718513
make all stats view use elasticsearch. Make sure that the document discourse types are taken form the predefined list
ymh <ymh.work@gmail.com>
parents:
319
diff
changeset
|
87 |
"_shards" : { |
52169c718513
make all stats view use elasticsearch. Make sure that the document discourse types are taken form the predefined list
ymh <ymh.work@gmail.com>
parents:
319
diff
changeset
|
88 |
"total" : 1, |
52169c718513
make all stats view use elasticsearch. Make sure that the document discourse types are taken form the predefined list
ymh <ymh.work@gmail.com>
parents:
319
diff
changeset
|
89 |
"successful" : 1, |
52169c718513
make all stats view use elasticsearch. Make sure that the document discourse types are taken form the predefined list
ymh <ymh.work@gmail.com>
parents:
319
diff
changeset
|
90 |
"failed" : 0 |
52169c718513
make all stats view use elasticsearch. Make sure that the document discourse types are taken form the predefined list
ymh <ymh.work@gmail.com>
parents:
319
diff
changeset
|
91 |
}, |
52169c718513
make all stats view use elasticsearch. Make sure that the document discourse types are taken form the predefined list
ymh <ymh.work@gmail.com>
parents:
319
diff
changeset
|
92 |
"hits" : { |
52169c718513
make all stats view use elasticsearch. Make sure that the document discourse types are taken form the predefined list
ymh <ymh.work@gmail.com>
parents:
319
diff
changeset
|
93 |
"total" : 3373, |
52169c718513
make all stats view use elasticsearch. Make sure that the document discourse types are taken form the predefined list
ymh <ymh.work@gmail.com>
parents:
319
diff
changeset
|
94 |
"max_score" : 0.0, |
52169c718513
make all stats view use elasticsearch. Make sure that the document discourse types are taken form the predefined list
ymh <ymh.work@gmail.com>
parents:
319
diff
changeset
|
95 |
"hits" : [ ] |
52169c718513
make all stats view use elasticsearch. Make sure that the document discourse types are taken form the predefined list
ymh <ymh.work@gmail.com>
parents:
319
diff
changeset
|
96 |
}, |
52169c718513
make all stats view use elasticsearch. Make sure that the document discourse types are taken form the predefined list
ymh <ymh.work@gmail.com>
parents:
319
diff
changeset
|
97 |
"aggregations" : { |
52169c718513
make all stats view use elasticsearch. Make sure that the document discourse types are taken form the predefined list
ymh <ymh.work@gmail.com>
parents:
319
diff
changeset
|
98 |
"discourses" : { |
52169c718513
make all stats view use elasticsearch. Make sure that the document discourse types are taken form the predefined list
ymh <ymh.work@gmail.com>
parents:
319
diff
changeset
|
99 |
"doc_count_error_upper_bound" : 0, |
52169c718513
make all stats view use elasticsearch. Make sure that the document discourse types are taken form the predefined list
ymh <ymh.work@gmail.com>
parents:
319
diff
changeset
|
100 |
"sum_other_doc_count" : 0, |
52169c718513
make all stats view use elasticsearch. Make sure that the document discourse types are taken form the predefined list
ymh <ymh.work@gmail.com>
parents:
319
diff
changeset
|
101 |
"buckets" : [ ] |
52169c718513
make all stats view use elasticsearch. Make sure that the document discourse types are taken form the predefined list
ymh <ymh.work@gmail.com>
parents:
319
diff
changeset
|
102 |
} |
52169c718513
make all stats view use elasticsearch. Make sure that the document discourse types are taken form the predefined list
ymh <ymh.work@gmail.com>
parents:
319
diff
changeset
|
103 |
} |
52169c718513
make all stats view use elasticsearch. Make sure that the document discourse types are taken form the predefined list
ymh <ymh.work@gmail.com>
parents:
319
diff
changeset
|
104 |
}', true)); |
52169c718513
make all stats view use elasticsearch. Make sure that the document discourse types are taken form the predefined list
ymh <ymh.work@gmail.com>
parents:
319
diff
changeset
|
105 |
$this->get('/api/v1/stats/discourses/')->assertTrue($this->response->isOk(), $this->response->content()); |
52169c718513
make all stats view use elasticsearch. Make sure that the document discourse types are taken form the predefined list
ymh <ymh.work@gmail.com>
parents:
319
diff
changeset
|
106 |
$this->seeJsonEquals(["discourses" => [ |
52169c718513
make all stats view use elasticsearch. Make sure that the document discourse types are taken form the predefined list
ymh <ymh.work@gmail.com>
parents:
319
diff
changeset
|
107 |
]]); |
160 | 108 |
} |
109 |
} |