|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
declare(strict_types=1); |
|
4
|
|
|
|
|
5
|
|
|
namespace App\Domain\Publisher\Tests; |
|
6
|
|
|
|
|
7
|
|
|
use App\Domain\Publisher\GoogleBookMapper; |
|
8
|
|
|
use PHPUnit\Framework\TestCase; |
|
9
|
|
|
use Scriptotek\GoogleBooks\Volume; |
|
10
|
|
|
|
|
11
|
|
|
class GoogleBookMapperTest extends TestCase |
|
12
|
|
|
{ |
|
13
|
|
|
/** |
|
14
|
|
|
* @var Volume |
|
15
|
|
|
*/ |
|
16
|
|
|
private $volume; |
|
17
|
|
|
|
|
18
|
|
|
public function setUp(): void |
|
19
|
|
|
{ |
|
20
|
|
|
$text = file_get_contents(__DIR__.'/googleBook.json'); |
|
21
|
|
|
$json = json_decode($text); |
|
22
|
|
|
|
|
23
|
|
|
$volumeInfo = $json->items[0]->volumeInfo; |
|
24
|
|
|
$this->volume = new Volume('bla', $volumeInfo); |
|
25
|
|
|
} |
|
26
|
|
|
|
|
27
|
|
|
public function testProcess() |
|
28
|
|
|
{ |
|
29
|
|
|
$mapper = new GoogleBookMapper(); |
|
30
|
|
|
$actual = $mapper->process($this->volume); |
|
31
|
|
|
|
|
32
|
|
|
$this::assertSame( |
|
33
|
|
|
[ |
|
34
|
|
|
'langue' => null, |
|
35
|
|
|
'auteur1' => 'Collectif', |
|
36
|
|
|
'auteur2' => null, |
|
37
|
|
|
'auteur3' => null, |
|
38
|
|
|
'titre' => 'Histoire de la Provence....', |
|
39
|
|
|
'sous-titre' => 'La Provence moderne, 1481-1800', |
|
40
|
|
|
'année' => '1991', |
|
41
|
|
|
'pages totales' => '', |
|
42
|
|
|
'isbn' => '9782737309526', |
|
43
|
|
|
'présentation en ligne' => null, |
|
44
|
|
|
'lire en ligne' => null, |
|
45
|
|
|
], |
|
46
|
|
|
$actual |
|
47
|
|
|
); |
|
48
|
|
|
} |
|
49
|
|
|
|
|
50
|
|
|
public function testProcessWithLang() |
|
51
|
|
|
{ |
|
52
|
|
|
$mapper = new GoogleBookMapper(); |
|
53
|
|
|
$mapper->mapLanguageData(true); |
|
54
|
|
|
$actual = $mapper->process($this->volume); |
|
55
|
|
|
|
|
56
|
|
|
$this::assertSame( |
|
57
|
|
|
[ |
|
58
|
|
|
'langue' => 'en', |
|
59
|
|
|
'auteur1' => 'Collectif', |
|
60
|
|
|
'auteur2' => null, |
|
61
|
|
|
'auteur3' => null, |
|
62
|
|
|
'titre' => 'Histoire de la Provence....', |
|
63
|
|
|
'sous-titre' => 'La Provence moderne, 1481-1800', |
|
64
|
|
|
'année' => '1991', |
|
65
|
|
|
'pages totales' => '', |
|
66
|
|
|
'isbn' => '9782737309526', |
|
67
|
|
|
'présentation en ligne' => null, |
|
68
|
|
|
'lire en ligne' => null, |
|
69
|
|
|
], |
|
70
|
|
|
$actual |
|
71
|
|
|
); |
|
72
|
|
|
} |
|
73
|
|
|
} |
|
74
|
|
|
|