133
|
1 |
<?php |
|
2 |
|
|
3 |
use Mockery as m; |
|
4 |
|
|
5 |
use CorpusParole\Services\BnfResolverException; |
|
6 |
|
|
7 |
/** |
|
8 |
* |
|
9 |
*/ |
|
10 |
class BnfControllerTest extends TestCase { |
|
11 |
|
|
12 |
private $bnfResolver; |
|
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->bnfResolver = m::mock('CorpusParole\Services\BnfResolverInterface'); |
|
21 |
$this->app->instance('CorpusParole\Services\BnfResolverInterface', $this->bnfResolver); |
|
22 |
} |
|
23 |
|
|
24 |
public function tearDown() { |
|
25 |
m::close(); |
|
26 |
parent::tearDown(); |
|
27 |
} |
|
28 |
|
|
29 |
public function testSetup() { |
|
30 |
//do nothing jsut test setup & teardown |
|
31 |
} |
|
32 |
|
|
33 |
public function testShow() { |
|
34 |
$this->bnfResolver |
|
35 |
->shouldReceive('getLabels') |
|
36 |
->with(['ark:/12148/cb11946662b', 'ark:/12148/cb11965628b']) |
|
37 |
->once() |
|
38 |
->andReturn([ |
|
39 |
'ark:/12148/cb11946662b' => 'parents et enfants', |
|
40 |
'ark:/12148/cb11965628b' => 'frères et soeurs' |
|
41 |
]); |
|
42 |
$response = $this->get('/api/v1/bnf/cb11946662b,cb11965628b')-> |
|
43 |
seeJsonEquals(['bnfids' => [ |
|
44 |
'ark:/12148/cb11946662b' => 'parents et enfants', |
|
45 |
'ark:/12148/cb11965628b' => 'frères et soeurs' |
|
46 |
]]); |
|
47 |
} |
|
48 |
|
|
49 |
public function testShowOne() { |
|
50 |
$this->bnfResolver |
|
51 |
->shouldReceive('getLabels') |
|
52 |
->with(['ark:/12148/cb11946662b']) |
|
53 |
->once() |
|
54 |
->andReturn([ |
|
55 |
'ark:/12148/cb11946662b' => 'parents et enfants' |
|
56 |
]); |
|
57 |
$response = $this->get('/api/v1/bnf/cb11946662b')-> |
|
58 |
seeJsonEquals(['bnfids' => [ |
|
59 |
'ark:/12148/cb11946662b' => 'parents et enfants' |
|
60 |
]]); |
|
61 |
} |
|
62 |
|
|
63 |
public function testShowUnknown() { |
|
64 |
$this->bnfResolver |
|
65 |
->shouldReceive('getLabels') |
|
66 |
->with(['ark:/12148/cb12345678b']) |
|
67 |
->once() |
|
68 |
->andReturn([ |
|
69 |
'ark:/12148/cb12345678b' => null |
|
70 |
]); |
|
71 |
$response = $this->get('/api/v1/bnf/cb12345678b')-> |
|
72 |
seeJsonEquals(['bnfids' => [ |
|
73 |
'ark:/12148/cb12345678b' => null |
|
74 |
]]); |
|
75 |
} |
|
76 |
|
|
77 |
public function testShowMalformed() { |
|
78 |
$this->bnfResolver |
|
79 |
->shouldReceive('getLabels') |
|
80 |
->with(['ark:/12148/abcdef','ark:/12148/ghij']) |
|
81 |
->once() |
|
82 |
->andThrow('CorpusParole\Services\BnfResolverException', "BnfId not in correct format", 500); |
|
83 |
$response = $this->get('/api/v1/bnf/abcdef,ghij'); |
|
84 |
|
|
85 |
$this->assertResponseStatus(500); |
|
86 |
} |
|
87 |
|
|
88 |
} |