diff -r a50cbd7d702f -r 037687868bc4 server/src/tests/Services/ViafResolverTest.php
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/server/src/tests/Services/ViafResolverTest.php Thu Dec 10 16:05:53 2015 +0100
@@ -0,0 +1,179 @@
+566660141961-10-23Guylaine Brun-TrigaudWarning: skos:prefLabels are not ensured against change!Guylaine Brun-TrigaudGuylaine Brun-TrigaudWarning: skos:prefLabels are not ensured against change!Guylaine Brun-TrigaudGuylaine Brun-TrigaudWarning: skos:prefLabels are not ensured against change!Guylaine Brun-TrigaudGuylaine Brun-TrigaudGuylaine Brun-TrigaudGuylaine Brun- TrigaudGuylaine Brun-TrigaudTrigaudBrun-Trigaud, Guylaine, 1961-....Trigaud Guylaine Brun-Brun-Trigaud, Guylainehttp://opc4.kb.nl/PPN?PPN=072991968Brun-Trigaud, GuylaineTrigaud, Guylaine Brun-Brun-Trigaud, Guylaine, 1961-....Trigaud, Guylaine Brun-Brun-Trigaud, Guylaine, 1961-....Trigaud, Guylaine Brun-
+EOT;
+ const VIAF_RDF_93752300 = <<93752300Sonia Branca-RosoffWarning: skos:prefLabels are not ensured against change!Sonia Branca-RosoffSonia Branca-RosoffWarning: skos:prefLabels are not ensured against change!Sonia Branca-RosoffSonia Branca-RosoffWarning: skos:prefLabels are not ensured against change!Sonia Branca-RosoffSonia Branca-RosoffWarning: skos:prefLabels are not ensured against change!Sonia Branca-RosoffSonia Branca-RosoffBCP47 tag for 'B2Q' is undetermined. Name is 'Sonia Branca-Rosoff'.Sonia Branca-RosoffSonia Branca-RosoffSonia Branca-RosoffSonia BrancaSoniaBrancaBrancaSonia CreusotSoniaCreusotSonia RosoffSoniaRosoffSonia Branca- RosoffSonia Branca-RosoffSonia Branca- RosoffSonia Branca-RosoffRosoffB2Q|0000099925Branca-Rosoff, Sonia.Branca SoniaRosoff SoniaBranca-Rosoff, Sonia.Branca, SoniaCreusot, SoniaRosoff, SoniaBranca-Rosoff, Sonia.Branca, SoniaRosoff, Sonia Branca-Branca-Rosoff, Sonia.http://opc4.kb.nl/PPN?PPN=146010671Branca-Rosoff, Sonia.Branca, SoniaCreusot, SoniaRosoff, SoniaRosoff, Sonia Branca-Branca-Rosoff, Sonia.Branca, SoniaRosoff, Sonia Branca-Branca-Rosoff, Sonia.Branca, SoniaRosoff, SoniaBranca-Rosoff, Sonia.Rosoff, Sonia Branca-.
+EOT;
+
+//""" (for syntax highliting)
+
+ function __construct(string $name = null) {
+ parent::__construct($name);
+ }
+
+ public function setUp() {
+ parent::setUp();
+ $this->container = [];
+ $history = Middleware::history($this->container);
+ $mock = new MockHandler([
+ new Response(200, [], self::VIAF_RDF_56666014),
+ new Response(200, [], self::VIAF_RDF_93752300),
+ ]);
+ $handler = HandlerStack::create($mock);
+ $handler->push($history);
+
+ $this->client = new Client(['handler' => $handler]);
+
+ $mock404 = new MockHandler([
+ new Response(404),
+ ]);
+ $this->client404 = new Client(['handler' => HandlerStack::create($mock404)]);
+
+ $mock401 = new MockHandler([
+ new Response(401, [], 'Unauthorized'),
+ new Response(500),
+ ]);
+ $this->client401 = new Client(['handler' => HandlerStack::create($mock401)]);
+
+ $mock500 = new MockHandler([
+ new Response(500, [], 'Internal Server Error'),
+ ]);
+ $this->client500 = new Client(['handler' => HandlerStack::create($mock500)]);
+
+ }
+
+ /**
+ * Jsut test the setup
+ *
+ * @return void
+ */
+ public function testSetUp() {
+ $this->assertTrue(true);
+ }
+
+ /**
+ * test getName
+ */
+ public function testGetName() {
+ $resolver = $this->app->make('CorpusParole\Services\ViafResolver', [$this->client]);
+ $name = $resolver->getName('56666014');
+
+ $this->assertEquals('Guylaine Brun-Trigaud', $name, "Name must be Guylaine Brun-Trigaud");
+
+ $this->assertCount(1, $this->container);
+
+ $this->assertEquals("http://viaf.org/viaf/56666014/", (string)$this->container[0]['request']->getUri());
+
+ }
+
+ /**
+ * test getName
+ */
+ public function testGetName93752300() {
+ $resolver = $this->app->make('CorpusParole\Services\ViafResolver', [$this->client]);
+ $name = $resolver->getName('56666014'); //first to consume responses
+
+ $name = $resolver->getName('93752300');
+
+ $this->assertEquals('Sonia Branca-Rosoff', $name, "Name must be Sonia Branca-Rosoff");
+
+ $this->assertCount(2, $this->container);
+
+ $this->assertEquals("http://viaf.org/viaf/93752300/", (string)$this->container[1]['request']->getUri());
+
+ }
+
+ /**
+ * test unknown id
+ */
+ public function testUnkownName404() {
+ $resolver = $this->app->make('CorpusParole\Services\ViafResolver', [$this->client404]);
+
+ $name = $resolver->getName('12345');
+
+ $this->assertNull($name);
+ }
+
+ /**
+ * test unknown id
+ */
+ public function testUnkownName() {
+ $resolver = $this->app->make('CorpusParole\Services\ViafResolver', [$this->client]);
+
+ $name = $resolver->getName('12345');
+
+ $this->assertNull($name);
+ }
+
+ /**
+ * Test exception 401
+ * @expectedException CorpusParole\Services\ViafResolverException
+ * @expectedExceptionMessage Client error: 401
+ * @expectedExceptionCode 401
+ */
+ public function test401Error() {
+ $resolver = $this->app->make('CorpusParole\Services\ViafResolver', [$this->client401]);
+
+ $name = $resolver->getName('12345');
+ }
+
+
+ /**
+ * Test exception 500
+ * @expectedException CorpusParole\Services\ViafResolverException
+ * @expectedExceptionMessage Server error: 500
+ * @expectedExceptionCode 500
+ */
+ public function test500Error() {
+ $resolver = $this->app->make('CorpusParole\Services\ViafResolver', [$this->client500]);
+
+ $name = $resolver->getName('12345');
+ }
+
+ /**
+ * Test exception malformed
+ * @expectedException CorpusParole\Services\ViafResolverException
+ * @expectedExceptionMessage ViafId not in correct format
+ * @expectedExceptionCode 400
+ */
+ public function testMalformedError() {
+ $resolver = $this->app->make('CorpusParole\Services\ViafResolver', [$this->client]);
+
+ $name = $resolver->getName('abcd');
+ }
+
+ /**
+ * test getnames
+ */
+ public function testGetNames() {
+ $resolver = $this->app->make('CorpusParole\Services\ViafResolver', [$this->client]);
+ $names = $resolver->getNames(['56666014', '93752300']);
+
+ $this->assertCount(2, $names);
+ $this->assertArrayHasKey('56666014', $names);
+ $this->assertArrayHasKey('93752300', $names);
+
+ $this->assertEquals('Sonia Branca-Rosoff', $names['93752300']);
+ $this->assertEquals('Guylaine Brun-Trigaud', $names['56666014']);
+
+ }
+
+}