1,8 → 1,9 |
<?php |
require_once dirname(__FILE__).'/../ServicePhpUnit.php'; |
|
class NomDetailsBdtfxTest extends ServicePhpUnit { |
class NomsServiceBdtfxTest extends ServicePhpUnit { |
|
private $retour = ''; |
private $nomDetailSqueletteUrl = 'http://localhost/service:eflore:0.2/bdtfx/noms/%s'; |
private $ontologieHrefTpl = 'http://localhost/service:eflore:0.2/bdnt/ontologies/rangTaxo:%s'; |
private $champsProjet = array( |
13,7 → 14,6 |
public function __construct() { |
$this->projet = 'bdtfx'; |
$this->service = 'noms'; |
$this->classeTestee = 'NomDetailsGenerique'; |
} |
|
public function initialiserService(NomsListe $service) { |
22,6 → 22,214 |
$service->setChampsProjet($this->champsProjet); |
} |
|
public function testVersionPrecise() { |
$ressources = array(); |
$parametres = array('version.projet' => '1.01', 'recherche' => 'etendue', 'masque' => 'acer'); |
|
$this->retour = $this->consulter($ressources, $parametres); |
|
$this->verifierStructureListe(); |
$this->verifierMasque('nom_sci=acer%'); |
$this->verifierTotal(156); |
$this->verifierNbreResultats(100); |
} |
|
public function testNomsVersionMultiple() { |
$ressources = array(); |
$parametres = array('version.projet' => '*', 'recherche' => 'etendue', 'masque' => 'acer'); |
|
$this->retour = $this->consulterBrut($ressources, $parametres); |
|
$this->verifierPresenceMessage("L'affichage de plusieurs versions ne fonctionne que pour les ressources de type /ressources/#id"); |
} |
|
public function testVersionInexistante() { |
$ressources = array(); |
$parametres = array('version.projet' => '99.00'); |
|
$this->retour = $this->consulterBrut($ressources, $parametres); |
|
$this->verifierPresenceMessage("La version '99.00' n'est pas disponible pour le projet 'bdtfx' !"); |
} |
|
public function testAucunResultat() { |
$ressources = array(); |
$parametres = array( |
'version.projet' => '1.01', |
'recherche' => 'stricte', |
'masque' => 'Axer'); |
|
$this->retour = $this->consulterBrut($ressources, $parametres); |
|
$this->verifierPresenceMessage("Aucun résultat ne correspond a votre requête !"); |
} |
|
public function testRechercheStricte() { |
$ressources = array(); |
$parametres = array( |
'version.projet' => '1.01', |
'recherche' => 'stricte', |
'masque' => 'Acer'); |
|
$this->retour = $this->consulter($ressources, $parametres); |
|
$this->verifierStructureListe(); |
$this->verifierMasque('nom_sci=Acer'); |
$this->verifierTotal(1); |
$this->verifierNbreResultats(1); |
} |
|
public function testResultatChamps() { |
$ressources = array(); |
$parametres = array( |
'version.projet' => '1.01', |
'recherche' => 'stricte', |
'masque.nn' => '182'); |
|
$this->retour = $this->consulter($ressources, $parametres); |
|
$this->verifierStructureListe(); |
$this->verifierMasque('num_nom=182'); |
$this->verifierTotal(1); |
$this->verifierNbreResultats(1); |
$this->verifierLigneResultatsStructure(182); |
$this->verifierResultatsLigneAttributValeur(182, 'retenu', true); |
$this->verifierResultatsLigneAttributValeur(182, 'nom_sci', 'Acer monspessulanum'); |
} |
|
public function testMasqueSg() { |
$ressources = array(); |
$parametres = array( |
'version.projet' => '1.01', |
'recherche' => 'stricte', |
'masque.sg' => 'Asteraceae'); |
|
$this->retour = $this->consulter($ressources, $parametres); |
|
$this->verifierStructureListe(); |
$this->verifierMasque('nom_supra_generique=Asteraceae'); |
$this->verifierTotal(1); |
$this->verifierNbreResultats(1); |
} |
|
public function testMasqueGenSpSspAuAn() { |
$ressources = array(); |
$parametres = array( |
'version.projet' => '1.01', |
'recherche' => 'stricte', |
'masque.gen' => 'Allium', |
'masque.sp' => 'carinatum', |
'masque.ssp' => 'consimile', |
'masque.au' => 'Gren.', |
'masque.an' => '1855'); |
|
$this->retour = $this->consulter($ressources, $parametres); |
|
$this->verifierStructureListe(); |
$this->verifierMasque('genre=Allium&epithete_sp=carinatum&epithete_infra_sp=consimile&auteur=Gren.&annee=1855'); |
$this->verifierTotal(1); |
$this->verifierNbreResultats(1); |
} |
|
public function testMasqueNn() { |
$ressources = array(); |
$parametres = array( |
'version.projet' => '1.01', |
'recherche' => 'stricte', |
'masque.nn' => '182'); |
|
$this->retour = $this->consulter($ressources, $parametres); |
|
$this->verifierStructureListe(); |
$this->verifierMasque('num_nom=182'); |
$this->verifierTotal(1); |
$this->verifierNbreResultats(1); |
$this->verifierLigneResultatsStructure(182); |
} |
|
public function testMasqueRg() { |
$ressources = array(); |
$parametres = array( |
'version.projet' => '1.01', |
'recherche' => 'stricte', |
'masque.rg' => '180'); |
|
$this->retour = $this->consulter($ressources, $parametres); |
|
$this->verifierStructureListe(); |
$this->verifierMasque('rang=180'); |
$this->verifierTotal(210); |
} |
|
// TODO : à implémenter! |
/* |
public function testNomsIdVersionMultiple() { |
$ressources = array('71711'); |
$parametres = array('version.projet' => '*'); |
|
$retour = $this->consulter($ressources, $parametres); |
$this->assertArrayHasKey('bdtfx_v1_01', $retour, "Le json ne contient pas d'attribut : bdtfx_v1_01."); |
$this->assertArrayHasKey('bdtfx_v1_02', $retour, "Le json ne contient pas d'attribut : bdtfx_v1_02."); |
$this->assertEquals('71711', $retour['bdtfx_v1_01']['id'], "'bdtfx_v1_01' doit contenir un attribut 'id' avec la valeur '71711'"); |
$this->assertEquals('71711', $retour['bdtfx_v1_02']['id'], "'bdtfx_v1_02' doit contenir un attribut 'id' avec la valeur '71711'"); |
}*/ |
|
// TODO : à implémenter |
/* |
public function testNsStructureTxt() { |
$ressources = array(); |
$parametres = array( |
'version.projet' => '1.01', |
'recherche' => 'stricte', |
'masque.nn' => '182', |
'ns.format' => 'txt', |
'ns.structure' => 'au,an,bib,ad'); |
|
$this->retour = $this->consulter($ressources, $parametres); |
|
$this->verifierStructureListe(); |
$this->verifierMasque('num_nom=182'); |
$this->verifierTotal(1); |
$this->verifierNbreResultats(1); |
$this->verifierResultatsLigneAttributValeur(182, 'nom_sci', 'Acer monspessulanum L. [1753, Sp. Pl., éd. 1 : 1056]'); |
}*/ |
|
// TODO : à implémenter |
/* |
public function testNsStructureHtml() { |
$ressources = array(); |
$parametres = array( |
'version.projet' => '1.01', |
'recherche' => 'stricte', |
'masque.nn' => '182', |
'ns.format' => 'htm', |
'ns.structure' => 'au,an,bib,ad'); |
|
$this->retour = $this->consulter($ressources, $parametres); |
|
$this->verifierStructureListe(); |
$this->verifierMasque('num_nom=182'); |
$this->verifierTotal(1); |
$this->verifierNbreResultats(1); |
$nomSciAttendu = '<span class="sci"><span class="gen">Acer</span> <span class="sp">monspessulanum</span></span> <span class="auteur">L.</span> [<span class="annee">1753</span>, <span class="biblio">Sp. Pl., éd. 1 : 1056</span>]'; |
$this->verifierResultatsLigneAttributValeur(182, 'nom_sci', $nomSciAttendu); |
}*/ |
|
public function testListeNomsAvecParametreRetourChamps() { |
$ressources = array(); |
$parametres = array('version.projet' => '1.01', |
'masque' => 'acer', |
'retour.champs' => 'auteur,nom_retenu.*'); |
|
$this->retour = $this->consulter($ressources, $parametres); |
|
$this->verifierStructureListe(); |
$this->presenceAttributDansResultat(83587, 'auteur'); |
$this->presenceAttributDansResultat(83587, 'nom_retenu.id'); |
$this->presenceAttributDansResultat(83587, 'nom_retenu.href'); |
$this->abscenceAttributDansResultat(83587, 'nom_retenu'); |
} |
|
public function testSansParametres() { |
$ressources = array('85'); |
$parametres = array(); |
77,5 → 285,48 |
$this->assertArrayNotHasKey('nom_retenu.href', $retour, 'Abscence champ nom_retenu.href'); |
} |
|
private function verifierPresenceMessage($messageAttendu) { |
$this->assertEquals($messageAttendu, $this->retour); |
} |
|
private function verifierStructureListe() { |
$this->assertArrayHasKey('entete', $this->retour, "Présence attribut : entete"); |
$this->assertArrayHasKey('masque', $this->retour['entete'], "Présence attribut : entete>masque"); |
$this->assertArrayHasKey('depart', $this->retour['entete'], "Présence attribut : entete>depart"); |
$this->assertArrayHasKey('limite', $this->retour['entete'], "Présence attribut : entete>limite"); |
$this->assertArrayHasKey('total', $this->retour['entete'], "Présence attribut : entete>total"); |
$this->assertArrayHasKey('resultats', $this->retour, "Présence attribut : resultats"); |
} |
|
private function verifierMasque($masque) { |
$this->assertEquals($masque, $this->retour['entete']['masque'], "Attribut 'entete>masque' = '$masque'"); |
} |
|
private function verifierTotal($total) { |
$this->assertSame($total, $this->retour['entete']['total'], "Attribut 'entete>total' = $total"); |
} |
|
private function verifierNbreResultats($nbre) { |
$this->assertSame($nbre, count($this->retour['resultats']), "Nbre 'resultats' = 1"); |
} |
|
private function verifierLigneResultatsStructure($ligne) { |
$this->assertArrayHasKey($ligne, $this->retour['resultats'], "Presence attribut : resultats>$ligne".print_r($this->retour, true)); |
$this->assertArrayHasKey('nom_sci', $this->retour['resultats'][$ligne], "Presence attribut : resultats>$ligne>nom_sci".print_r($this->retour, true)); |
$this->assertArrayHasKey('retenu', $this->retour['resultats'][$ligne], "Presence attribut : resultats>$ligne>retenu".print_r($this->retour, true)); |
$this->assertArrayHasKey('href', $this->retour['resultats'][$ligne], "Presence attribut : resultats>$ligne>href".print_r($this->retour, true)); |
} |
|
private function presenceAttributDansResultat($ligne, $attribut) { |
$this->assertArrayHasKey($attribut, $this->retour['resultats'][$ligne], "Présence attribut : resultats>$ligne>$attribut"); |
} |
|
private function abscenceAttributDansResultat($ligne, $attribut) { |
$this->assertArrayNotHasKey($attribut, $this->retour['resultats'][$ligne], "Présence attribut : resultats>$ligne>$attribut"); |
} |
|
private function verifierResultatsLigneAttributValeur($ligne, $attribut, $valeur) { |
$this->assertSame($valeur, $this->retour['resultats'][$ligne][$attribut], "Attribut 'resultats>$ligne>$attribut' = $valeur"); |
} |
} |
?> |