145 |
jpm |
1 |
<?php
|
|
|
2 |
include_once dirname(__FILE__).'/ResultatFormateurCommun.php';
|
|
|
3 |
|
|
|
4 |
class DeterminationFormateurTest extends ResultatFormateurCommun {
|
|
|
5 |
|
|
|
6 |
public function testerFormater() {
|
|
|
7 |
$Formateur = $this->initialiserDeterminationFormateur();
|
|
|
8 |
|
|
|
9 |
$Formateur->formater();
|
|
|
10 |
$infos = $Formateur->getTplInfos();
|
|
|
11 |
|
|
|
12 |
$this->assertArrayHasKey('noms', $infos, print_r($infos, true));
|
|
|
13 |
foreach ($infos['noms'] as $id => $nom) {
|
|
|
14 |
$this->assertTrue(is_int($id), "L'id '$id' doit être un nombre entier.");
|
|
|
15 |
$this->assertCount(3, $nom);
|
|
|
16 |
$this->assertArrayHasKey('nomSciRetenu', $infos['noms'][$id], print_r($infos, true));
|
|
|
17 |
$this->assertArrayHasKey('urlFiche', $infos['noms'][$id], print_r($infos, true));
|
|
|
18 |
$urlFicheAttendue = sprintf(self::TPL_URL_FICHE, $id);
|
|
|
19 |
$this->assertEquals($urlFicheAttendue, $infos['noms'][$id]['urlFiche'], print_r($infos, true));
|
|
|
20 |
if (array_key_exists('synonymes', $infos['noms'][$id])) {
|
|
|
21 |
$synonymes = $infos['noms'][$id]['synonymes'];
|
|
|
22 |
$this->assertTrue(is_array($infos['noms'][$id]['synonymes']));
|
|
|
23 |
foreach ($synonymes as $synonyme) {
|
|
|
24 |
$this->assertCount(3, $synonyme, print_r($infos, true));
|
|
|
25 |
$this->assertArrayHasKey('nn', $synonyme, print_r($infos, true));
|
|
|
26 |
$this->assertTrue(is_int($synonyme['nn']), "La valeur nn (num_nom) '{$synonyme['nn']}' doit être un nombre entier.");
|
|
|
27 |
$this->assertArrayHasKey('nomSci', $synonyme, print_r($infos, true));
|
|
|
28 |
$this->assertArrayHasKey('urlFiche', $synonyme, print_r($infos, true));
|
|
|
29 |
$urlSynoAttendue = sprintf(self::TPL_URL_FICHE, $synonyme['nn']);
|
|
|
30 |
$this->assertEquals($urlSynoAttendue, $synonyme['urlFiche'], print_r($infos, true));
|
|
|
31 |
}
|
|
|
32 |
}
|
|
|
33 |
}
|
|
|
34 |
|
|
|
35 |
$this->assertArrayHasKey('nomsSansCorrespondance', $infos, print_r($infos, true));
|
|
|
36 |
$this->assertEmpty($infos['nomsSansCorrespondance']);
|
|
|
37 |
|
|
|
38 |
$this->assertArrayHasKey('imagesUrls', $infos, print_r($infos, true));
|
|
|
39 |
$this->assertTrue(is_array($infos['imagesUrls']), "'imagesUrls' doit être un tableau");
|
|
|
40 |
$this->assertArrayHasKey('72117', $infos['imagesUrls'], print_r($infos, true));
|
|
|
41 |
$this->assertArrayHasKey('72288', $infos['imagesUrls'], print_r($infos, true));
|
|
|
42 |
foreach ($infos['imagesUrls'] as $imgUrl) {
|
|
|
43 |
$this->assertTrue(is_array($imgUrl), "Chaque taxon doit avoir un tableau d'url d'images");
|
|
|
44 |
foreach ($imgUrl as $url) {
|
|
|
45 |
$this->assertRegExp('/^http:\/\/www\.tela-botanica\.org\/appli:cel-img:[0-9]{9}CS\.jpg$/', $url);
|
|
|
46 |
}
|
|
|
47 |
}
|
|
|
48 |
}
|
|
|
49 |
|
|
|
50 |
public function testerTrier() {
|
|
|
51 |
$Formateur = $this->initialiserDeterminationFormateur();
|
|
|
52 |
|
|
|
53 |
$Formateur->formater();
|
|
|
54 |
$Formateur->trier();
|
|
|
55 |
$infos = $Formateur->getTplInfos();
|
|
|
56 |
|
|
|
57 |
$this->assertArrayHasKey('noms', $infos, print_r($infos, true));
|
|
|
58 |
$ordreClesAttendu = array(72288, 72201, 72117);
|
|
|
59 |
$ordreClesTriees = array_keys($infos['noms']);
|
|
|
60 |
$this->assertEquals($ordreClesAttendu, $ordreClesTriees, print_r($ordreClesTriees, true));
|
|
|
61 |
}
|
|
|
62 |
|
|
|
63 |
public function testerSurligner() {
|
|
|
64 |
$Formateur = $this->initialiserDeterminationFormateur();
|
|
|
65 |
|
|
|
66 |
$Formateur->formater();
|
|
|
67 |
$Formateur->surligner();
|
|
|
68 |
$infos = $Formateur->getTplInfos();
|
|
|
69 |
|
|
|
70 |
$this->assertArrayHasKey('noms', $infos, print_r($infos, true));
|
|
|
71 |
foreach ($infos['noms'] as $id => $nom) {
|
|
|
72 |
$this->assertArrayHasKey($id, $infos['noms'], print_r($infos, true));
|
|
|
73 |
$this->assertArrayHasKey('nomSciRetenu', $infos['noms'][$id], print_r($infos, true));
|
|
|
74 |
$this->assertContains('<span class="surlignage">Viola</span>', $infos['noms'][$id]['nomSciRetenu'], print_r($infos, true));
|
|
|
75 |
|
|
|
76 |
}
|
|
|
77 |
}
|
|
|
78 |
|
|
|
79 |
private function initialiserDeterminationFormateur($masque = 'viola his') {
|
|
|
80 |
$parametres = $this->getParametres('determination', $masque);
|
|
|
81 |
$resultats = $this->getResultatsPourMasque($masque);
|
|
|
82 |
$surligneur = $this->getSurligneur();
|
|
|
83 |
$trieur = $this->getTrieur();
|
|
|
84 |
$appsUrls = $this->getAppUrls();
|
|
|
85 |
$images = $this->getImagesService();
|
|
|
86 |
return new DeterminationFormateur($parametres, $resultats, $surligneur, $trieur, $appsUrls, null, $images);
|
|
|
87 |
}
|
|
|
88 |
|
|
|
89 |
private function getImagesService() {
|
|
|
90 |
$retour = array(
|
|
|
91 |
'bdtfx.72117' => array(
|
|
|
92 |
'http://www.tela-botanica.org/appli:cel-img:000025491CS.jpg',
|
|
|
93 |
'http://www.tela-botanica.org/appli:cel-img:000025514CS.jpg',
|
|
|
94 |
'http://www.tela-botanica.org/appli:cel-img:000025520CS.jpg'),
|
|
|
95 |
'bdtfx.72288' => array(
|
|
|
96 |
'http://www.tela-botanica.org/appli:cel-img:000032710CS.jpg',
|
|
|
97 |
'http://www.tela-botanica.org/appli:cel-img:000032711CS.jpg',
|
|
|
98 |
'http://www.tela-botanica.org/appli:cel-img:000032712CS.jpg'));
|
|
|
99 |
|
|
|
100 |
$Images = $this->getMock('Images', array('getUrlsImagesParIdsNoms'), array(), '', false);
|
|
|
101 |
$Images->expects($this->any())
|
|
|
102 |
->method('getUrlsImagesParIdsNoms')
|
|
|
103 |
->will($this->returnValue($retour));
|
|
|
104 |
return $Images;
|
|
|
105 |
}
|
|
|
106 |
}
|
|
|
107 |
?>
|