server/src/tests/Repositories/DocumentRepositoryIntegrationTest.php
author ymh <ymh.work@gmail.com>
Mon, 06 Feb 2017 15:22:39 +0100
changeset 500 4f507ba2bb4c
parent 405 f239c8c5bb94
permissions -rw-r--r--
add alternativeTitle. Prepare #0025746
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
4
f55970e41793 first skeleton of bo client in ember
ymh <ymh.work@gmail.com>
parents:
diff changeset
     1
<?php
f55970e41793 first skeleton of bo client in ember
ymh <ymh.work@gmail.com>
parents:
diff changeset
     2
f55970e41793 first skeleton of bo client in ember
ymh <ymh.work@gmail.com>
parents:
diff changeset
     3
use Illuminate\Support\Facades\Facade;
f55970e41793 first skeleton of bo client in ember
ymh <ymh.work@gmail.com>
parents:
diff changeset
     4
use Illuminate\Support\Facades\Config;
f55970e41793 first skeleton of bo client in ember
ymh <ymh.work@gmail.com>
parents:
diff changeset
     5
f55970e41793 first skeleton of bo client in ember
ymh <ymh.work@gmail.com>
parents:
diff changeset
     6
use CorpusParole\Repositories\DocumentRepository;
f55970e41793 first skeleton of bo client in ember
ymh <ymh.work@gmail.com>
parents:
diff changeset
     7
use CorpusParole\Repositories\RdfDocumentRepository;
f55970e41793 first skeleton of bo client in ember
ymh <ymh.work@gmail.com>
parents:
diff changeset
     8
use CorpusParole\Models\Document;
168
17f10b56c079 improve document model and propagate changes. This include the change of document fixtures to better reflect what the api is effectively returning
ymh <ymh.work@gmail.com>
parents: 143
diff changeset
     9
use CorpusParole\Models\DocumentResult;
17f10b56c079 improve document model and propagate changes. This include the change of document fixtures to better reflect what the api is effectively returning
ymh <ymh.work@gmail.com>
parents: 143
diff changeset
    10
4
f55970e41793 first skeleton of bo client in ember
ymh <ymh.work@gmail.com>
parents:
diff changeset
    11
f55970e41793 first skeleton of bo client in ember
ymh <ymh.work@gmail.com>
parents:
diff changeset
    12
use SebastianBergmann\Diff\Differ;
f55970e41793 first skeleton of bo client in ember
ymh <ymh.work@gmail.com>
parents:
diff changeset
    13
f55970e41793 first skeleton of bo client in ember
ymh <ymh.work@gmail.com>
parents:
diff changeset
    14
use GuzzleHttp\Client;
f55970e41793 first skeleton of bo client in ember
ymh <ymh.work@gmail.com>
parents:
diff changeset
    15
f55970e41793 first skeleton of bo client in ember
ymh <ymh.work@gmail.com>
parents:
diff changeset
    16
class DocumentRepositoryIntegrationTest extends TestCase {
f55970e41793 first skeleton of bo client in ember
ymh <ymh.work@gmail.com>
parents:
diff changeset
    17
277
bd4bc1db4f40 add blank node save and geoinfo to back model
ymh <ymh.work@gmail.com>
parents: 168
diff changeset
    18
    const REPO_CREATION_TTL = __DIR__.'/files/DocumentRepositoryIntegrationTest/repo_creation.ttl';
19
eadaf0b8f02e Bo conception step. back to ember page
ymh <ymh.work@gmail.com>
parents: 4
diff changeset
    19
277
bd4bc1db4f40 add blank node save and geoinfo to back model
ymh <ymh.work@gmail.com>
parents: 168
diff changeset
    20
    const TEST_DOC = __DIR__.'/files/DocumentRepositoryIntegrationTest/test_doc.ttl';
bd4bc1db4f40 add blank node save and geoinfo to back model
ymh <ymh.work@gmail.com>
parents: 168
diff changeset
    21
    const TEST_DOC_NO_GEO = __DIR__.'/files/DocumentRepositoryIntegrationTest/test_doc_no_geo.ttl';
4
f55970e41793 first skeleton of bo client in ember
ymh <ymh.work@gmail.com>
parents:
diff changeset
    22
f55970e41793 first skeleton of bo client in ember
ymh <ymh.work@gmail.com>
parents:
diff changeset
    23
    function __construct(string $name = null) {
f55970e41793 first skeleton of bo client in ember
ymh <ymh.work@gmail.com>
parents:
diff changeset
    24
        parent::__construct($name);
f55970e41793 first skeleton of bo client in ember
ymh <ymh.work@gmail.com>
parents:
diff changeset
    25
    }
f55970e41793 first skeleton of bo client in ember
ymh <ymh.work@gmail.com>
parents:
diff changeset
    26
f55970e41793 first skeleton of bo client in ember
ymh <ymh.work@gmail.com>
parents:
diff changeset
    27
    public function setUp() {
f55970e41793 first skeleton of bo client in ember
ymh <ymh.work@gmail.com>
parents:
diff changeset
    28
        parent::setUp();
277
bd4bc1db4f40 add blank node save and geoinfo to back model
ymh <ymh.work@gmail.com>
parents: 168
diff changeset
    29
        $this->graph = new EasyRdf\Graph(config('corpusparole.corpus_doc_id_base_uri')."crdo-ALA_738", sprintf(file_get_contents(DocumentRepositoryIntegrationTest::TEST_DOC), config('corpusparole.corpus_doc_id_base_uri')));
4
f55970e41793 first skeleton of bo client in ember
ymh <ymh.work@gmail.com>
parents:
diff changeset
    30
405
f239c8c5bb94 migrate to rdf4j (2.1.1) from sesame (4.1.1)
ymh <ymh.work@gmail.com>
parents: 371
diff changeset
    31
        $this->httpClient = new Client(['base_uri' => config('corpusparole.rdf4j_base_url')]);
f239c8c5bb94 migrate to rdf4j (2.1.1) from sesame (4.1.1)
ymh <ymh.work@gmail.com>
parents: 371
diff changeset
    32
        $this->rdf4jRepository = config('corpusparole.rdf4j_repository');
19
eadaf0b8f02e Bo conception step. back to ember page
ymh <ymh.work@gmail.com>
parents: 4
diff changeset
    33
        $this->corpusDocIdBaseUri = config('corpusparole.corpus_doc_id_base_uri');
4
f55970e41793 first skeleton of bo client in ember
ymh <ymh.work@gmail.com>
parents:
diff changeset
    34
f55970e41793 first skeleton of bo client in ember
ymh <ymh.work@gmail.com>
parents:
diff changeset
    35
        $this->documentRepository = $this->app->make('CorpusParole\Repositories\DocumentRepository');
f55970e41793 first skeleton of bo client in ember
ymh <ymh.work@gmail.com>
parents:
diff changeset
    36
        $uniqueid = uniqid('corpusparole', true);
405
f239c8c5bb94 migrate to rdf4j (2.1.1) from sesame (4.1.1)
ymh <ymh.work@gmail.com>
parents: 371
diff changeset
    37
        $repoCreateStmt = sprintf(file_get_contents(DocumentRepositoryIntegrationTest::REPO_CREATION_TTL), $this->rdf4jRepository);
f239c8c5bb94 migrate to rdf4j (2.1.1) from sesame (4.1.1)
ymh <ymh.work@gmail.com>
parents: 371
diff changeset
    38
        $this->httpClient->delete("repositories/$this->rdf4jRepository", ['http_errors' => false]);
4
f55970e41793 first skeleton of bo client in ember
ymh <ymh.work@gmail.com>
parents:
diff changeset
    39
        $this->httpClient->post('repositories/SYSTEM/statements', [
f55970e41793 first skeleton of bo client in ember
ymh <ymh.work@gmail.com>
parents:
diff changeset
    40
            'headers' => ['Content-type' => 'application/x-turtle;charset=UTF-8'],
f55970e41793 first skeleton of bo client in ember
ymh <ymh.work@gmail.com>
parents:
diff changeset
    41
            'query' => ['context' => "_:$uniqueid"],
f55970e41793 first skeleton of bo client in ember
ymh <ymh.work@gmail.com>
parents:
diff changeset
    42
            'body' => $repoCreateStmt,
f55970e41793 first skeleton of bo client in ember
ymh <ymh.work@gmail.com>
parents:
diff changeset
    43
        ]);
405
f239c8c5bb94 migrate to rdf4j (2.1.1) from sesame (4.1.1)
ymh <ymh.work@gmail.com>
parents: 371
diff changeset
    44
        $this->httpClient->put("repositories/$this->rdf4jRepository/statements", [
4
f55970e41793 first skeleton of bo client in ember
ymh <ymh.work@gmail.com>
parents:
diff changeset
    45
            'headers' => ['Content-type' => 'text/turtle;charset=UTF-8'],
277
bd4bc1db4f40 add blank node save and geoinfo to back model
ymh <ymh.work@gmail.com>
parents: 168
diff changeset
    46
            'body' => sprintf(file_get_contents(DocumentRepositoryIntegrationTest::TEST_DOC), config('corpusparole.corpus_doc_id_base_uri')),
143
023b6d467566 Change id prefix + url + correct tests
ymh <ymh.work@gmail.com>
parents: 122
diff changeset
    47
            'query' => ['context' => "<".config('corpusparole.corpus_doc_id_base_uri')."crdo-ALA_738>"],
4
f55970e41793 first skeleton of bo client in ember
ymh <ymh.work@gmail.com>
parents:
diff changeset
    48
        ]);
405
f239c8c5bb94 migrate to rdf4j (2.1.1) from sesame (4.1.1)
ymh <ymh.work@gmail.com>
parents: 371
diff changeset
    49
        $this->httpClient->put("repositories/$this->rdf4jRepository/statements", [
277
bd4bc1db4f40 add blank node save and geoinfo to back model
ymh <ymh.work@gmail.com>
parents: 168
diff changeset
    50
            'headers' => ['Content-type' => 'text/turtle;charset=UTF-8'],
bd4bc1db4f40 add blank node save and geoinfo to back model
ymh <ymh.work@gmail.com>
parents: 168
diff changeset
    51
            'body' => sprintf(file_get_contents(DocumentRepositoryIntegrationTest::TEST_DOC_NO_GEO), config('corpusparole.corpus_doc_id_base_uri')),
bd4bc1db4f40 add blank node save and geoinfo to back model
ymh <ymh.work@gmail.com>
parents: 168
diff changeset
    52
            'query' => ['context' => "<".config('corpusparole.corpus_doc_id_base_uri')."crdo-ALA_739>"],
bd4bc1db4f40 add blank node save and geoinfo to back model
ymh <ymh.work@gmail.com>
parents: 168
diff changeset
    53
        ]);
bd4bc1db4f40 add blank node save and geoinfo to back model
ymh <ymh.work@gmail.com>
parents: 168
diff changeset
    54
4
f55970e41793 first skeleton of bo client in ember
ymh <ymh.work@gmail.com>
parents:
diff changeset
    55
    }
f55970e41793 first skeleton of bo client in ember
ymh <ymh.work@gmail.com>
parents:
diff changeset
    56
f55970e41793 first skeleton of bo client in ember
ymh <ymh.work@gmail.com>
parents:
diff changeset
    57
    public function tearDown() {
405
f239c8c5bb94 migrate to rdf4j (2.1.1) from sesame (4.1.1)
ymh <ymh.work@gmail.com>
parents: 371
diff changeset
    58
        $this->httpClient->delete("repositories/$this->rdf4jRepository");
4
f55970e41793 first skeleton of bo client in ember
ymh <ymh.work@gmail.com>
parents:
diff changeset
    59
        parent::tearDown();
f55970e41793 first skeleton of bo client in ember
ymh <ymh.work@gmail.com>
parents:
diff changeset
    60
    }
f55970e41793 first skeleton of bo client in ember
ymh <ymh.work@gmail.com>
parents:
diff changeset
    61
f55970e41793 first skeleton of bo client in ember
ymh <ymh.work@gmail.com>
parents:
diff changeset
    62
    public function testAll() {
19
eadaf0b8f02e Bo conception step. back to ember page
ymh <ymh.work@gmail.com>
parents: 4
diff changeset
    63
        $expectedId = $this->corpusDocIdBaseUri.'crdo-ALA_738';
4
f55970e41793 first skeleton of bo client in ember
ymh <ymh.work@gmail.com>
parents:
diff changeset
    64
        $docList = $this->documentRepository->all();
326
226d5b17a119 - First implementation of filter for languages.
ymh <ymh.work@gmail.com>
parents: 277
diff changeset
    65
        $this->assertCount(2, $docList, "Should have 2 element");
4
f55970e41793 first skeleton of bo client in ember
ymh <ymh.work@gmail.com>
parents:
diff changeset
    66
f55970e41793 first skeleton of bo client in ember
ymh <ymh.work@gmail.com>
parents:
diff changeset
    67
        $resDoc = $docList[0];
f55970e41793 first skeleton of bo client in ember
ymh <ymh.work@gmail.com>
parents:
diff changeset
    68
168
17f10b56c079 improve document model and propagate changes. This include the change of document fixtures to better reflect what the api is effectively returning
ymh <ymh.work@gmail.com>
parents: 143
diff changeset
    69
        $this->assertInstanceOf(DocumentResult::class, $resDoc, "Res doc must be a Document");
143
023b6d467566 Change id prefix + url + correct tests
ymh <ymh.work@gmail.com>
parents: 122
diff changeset
    70
        $this->assertEquals(config('corpusparole.corpus_id_scheme').'crdo-ALA_738', $resDoc->getId(), "id must be crdo...");
4
f55970e41793 first skeleton of bo client in ember
ymh <ymh.work@gmail.com>
parents:
diff changeset
    71
        $this->assertEquals($expectedId, $resDoc->getUri(), 'url must be ...');
26
72f51a9386ff upgrade libs and correct tests
ymh <ymh.work@gmail.com>
parents: 19
diff changeset
    72
        $this->assertNotNull($resDoc->getGraph(), 'Graph must not be null');
4
f55970e41793 first skeleton of bo client in ember
ymh <ymh.work@gmail.com>
parents:
diff changeset
    73
f55970e41793 first skeleton of bo client in ember
ymh <ymh.work@gmail.com>
parents:
diff changeset
    74
    }
f55970e41793 first skeleton of bo client in ember
ymh <ymh.work@gmail.com>
parents:
diff changeset
    75
f55970e41793 first skeleton of bo client in ember
ymh <ymh.work@gmail.com>
parents:
diff changeset
    76
    public function testGet() {
f55970e41793 first skeleton of bo client in ember
ymh <ymh.work@gmail.com>
parents:
diff changeset
    77
19
eadaf0b8f02e Bo conception step. back to ember page
ymh <ymh.work@gmail.com>
parents: 4
diff changeset
    78
        $expectedId = $this->corpusDocIdBaseUri.'crdo-ALA_738';
277
bd4bc1db4f40 add blank node save and geoinfo to back model
ymh <ymh.work@gmail.com>
parents: 168
diff changeset
    79
        $returnedGraph = new EasyRdf\Graph($expectedId, sprintf(file_get_contents(DocumentRepositoryIntegrationTest::TEST_DOC),config('corpusparole.corpus_doc_id_base_uri')));
4
f55970e41793 first skeleton of bo client in ember
ymh <ymh.work@gmail.com>
parents:
diff changeset
    80
19
eadaf0b8f02e Bo conception step. back to ember page
ymh <ymh.work@gmail.com>
parents: 4
diff changeset
    81
        $res = $this->documentRepository->get('crdo-ALA_738');
4
f55970e41793 first skeleton of bo client in ember
ymh <ymh.work@gmail.com>
parents:
diff changeset
    82
f55970e41793 first skeleton of bo client in ember
ymh <ymh.work@gmail.com>
parents:
diff changeset
    83
        $this->assertInstanceOf(Document::class, $res, "Result must be of type Document");
143
023b6d467566 Change id prefix + url + correct tests
ymh <ymh.work@gmail.com>
parents: 122
diff changeset
    84
        $this->assertEquals(config('corpusparole.corpus_id_scheme').'crdo-ALA_738', $res->getId(), 'id should be crdo-ALA_738' );
500
4f507ba2bb4c add alternativeTitle. Prepare #0025746
ymh <ymh.work@gmail.com>
parents: 405
diff changeset
    85
        $this->assertNotNull($res->getGraph(), "Graph should not be null");
143
023b6d467566 Change id prefix + url + correct tests
ymh <ymh.work@gmail.com>
parents: 122
diff changeset
    86
        $this->assertEquals(config('corpusparole.corpus_doc_id_base_uri')."crdo-ALA_738",$res->getGraph()->getUri(), "uri of graph must be ".config('corpusparole.corpus_doc_id_base_uri')."crdo-ALA_738");
4
f55970e41793 first skeleton of bo client in ember
ymh <ymh.work@gmail.com>
parents:
diff changeset
    87
        $this->assertTrue(EasyRdf\Isomorphic::isomorphic($res->getGraph(),$returnedGraph));
f55970e41793 first skeleton of bo client in ember
ymh <ymh.work@gmail.com>
parents:
diff changeset
    88
    }
f55970e41793 first skeleton of bo client in ember
ymh <ymh.work@gmail.com>
parents:
diff changeset
    89
168
17f10b56c079 improve document model and propagate changes. This include the change of document fixtures to better reflect what the api is effectively returning
ymh <ymh.work@gmail.com>
parents: 143
diff changeset
    90
    public function testGetShort() {
17f10b56c079 improve document model and propagate changes. This include the change of document fixtures to better reflect what the api is effectively returning
ymh <ymh.work@gmail.com>
parents: 143
diff changeset
    91
17f10b56c079 improve document model and propagate changes. This include the change of document fixtures to better reflect what the api is effectively returning
ymh <ymh.work@gmail.com>
parents: 143
diff changeset
    92
        $expectedId = $this->corpusDocIdBaseUri.'crdo-ALA_738';
277
bd4bc1db4f40 add blank node save and geoinfo to back model
ymh <ymh.work@gmail.com>
parents: 168
diff changeset
    93
        $returnedGraph = new EasyRdf\Graph($expectedId, sprintf(file_get_contents(DocumentRepositoryIntegrationTest::TEST_DOC),config('corpusparole.corpus_doc_id_base_uri')));
168
17f10b56c079 improve document model and propagate changes. This include the change of document fixtures to better reflect what the api is effectively returning
ymh <ymh.work@gmail.com>
parents: 143
diff changeset
    94
17f10b56c079 improve document model and propagate changes. This include the change of document fixtures to better reflect what the api is effectively returning
ymh <ymh.work@gmail.com>
parents: 143
diff changeset
    95
        $res = $this->documentRepository->get('crdo-ALA_738', true);
17f10b56c079 improve document model and propagate changes. This include the change of document fixtures to better reflect what the api is effectively returning
ymh <ymh.work@gmail.com>
parents: 143
diff changeset
    96
17f10b56c079 improve document model and propagate changes. This include the change of document fixtures to better reflect what the api is effectively returning
ymh <ymh.work@gmail.com>
parents: 143
diff changeset
    97
        $this->assertInstanceOf(DocumentResult::class, $res, "Result must be of type DocumentResult");
17f10b56c079 improve document model and propagate changes. This include the change of document fixtures to better reflect what the api is effectively returning
ymh <ymh.work@gmail.com>
parents: 143
diff changeset
    98
        $this->assertEquals(config('corpusparole.corpus_id_scheme').'crdo-ALA_738', $res->getId(), 'id should be crdo-ALA_738' );
17f10b56c079 improve document model and propagate changes. This include the change of document fixtures to better reflect what the api is effectively returning
ymh <ymh.work@gmail.com>
parents: 143
diff changeset
    99
        $this->assertNotNull($res->getGraph(), "Graph shoul not be null");
17f10b56c079 improve document model and propagate changes. This include the change of document fixtures to better reflect what the api is effectively returning
ymh <ymh.work@gmail.com>
parents: 143
diff changeset
   100
        $this->assertEquals(config('corpusparole.corpus_doc_id_base_uri')."crdo-ALA_738",$res->getGraph()->getUri(), "uri of graph must be ".config('corpusparole.corpus_doc_id_base_uri')."crdo-ALA_738");
17f10b56c079 improve document model and propagate changes. This include the change of document fixtures to better reflect what the api is effectively returning
ymh <ymh.work@gmail.com>
parents: 143
diff changeset
   101
        $this->assertTrue(EasyRdf\Isomorphic::isomorphic($res->getGraph(),$returnedGraph));
17f10b56c079 improve document model and propagate changes. This include the change of document fixtures to better reflect what the api is effectively returning
ymh <ymh.work@gmail.com>
parents: 143
diff changeset
   102
    }
17f10b56c079 improve document model and propagate changes. This include the change of document fixtures to better reflect what the api is effectively returning
ymh <ymh.work@gmail.com>
parents: 143
diff changeset
   103
277
bd4bc1db4f40 add blank node save and geoinfo to back model
ymh <ymh.work@gmail.com>
parents: 168
diff changeset
   104
    public function testNoGeo() {
bd4bc1db4f40 add blank node save and geoinfo to back model
ymh <ymh.work@gmail.com>
parents: 168
diff changeset
   105
        $expectedId = $this->corpusDocIdBaseUri.'crdo-ALA_739';
bd4bc1db4f40 add blank node save and geoinfo to back model
ymh <ymh.work@gmail.com>
parents: 168
diff changeset
   106
        $returnedGraph = new EasyRdf\Graph($expectedId, sprintf(file_get_contents(DocumentRepositoryIntegrationTest::TEST_DOC_NO_GEO),config('corpusparole.corpus_doc_id_base_uri')));
bd4bc1db4f40 add blank node save and geoinfo to back model
ymh <ymh.work@gmail.com>
parents: 168
diff changeset
   107
bd4bc1db4f40 add blank node save and geoinfo to back model
ymh <ymh.work@gmail.com>
parents: 168
diff changeset
   108
        $res = $this->documentRepository->get('crdo-ALA_739');
bd4bc1db4f40 add blank node save and geoinfo to back model
ymh <ymh.work@gmail.com>
parents: 168
diff changeset
   109
bd4bc1db4f40 add blank node save and geoinfo to back model
ymh <ymh.work@gmail.com>
parents: 168
diff changeset
   110
        $this->assertNull($res->getGeoInfo(), "Must have no geo info");
bd4bc1db4f40 add blank node save and geoinfo to back model
ymh <ymh.work@gmail.com>
parents: 168
diff changeset
   111
bd4bc1db4f40 add blank node save and geoinfo to back model
ymh <ymh.work@gmail.com>
parents: 168
diff changeset
   112
    }
bd4bc1db4f40 add blank node save and geoinfo to back model
ymh <ymh.work@gmail.com>
parents: 168
diff changeset
   113
bd4bc1db4f40 add blank node save and geoinfo to back model
ymh <ymh.work@gmail.com>
parents: 168
diff changeset
   114
    /**
bd4bc1db4f40 add blank node save and geoinfo to back model
ymh <ymh.work@gmail.com>
parents: 168
diff changeset
   115
     * @expectedException        CorpusParole\Libraries\CorpusParoleException
bd4bc1db4f40 add blank node save and geoinfo to back model
ymh <ymh.work@gmail.com>
parents: 168
diff changeset
   116
     * @expectedExceptionMessage GetDeltaList called when changes are pending
bd4bc1db4f40 add blank node save and geoinfo to back model
ymh <ymh.work@gmail.com>
parents: 168
diff changeset
   117
     */
bd4bc1db4f40 add blank node save and geoinfo to back model
ymh <ymh.work@gmail.com>
parents: 168
diff changeset
   118
    public function testAddGeoNoCommit() {
bd4bc1db4f40 add blank node save and geoinfo to back model
ymh <ymh.work@gmail.com>
parents: 168
diff changeset
   119
bd4bc1db4f40 add blank node save and geoinfo to back model
ymh <ymh.work@gmail.com>
parents: 168
diff changeset
   120
        $doc = $this->documentRepository->get('crdo-ALA_739');
bd4bc1db4f40 add blank node save and geoinfo to back model
ymh <ymh.work@gmail.com>
parents: 168
diff changeset
   121
bd4bc1db4f40 add blank node save and geoinfo to back model
ymh <ymh.work@gmail.com>
parents: 168
diff changeset
   122
        $geoInfo = $doc->addGeoInfo();
bd4bc1db4f40 add blank node save and geoinfo to back model
ymh <ymh.work@gmail.com>
parents: 168
diff changeset
   123
bd4bc1db4f40 add blank node save and geoinfo to back model
ymh <ymh.work@gmail.com>
parents: 168
diff changeset
   124
        $res = $this->documentRepository->save($doc);
bd4bc1db4f40 add blank node save and geoinfo to back model
ymh <ymh.work@gmail.com>
parents: 168
diff changeset
   125
    }
bd4bc1db4f40 add blank node save and geoinfo to back model
ymh <ymh.work@gmail.com>
parents: 168
diff changeset
   126
bd4bc1db4f40 add blank node save and geoinfo to back model
ymh <ymh.work@gmail.com>
parents: 168
diff changeset
   127
bd4bc1db4f40 add blank node save and geoinfo to back model
ymh <ymh.work@gmail.com>
parents: 168
diff changeset
   128
    public function testAddGeo() {
bd4bc1db4f40 add blank node save and geoinfo to back model
ymh <ymh.work@gmail.com>
parents: 168
diff changeset
   129
bd4bc1db4f40 add blank node save and geoinfo to back model
ymh <ymh.work@gmail.com>
parents: 168
diff changeset
   130
        $doc = $this->documentRepository->get('crdo-ALA_739');
bd4bc1db4f40 add blank node save and geoinfo to back model
ymh <ymh.work@gmail.com>
parents: 168
diff changeset
   131
bd4bc1db4f40 add blank node save and geoinfo to back model
ymh <ymh.work@gmail.com>
parents: 168
diff changeset
   132
        $geoInfo = $doc->addGeoInfo();
bd4bc1db4f40 add blank node save and geoinfo to back model
ymh <ymh.work@gmail.com>
parents: 168
diff changeset
   133
        $geoInfo->commit();
bd4bc1db4f40 add blank node save and geoinfo to back model
ymh <ymh.work@gmail.com>
parents: 168
diff changeset
   134
bd4bc1db4f40 add blank node save and geoinfo to back model
ymh <ymh.work@gmail.com>
parents: 168
diff changeset
   135
        $res = $this->documentRepository->save($doc);
bd4bc1db4f40 add blank node save and geoinfo to back model
ymh <ymh.work@gmail.com>
parents: 168
diff changeset
   136
bd4bc1db4f40 add blank node save and geoinfo to back model
ymh <ymh.work@gmail.com>
parents: 168
diff changeset
   137
        $res = $this->documentRepository->get('crdo-ALA_739');
bd4bc1db4f40 add blank node save and geoinfo to back model
ymh <ymh.work@gmail.com>
parents: 168
diff changeset
   138
bd4bc1db4f40 add blank node save and geoinfo to back model
ymh <ymh.work@gmail.com>
parents: 168
diff changeset
   139
        $geoInfo = $res->getGeoInfo();
bd4bc1db4f40 add blank node save and geoinfo to back model
ymh <ymh.work@gmail.com>
parents: 168
diff changeset
   140
bd4bc1db4f40 add blank node save and geoinfo to back model
ymh <ymh.work@gmail.com>
parents: 168
diff changeset
   141
        $this->assertNotNull($geoInfo, "Must have Geo info");
bd4bc1db4f40 add blank node save and geoinfo to back model
ymh <ymh.work@gmail.com>
parents: 168
diff changeset
   142
bd4bc1db4f40 add blank node save and geoinfo to back model
ymh <ymh.work@gmail.com>
parents: 168
diff changeset
   143
        $notes = $geoInfo->getNotes();
bd4bc1db4f40 add blank node save and geoinfo to back model
ymh <ymh.work@gmail.com>
parents: 168
diff changeset
   144
bd4bc1db4f40 add blank node save and geoinfo to back model
ymh <ymh.work@gmail.com>
parents: 168
diff changeset
   145
        $this->assertTrue(is_array($notes));
bd4bc1db4f40 add blank node save and geoinfo to back model
ymh <ymh.work@gmail.com>
parents: 168
diff changeset
   146
        $this->assertCount(0, $notes);
bd4bc1db4f40 add blank node save and geoinfo to back model
ymh <ymh.work@gmail.com>
parents: 168
diff changeset
   147
bd4bc1db4f40 add blank node save and geoinfo to back model
ymh <ymh.work@gmail.com>
parents: 168
diff changeset
   148
        $refLocs = $geoInfo->getRefLocs();
bd4bc1db4f40 add blank node save and geoinfo to back model
ymh <ymh.work@gmail.com>
parents: 168
diff changeset
   149
bd4bc1db4f40 add blank node save and geoinfo to back model
ymh <ymh.work@gmail.com>
parents: 168
diff changeset
   150
        $this->assertTrue(is_array($refLocs));
bd4bc1db4f40 add blank node save and geoinfo to back model
ymh <ymh.work@gmail.com>
parents: 168
diff changeset
   151
        $this->assertCount(0,$refLocs);
bd4bc1db4f40 add blank node save and geoinfo to back model
ymh <ymh.work@gmail.com>
parents: 168
diff changeset
   152
bd4bc1db4f40 add blank node save and geoinfo to back model
ymh <ymh.work@gmail.com>
parents: 168
diff changeset
   153
    }
bd4bc1db4f40 add blank node save and geoinfo to back model
ymh <ymh.work@gmail.com>
parents: 168
diff changeset
   154
bd4bc1db4f40 add blank node save and geoinfo to back model
ymh <ymh.work@gmail.com>
parents: 168
diff changeset
   155
    public function testAddGeoExisting() {
bd4bc1db4f40 add blank node save and geoinfo to back model
ymh <ymh.work@gmail.com>
parents: 168
diff changeset
   156
bd4bc1db4f40 add blank node save and geoinfo to back model
ymh <ymh.work@gmail.com>
parents: 168
diff changeset
   157
        $doc = $this->documentRepository->get('crdo-ALA_738');
bd4bc1db4f40 add blank node save and geoinfo to back model
ymh <ymh.work@gmail.com>
parents: 168
diff changeset
   158
bd4bc1db4f40 add blank node save and geoinfo to back model
ymh <ymh.work@gmail.com>
parents: 168
diff changeset
   159
        $geoInfo = $doc->addGeoInfo();
bd4bc1db4f40 add blank node save and geoinfo to back model
ymh <ymh.work@gmail.com>
parents: 168
diff changeset
   160
        $geoInfo->commit();
bd4bc1db4f40 add blank node save and geoinfo to back model
ymh <ymh.work@gmail.com>
parents: 168
diff changeset
   161
bd4bc1db4f40 add blank node save and geoinfo to back model
ymh <ymh.work@gmail.com>
parents: 168
diff changeset
   162
        $res = $this->documentRepository->save($doc);
bd4bc1db4f40 add blank node save and geoinfo to back model
ymh <ymh.work@gmail.com>
parents: 168
diff changeset
   163
bd4bc1db4f40 add blank node save and geoinfo to back model
ymh <ymh.work@gmail.com>
parents: 168
diff changeset
   164
        $res = $this->documentRepository->get('crdo-ALA_738');
bd4bc1db4f40 add blank node save and geoinfo to back model
ymh <ymh.work@gmail.com>
parents: 168
diff changeset
   165
bd4bc1db4f40 add blank node save and geoinfo to back model
ymh <ymh.work@gmail.com>
parents: 168
diff changeset
   166
        $geoInfo = $res->getGeoInfo();
bd4bc1db4f40 add blank node save and geoinfo to back model
ymh <ymh.work@gmail.com>
parents: 168
diff changeset
   167
bd4bc1db4f40 add blank node save and geoinfo to back model
ymh <ymh.work@gmail.com>
parents: 168
diff changeset
   168
        $this->assertNotNull($geoInfo, "Must have Geo info");
bd4bc1db4f40 add blank node save and geoinfo to back model
ymh <ymh.work@gmail.com>
parents: 168
diff changeset
   169
bd4bc1db4f40 add blank node save and geoinfo to back model
ymh <ymh.work@gmail.com>
parents: 168
diff changeset
   170
        $notes = $geoInfo->getNotes();
bd4bc1db4f40 add blank node save and geoinfo to back model
ymh <ymh.work@gmail.com>
parents: 168
diff changeset
   171
bd4bc1db4f40 add blank node save and geoinfo to back model
ymh <ymh.work@gmail.com>
parents: 168
diff changeset
   172
        $this->assertTrue(is_array($notes));
bd4bc1db4f40 add blank node save and geoinfo to back model
ymh <ymh.work@gmail.com>
parents: 168
diff changeset
   173
        $this->assertCount(3, $notes);
bd4bc1db4f40 add blank node save and geoinfo to back model
ymh <ymh.work@gmail.com>
parents: 168
diff changeset
   174
bd4bc1db4f40 add blank node save and geoinfo to back model
ymh <ymh.work@gmail.com>
parents: 168
diff changeset
   175
        $refLocs = $geoInfo->getRefLocs();
bd4bc1db4f40 add blank node save and geoinfo to back model
ymh <ymh.work@gmail.com>
parents: 168
diff changeset
   176
bd4bc1db4f40 add blank node save and geoinfo to back model
ymh <ymh.work@gmail.com>
parents: 168
diff changeset
   177
        $this->assertTrue(is_array($refLocs));
bd4bc1db4f40 add blank node save and geoinfo to back model
ymh <ymh.work@gmail.com>
parents: 168
diff changeset
   178
        $this->assertCount(1,$refLocs);
bd4bc1db4f40 add blank node save and geoinfo to back model
ymh <ymh.work@gmail.com>
parents: 168
diff changeset
   179
bd4bc1db4f40 add blank node save and geoinfo to back model
ymh <ymh.work@gmail.com>
parents: 168
diff changeset
   180
    }
bd4bc1db4f40 add blank node save and geoinfo to back model
ymh <ymh.work@gmail.com>
parents: 168
diff changeset
   181
bd4bc1db4f40 add blank node save and geoinfo to back model
ymh <ymh.work@gmail.com>
parents: 168
diff changeset
   182
    public function testGeoSetRefLoc() {
bd4bc1db4f40 add blank node save and geoinfo to back model
ymh <ymh.work@gmail.com>
parents: 168
diff changeset
   183
bd4bc1db4f40 add blank node save and geoinfo to back model
ymh <ymh.work@gmail.com>
parents: 168
diff changeset
   184
        $doc = $this->documentRepository->get('crdo-ALA_738');
bd4bc1db4f40 add blank node save and geoinfo to back model
ymh <ymh.work@gmail.com>
parents: 168
diff changeset
   185
        $geoInfo = $doc->addGeoInfo();
bd4bc1db4f40 add blank node save and geoinfo to back model
ymh <ymh.work@gmail.com>
parents: 168
diff changeset
   186
bd4bc1db4f40 add blank node save and geoinfo to back model
ymh <ymh.work@gmail.com>
parents: 168
diff changeset
   187
        $newRefLocs = [ 'http://sws.geonames.org/2643743/' ];
bd4bc1db4f40 add blank node save and geoinfo to back model
ymh <ymh.work@gmail.com>
parents: 168
diff changeset
   188
bd4bc1db4f40 add blank node save and geoinfo to back model
ymh <ymh.work@gmail.com>
parents: 168
diff changeset
   189
        $geoInfo->setRefLocs($newRefLocs);
bd4bc1db4f40 add blank node save and geoinfo to back model
ymh <ymh.work@gmail.com>
parents: 168
diff changeset
   190
bd4bc1db4f40 add blank node save and geoinfo to back model
ymh <ymh.work@gmail.com>
parents: 168
diff changeset
   191
        $geoInfo->commit();
bd4bc1db4f40 add blank node save and geoinfo to back model
ymh <ymh.work@gmail.com>
parents: 168
diff changeset
   192
bd4bc1db4f40 add blank node save and geoinfo to back model
ymh <ymh.work@gmail.com>
parents: 168
diff changeset
   193
        $res = $this->documentRepository->save($doc);
bd4bc1db4f40 add blank node save and geoinfo to back model
ymh <ymh.work@gmail.com>
parents: 168
diff changeset
   194
bd4bc1db4f40 add blank node save and geoinfo to back model
ymh <ymh.work@gmail.com>
parents: 168
diff changeset
   195
        $res = $this->documentRepository->get('crdo-ALA_738');
bd4bc1db4f40 add blank node save and geoinfo to back model
ymh <ymh.work@gmail.com>
parents: 168
diff changeset
   196
bd4bc1db4f40 add blank node save and geoinfo to back model
ymh <ymh.work@gmail.com>
parents: 168
diff changeset
   197
        $geoInfo = $res->getGeoInfo();
bd4bc1db4f40 add blank node save and geoinfo to back model
ymh <ymh.work@gmail.com>
parents: 168
diff changeset
   198
bd4bc1db4f40 add blank node save and geoinfo to back model
ymh <ymh.work@gmail.com>
parents: 168
diff changeset
   199
        $refLocs = $geoInfo->getRefLocs();
bd4bc1db4f40 add blank node save and geoinfo to back model
ymh <ymh.work@gmail.com>
parents: 168
diff changeset
   200
bd4bc1db4f40 add blank node save and geoinfo to back model
ymh <ymh.work@gmail.com>
parents: 168
diff changeset
   201
        $this->assertTrue(is_array($refLocs));
bd4bc1db4f40 add blank node save and geoinfo to back model
ymh <ymh.work@gmail.com>
parents: 168
diff changeset
   202
        $this->assertCount(1,$refLocs);
bd4bc1db4f40 add blank node save and geoinfo to back model
ymh <ymh.work@gmail.com>
parents: 168
diff changeset
   203
bd4bc1db4f40 add blank node save and geoinfo to back model
ymh <ymh.work@gmail.com>
parents: 168
diff changeset
   204
        $this->assertEquals(['http://sws.geonames.org/2643743/'], $refLocs);
bd4bc1db4f40 add blank node save and geoinfo to back model
ymh <ymh.work@gmail.com>
parents: 168
diff changeset
   205
bd4bc1db4f40 add blank node save and geoinfo to back model
ymh <ymh.work@gmail.com>
parents: 168
diff changeset
   206
    }
bd4bc1db4f40 add blank node save and geoinfo to back model
ymh <ymh.work@gmail.com>
parents: 168
diff changeset
   207
bd4bc1db4f40 add blank node save and geoinfo to back model
ymh <ymh.work@gmail.com>
parents: 168
diff changeset
   208
168
17f10b56c079 improve document model and propagate changes. This include the change of document fixtures to better reflect what the api is effectively returning
ymh <ymh.work@gmail.com>
parents: 143
diff changeset
   209
4
f55970e41793 first skeleton of bo client in ember
ymh <ymh.work@gmail.com>
parents:
diff changeset
   210
    public function testSave() {
f55970e41793 first skeleton of bo client in ember
ymh <ymh.work@gmail.com>
parents:
diff changeset
   211
143
023b6d467566 Change id prefix + url + correct tests
ymh <ymh.work@gmail.com>
parents: 122
diff changeset
   212
        $doc = new Document(config('corpusparole.corpus_doc_id_base_uri')."crdo-ALA_738", $this->graph);
371
0365fd9977a4 Discourse types are now bnf ark resources
ymh <ymh.work@gmail.com>
parents: 326
diff changeset
   213
        $updatedDiscourseTypes = ["http://ark.bnf.fr/ark:/12148/cb13319048g", "http://ark.bnf.fr/ark:/12148/cb11949715t" , "http://ark.bnf.fr/ark:/12148/cb119783362"];
0365fd9977a4 Discourse types are now bnf ark resources
ymh <ymh.work@gmail.com>
parents: 326
diff changeset
   214
        $doc->updateDiscourseTypes($updatedDiscourseTypes);
4
f55970e41793 first skeleton of bo client in ember
ymh <ymh.work@gmail.com>
parents:
diff changeset
   215
f55970e41793 first skeleton of bo client in ember
ymh <ymh.work@gmail.com>
parents:
diff changeset
   216
        $res = $this->documentRepository->save($doc);
f55970e41793 first skeleton of bo client in ember
ymh <ymh.work@gmail.com>
parents:
diff changeset
   217
f55970e41793 first skeleton of bo client in ember
ymh <ymh.work@gmail.com>
parents:
diff changeset
   218
        $this->assertTrue($res, 'Has started a transaction');
f55970e41793 first skeleton of bo client in ember
ymh <ymh.work@gmail.com>
parents:
diff changeset
   219
19
eadaf0b8f02e Bo conception step. back to ember page
ymh <ymh.work@gmail.com>
parents: 4
diff changeset
   220
        $res = $this->documentRepository->get('crdo-ALA_738');
4
f55970e41793 first skeleton of bo client in ember
ymh <ymh.work@gmail.com>
parents:
diff changeset
   221
f55970e41793 first skeleton of bo client in ember
ymh <ymh.work@gmail.com>
parents:
diff changeset
   222
        $discoursesTypes = $res->getDiscourseTypes();
f55970e41793 first skeleton of bo client in ember
ymh <ymh.work@gmail.com>
parents:
diff changeset
   223
371
0365fd9977a4 Discourse types are now bnf ark resources
ymh <ymh.work@gmail.com>
parents: 326
diff changeset
   224
        $this->assertCount(3, $discoursesTypes, "types array must be of size 3");
4
f55970e41793 first skeleton of bo client in ember
ymh <ymh.work@gmail.com>
parents:
diff changeset
   225
371
0365fd9977a4 Discourse types are now bnf ark resources
ymh <ymh.work@gmail.com>
parents: 326
diff changeset
   226
        $this->assertContainsOnlyInstancesOf("EasyRdf\Resource", $discoursesTypes, "Result contains only resources");
4
f55970e41793 first skeleton of bo client in ember
ymh <ymh.work@gmail.com>
parents:
diff changeset
   227
f55970e41793 first skeleton of bo client in ember
ymh <ymh.work@gmail.com>
parents:
diff changeset
   228
        $newDiscoursesTypes = [];
f55970e41793 first skeleton of bo client in ember
ymh <ymh.work@gmail.com>
parents:
diff changeset
   229
        foreach($discoursesTypes as $dt) {
371
0365fd9977a4 Discourse types are now bnf ark resources
ymh <ymh.work@gmail.com>
parents: 326
diff changeset
   230
            array_push($newDiscoursesTypes, $dt->getUri());
0365fd9977a4 Discourse types are now bnf ark resources
ymh <ymh.work@gmail.com>
parents: 326
diff changeset
   231
            $this->assertContains($dt->getUri(), $updatedDiscourseTypes,"Value in ".print_r($updatedDiscourseTypes, true));
4
f55970e41793 first skeleton of bo client in ember
ymh <ymh.work@gmail.com>
parents:
diff changeset
   232
        }
f55970e41793 first skeleton of bo client in ember
ymh <ymh.work@gmail.com>
parents:
diff changeset
   233
        sort($newDiscoursesTypes);
371
0365fd9977a4 Discourse types are now bnf ark resources
ymh <ymh.work@gmail.com>
parents: 326
diff changeset
   234
        sort($updatedDiscourseTypes);
0365fd9977a4 Discourse types are now bnf ark resources
ymh <ymh.work@gmail.com>
parents: 326
diff changeset
   235
0365fd9977a4 Discourse types are now bnf ark resources
ymh <ymh.work@gmail.com>
parents: 326
diff changeset
   236
        $this->assertEquals($updatedDiscourseTypes, $newDiscoursesTypes, "array type must the same");
4
f55970e41793 first skeleton of bo client in ember
ymh <ymh.work@gmail.com>
parents:
diff changeset
   237
    }
f55970e41793 first skeleton of bo client in ember
ymh <ymh.work@gmail.com>
parents:
diff changeset
   238
f55970e41793 first skeleton of bo client in ember
ymh <ymh.work@gmail.com>
parents:
diff changeset
   239
    public function testCount() {
f55970e41793 first skeleton of bo client in ember
ymh <ymh.work@gmail.com>
parents:
diff changeset
   240
        $res = $this->documentRepository->getCount();
f55970e41793 first skeleton of bo client in ember
ymh <ymh.work@gmail.com>
parents:
diff changeset
   241
f55970e41793 first skeleton of bo client in ember
ymh <ymh.work@gmail.com>
parents:
diff changeset
   242
        $this->assertNotNull($res, "Res should not be null");
277
bd4bc1db4f40 add blank node save and geoinfo to back model
ymh <ymh.work@gmail.com>
parents: 168
diff changeset
   243
        $this->assertSame(2, $res, "should have 2 documents");
4
f55970e41793 first skeleton of bo client in ember
ymh <ymh.work@gmail.com>
parents:
diff changeset
   244
    }
f55970e41793 first skeleton of bo client in ember
ymh <ymh.work@gmail.com>
parents:
diff changeset
   245
f55970e41793 first skeleton of bo client in ember
ymh <ymh.work@gmail.com>
parents:
diff changeset
   246
f55970e41793 first skeleton of bo client in ember
ymh <ymh.work@gmail.com>
parents:
diff changeset
   247
}