author | ymh <ymh.work@gmail.com> |
Mon, 12 Jun 2017 14:53:59 +0200 | |
changeset 537 | d2e6ee099125 |
parent 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 |
||
407
2dba812c7ef2
add a way to build rpm for puppet files, correct elasticsearch provisioning, correct error on elasticsearch queries + tests
ymh <ymh.work@gmail.com>
parents:
377
diff
changeset
|
10 |
private $ES_QUERY; |
2dba812c7ef2
add a way to build rpm for puppet files, correct elasticsearch provisioning, correct error on elasticsearch queries + tests
ymh <ymh.work@gmail.com>
parents:
377
diff
changeset
|
11 |
|
2dba812c7ef2
add a way to build rpm for puppet files, correct elasticsearch provisioning, correct error on elasticsearch queries + tests
ymh <ymh.work@gmail.com>
parents:
377
diff
changeset
|
12 |
public function setUp() { |
2dba812c7ef2
add a way to build rpm for puppet files, correct elasticsearch provisioning, correct error on elasticsearch queries + tests
ymh <ymh.work@gmail.com>
parents:
377
diff
changeset
|
13 |
$this->ES_QUERY = [ |
2dba812c7ef2
add a way to build rpm for puppet files, correct elasticsearch provisioning, correct error on elasticsearch queries + tests
ymh <ymh.work@gmail.com>
parents:
377
diff
changeset
|
14 |
'index' => 'corpus', |
2dba812c7ef2
add a way to build rpm for puppet files, correct elasticsearch provisioning, correct error on elasticsearch queries + tests
ymh <ymh.work@gmail.com>
parents:
377
diff
changeset
|
15 |
'body' => [ |
2dba812c7ef2
add a way to build rpm for puppet files, correct elasticsearch provisioning, correct error on elasticsearch queries + tests
ymh <ymh.work@gmail.com>
parents:
377
diff
changeset
|
16 |
"size" => 0, |
2dba812c7ef2
add a way to build rpm for puppet files, correct elasticsearch provisioning, correct error on elasticsearch queries + tests
ymh <ymh.work@gmail.com>
parents:
377
diff
changeset
|
17 |
"query" => [ "match_all" => (object) null ], |
2dba812c7ef2
add a way to build rpm for puppet files, correct elasticsearch provisioning, correct error on elasticsearch queries + tests
ymh <ymh.work@gmail.com>
parents:
377
diff
changeset
|
18 |
"aggs" => [ |
2dba812c7ef2
add a way to build rpm for puppet files, correct elasticsearch provisioning, correct error on elasticsearch queries + tests
ymh <ymh.work@gmail.com>
parents:
377
diff
changeset
|
19 |
"discourses" => [ |
2dba812c7ef2
add a way to build rpm for puppet files, correct elasticsearch provisioning, correct error on elasticsearch queries + tests
ymh <ymh.work@gmail.com>
parents:
377
diff
changeset
|
20 |
"terms" => [ "field" => "discourse_types", "order" => [ "_count" => "desc" ], "size" => 2147483647 ] |
2dba812c7ef2
add a way to build rpm for puppet files, correct elasticsearch provisioning, correct error on elasticsearch queries + tests
ymh <ymh.work@gmail.com>
parents:
377
diff
changeset
|
21 |
] |
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
|
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
|
23 |
] |
407
2dba812c7ef2
add a way to build rpm for puppet files, correct elasticsearch provisioning, correct error on elasticsearch queries + tests
ymh <ymh.work@gmail.com>
parents:
377
diff
changeset
|
24 |
]; |
160 | 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() |
407
2dba812c7ef2
add a way to build rpm for puppet files, correct elasticsearch provisioning, correct error on elasticsearch queries + tests
ymh <ymh.work@gmail.com>
parents:
377
diff
changeset
|
38 |
->with($this->ES_QUERY) |
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
|
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 |
|
537
d2e6ee099125
upgrade ember + laravel + make everything work
ymh <ymh.work@gmail.com>
parents:
407
diff
changeset
|
70 |
$response = $this->get('/api/v1/stats/discourses/'); |
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 |
|
537
d2e6ee099125
upgrade ember + laravel + make everything work
ymh <ymh.work@gmail.com>
parents:
407
diff
changeset
|
72 |
$response |
d2e6ee099125
upgrade ember + laravel + make everything work
ymh <ymh.work@gmail.com>
parents:
407
diff
changeset
|
73 |
->assertStatus(200) |
d2e6ee099125
upgrade ember + laravel + make everything work
ymh <ymh.work@gmail.com>
parents:
407
diff
changeset
|
74 |
->assertJson(["discourses" => [ |
160 | 75 |
"http://ark.bnf.fr/ark:/12148/cb12083158d" => ["label" => "argumentation", "count" => 44], |
76 |
"http://ark.bnf.fr/ark:/12148/cb119783362" => ["label" => "bavardage", "count" => 33], |
|
77 |
"http://ark.bnf.fr/ark:/12148/cb13319048g" => ["label" => "chansons", "count" => 22], |
|
78 |
]]); |
|
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
|
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 |
} |
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 |
|
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 |
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
|
83 |
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
|
84 |
->once() |
407
2dba812c7ef2
add a way to build rpm for puppet files, correct elasticsearch provisioning, correct error on elasticsearch queries + tests
ymh <ymh.work@gmail.com>
parents:
377
diff
changeset
|
85 |
->with($this->ES_QUERY) |
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
|
86 |
->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
|
87 |
"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
|
88 |
"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
|
89 |
"_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
|
90 |
"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
|
91 |
"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
|
92 |
"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
|
93 |
}, |
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 |
"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
|
95 |
"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
|
96 |
"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
|
97 |
"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
|
98 |
}, |
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 |
"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
|
100 |
"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
|
101 |
"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
|
102 |
"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
|
103 |
"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
|
104 |
} |
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 |
} |
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 |
}', true)); |
537
d2e6ee099125
upgrade ember + laravel + make everything work
ymh <ymh.work@gmail.com>
parents:
407
diff
changeset
|
107 |
$response = $this->get('/api/v1/stats/discourses/'); |
d2e6ee099125
upgrade ember + laravel + make everything work
ymh <ymh.work@gmail.com>
parents:
407
diff
changeset
|
108 |
$response |
d2e6ee099125
upgrade ember + laravel + make everything work
ymh <ymh.work@gmail.com>
parents:
407
diff
changeset
|
109 |
->assertStatus(200) |
d2e6ee099125
upgrade ember + laravel + make everything work
ymh <ymh.work@gmail.com>
parents:
407
diff
changeset
|
110 |
->assertJson(["discourses" => [ |
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
|
111 |
]]); |
160 | 112 |
} |
113 |
} |