|
1 <?php |
|
2 |
|
3 use Mockery as m; |
|
4 |
|
5 use CorpusParole\Services\ViafResolverException; |
|
6 |
|
7 /** |
|
8 * |
|
9 */ |
|
10 class ViafControllerTest extends TestCase { |
|
11 |
|
12 private $viafResolver; |
|
13 |
|
14 public function setUp() { |
|
15 |
|
16 parent::setup(); |
|
17 |
|
18 // create a mock of the post repository interface and inject it into the |
|
19 // IoC container |
|
20 $this->viafResolver = m::mock('CorpusParole\Services\ViafResolverInterface'); |
|
21 $this->app->instance('CorpusParole\Services\ViafResolverInterface', $this->viafResolver); |
|
22 } |
|
23 |
|
24 public function tearDown() { |
|
25 m::close(); |
|
26 parent::tearDown(); |
|
27 } |
|
28 |
|
29 public function testShow() { |
|
30 $this->viafResolver |
|
31 ->shouldReceive('getNames') |
|
32 ->with(['93752300', '56666014']) |
|
33 ->once() |
|
34 ->andReturn([ |
|
35 '56666014' => 'Guylaine Brun-Trigaud', |
|
36 '93752300' => 'Sonia Branca-Rosoff' |
|
37 ]); |
|
38 $response = $this->get('/api/v1/viaf/93752300,56666014')-> |
|
39 seeJsonEquals(['viafids' => [ |
|
40 '56666014' => 'Guylaine Brun-Trigaud', |
|
41 '93752300' => 'Sonia Branca-Rosoff' |
|
42 ]]); |
|
43 } |
|
44 |
|
45 public function testShowOne() { |
|
46 $this->viafResolver |
|
47 ->shouldReceive('getNames') |
|
48 ->with(['93752300']) |
|
49 ->once() |
|
50 ->andReturn([ |
|
51 '93752300' => 'Sonia Branca-Rosoff' |
|
52 ]); |
|
53 $response = $this->get('/api/v1/viaf/93752300')-> |
|
54 seeJsonEquals(['viafids' => [ |
|
55 '93752300' => 'Sonia Branca-Rosoff' |
|
56 ]]); |
|
57 } |
|
58 |
|
59 public function testShowUnknown() { |
|
60 $this->viafResolver |
|
61 ->shouldReceive('getNames') |
|
62 ->with(['12345']) |
|
63 ->once() |
|
64 ->andReturn([ |
|
65 '12345' => null |
|
66 ]); |
|
67 $response = $this->get('/api/v1/viaf/12345')-> |
|
68 seeJsonEquals(['viafids' => [ |
|
69 '12345' => null |
|
70 ]]); |
|
71 } |
|
72 |
|
73 public function testShowMalformed() { |
|
74 $this->viafResolver |
|
75 ->shouldReceive('getNames') |
|
76 ->with(['abcdef','ghij']) |
|
77 ->once() |
|
78 ->andThrow('CorpusParole\Services\ViafResolverException', "ViafId not in correct format", 400); |
|
79 $response = $this->get('/api/v1/viaf/abcdef,ghij'); |
|
80 |
|
81 $this->assertResponseStatus(400); |
|
82 } |
|
83 |
|
84 } |