|
1 <?php |
|
2 |
|
3 use Mockery as m; |
|
4 |
|
5 use EasyRdf\Resource; |
|
6 use EasyRdf\Literal; |
|
7 use CorpusParole\Services\ViafResolverException; |
|
8 |
|
9 /** |
|
10 * |
|
11 */ |
|
12 class LanguageControllerTest extends TestCase { |
|
13 |
|
14 private $sparqlClient; |
|
15 |
|
16 public function setUp() { |
|
17 |
|
18 parent::setup(); |
|
19 |
|
20 // create a mock of the post repository interface and inject it into the |
|
21 // IoC container |
|
22 $this->sparqlClient = m::mock('CorpusParole\Libraries\Sparql\SparqlClient'); |
|
23 $this->app->instance('CorpusParole\Libraries\Sparql\SparqlClient', $this->sparqlClient); |
|
24 } |
|
25 |
|
26 public function tearDown() { |
|
27 m::close(); |
|
28 parent::tearDown(); |
|
29 } |
|
30 |
|
31 public function testIndex() { |
|
32 $query = "select ?lang (count(?lang) as ?count) where { |
|
33 ?s a <http://www.europeana.eu/schemas/edm/ProvidedCHO>. |
|
34 ?s <http://purl.org/dc/elements/1.1/language> ?lang |
|
35 } |
|
36 GROUP BY ?lang |
|
37 ORDER BY DESC(?count)"; |
|
38 |
|
39 $this->sparqlClient |
|
40 ->shouldReceive('query') |
|
41 ->with($query) |
|
42 ->once() |
|
43 ->andReturn(new \ArrayIterator([ |
|
44 (object)['lang'=>new Resource('http://lexvo.org/id/iso639-3/gsw'), 'count' => Literal::create(44)], |
|
45 (object)['lang'=>new Resource('http://lexvo.org/id/iso639-3/fra'), 'count' => Literal::create(33)], |
|
46 (object)['lang'=>new Resource('http://lexvo.org/id/iso639-3/bre'), 'count' => Literal::create(22)], |
|
47 ])); |
|
48 $response = $this->get('/api/v1/languages/')-> |
|
49 seeJsonEquals(['languages' => [ |
|
50 'http://lexvo.org/id/iso639-3/gsw' => 44, |
|
51 'http://lexvo.org/id/iso639-3/fra' => 33, |
|
52 'http://lexvo.org/id/iso639-3/bre' => 22, |
|
53 ]]); |
|
54 } |
|
55 } |