author | ymh <ymh.work@gmail.com> |
Wed, 09 Nov 2016 15:05:41 +0100 | |
changeset 406 | cf0f23803a53 |
parent 306 | 3fccf43160a7 |
child 407 | 2dba812c7ef2 |
permissions | -rw-r--r-- |
23 | 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 |
]); |
|
306
3fccf43160a7
Some more changes linked to the change of api organization + some jshint error cleaning
ymh <ymh.work@gmail.com>
parents:
23
diff
changeset
|
38 |
$response = $this->get('/api/v1/resolvers/viaf/93752300,56666014')-> |
23 | 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 |
]); |
|
306
3fccf43160a7
Some more changes linked to the change of api organization + some jshint error cleaning
ymh <ymh.work@gmail.com>
parents:
23
diff
changeset
|
53 |
$response = $this->get('/api/v1/resolvers/viaf/93752300')-> |
23 | 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 |
]); |
|
306
3fccf43160a7
Some more changes linked to the change of api organization + some jshint error cleaning
ymh <ymh.work@gmail.com>
parents:
23
diff
changeset
|
67 |
$response = $this->get('/api/v1/resolvers/viaf/12345')-> |
23 | 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); |
|
306
3fccf43160a7
Some more changes linked to the change of api organization + some jshint error cleaning
ymh <ymh.work@gmail.com>
parents:
23
diff
changeset
|
79 |
$response = $this->get('/api/v1/resolvers/viaf/abcdef,ghij'); |
23 | 80 |
|
81 |
$this->assertResponseStatus(400); |
|
82 |
} |
|
83 |
||
84 |
} |