1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* This file is part of dispositif/wikibot application |
4
|
|
|
* 2019 : Philippe M. <[email protected]> |
5
|
|
|
* For the full copyright and MIT license information, please view the LICENSE file. |
6
|
|
|
*/ |
7
|
|
|
|
8
|
|
|
declare(strict_types=1); |
9
|
|
|
|
10
|
|
|
namespace App\Infrastructure\Tests; |
11
|
|
|
|
12
|
|
|
use App\Infrastructure\WikidataAdapter; |
13
|
|
|
use GuzzleHttp\Client; |
14
|
|
|
use GuzzleHttp\Handler\MockHandler; |
15
|
|
|
use GuzzleHttp\HandlerStack; |
16
|
|
|
use GuzzleHttp\Psr7\Response; |
17
|
|
|
use PHPUnit\Framework\TestCase; |
18
|
|
|
|
19
|
|
|
/** |
20
|
|
|
* Class WikidataAdapterTest |
21
|
|
|
* |
22
|
|
|
* @package App\Infrastructure\Tests |
23
|
|
|
*/ |
24
|
|
|
class WikidataAdapterTest extends TestCase |
25
|
|
|
{ |
26
|
|
|
public function testFindArticleByISBN() |
27
|
|
|
{ |
28
|
|
|
$jsonFixture = file_get_contents(__DIR__.'/fixture_WD_ISBN.json'); |
29
|
|
|
|
30
|
|
|
$mock = new MockHandler( |
31
|
|
|
[ |
32
|
|
|
new Response(200, ['X-Foo' => 'Bar'], $jsonFixture), |
33
|
|
|
] |
34
|
|
|
); |
35
|
|
|
$handler = HandlerStack::create($mock); |
36
|
|
|
$clientMocked = new Client(['handler' => $handler]); |
37
|
|
|
|
38
|
|
|
$wikidata = new WikidataAdapter($clientMocked); |
39
|
|
|
$actual = $wikidata->findArticleByISBN13('9782-081246331'); |
40
|
|
|
|
41
|
|
|
$this::assertSame( |
42
|
|
|
'https://fr.wikipedia.org/wiki/La_Carte_et_le_Territoire', |
43
|
|
|
$actual['article']['value'] |
44
|
|
|
); |
45
|
|
|
|
46
|
|
|
$this::assertSame( |
47
|
|
|
'La Carte et le Territoire', |
48
|
|
|
$actual['workLabel']['value'] |
49
|
|
|
); |
50
|
|
|
|
51
|
|
|
$this::assertSame( |
52
|
|
|
'978-2-08-124633-1', |
53
|
|
|
$actual['isbn']['value'] |
54
|
|
|
); |
55
|
|
|
} |
56
|
|
|
|
57
|
|
|
public function testSearchISNI() |
58
|
|
|
{ |
59
|
|
|
$jsonFixture = file_get_contents(__DIR__.'/fixture_WD_ISNI.json'); |
60
|
|
|
|
61
|
|
|
$mock = new MockHandler( |
62
|
|
|
[ |
63
|
|
|
new Response(200, ['X-Foo' => 'Bar'], $jsonFixture), |
64
|
|
|
] |
65
|
|
|
); |
66
|
|
|
$handler = HandlerStack::create($mock); |
67
|
|
|
$clientMocked = new Client(['handler' => $handler]); |
68
|
|
|
|
69
|
|
|
$wikidata = new WikidataAdapter($clientMocked); |
70
|
|
|
$actual = $wikidata->searchByISNI('0000 0001 2137 320X'); |
71
|
|
|
|
72
|
|
|
$this::assertSame( |
73
|
|
|
'https://fr.wikipedia.org/wiki/Michel_Houellebecq', |
74
|
|
|
$actual['article']['value'] |
75
|
|
|
); |
76
|
|
|
|
77
|
|
|
$this::assertSame( |
78
|
|
|
'66522427', |
79
|
|
|
$actual['viaf']['value'] |
80
|
|
|
); |
81
|
|
|
} |
82
|
|
|
} |
83
|
|
|
|