server/src/tests/Controllers/DiscourseControllerTest.php
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--
Work on front and back integration, correct the expected data format
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
160
c77f06ff3e54 add discourse controler + fixtures
ymh <ymh.work@gmail.com>
parents:
diff changeset
     1
<?php
c77f06ff3e54 add discourse controler + fixtures
ymh <ymh.work@gmail.com>
parents:
diff changeset
     2
c77f06ff3e54 add discourse controler + fixtures
ymh <ymh.work@gmail.com>
parents:
diff changeset
     3
use Mockery as m;
c77f06ff3e54 add discourse controler + fixtures
ymh <ymh.work@gmail.com>
parents:
diff changeset
     4
c77f06ff3e54 add discourse controler + fixtures
ymh <ymh.work@gmail.com>
parents:
diff changeset
     5
use EasyRdf\Resource;
c77f06ff3e54 add discourse controler + fixtures
ymh <ymh.work@gmail.com>
parents:
diff changeset
     6
use EasyRdf\Literal;
c77f06ff3e54 add discourse controler + fixtures
ymh <ymh.work@gmail.com>
parents:
diff changeset
     7
c77f06ff3e54 add discourse controler + fixtures
ymh <ymh.work@gmail.com>
parents:
diff changeset
     8
/**
c77f06ff3e54 add discourse controler + fixtures
ymh <ymh.work@gmail.com>
parents:
diff changeset
     9
 *
c77f06ff3e54 add discourse controler + fixtures
ymh <ymh.work@gmail.com>
parents:
diff changeset
    10
 */
c77f06ff3e54 add discourse controler + fixtures
ymh <ymh.work@gmail.com>
parents:
diff changeset
    11
class DiscourseControllerTest extends TestCase {
c77f06ff3e54 add discourse controler + fixtures
ymh <ymh.work@gmail.com>
parents:
diff changeset
    12
c77f06ff3e54 add discourse controler + fixtures
ymh <ymh.work@gmail.com>
parents:
diff changeset
    13
    private $sparqlClient;
c77f06ff3e54 add discourse controler + fixtures
ymh <ymh.work@gmail.com>
parents:
diff changeset
    14
c77f06ff3e54 add discourse controler + fixtures
ymh <ymh.work@gmail.com>
parents:
diff changeset
    15
    public function setUp() {
c77f06ff3e54 add discourse controler + fixtures
ymh <ymh.work@gmail.com>
parents:
diff changeset
    16
c77f06ff3e54 add discourse controler + fixtures
ymh <ymh.work@gmail.com>
parents:
diff changeset
    17
        parent::setup();
c77f06ff3e54 add discourse controler + fixtures
ymh <ymh.work@gmail.com>
parents:
diff changeset
    18
c77f06ff3e54 add discourse controler + fixtures
ymh <ymh.work@gmail.com>
parents:
diff changeset
    19
        // create a mock of the post repository interface and inject it into the
c77f06ff3e54 add discourse controler + fixtures
ymh <ymh.work@gmail.com>
parents:
diff changeset
    20
        // IoC container
c77f06ff3e54 add discourse controler + fixtures
ymh <ymh.work@gmail.com>
parents:
diff changeset
    21
        $this->sparqlClient = m::mock('CorpusParole\Libraries\Sparql\SparqlClient');
c77f06ff3e54 add discourse controler + fixtures
ymh <ymh.work@gmail.com>
parents:
diff changeset
    22
        $this->app->instance('CorpusParole\Libraries\Sparql\SparqlClient', $this->sparqlClient);
c77f06ff3e54 add discourse controler + fixtures
ymh <ymh.work@gmail.com>
parents:
diff changeset
    23
    }
c77f06ff3e54 add discourse controler + fixtures
ymh <ymh.work@gmail.com>
parents:
diff changeset
    24
c77f06ff3e54 add discourse controler + fixtures
ymh <ymh.work@gmail.com>
parents:
diff changeset
    25
    public function tearDown() {
c77f06ff3e54 add discourse controler + fixtures
ymh <ymh.work@gmail.com>
parents:
diff changeset
    26
        m::close();
c77f06ff3e54 add discourse controler + fixtures
ymh <ymh.work@gmail.com>
parents:
diff changeset
    27
        parent::tearDown();
c77f06ff3e54 add discourse controler + fixtures
ymh <ymh.work@gmail.com>
parents:
diff changeset
    28
    }
c77f06ff3e54 add discourse controler + fixtures
ymh <ymh.work@gmail.com>
parents:
diff changeset
    29
c77f06ff3e54 add discourse controler + fixtures
ymh <ymh.work@gmail.com>
parents:
diff changeset
    30
    public function testIndexQuery() {
c77f06ff3e54 add discourse controler + fixtures
ymh <ymh.work@gmail.com>
parents:
diff changeset
    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
c77f06ff3e54 add discourse controler + fixtures
ymh <ymh.work@gmail.com>
parents:
diff changeset
    33
            ?s a <http://www.europeana.eu/schemas/edm/ProvidedCHO>.
c77f06ff3e54 add discourse controler + fixtures
ymh <ymh.work@gmail.com>
parents:
diff changeset
    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
c77f06ff3e54 add discourse controler + fixtures
ymh <ymh.work@gmail.com>
parents:
diff changeset
    36
        }
c77f06ff3e54 add discourse controler + fixtures
ymh <ymh.work@gmail.com>
parents:
diff changeset
    37
        GROUP BY ?o
c77f06ff3e54 add discourse controler + fixtures
ymh <ymh.work@gmail.com>
parents:
diff changeset
    38
        ORDER BY DESC(?count)");
c77f06ff3e54 add discourse controler + fixtures
ymh <ymh.work@gmail.com>
parents:
diff changeset
    39
c77f06ff3e54 add discourse controler + fixtures
ymh <ymh.work@gmail.com>
parents:
diff changeset
    40
        $this->sparqlClient
c77f06ff3e54 add discourse controler + fixtures
ymh <ymh.work@gmail.com>
parents:
diff changeset
    41
            ->shouldReceive('query')
c77f06ff3e54 add discourse controler + fixtures
ymh <ymh.work@gmail.com>
parents:
diff changeset
    42
            ->with($query)
c77f06ff3e54 add discourse controler + fixtures
ymh <ymh.work@gmail.com>
parents:
diff changeset
    43
            ->once()
c77f06ff3e54 add discourse controler + fixtures
ymh <ymh.work@gmail.com>
parents:
diff changeset
    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
c77f06ff3e54 add discourse controler + fixtures
ymh <ymh.work@gmail.com>
parents:
diff changeset
    46
    }
c77f06ff3e54 add discourse controler + fixtures
ymh <ymh.work@gmail.com>
parents:
diff changeset
    47
c77f06ff3e54 add discourse controler + fixtures
ymh <ymh.work@gmail.com>
parents:
diff changeset
    48
    public function testIndex() {
c77f06ff3e54 add discourse controler + fixtures
ymh <ymh.work@gmail.com>
parents:
diff changeset
    49
c77f06ff3e54 add discourse controler + fixtures
ymh <ymh.work@gmail.com>
parents:
diff changeset
    50
        $this->sparqlClient
c77f06ff3e54 add discourse controler + fixtures
ymh <ymh.work@gmail.com>
parents:
diff changeset
    51
            ->shouldReceive('query')
c77f06ff3e54 add discourse controler + fixtures
ymh <ymh.work@gmail.com>
parents:
diff changeset
    52
            ->once()
c77f06ff3e54 add discourse controler + fixtures
ymh <ymh.work@gmail.com>
parents:
diff changeset
    53
            ->andReturn(new \ArrayIterator([
c77f06ff3e54 add discourse controler + fixtures
ymh <ymh.work@gmail.com>
parents:
diff changeset
    54
                (object)['res'=>new Resource('http://ark.bnf.fr/ark:/12148/cb12083158d'), 'count' => Literal::create(44)],
c77f06ff3e54 add discourse controler + fixtures
ymh <ymh.work@gmail.com>
parents:
diff changeset
    55
                (object)['res'=>new Resource('http://ark.bnf.fr/ark:/12148/cb119783362'), 'count' => Literal::create(33)],
c77f06ff3e54 add discourse controler + fixtures
ymh <ymh.work@gmail.com>
parents:
diff changeset
    56
                (object)['res'=>new Resource('http://ark.bnf.fr/ark:/12148/cb13319048g'), 'count' => Literal::create(22)],
c77f06ff3e54 add discourse controler + fixtures
ymh <ymh.work@gmail.com>
parents:
diff changeset
    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
c77f06ff3e54 add discourse controler + fixtures
ymh <ymh.work@gmail.com>
parents:
diff changeset
    59
        $this->seeJsonEquals(["discourses" => [
c77f06ff3e54 add discourse controler + fixtures
ymh <ymh.work@gmail.com>
parents:
diff changeset
    60
            "http://ark.bnf.fr/ark:/12148/cb12083158d" => ["label" => "argumentation", "count" => 44],
c77f06ff3e54 add discourse controler + fixtures
ymh <ymh.work@gmail.com>
parents:
diff changeset
    61
            "http://ark.bnf.fr/ark:/12148/cb119783362" => ["label" => "bavardage", "count" => 33],
c77f06ff3e54 add discourse controler + fixtures
ymh <ymh.work@gmail.com>
parents:
diff changeset
    62
            "http://ark.bnf.fr/ark:/12148/cb13319048g" => ["label" => "chansons", "count" => 22],
c77f06ff3e54 add discourse controler + fixtures
ymh <ymh.work@gmail.com>
parents:
diff changeset
    63
        ]]);
c77f06ff3e54 add discourse controler + fixtures
ymh <ymh.work@gmail.com>
parents:
diff changeset
    64
    }
c77f06ff3e54 add discourse controler + fixtures
ymh <ymh.work@gmail.com>
parents:
diff changeset
    65
}