server/src/tests/Services/ViafResolverTest.php
changeset 537 d2e6ee099125
parent 28 b0b56e0f8c7f
equal deleted inserted replaced
536:b64c8c35c67d 537:d2e6ee099125
    67 
    67 
    68     /**
    68     /**
    69      * test getName
    69      * test getName
    70      */
    70      */
    71     public function testGetName() {
    71     public function testGetName() {
    72         $resolver = $this->app->make('CorpusParole\Services\ViafResolver', [$this->client]);
    72         $resolver = new \CorpusParole\Services\ViafResolver($this->client);
    73         $name = $resolver->getName('56666014');
    73         $name = $resolver->getName('56666014');
    74 
    74 
    75         $this->assertEquals('Guylaine Brun-Trigaud', $name, "Name must be Guylaine Brun-Trigaud");
    75         $this->assertEquals('Guylaine Brun-Trigaud', $name, "Name must be Guylaine Brun-Trigaud");
    76 
    76 
    77         $this->assertCount(1, $this->container);
    77         $this->assertCount(1, $this->container);
    82 
    82 
    83     /**
    83     /**
    84      * test getName
    84      * test getName
    85      */
    85      */
    86     public function testGetName93752300() {
    86     public function testGetName93752300() {
    87         $resolver = $this->app->make('CorpusParole\Services\ViafResolver', [$this->client]);
    87         $resolver = new \CorpusParole\Services\ViafResolver($this->client);
    88         $name = $resolver->getName('56666014'); //first to consume responses
    88         $name = $resolver->getName('56666014'); //first to consume responses
    89 
    89 
    90         $name = $resolver->getName('93752300');
    90         $name = $resolver->getName('93752300');
    91 
    91 
    92         $this->assertEquals('Sonia Branca-Rosoff', $name, "Name must be Sonia Branca-Rosoff");
    92         $this->assertEquals('Sonia Branca-Rosoff', $name, "Name must be Sonia Branca-Rosoff");
    99 
    99 
   100     /**
   100     /**
   101      * test unknown id
   101      * test unknown id
   102      */
   102      */
   103     public function testUnkownName404() {
   103     public function testUnkownName404() {
   104         $resolver = $this->app->make('CorpusParole\Services\ViafResolver', [$this->client404]);
   104         $resolver = new \CorpusParole\Services\ViafResolver($this->client404);
   105 
   105 
   106         $name = $resolver->getName('12345');
   106         $name = $resolver->getName('12345');
   107 
   107 
   108         $this->assertNull($name);
   108         $this->assertNull($name);
   109     }
   109     }
   110 
   110 
   111     /**
   111     /**
   112      * test unknown id
   112      * test unknown id
   113      */
   113      */
   114     public function testUnkownName() {
   114     public function testUnkownName() {
   115         $resolver = $this->app->make('CorpusParole\Services\ViafResolver', [$this->client]);
   115         $resolver = new \CorpusParole\Services\ViafResolver($this->client);
   116 
   116 
   117         $name = $resolver->getName('12345');
   117         $name = $resolver->getName('12345');
   118 
   118 
   119         $this->assertNull($name);
   119         $this->assertNull($name);
   120     }
   120     }
   124      * @expectedException        CorpusParole\Services\ViafResolverException
   124      * @expectedException        CorpusParole\Services\ViafResolverException
   125      * @expectedExceptionMessage Client error: `GET http://viaf.org/viaf/12345/` resulted in a `401 Unauthorized` response:
   125      * @expectedExceptionMessage Client error: `GET http://viaf.org/viaf/12345/` resulted in a `401 Unauthorized` response:
   126      * @expectedExceptionCode 401
   126      * @expectedExceptionCode 401
   127      */
   127      */
   128     public function test401Error() {
   128     public function test401Error() {
   129         $resolver = $this->app->make('CorpusParole\Services\ViafResolver', [$this->client401]);
   129         $resolver = new \CorpusParole\Services\ViafResolver($this->client401);
   130 
   130 
   131         $name = $resolver->getName('12345');
   131         $name = $resolver->getName('12345');
   132     }
   132     }
   133 
   133 
   134 
   134 
   137      * @expectedException        CorpusParole\Services\ViafResolverException
   137      * @expectedException        CorpusParole\Services\ViafResolverException
   138      * @expectedExceptionMessage Server error: `GET http://viaf.org/viaf/12345/` resulted in a `500 Internal Server Error` response:
   138      * @expectedExceptionMessage Server error: `GET http://viaf.org/viaf/12345/` resulted in a `500 Internal Server Error` response:
   139      * @expectedExceptionCode 500
   139      * @expectedExceptionCode 500
   140      */
   140      */
   141     public function test500Error() {
   141     public function test500Error() {
   142         $resolver = $this->app->make('CorpusParole\Services\ViafResolver', [$this->client500]);
   142         $resolver = new \CorpusParole\Services\ViafResolver($this->client500);
   143 
   143 
   144         $name = $resolver->getName('12345');
   144         $name = $resolver->getName('12345');
   145     }
   145     }
   146 
   146 
   147     /**
   147     /**
   149      * @expectedException        CorpusParole\Services\ViafResolverException
   149      * @expectedException        CorpusParole\Services\ViafResolverException
   150      * @expectedExceptionMessage ViafId not in correct format
   150      * @expectedExceptionMessage ViafId not in correct format
   151      * @expectedExceptionCode 400
   151      * @expectedExceptionCode 400
   152      */
   152      */
   153     public function testMalformedError() {
   153     public function testMalformedError() {
   154         $resolver = $this->app->make('CorpusParole\Services\ViafResolver', [$this->client]);
   154         $resolver = new \CorpusParole\Services\ViafResolver($this->client);
   155 
   155 
   156         $name = $resolver->getName('abcd');
   156         $name = $resolver->getName('abcd');
   157     }
   157     }
   158 
   158 
   159     /**
   159     /**
   160      * test getnames
   160      * test getnames
   161      */
   161      */
   162     public function testGetNames() {
   162     public function testGetNames() {
   163         $resolver = $this->app->make('CorpusParole\Services\ViafResolver', [$this->client]);
   163         $resolver = new \CorpusParole\Services\ViafResolver($this->client);
   164         $names = $resolver->getNames(['56666014', '93752300']);
   164         $names = $resolver->getNames(['56666014', '93752300']);
   165 
   165 
   166         $this->assertCount(2, $names);
   166         $this->assertCount(2, $names);
   167         $this->assertArrayHasKey('56666014', $names);
   167         $this->assertArrayHasKey('56666014', $names);
   168         $this->assertArrayHasKey('93752300', $names);
   168         $this->assertArrayHasKey('93752300', $names);