author | ymh <ymh.work@gmail.com> |
Thu, 16 Nov 2017 16:31:09 +0100 | |
changeset 554 | f28a539ba106 |
parent 537 | d2e6ee099125 |
permissions | -rw-r--r-- |
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 |
]); |
|
306
3fccf43160a7
Some more changes linked to the change of api organization + some jshint error cleaning
ymh <ymh.work@gmail.com>
parents:
133
diff
changeset
|
42 |
$response = $this->get('/api/v1/resolvers/bnf/cb11946662b,cb11965628b')-> |
537
d2e6ee099125
upgrade ember + laravel + make everything work
ymh <ymh.work@gmail.com>
parents:
306
diff
changeset
|
43 |
assertJson(['bnfids' => [ |
133 | 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 |
]); |
|
306
3fccf43160a7
Some more changes linked to the change of api organization + some jshint error cleaning
ymh <ymh.work@gmail.com>
parents:
133
diff
changeset
|
57 |
$response = $this->get('/api/v1/resolvers/bnf/cb11946662b')-> |
537
d2e6ee099125
upgrade ember + laravel + make everything work
ymh <ymh.work@gmail.com>
parents:
306
diff
changeset
|
58 |
assertJson(['bnfids' => [ |
133 | 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 |
]); |
|
306
3fccf43160a7
Some more changes linked to the change of api organization + some jshint error cleaning
ymh <ymh.work@gmail.com>
parents:
133
diff
changeset
|
71 |
$response = $this->get('/api/v1/resolvers/bnf/cb12345678b')-> |
537
d2e6ee099125
upgrade ember + laravel + make everything work
ymh <ymh.work@gmail.com>
parents:
306
diff
changeset
|
72 |
assertJson(['bnfids' => [ |
133 | 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); |
|
306
3fccf43160a7
Some more changes linked to the change of api organization + some jshint error cleaning
ymh <ymh.work@gmail.com>
parents:
133
diff
changeset
|
83 |
$response = $this->get('/api/v1/resolvers/bnf/abcdef,ghij'); |
133 | 84 |
|
537
d2e6ee099125
upgrade ember + laravel + make everything work
ymh <ymh.work@gmail.com>
parents:
306
diff
changeset
|
85 |
$response->assertStatus(500); |
133 | 86 |
} |
87 |
||
88 |
} |