server/src/tests/Controllers/DiscourseControllerTest.php
changeset 160 c77f06ff3e54
child 306 3fccf43160a7
equal deleted inserted replaced
159:dd4ee1d4122c 160:c77f06ff3e54
       
     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 
       
    32         $query = preg_replace('/\s+/', ' ', "select (?o as ?res) (COUNT(?s) as ?count) where {
       
    33             ?s a <http://www.europeana.eu/schemas/edm/ProvidedCHO>.
       
    34             ?s <http://purl.org/dc/elements/1.1/type> ?o.
       
    35             filter(uri(?o) in (<".implode('>,<', array_keys(config('corpusparole.corpus_discourse_type'))).">))
       
    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([]));
       
    45         $this->get('/api/v1/discourses/');
       
    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             ]));
       
    58         $this->get('/api/v1/discourses/')->assertTrue($this->response->isOk(), $this->response->content());
       
    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 }