author | ymh <ymh.work@gmail.com> |
Tue, 04 Oct 2016 11:58:39 +0200 | |
changeset 319 | 78990a8a069b |
parent 306 | 3fccf43160a7 |
child 377 | 52169c718513 |
permissions | -rw-r--r-- |
160 | 1 |
<?php |
2 |
||
3 |
use Mockery as m; |
|
4 |
||
5 |
use EasyRdf\Resource; |
|
6 |
use EasyRdf\Literal; |
|
7 |
||
8 |
/** |
|
9 |
* |
|
10 |
*/ |
|
11 |
class DiscourseControllerTest extends TestCase { |
|
12 |
||
13 |
private $sparqlClient; |
|
14 |
||
15 |
public function setUp() { |
|
16 |
||
17 |
parent::setup(); |
|
18 |
||
19 |
// create a mock of the post repository interface and inject it into the |
|
20 |
// IoC container |
|
21 |
$this->sparqlClient = m::mock('CorpusParole\Libraries\Sparql\SparqlClient'); |
|
22 |
$this->app->instance('CorpusParole\Libraries\Sparql\SparqlClient', $this->sparqlClient); |
|
23 |
} |
|
24 |
||
25 |
public function tearDown() { |
|
26 |
m::close(); |
|
27 |
parent::tearDown(); |
|
28 |
} |
|
29 |
||
30 |
public function testIndexQuery() { |
|
31 |
||
319
78990a8a069b
Work on front and back integration, correct the expected data format
ymh <ymh.work@gmail.com>
parents:
306
diff
changeset
|
32 |
$query = preg_replace('/\s+/', ' ', "SELECT (?o AS ?res) (COUNT(?s) AS ?count) WHERE { |
160 | 33 |
?s a <http://www.europeana.eu/schemas/edm/ProvidedCHO>. |
34 |
?s <http://purl.org/dc/elements/1.1/type> ?o. |
|
319
78990a8a069b
Work on front and back integration, correct the expected data format
ymh <ymh.work@gmail.com>
parents:
306
diff
changeset
|
35 |
FILTER(uri(?o) in (<".implode('>,<', array_keys(config('corpusparole.corpus_discourse_type'))).">)) |
160 | 36 |
} |
37 |
GROUP BY ?o |
|
38 |
ORDER BY DESC(?count)"); |
|
39 |
||
40 |
$this->sparqlClient |
|
41 |
->shouldReceive('query') |
|
42 |
->with($query) |
|
43 |
->once() |
|
44 |
->andReturn(new \ArrayIterator([])); |
|
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
|
45 |
$this->get('/api/v1/stats/discourses/'); |
160 | 46 |
} |
47 |
||
48 |
public function testIndex() { |
|
49 |
||
50 |
$this->sparqlClient |
|
51 |
->shouldReceive('query') |
|
52 |
->once() |
|
53 |
->andReturn(new \ArrayIterator([ |
|
54 |
(object)['res'=>new Resource('http://ark.bnf.fr/ark:/12148/cb12083158d'), 'count' => Literal::create(44)], |
|
55 |
(object)['res'=>new Resource('http://ark.bnf.fr/ark:/12148/cb119783362'), 'count' => Literal::create(33)], |
|
56 |
(object)['res'=>new Resource('http://ark.bnf.fr/ark:/12148/cb13319048g'), 'count' => Literal::create(22)], |
|
57 |
])); |
|
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
|
58 |
$this->get('/api/v1/stats/discourses/')->assertTrue($this->response->isOk(), $this->response->content()); |
160 | 59 |
$this->seeJsonEquals(["discourses" => [ |
60 |
"http://ark.bnf.fr/ark:/12148/cb12083158d" => ["label" => "argumentation", "count" => 44], |
|
61 |
"http://ark.bnf.fr/ark:/12148/cb119783362" => ["label" => "bavardage", "count" => 33], |
|
62 |
"http://ark.bnf.fr/ark:/12148/cb13319048g" => ["label" => "chansons", "count" => 22], |
|
63 |
]]); |
|
64 |
} |
|
65 |
} |