server/src/tests/Controllers/ThemeControllerTest.php
changeset 306 3fccf43160a7
parent 160 c77f06ff3e54
child 322 084aae09edf4
equal deleted inserted replaced
305:ff6cf3fc5f40 306:3fccf43160a7
    40         $this->sparqlClient
    40         $this->sparqlClient
    41             ->shouldReceive('query')
    41             ->shouldReceive('query')
    42             ->with($query)
    42             ->with($query)
    43             ->once()
    43             ->once()
    44             ->andReturn(new \ArrayIterator([]));
    44             ->andReturn(new \ArrayIterator([]));
    45         $this->get('/api/v1/themes/');
    45         $this->get('/api/v1/stats/themes/');
    46     }
    46     }
    47 
    47 
    48     public function testIndexQueryBnf() {
    48     public function testIndexQueryBnf() {
    49 
    49 
    50         $query = preg_replace('/\s+/', ' ', "select (?o as ?theme) (COUNT(?s) as ?count) where {
    50         $query = preg_replace('/\s+/', ' ', "select (?o as ?theme) (COUNT(?s) as ?count) where {
    58         $this->sparqlClient
    58         $this->sparqlClient
    59             ->shouldReceive('query')
    59             ->shouldReceive('query')
    60             ->with($query)
    60             ->with($query)
    61             ->once()
    61             ->once()
    62             ->andReturn(new \ArrayIterator([]));
    62             ->andReturn(new \ArrayIterator([]));
    63         $this->get('/api/v1/themes/?filter=bnf');
    63         $this->get('/api/v1/stats/themes/?filter=bnf');
    64     }
    64     }
    65 
    65 
    66 
    66 
    67     public function testIndexQueryAll() {
    67     public function testIndexQueryAll() {
    68 
    68 
    76         $this->sparqlClient
    76         $this->sparqlClient
    77             ->shouldReceive('query')
    77             ->shouldReceive('query')
    78             ->with($query)
    78             ->with($query)
    79             ->once()
    79             ->once()
    80             ->andReturn(new \ArrayIterator([]));
    80             ->andReturn(new \ArrayIterator([]));
    81         $this->get('/api/v1/themes/?filter=all');
    81         $this->get('/api/v1/stats/themes/?filter=all');
    82     }
    82     }
    83 
    83 
    84 
    84 
    85     public function testIndexQueryNone() {
    85     public function testIndexQueryNone() {
    86 
    86 
    94         $this->sparqlClient
    94         $this->sparqlClient
    95             ->shouldReceive('query')
    95             ->shouldReceive('query')
    96             ->with($query)
    96             ->with($query)
    97             ->once()
    97             ->once()
    98             ->andReturn(new \ArrayIterator([]));
    98             ->andReturn(new \ArrayIterator([]));
    99         $this->get('/api/v1/themes/?filter=none');
    99         $this->get('/api/v1/stats/themes/?filter=none');
   100     }
   100     }
   101 
   101 
   102 
   102 
   103     public function testIndexQueryEmpty() {
   103     public function testIndexQueryEmpty() {
   104 
   104 
   112         $this->sparqlClient
   112         $this->sparqlClient
   113             ->shouldReceive('query')
   113             ->shouldReceive('query')
   114             ->with($query)
   114             ->with($query)
   115             ->once()
   115             ->once()
   116             ->andReturn(new \ArrayIterator([]));
   116             ->andReturn(new \ArrayIterator([]));
   117         $this->get('/api/v1/themes/?filter=');
   117         $this->get('/api/v1/stats/themes/?filter=');
   118     }
   118     }
   119 
   119 
   120     public function testIndexQueryUri() {
   120     public function testIndexQueryUri() {
   121 
   121 
   122         $query = preg_replace('/\s+/', ' ', "select (?o as ?theme) (COUNT(?s) as ?count) where {
   122         $query = preg_replace('/\s+/', ' ', "select (?o as ?theme) (COUNT(?s) as ?count) where {
   130         $this->sparqlClient
   130         $this->sparqlClient
   131             ->shouldReceive('query')
   131             ->shouldReceive('query')
   132             ->with($query)
   132             ->with($query)
   133             ->once()
   133             ->once()
   134             ->andReturn(new \ArrayIterator([]));
   134             ->andReturn(new \ArrayIterator([]));
   135         $this->get('/api/v1/themes/?filter=uri');
   135         $this->get('/api/v1/stats/themes/?filter=uri');
   136     }
   136     }
   137 
   137 
   138 
   138 
   139     public function testIndex() {
   139     public function testIndex() {
   140 
   140 
   144             ->andReturn(new \ArrayIterator([
   144             ->andReturn(new \ArrayIterator([
   145                 (object)['theme'=>new Resource('http://lexvo.org/id/iso639-3/gsw'), 'count' => Literal::create(44)],
   145                 (object)['theme'=>new Resource('http://lexvo.org/id/iso639-3/gsw'), 'count' => Literal::create(44)],
   146                 (object)['theme'=>new Resource('http://ark.bnf.fr/ark:/12148/cb119339867'), 'count' => Literal::create(33)],
   146                 (object)['theme'=>new Resource('http://ark.bnf.fr/ark:/12148/cb119339867'), 'count' => Literal::create(33)],
   147                 (object)['theme'=>Literal::create('Français', 'fr'), 'count' => Literal::create(22)],
   147                 (object)['theme'=>Literal::create('Français', 'fr'), 'count' => Literal::create(22)],
   148             ]));
   148             ]));
   149         $this->get('/api/v1/themes/')->assertTrue($this->response->isOk(), $this->response->content());
   149         $this->get('/api/v1/stats/themes/')->assertTrue($this->response->isOk(), $this->response->content());
   150         $this->seeJsonEquals(["themes" => [
   150         $this->seeJsonEquals(["themes" => [
   151             "http://lexvo.org/id/iso639-3/gsw" => ["label" => "alémanique", "count" => 44],
   151             "http://lexvo.org/id/iso639-3/gsw" => ["label" => "alémanique", "count" => 44],
   152             "http://ark.bnf.fr/ark:/12148/cb119339867" => ["label" => "famille", "count" => 33],
   152             "http://ark.bnf.fr/ark:/12148/cb119339867" => ["label" => "famille", "count" => 33],
   153             "Français" => ["label" => "Français", "count" => 22],
   153             "Français" => ["label" => "Français", "count" => 22],
   154         ]]);
   154         ]]);