|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
declare(strict_types=1); |
|
4
|
|
|
|
|
5
|
|
|
namespace App\Domain\Publisher\Tests; |
|
6
|
|
|
|
|
7
|
|
|
use App\Domain\OuvrageOptimize; |
|
8
|
|
|
use App\Domain\Publisher\Wikidata2Ouvrage; |
|
9
|
|
|
use App\Domain\WikiTemplateFactory; |
|
10
|
|
|
use App\Infrastructure\WikidataAdapter; |
|
11
|
|
|
use Exception; |
|
12
|
|
|
use GuzzleHttp\Client; |
|
13
|
|
|
use PHPUnit\Framework\TestCase; |
|
14
|
|
|
|
|
15
|
|
|
include __DIR__.'/../../../Application/myBootstrap.php'; |
|
16
|
|
|
|
|
17
|
|
|
class Wikidata2OuvrageTest extends TestCase |
|
18
|
|
|
{ |
|
19
|
|
|
/** |
|
20
|
|
|
* @throws Exception |
|
21
|
|
|
*/ |
|
22
|
|
|
public function testIntegrationComplete() |
|
23
|
|
|
{ |
|
24
|
|
|
$this::markTestSkipped("test d'integration avec requete WIKIDATA"); |
|
25
|
|
|
// besoin bootstrap user-agent pour requete ? |
|
26
|
|
|
|
|
27
|
|
|
$ouvrage = WikiTemplateFactory::create('ouvrage'); |
|
28
|
|
|
$ouvrage->hydrateFromText('{{Ouvrage|auteur=Bob|titre=Ma vie|passage=407-408}}'); |
|
29
|
|
|
// Houellebecq : La carte et le Territoire |
|
30
|
|
|
$ouvrage->setInfos( |
|
31
|
|
|
[ |
|
32
|
|
|
'isbn' => '978-2-08-124633-1', |
|
33
|
|
|
'ISNIAuteur1' => '0000 0001 2137 320X', |
|
34
|
|
|
] |
|
35
|
|
|
); |
|
36
|
|
|
|
|
37
|
|
|
$wikidataAdapter = new WikidataAdapter( |
|
38
|
|
|
new Client(['timeout' => 60, 'headers' => ['User-Agent' => getenv('USER_AGENT')]]) |
|
39
|
|
|
); |
|
40
|
|
|
$convert = new Wikidata2Ouvrage($wikidataAdapter, $ouvrage); |
|
41
|
|
|
$wdOuvrage = $convert->getOuvrage(); |
|
42
|
|
|
$this::assertSame( |
|
43
|
|
|
'{{Ouvrage|auteur1=Bob|lien auteur1=Michel Houellebecq|titre=Ma vie|lien titre=La Carte et le Territoire|éditeur=|année=|passage=407-408 |pages totales=|isbn=}}', |
|
44
|
|
|
$wdOuvrage->serialize(true) |
|
45
|
|
|
); |
|
46
|
|
|
|
|
47
|
|
|
// Après optimization |
|
48
|
|
|
$optimizer = new OuvrageOptimize($wdOuvrage, 'Bla'); |
|
49
|
|
|
$optimizer->doTasks(); |
|
50
|
|
|
$this::assertSame( |
|
51
|
|
|
'{{Ouvrage|auteur1=Bob|lien auteur1=Michel Houellebecq|titre=Ma vie|lien titre=La Carte et le Territoire|éditeur=|année=|passage=407-408 |pages totales=|isbn=}}', |
|
52
|
|
|
$optimizer->getOuvrage()->serialize(true) |
|
53
|
|
|
); |
|
54
|
|
|
} |
|
55
|
|
|
} |
|
56
|
|
|
|