--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/server/src/tests/Controllers/BnfControllerTest.php Thu Feb 25 21:26:15 2016 +0100
@@ -0,0 +1,88 @@
+<?php
+
+use Mockery as m;
+
+use CorpusParole\Services\BnfResolverException;
+
+/**
+ *
+ */
+class BnfControllerTest extends TestCase {
+
+ private $bnfResolver;
+
+ public function setUp() {
+
+ parent::setup();
+
+ // create a mock of the post repository interface and inject it into the
+ // IoC container
+ $this->bnfResolver = m::mock('CorpusParole\Services\BnfResolverInterface');
+ $this->app->instance('CorpusParole\Services\BnfResolverInterface', $this->bnfResolver);
+ }
+
+ public function tearDown() {
+ m::close();
+ parent::tearDown();
+ }
+
+ public function testSetup() {
+ //do nothing jsut test setup & teardown
+ }
+
+ public function testShow() {
+ $this->bnfResolver
+ ->shouldReceive('getLabels')
+ ->with(['ark:/12148/cb11946662b', 'ark:/12148/cb11965628b'])
+ ->once()
+ ->andReturn([
+ 'ark:/12148/cb11946662b' => 'parents et enfants',
+ 'ark:/12148/cb11965628b' => 'frères et soeurs'
+ ]);
+ $response = $this->get('/api/v1/bnf/cb11946662b,cb11965628b')->
+ seeJsonEquals(['bnfids' => [
+ 'ark:/12148/cb11946662b' => 'parents et enfants',
+ 'ark:/12148/cb11965628b' => 'frères et soeurs'
+ ]]);
+ }
+
+ public function testShowOne() {
+ $this->bnfResolver
+ ->shouldReceive('getLabels')
+ ->with(['ark:/12148/cb11946662b'])
+ ->once()
+ ->andReturn([
+ 'ark:/12148/cb11946662b' => 'parents et enfants'
+ ]);
+ $response = $this->get('/api/v1/bnf/cb11946662b')->
+ seeJsonEquals(['bnfids' => [
+ 'ark:/12148/cb11946662b' => 'parents et enfants'
+ ]]);
+ }
+
+ public function testShowUnknown() {
+ $this->bnfResolver
+ ->shouldReceive('getLabels')
+ ->with(['ark:/12148/cb12345678b'])
+ ->once()
+ ->andReturn([
+ 'ark:/12148/cb12345678b' => null
+ ]);
+ $response = $this->get('/api/v1/bnf/cb12345678b')->
+ seeJsonEquals(['bnfids' => [
+ 'ark:/12148/cb12345678b' => null
+ ]]);
+ }
+
+ public function testShowMalformed() {
+ $this->bnfResolver
+ ->shouldReceive('getLabels')
+ ->with(['ark:/12148/abcdef','ark:/12148/ghij'])
+ ->once()
+ ->andThrow('CorpusParole\Services\BnfResolverException', "BnfId not in correct format", 500);
+ $response = $this->get('/api/v1/bnf/abcdef,ghij');
+
+ $this->assertResponseStatus(500);
+ }
+
+}