Subversion Repositories eFlore/Projets.eflore-projets

Compare Revisions

No changes between revisions

Ignore whitespace Rev 923 → Rev 922

/trunk/services/tests/0.2/bdtfx/NomsServiceBdftxTest.php
New file
0,0 → 1,399
<?php
require_once dirname(__FILE__).'/../ServicePhpUnit.php';
 
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(
'presence_Ga' => 'presence_Ga.code',
'presence_Co' => 'presence_Co.code'
);
 
public function __construct() {
$this->projet = 'bdtfx';
$this->service = 'noms';
}
 
public function initialiserService(NomsListe $service) {
$service->setDetailsHrefTpl($this->nomDetailSqueletteUrl);
$service->setOntologieHrefTpl($this->ontologieHrefTpl);
$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);
}*/
 
// TODO : à implémenter
/*
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');
}*/
 
// TODO : à implémenter
/*
public function testNomsIdAvecParametreRetourChamps() {
$ressources = array('1');
$parametres = array('version.projet' => '1.01',
'retour.champs' => 'nom_retenu.*');
 
$this->retour = $this->consulter($ressources, $parametres);
 
$this->presenceAttribut('nom_retenu.id');
$this->presenceAttribut('nom_retenu.href');
$this->abscenceAttribut('nom_retenu');
$this->abscenceAttribut('auteur');
}*/
 
// TODO : à implémenter
/*
public function testListeNomAvecParametreNsStructureAuAnBibAd() {
$ressources = array();
$parametres = array('version.projet' => '1.01',
'masque.nn' => '39607',
'ns.structure' => 'au,an,bib,ad');
 
$this->retour = $this->consulter($ressources, $parametres);
 
$this->verifierStructureListe();
$this->presenceAttributDansResultat(39607, 'nom_sci');
 
$nomSciTxt = 'Lolium annuum Gilib. [1792, Exercit. Phytol., 2 : 520] [nom. invalid.]';
$this->verifierResultatsLigneAttributValeur(39607, 'nom_sci', $nomSciTxt);
}*/
 
// TODO : à implémenter
/*
public function testListeNomAvecParametreNsStructureAuAnBibAdEtNsFormatHtm() {
$ressources = array();
$parametres = array('version.projet' => '1.01',
'masque.nn' => '39607',
'ns.structure' => 'au,an,bib,ad',
'ns.format' => 'htm');
 
$this->retour = $this->consulter($ressources, $parametres);
 
$this->verifierStructureListe();
$this->verifierMasque('num_nom=39607');
 
$this->presenceAttributDansResultat(39607, 'nom_sci');
 
$nomSciHtml = "<span class=\"sci\"><span class=\"gen\">Lolium</span> <span class=\"sp\">annuum</span></span> <span class=\"auteur\">Gilib.</span> [<span class=\"annee\">1792</span>, <span class=\"biblio\">Exercit. Phytol., 2 : 520</span>] [<span class=\"adendum\">nom. invalid.</span>]";
$this->verifierResultatsLigneAttributValeur(39607, 'nom_sci', $nomSciHtml);
}*/
 
public function testSansParametres() {
$ressources = array('85');
$parametres = array();
 
$retour = $this->consulter($ressources, $parametres);
 
$this->assertTrue(is_array($retour), 'Retour est un tableau');
$this->assertArrayHasKey('id', $retour, 'Présence champ id');
$this->assertSame(85, $retour['id'], 'Valeur champ id = 85');
$this->assertArrayHasKey('nom_sci', $retour, 'Présence champ nom_sci');
 
$this->assertSame('Abutilon theophrasti', $retour['nom_sci'], 'Valeur champ nom_sci = Abutilon theophrasti');
$this->assertArrayHasKey('nom_retenu.id', $retour, 'Présence champ nom_retenu.id');
$this->assertSame(85, $retour['nom_retenu.id'], 'Valeur champ nom_sci = 85');
$this->assertArrayHasKey('nom_retenu', $retour, 'Présence champ nom_retenu');
$this->assertSame('Abutilon theophrasti', $retour['nom_retenu'], 'Valeur champ nom_retenu = Abutilon theophrasti');
$this->assertArrayHasKey('nom_retenu.href', $retour, 'Présence champ nom_retenu.href');
$urlNomRetenuHrefAttendue = sprintf($this->nomDetailSqueletteUrl, 85);
$this->assertSame($urlNomRetenuHrefAttendue, $retour['nom_retenu.href'], "Valeur champ nom_retenu.href = $urlNomRetenuHrefAttendue");
 
$this->assertArrayHasKey('rang.code', $retour, 'Présence champ rang.code');
$this->assertSame('bdnt.rangTaxo:290', $retour['rang.code'], 'Valeur champ rang.code = bdnt.rangTaxo:290');
$this->assertArrayHasKey('rang', $retour, 'Présence champ rang');
$this->assertSame('Espèce', $retour['rang'], 'Valeur champ rang = Espèce');
 
$this->assertArrayHasKey('rang.href', $retour, 'Présence champ rang.href');
$hrefAttendue =sprintf($this->ontologieHrefTpl, 290);
$this->assertSame($hrefAttendue, $retour['rang.href'], "Valeur champ rang.href = $hrefAttendue");
 
$this->assertArrayHasKey('nom_sci.genre', $retour, 'Présence champ nom_sci.genre');
$this->assertSame('Abutilon', $retour['nom_sci.genre'], "Valeur champ nom_sci.genre = 'Abutilon'");
$this->assertArrayHasKey('nom_sci.sp', $retour, 'Présence champ nom_sci.sp');
$this->assertSame('theophrasti', $retour['nom_sci.sp'], "Valeur champ nom_sci.sp = theophrasti");
 
$this->assertArrayHasKey('auteur', $retour, 'Présence champ auteur');
$this->assertSame('Medik.', $retour['auteur'], "Valeur champ auteur = 'Medik.'");
 
$this->assertArrayHasKey('presence_Ga.code', $retour, 'Présence champ presence_Ga.code'.print_r($retour,true));
$this->assertSame('P', $retour['presence_Ga.code'], "Valeur champ presence_Ga.code = 'P'");
$this->assertArrayHasKey('presence_Co.code', $retour, 'Présence champ "presence_Co.code');
$this->assertSame('P', $retour['presence_Co.code'], "Valeur champ page = P");
}
 
public function testNomSansCorrespondance() {
$ressources = array('98940');
$parametres = array();
 
$this->retour = $this->consulter($ressources, $parametres);
 
$this->abscenceAttribut('nom_retenu.id');
$this->abscenceAttribut('nom_retenu.href');
$this->verifierAttributValeur('nom_retenu', null);
}
 
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($ligne, $this->retour['resultats'], "Présence ligne : resultats>$ligne");
$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");
}
 
private function presenceAttribut($attribut) {
$this->assertArrayHasKey($attribut, $this->retour);
}
 
private function abscenceAttribut($attribut) {
$this->assertArrayNotHasKey($attribut, $this->retour);
}
 
private function verifierAttributValeur($attribut, $valeur) {
$this->presenceAttribut($attribut);
$this->assertSame($valeur, $this->retour[$attribut]);
}
}
?>
/trunk/services/tests/0.2/bdd/tb_eflore.sqlite
Cannot display: file marked as a binary type.
svn:mime-type = application/octet-stream
/trunk/services/tests/0.2/bdd/tb_eflore.sqlite
New file
Property changes:
Added: svn:mime-type
+application/octet-stream
\ No newline at end of property
/trunk/services/tests/0.2/bdd/mysql2sqlite.sh
New file
0,0 → 1,109
#!/bin/sh
# Converts a mysqldump file into a Sqlite 3 compatible file. It also extracts the MySQL `KEY xxxxx` from the
# CREATE block and create them in separate commands _after_ all the INSERTs.
 
# Awk is choosen because it's fast and portable. You can use gawk, original awk or even the lightning fast mawk.
# The mysqldump file is traversed only once.
 
# Usage: $ ./mysql2sqlite mysqldump-opts db-name | sqlite3 database.sqlite
# Example: $ ./mysql2sqlite --no-data -u root -pMySecretPassWord myDbase | sqlite3 database.sqlite
 
# Thanks to and @artemyk and @gkuenning for their nice tweaks.
 
# AJOUT 2011-12-27 : chemin vers lampp pour le dump mysql, suppression des commentaires, insenssibilité à la casse pour tous les champs
 
# USAGE :
# ./mysql2sqlite.sh --default-character-set=utf8 -u root -p tb_eflore bdnt_meta bdnt_ontologies_v4_30 bdtfx_meta bdtfx_v1_01 \
# bdtfx_v1_02 fournier_meta fournier_v1_00 | \
# sqlite3 /home/jpm/web/eflore/eflore-projets/services/tests/0.2/bdd/tb_eflore.sqlite
 
/opt/lampp/bin/mysqldump --compatible=ansi --skip-extended-insert --compact "$@" | \
 
awk '
 
BEGIN {
FS=",$"
print "PRAGMA synchronous = OFF;"
print "PRAGMA journal_mode = MEMORY;"
print "BEGIN TRANSACTION;"
}
 
# CREATE TRIGGER statements have funny commenting. Remember we are in trigger.
/^\/\*.*CREATE.*TRIGGER/ {
gsub( /^.*TRIGGER/, "CREATE TRIGGER" )
print
inTrigger = 1
next
}
 
# The end of CREATE TRIGGER has a stray comment terminator
/END \*\/;;/ { gsub( /\*\//, "" ); print; inTrigger = 0; next }
 
# The rest of triggers just get passed through
inTrigger != 0 { print; next }
 
# Skip other comments
/^\/\*/ { next }
 
# Print all `INSERT` lines. The single quotes are protected by another single quote.
/INSERT/ {
gsub( /\\\047/, "\047\047" )
gsub(/\\n/, "\n")
gsub(/\\r/, "\r")
gsub(/\\"/, "\"")
gsub(/\\\\/, "\\")
gsub(/\\\032/, "\032")
print
next
}
 
# Print the `CREATE` line as is and capture the table name.
/^CREATE/ {
print
if ( match( $0, /\"[^\"]+/ ) ) tableName = substr( $0, RSTART+1, RLENGTH-1 )
}
 
# Replace `FULLTEXT KEY` or any other `XXXXX KEY` except PRIMARY by `KEY`
/^ [^"]+KEY/ && !/^ PRIMARY KEY/ { gsub( /.+KEY/, " KEY" ) }
 
# Get rid of field lengths in KEY lines
/ KEY/ { gsub(/\([0-9]+\)/, "") }
 
# Print all fields definition lines except the `KEY` lines.
/^ / && !/^( KEY|\);)/ {
gsub( /AUTO_INCREMENT|auto_increment/, "" )
gsub( /(CHARACTER SET|character set) [^ ]+ /, "" )
gsub( /DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP|default current_timestamp on update current_timestamp/, "" )
gsub( /(COLLATE|collate) [^ ]+ /, "" )
gsub(/(ENUM|enum)[^)]+\)/, "text ")
gsub(/(SET|set)\([^)]+\)/, "text ")
gsub(/UNSIGNED|unsigned/, "")
# AJOUT : suppression des commentaires
gsub(/(COMMENT|comment) '"'"'.+'"'"',/, ",")
# AJOUT : insenssibilité à la casse pour tous les champs
if (prev) print prev " COLLATE NOCASE,"
prev = $1
}
 
# `KEY` lines are extracted from the `CREATE` block and stored in array for later print
# in a separate `CREATE KEY` command. The index name is prefixed by the table name to
# avoid a sqlite error for duplicate index name.
/^( KEY|\);)/ {
if (prev) print prev
prev=""
if ($0 == ");"){
print
} else {
if ( match( $0, /\"[^"]+/ ) ) indexName = substr( $0, RSTART+1, RLENGTH-1 )
if ( match( $0, /\([^()]+/ ) ) indexKey = substr( $0, RSTART+1, RLENGTH-1 )
key[tableName]=key[tableName] "CREATE INDEX \"" tableName "_" indexName "\" ON \"" tableName "\" (" indexKey ");\n"
}
}
 
# Print all `KEY` creation lines.
END {
for (table in key) printf key[table]
print "END TRANSACTION;"
}
'
exit 0
Property changes:
Added: svn:eol-style
+native
\ No newline at end of property
Added: svn:executable
+*
\ No newline at end of property
/trunk/services/tests/0.2/fournier/NomsListeFournierTest.php
New file
0,0 → 1,211
<?php
require_once dirname(__FILE__).'/../ServicePhpUnit.php';
 
class NomsListeFournierTest extends ServicePhpUnit {
 
private $listeUrl = 'http://localhost/service:eflore:0.2/fournier/noms';
private $nomDetailSqueletteUrl = 'http://localhost/service:eflore:0.2/fournier/noms/%s';
private $nbreNom = 168;
 
public function __construct() {
$this->projet = 'fournier';
$this->service = 'noms';
}
 
public function testSansParametres() {
$ressources = array();
$parametres = array();
 
$retour = $this->consulter($ressources, $parametres);
$this->assertArrayHasKey('entete', $retour, 'Présence champ entete');
$this->assertArrayHasKey('masque', $retour['entete'], 'Présence champ entete>masque');
$this->assertEmpty($retour['entete']['masque'], 'Valeur champ entete>masque = vide');
$this->assertArrayHasKey('depart', $retour['entete'], 'Présence champ entete>depart');
$this->assertSame(0, $retour['entete']['depart'], 'Valeur champ entete>depart = 0');
$this->assertArrayHasKey('limite', $retour['entete'], 'Présence champ entete>limite');
$this->assertSame(100, $retour['entete']['limite'], 'Valeur champ entete>limite = 100');
$this->assertArrayHasKey('total', $retour['entete'], 'Présence champ entete>total');
$this->assertNotEquals(0, $retour['entete']['total'], 'Valeur champ entete>total != 0');
$this->assertSame($this->nbreNom, $retour['entete']['total'], 'Valeur champ entete>total = 168');
$this->assertArrayNotHasKey('href.precedent', $retour['entete'], "Abscence champ entete>href.precedent");
$this->assertArrayHasKey('href.suivant', $retour['entete'], "Présence champ entete>href.suivant");
$url = $this->listeUrl.'?navigation.depart=100&navigation.limite=100';
$this->assertEquals($url, $retour['entete']['href.suivant'], "Valeur champ entete>href.suivant = $url");
 
$this->assertArrayHasKey('resultats', $retour, 'Valeur champ resultats');
$this->assertCount(100, $retour['resultats'], 'Nombre de valeurs dans resultats = 100');
$this->assertArrayNotHasKey('1', $retour['resultats'], 'Abscence champ resultats>1 car trie sur nom_sci ASC');
$this->assertArrayHasKey('2', $retour['resultats'], 'Présence champ resultats>2');
$this->assertArrayHasKey('nom_sci', $retour['resultats']['2'], 'Présence champ resultats>2>nom_sci');
$this->assertCount(3, $retour['resultats']['2'], 'Nombre de valeurs dans resultats>2 = 3');
$this->assertEquals('Cryptogames', $retour['resultats']['2']['nom_sci'], 'Test valeur champ resultats>2>nom_sci = Plantae');
$this->assertArrayHasKey('retenu', $retour['resultats']['2'], 'Présence champ resultats>2>retenu');
$this->assertTrue($retour['resultats']['2']['retenu'], 'Valeur champ resultats>2>retenu = true');
$this->assertArrayHasKey('href', $retour['resultats']['2'], 'Présence champ resultats>2>href');
$url = sprintf($this->nomDetailSqueletteUrl, '2');
$this->assertEquals($url, $retour['resultats']['2']['href'], "Valeur champ resultats>2>nom_sci = $url");
}
 
public function testParametreNavigationDepart100() {
$ressources = array();
$parametres = array('navigation.depart' => 100);
 
$retour = $this->consulter($ressources, $parametres);
 
$this->assertArrayHasKey('depart', $retour['entete'], 'Présence champ entete>depart');
$this->assertSame(100, $retour['entete']['depart'], 'Valeur champ entete>depart = 100');
$this->assertArrayHasKey('limite', $retour['entete'], 'Présence champ entete>limite');
$this->assertSame(100, $retour['entete']['limite'], 'Valeur champ entete>limite = 100');
$this->assertSame($this->nbreNom, $retour['entete']['total'], 'Valeur champ entete>total = 168');
$this->assertArrayNotHasKey('href.suivant', $retour['entete'], "Abscence champ entete>href.suivant");
$this->assertArrayHasKey('href.precedent', $retour['entete'], "Présence champ entete>href.precedent");
$url = $this->listeUrl.'?navigation.depart=0&navigation.limite=100';
$this->assertEquals($url, $retour['entete']['href.precedent'], "Valeur champ entete>href.precedent = $url");
}
 
public function testRechercheDefautMasque() {
$ressources = array();
$parametres = array('masque' => 'Lycopodium');
 
$retour = $this->consulter($ressources, $parametres);
 
$this->assertArrayHasKey('masque', $retour['entete'], 'Présence champ entete>masque');
$this->assertEquals('nom_sci=Lycopodium', $retour['entete']['masque'], 'Valeur champ entete>masque = "nom_sci=Lycopodium"');
$this->assertCount(1, $retour['resultats'], 'Nombre de valeurs dans resultats = 1');
$this->assertEquals('Lycopodium', $retour['resultats']['5']['nom_sci'], 'Test valeur champ resultats>5>nom_sci = Lycopodium');
}
 
public function testRechercheStricteMasque() {
$ressources = array();
$parametres = array('masque' => 'Lycopodium', 'recherche' => 'stricte');
 
$retour = $this->consulter($ressources, $parametres);
 
$this->assertArrayHasKey('masque', $retour['entete'], 'Présence champ entete>masque');
$this->assertEquals('nom_sci=Lycopodium', $retour['entete']['masque'], 'Valeur champ entete>masque = "nom_sci=Lycopodium"');
$this->assertCount(1, $retour['resultats'], 'Nombre de valeurs dans resultats = 1');
$this->assertEquals('Lycopodium', $retour['resultats']['5']['nom_sci'], 'Test valeur champ resultats>5>nom_sci = Lycopodium');
}
 
public function testerRechercheEtendueMasque() {
$ressources = array();
$parametres = array('masque' => 'Lycopodium', 'recherche' => 'etendue');
 
$retour = $this->consulter($ressources, $parametres);
 
$this->assertArrayHasKey('masque', $retour['entete'], 'Présence champ entete>masque');
$this->assertEquals('nom_sci=Lycopodium%', $retour['entete']['masque'], 'Valeur champ entete>masque = "nom_sci=Lycopodium%"');
$this->assertCount(11, $retour['resultats'], 'Nombre de valeurs dans resultats = 10');
foreach ($retour['resultats'] as $nom) {
$this->assertContains('Lycopodium', $nom['nom_sci'], 'Test valeur champ resultats>...>nom_sci contient Lycopodium');
}
}
 
public function testerRechercheFloueMasque() {
$ressources = array();
$parametres = array('masque' => 'Licopodium', 'recherche' => 'floue');
 
$retour = $this->consulter($ressources, $parametres);
 
$this->assertArrayHasKey('masque', $retour['entete'], 'Présence champ entete>masque');
$this->assertEquals('nom_sci=Licopodium', $retour['entete']['masque'], 'Valeur champ entete>masque = "nom_sci=Licopodium"');
$this->assertCount(1, $retour['resultats'], 'Nombre de valeurs dans resultats = 1');
$this->assertContains('Lycopodium', $retour['resultats'][5]['nom_sci'], 'Test valeur champ resultats>5>nom_sci contient Lycopodium');
}
 
public function testRechercheDefautMasqueSg() {
$ressources = array();
$parametres = array('masque.sg' => 'Lycopodiaceae');
 
$retour = $this->consulter($ressources, $parametres);
 
$this->assertArrayHasKey('masque', $retour['entete'], 'Présence champ entete>masque');
$this->assertEquals('nom_supra_generique=Lycopodiaceae', $retour['entete']['masque'], 'Valeur champ entete>masque = "nom_sci=Lycopodiaceae"');
$this->assertCount(1, $retour['resultats'], 'Nombre de valeurs dans resultats = 1');
$this->assertEquals('Lycopodiaceae', $retour['resultats']['4']['nom_sci'], 'Test valeur champ resultats>4>nom_sci = Lycopodiaceae');
}
 
public function testRechercheDefautMasqueGen() {
$ressources = array();
$parametres = array('masque.gen' => 'Lycopodium');
 
$retour = $this->consulter($ressources, $parametres);
 
$this->assertArrayHasKey('masque', $retour['entete'], 'Présence champ entete>masque');
$this->assertEquals('genre=Lycopodium', $retour['entete']['masque'], 'Valeur champ entete>masque = "genre=Lycopodium"');
$this->assertCount(11, $retour['resultats'], 'Nombre de valeurs dans resultats = 11');
foreach ($retour['resultats'] as $id => $info) {
$this->assertContains('Lycopodium', $info['nom_sci'], "Test valeur champ resultats>$id>nom_sci contient Lycopodium");
}
}
 
public function testRechercheDefautMasqueSp() {
$ressources = array();
$parametres = array('masque.sp' => 'alpinum');
 
$retour = $this->consulter($ressources, $parametres);
 
$this->assertArrayHasKey('masque', $retour['entete'], 'Présence champ entete>masque');
$this->assertEquals('epithete_sp=alpinum', $retour['entete']['masque'], 'Valeur champ entete>masque = "epithete_sp=alpinum"');
$this->assertCount(2, $retour['resultats'], 'Nombre de valeurs dans resultats = 2');
foreach ($retour['resultats'] as $id => $info) {
$this->assertContains('alpinum', $info['nom_sci'], "Test valeur champ resultats>$id>nom_sci contient alpinum");
}
}
 
public function testRechercheEtendueMasqueSg() {
$ressources = array();
$parametres = array('masque.sg' => 'Lycopodiaceae', 'recherche' => 'etendue');
 
$retour = $this->consulter($ressources, $parametres);
 
$this->assertArrayHasKey('masque', $retour['entete'], 'Présence champ entete>masque');
$this->assertEquals('nom_supra_generique=Lycopodiaceae%', $retour['entete']['masque'], 'Valeur champ entete>masque = "nom_sci=Lycopodiaceae"');
$this->assertCount(1, $retour['resultats'], 'Nombre de valeurs dans resultats = 1');
$this->assertEquals('Lycopodiaceae', $retour['resultats']['4']['nom_sci'], 'Test valeur champ resultats>4>nom_sci = Lycopodiaceae');
}
 
public function testRechercheEtendueMasqueGen() {
$ressources = array();
$parametres = array('masque.gen' => 'Lycopodium', 'recherche' => 'etendue');
 
$retour = $this->consulter($ressources, $parametres);
 
$this->assertArrayHasKey('masque', $retour['entete'], 'Présence champ entete>masque');
$this->assertEquals('genre=Lycopodium%', $retour['entete']['masque'], 'Valeur champ entete>masque = "genre=Lycopodium"');
$this->assertCount(11, $retour['resultats'], 'Nombre de valeurs dans resultats = 11');
foreach ($retour['resultats'] as $id => $info) {
$this->assertContains('Lycopodium', $info['nom_sci'], "Test valeur champ resultats>$id>nom_sci contient Lycopodium");
}
}
 
public function testRechercheEtendueMasqueSp() {
$ressources = array();
$parametres = array('masque.sp' => 'alpinum', 'recherche' => 'etendue');
 
$retour = $this->consulter($ressources, $parametres);
 
$this->assertArrayHasKey('masque', $retour['entete'], 'Présence champ entete>masque');
$this->assertEquals('epithete_sp=alpinum%', $retour['entete']['masque'], 'Valeur champ entete>masque = "epithete_sp=alpinum"');
$this->assertCount(2, $retour['resultats'], 'Nombre de valeurs dans resultats = 2');
foreach ($retour['resultats'] as $id => $info) {
$this->assertContains('alpinum', $info['nom_sci'], "Test valeur champ resultats>$id>nom_sci contient alpinum");
}
}
 
public function testRetourChamps() {
$ressources = array();
$parametres = array('retour.champs' => 'nom_retenu');
 
$retour = $this->consulter($ressources, $parametres);
 
$this->assertArrayHasKey('href.suivant', $retour['entete'], "Présence champ entete>href.suivant");
$url = $this->listeUrl.'?retour.champs=nom_retenu&navigation.depart=100&navigation.limite=100';
$this->assertEquals($url, $retour['entete']['href.suivant'], "Valeur champ entete>href.suivant = $url");
foreach ($retour['resultats'] as $id => $info) {
$this->assertArrayHasKey('nom_retenu', $info, "Présence champ resultats>$id>nom_retenu ");
}
}
 
}
?>
/trunk/services/tests/0.2/fournier/NomDetailsFournierTest.php
New file
0,0 → 1,61
<?php
require_once dirname(__FILE__).'/../ServicePhpUnit.php';
 
class NomDetailsFournierTest extends ServicePhpUnit {
 
private $nomDetailSqueletteUrl = 'http://localhost/service:eflore:0.2/fournier/noms/%s';
private $ontologieHrefTpl = 'http://localhost/service:eflore:0.2/bdnt/ontologies/rangTaxo:%s';
private $champsProjet = array(
'nom_scientifique' => 'nom_scientifique',
'auteur_origine' => 'auteur_origine',
'nom_vernaculaire' => 'nom_vernaculaire',
'page' => 'page',
'code_taxon' => 'code_taxon',
'milieu' => 'milieu',
'floraison' => 'floraison',
'type' => 'type',
'sol' => 'sol',
'rarete_region_alt' => 'rarete_region_alt',
'region_bota_monde' => 'region_bota_monde',
'etymologie' => 'etymologie',
'taille' => 'taille',
'formule_hybridite' => 'formule_hybridite',
'culture' => 'culture');
 
public function __construct() {
$this->projet = 'fournier';
$this->service = 'noms';
}
 
public function testSansParametres() {
$ressources = array('85');
$parametres = array();
 
$retour = $this->consulter($ressources, $parametres);
 
$this->assertTrue(is_array($retour), 'Retour est un tableau');
$this->assertArrayHasKey('id', $retour, 'Présence champ id');
$this->assertSame(85, $retour['id'], 'Valeur champ id = 85');
$this->assertArrayHasKey('nom_sci', $retour, 'Présence champ nom_sci');
$this->assertSame('Hymenophyllum peltatum', $retour['nom_sci'], 'Valeur champ nom_sci = Hymenophyllum peltatum');
$this->assertArrayHasKey('nom_retenu.id', $retour, 'Présence champ nom_retenu.id');
$this->assertSame(84, $retour['nom_retenu.id'], 'Valeur champ nom_sci = 84');
$this->assertArrayHasKey('nom_retenu', $retour, 'Présence champ nom_retenu');
$this->assertSame('Hymenophyllum unilaterale', $retour['nom_retenu'], 'Valeur champ nom_retenu = Hymenophyllum unilaterale');
$this->assertArrayHasKey('nom_retenu.href', $retour, 'Présence champ nom_retenu.href');
$urlNomRetenuHrefAttendue = sprintf($this->nomDetailSqueletteUrl, 84);
$this->assertSame($urlNomRetenuHrefAttendue, $retour['nom_retenu.href'], "Valeur champ nom_retenu.href = $urlNomRetenuHrefAttendue");
 
$this->assertArrayHasKey('rang.code', $retour, 'Présence champ rang.code');
$this->assertSame('bdnt.rangTaxo:290', $retour['rang.code'], 'Valeur champ rang.code = bdnt.rangTaxo:290');
$this->assertArrayHasKey('rang', $retour, 'Présence champ rang');
$this->assertSame('Espèce', $retour['rang'], 'Valeur champ rang = Espèce');
 
$this->assertArrayHasKey('rang.href', $retour, 'Présence champ rang.href');
$hrefAttendue =sprintf($this->ontologieHrefTpl, 290);
$this->assertSame($hrefAttendue, $retour['rang.href'], "Valeur champ rang.href = $hrefAttendue");
 
}
 
}
?>
/trunk/services/tests/0.2/bibliotheque/ParametresVerificateurTest.php
New file
0,0 → 1,112
<?php
require_once dirname(__FILE__).'/../ServicePhpUnit.php';
 
class ParametresVerificateurTest extends ServicePhpUnit {
 
private function initialiser($parametresUrl = array(), $parametresAPI = array()) {
$bdd = $this->getMock('Bdd');
$parametres = new Parametres($parametresUrl, $bdd);
$verificateur = new ParametresVerificateur($parametres, $parametresAPI);
return $verificateur;
}
 
public function testerValeursPermises() {
$parametresUrl = array(
'recherche' => 'declencheException',
'ns.format' => 'declencheException',
'retour' => 'declencheException',
'retour.format' => 'declencheException',
'retour.langue' => 'declencheException',
'ns.structure' => 'declencheException',
'version.projet' => 'declencheException');
 
$verificateur = $this->initialiser($parametresUrl);
 
try {
$verificateur->verifierValeurs();
} catch(Exception $e) {
$messageComplet = array("Erreur dans le paramètrage de votre URL :");
$messageTpl = "Le paramètre '%s' ne peut pas prendre la valeur 'declencheException'. Valeurs permises : %s";
$messageComplet[] = $messageAttendu = sprintf($messageTpl, 'recherche', 'stricte|floue|etendue');
$this->assertContains($messageAttendu, $e->getMessage());
$messageComplet[] = $messageAttendu = sprintf($messageTpl, 'ns.format', 'htm|txt');
$this->assertContains($messageAttendu, $e->getMessage());
$messageComplet[] = $messageAttendu = sprintf($messageTpl, 'retour', 'application/json|image/jpeg');
$this->assertContains($messageAttendu, $e->getMessage());
$messageComplet[] = $messageAttendu = sprintf($messageTpl, 'retour.format', 'min|max|oss|perso');
$this->assertContains($messageAttendu, $e->getMessage());
$messageComplet[] = $messageAttendu = sprintf($messageTpl, 'retour.langue', '/^(?:[*]|orig|[a-z]{2})$/');
$this->assertContains($messageAttendu, $e->getMessage());
$messageComplet[] = $messageAttendu = sprintf($messageTpl, 'ns.structure', '|an|au|bib|ad');
$this->assertContains($messageAttendu, $e->getMessage());
$messageComplet[] = $messageAttendu = sprintf($messageTpl, 'version.projet', '/^(?:[0-9]+[.][0-9]+|[*+])$/');
$this->assertContains($messageAttendu, $e->getMessage());
 
$this->assertEquals(implode('<br/>', $messageComplet), $e->getMessage());
return null;
}
$this->fail("Aucune exception n'a été soulevée.");
}
 
public function testerExceptionVerificationConformiteApi() {
$parametresUrl = array('code1' => 'val1');
$parametresAPI = array('paramApi');
 
$verificateur = $this->initialiser($parametresUrl, $parametresAPI);
 
try {
$verificateur->verifierConformiteApi();
} catch(Exception $e) {
$messageAttendu = "Le paramètre 'code1' n'est pas pris en compte par cette version de l'API.";
$this->assertEquals($messageAttendu, $e->getMessage());
return null;
}
$this->fail("Aucune exception n'a été soulevée.");
}
 
public function testerExceptionVerifierValeurSimple() {
$parametresUrl = array('recherche' => 'declencheException');
 
$verificateur = $this->initialiser($parametresUrl);
 
try {
$verificateur->verifierValeurs();
} catch(Exception $e) {
$messageAttendu = "Le paramètre 'recherche' ne peut pas prendre la valeur 'declencheException'. Valeurs permises : ";
$this->assertContains($messageAttendu, $e->getMessage());
return null;
}
$this->fail("Aucune exception n'a été soulevée.");
}
 
public function testerExceptionVerifierValeurRegExp() {
$parametresUrl = array('retour.langue' => '1');
 
$verificateur = $this->initialiser($parametresUrl);
 
try {
$verificateur->verifierValeurs();
} catch(Exception $e) {
$messageAttendu = "Le paramètre 'retour.langue' ne peut pas prendre la valeur '1'. Valeurs permises : ";
$this->assertContains($messageAttendu, $e->getMessage());
return null;
}
$this->fail("Aucune exception n'a été soulevée.");
}
 
public function testerExceptionVerifierValeurMultiple() {
$parametresUrl = array('ns.structure' => 'an,1');
 
$verificateur = $this->initialiser($parametresUrl);
 
try {
$verificateur->verifierValeurs();
} catch(Exception $e) {
$messageAttendu = "Le paramètre 'ns.structure' ne peut pas prendre la valeur '1'. Valeurs permises : ";
$this->assertContains($messageAttendu, $e->getMessage());
return null;
}
$this->fail("Aucune exception n'a été soulevée.");
}
}
?>
/trunk/services/tests/0.2/bibliotheque/ParametresTest.php
New file
0,0 → 1,89
<?php
require_once dirname(__FILE__).'/../ServicePhpUnit.php';
 
class ParametresTest extends ServicePhpUnit {
 
private function initialiser($parametresUrl = array()) {
$bdd = $this->getMock('Bdd');
 
$parametres = new Parametres($parametresUrl, $bdd);
return $parametres;
}
 
public function testerParametreParDefaut() {
$parametres = $this->initialiser();
 
$this->assertEquals('stricte', $parametres->get('recherche'));
$this->assertEquals('txt', $parametres->get('ns.format'));
$this->assertEquals('application/json', $parametres->get('retour'));
$this->assertEquals('max', $parametres->get('retour.format'));
$this->assertEquals('fr', $parametres->get('retour.langue'));
$this->assertEquals('+', $parametres->get('version.projet'));
$this->assertSame(0, $parametres->get('navigation.depart'));
$this->assertSame(100, $parametres->get('navigation.limite'));
}
 
public function testerExisterRetourneBouleen() {
$parametresUrl = array('masque.id' => '12,15,18');
 
$parametres = $this->initialiser($parametresUrl);
 
$this->assertTrue($parametres->exister('masque.id'));
$this->assertFalse($parametres->exister('masque'));
$this->assertTrue($parametres->exister('recherche'));
}
 
public function testerGetRetourneValeur() {
$parametresUrl = array('masque.id' => '12,15,18');
 
$parametres = $this->initialiser($parametresUrl);
 
$this->assertEquals('12,15,18', $parametres->get('masque.id'));
}
 
public function testerGetListeRetourneTableau() {
$parametresUrl = array('masque.id' => '12,15,18');
 
$parametres = $this->initialiser($parametresUrl);
$liste = $parametres->getListe('masque.id');
 
$this->assertTrue(is_array($liste));
$this->assertCount(3, $liste);
$this->assertContains(12, $liste);
$this->assertContains(15, $liste);
$this->assertContains(18, $liste);
}
 
public function testerIterateur() {
$parametresUrl = array('code1' => 'val1', 'code2' => 'val2', 'code3' => 'val3');
 
$parametres = $this->initialiser($parametresUrl);
 
$parametres->rewind();
$code = $parametres->key();
$valeur = $parametres->current();
$this->assertEquals('code1', $code);
$this->assertEquals('val1', $valeur);
 
$parametres->next();
$code = $parametres->key();
$valeur = $parametres->current();
$this->assertEquals('code2', $code);
$this->assertEquals('val2', $valeur);
 
$parametres->next();
$code = $parametres->key();
$valeur = $parametres->current();
$this->assertEquals('code3', $code);
$this->assertEquals('val3', $valeur);
 
$parametres->next();
$this->assertFalse($parametres->valid());
 
$parametres->rewind();
$this->assertTrue($parametres->valid());
$code = $parametres->key();
$this->assertEquals('code1', $code);
}
 
}
/trunk/services/tests/0.2/bibliotheque/ProjetTest.php
New file
0,0 → 1,66
<?php
require_once dirname(__FILE__).'/../ServicePhpUnit.php';
 
class ProjetTest extends ServicePhpUnit {
 
private function initialiser($ressourcesUrl = array()) {
$ressources = new Ressources($ressourcesUrl);
$projet = new Projet($ressources);
$projet->setCheminBase(realpath(dirname(__FILE__).'/../../../modules/0.2').'/');
$projet->setCheminConfig(realpath(dirname(__FILE__).'/../../../configurations').'/');
$projet->setCheminBiblio(realpath(dirname(__FILE__).'/../../../bibliotheque').'/');
$paramsVerif = $this->getMock('ParametresVerificateur');
$projet->setParamsVerif($paramsVerif);
$ressourcesVerif = $this->getMock('RessourcesVerificateur');
$projet->setRessourcesVerif($ressourcesVerif);
$versionVerif = $this->getMock('VersionVerificateur');
$projet->setVersionVerif($versionVerif);
return $projet;
}
 
public function testerInitialiserAutoLoad() {
$ressourcesUrl = array('fournier', 'noms', '1');
 
$projet = $this->initialiser($ressourcesUrl);
$projet->initialiser();
 
$nomDetails = $this->getMock('NomDetailsGenerique');
$test = new NomDetailsFournier($nomDetails);
}
 
public function testerInitialiserConfig() {
$ressourcesUrl = array('fournier', 'noms', '1');
 
$projet = $this->initialiser($ressourcesUrl);
$projet->initialiser();
 
$this->assertNotNull(Config::get('nomProjet'));
$this->assertNotNull(Config::get('bddTable'));
$this->assertNotNull(Config::get('bddTableMeta'));
$this->assertNotNull(Config::get('baseServiceUrl'));
$this->assertNotNull(Config::get('baseProjetUrl'));
$this->assertNotNull(Config::get('listeUrl'));
$this->assertNotNull(Config::get('detailsHrefTpl'));
$this->assertNotNull(Config::get('ontologieHrefTpl'));
$this->assertNotNull(Config::get('servicesDispo'));
$this->assertNotNull(Config::get('parametresAPI'));
$this->assertNotNull(Config::get('champsProjet'));
}
 
public function testerVerifierExistanceClasseService() {
$ressourcesUrl = array('fournier', 'ServiceInexistant', '1');
 
$projet = $this->initialiser($ressourcesUrl);
 
try {
$projet->verifier();
} catch(Exception $e) {
$messageAttendu = "La classe du service demandé 'ServiceInexistant' n'existe pas dans le projet 'fournier' !";
$this->assertEquals($messageAttendu, $e->getMessage());
$this->assertEquals(404, $e->getCode());
return null;
}
$this->fail("Aucune exception n'a été soulevée.");
}
}
?>
/trunk/services/tests/0.2/bibliotheque/EnteteHttpTest.php
New file
0,0 → 1,14
<?php
require_once dirname(__FILE__).'/../ServicePhpUnit.php';
 
class EnteteHttpTest extends ServicePhpUnit {
 
public function testerEnteteHttpParDefaut() {
$enteteHttp = new EnteteHttp();
 
$this->assertEquals('200', $enteteHttp->code);
$this->assertEquals('utf-8', $enteteHttp->encodage);
$this->assertEquals('application/json', $enteteHttp->mime);
}
}
?>
/trunk/services/tests/0.2/ServicePhpUnit.php
New file
0,0 → 1,168
<?php
// declare(encoding='UTF-8');
/**
* Classe contenant des méthodes :
* - d'intialisation des tests,
* - refactorisant le code des tests,
* - facilitant les tests.
*
* @category php 5.3
* @package Tests/Services
* @author Jean-Pascal MILCENT <jpm@tela-botanica.org>
* @copyright Copyright (c) 2011, Tela Botanica (accueil@tela-botanica.org)
* @license http://www.cecill.info/licences/Licence_CeCILL_V2-fr.txt Licence CECILL
* @license http://www.gnu.org/licenses/gpl.html Licence GNU-GPL
* @version $Id$
*/
abstract class ServicePhpUnit extends PHPUnit_Framework_TestCase {
 
protected static $cheminBase = '';
protected $projet = '';
protected $service = '';
protected $baseUrl = 'http://localhost/service:eflore:0.1/';
protected $serviceBaseUrl = '';
//+------------------------------------------------------------------------------------------------------+
// Intialisation
 
public static function setUpBeforeClass() {
error_reporting(E_ALL);
$_SERVER['argv'][] = '-contexte';
$_SERVER['argv'][] = $_GET['contexte'] = 'test';
self::chargerFramework();
self::$cheminBase = realpath(__DIR__.'/../../modules/0.2').'/';
// Enregistrement en première position des autoload de la méthode gérant les classes des services
spl_autoload_register(array(get_class($this), 'chargerClasseAuto'));
}
 
public static function chargerClasseAuto($classe) {
if (class_exists($classe)) {
return null;
}
 
$cheminCommun = self::$cheminBase.'commun/';
$cheminBibliotheque = realpath(__DIR__.'/../../bibliotheque').'/';
$cheminBiblioInterfaces = $cheminBibliotheque.'interfaces/';
$cheminBiblioNom = $cheminBibliotheque.'nom/';
$cheminBiblioNomDeco = $cheminBiblioNom.'decorateurs/';
$cheminsTests = __DIR__.'/';
$chemins = array(
self::$cheminBase,
$cheminCommun,
$cheminBibliotheque,
$cheminsTests,
$cheminBiblioInterfaces,
$cheminBiblioNom,
$cheminBiblioNomDeco);
 
foreach ($chemins as $chemin) {
$chemin = $chemin.$classe.'.php';
if (file_exists($chemin)) {
require_once $chemin;
}
}
}
 
private static function chargerFramework() {
$cheminRacine = realpath(dirname(__FILE__).'/../..').'/';
$framework = $cheminRacine.'framework.php';
if (!file_exists($framework)) {
$e = "Veuillez paramétrer l'emplacement et la version du Framework dans le fichier $framework";
trigger_error($e, E_USER_ERROR);
} else {
// Inclusion du Framework
require_once $framework;
 
// Ajout d'information concernant cette application
Framework::setCheminAppli($cheminRacine);// Obligatoire
}
}
 
//+------------------------------------------------------------------------------------------------------+
// Refactorisation
protected function consulter($ressources, $parametres) {
$retourJson = $this->consulterBrut($ressources, $parametres);
$retour = json_decode($retourJson, true);
$this->assertEquals(JSON_ERROR_NONE, json_last_error(), "Le json contient des erreurs qui bloquent le décodage. Voir : $url");
return $retour;
}
 
protected function consulterBrut($ressources, $parametres) {
array_unshift($ressources, $this->service);
array_unshift($ressources, $this->projet);
$projet = new Projets();
$retourJson = $projet->consulter($ressources, $parametres);
return $retourJson;
}
 
protected function creerUrl($ressources, $parametres) {
$version = '';
$ressourcesUrl = array();
foreach ($ressources as $ressource) {
$ressourcesUrl[] = $ressource;
}
$ressourcesUrl = count($ressourcesUrl) > 0 ? '/'.implode('/', $ressourcesUrl) : '';
 
$parametresUrl = '';
if (count($parametres) > 0) {
foreach ($parametres as $cle => $valeur) {
$parametresUrl[] = $cle.'='.rawurlencode($valeur);
}
$parametresUrl = '?'.implode('&', $parametresUrl);
}
$url = $this->baseUrl.$this->projet.'/'.$version.$this->service.$ressourcesUrl.$parametresUrl;
return $url;
}
 
//+------------------------------------------------------------------------------------------------------+
// Méthodes facilitant les tests
 
/**
* Récupère un bouchon de classe abstraite.
* Comment l'utiliser :
* $classeAstraite = $this->getClasseAbstraite('MaClasse', array('param1', 'param2'));
* $foo = $classeAstraite->methodeConcretePublique();
*
* @param String $classeNom Le nom de la classe
* @param Array $parametres Les paramètres à passer au constructeur.
* @return Object Le bouchon de la classe abstraite
*/
public function getClasseAbstraite($classeNom, Array $parametres) {
$efloreScript = $this->getMockForAbstractClass($classeNom, $parametres);
return $efloreScript;
}
 
/**
* Récupère une méthode privée d'une classe pour tester/documenter.
* Comment l'utiliser :
* MyClass->foo():
* $cls = new MyClass();
* $foo = self::getPrivateMethode($cls, 'foo');
* $foo->invoke($cls, $...);
*
* @param object $objet Une instance de votre classe
* @param string $methode Le nom de la méthode private
* @return ReflectionMethod La méthode demandée
*/
public static function getMethodePrivee($objet, $nomMethode) {
$classe = new ReflectionClass($objet);
$methode = $classe->getMethod($nomMethode);
$methode->setAccessible(true);
return $methode;
}
 
/**
* Récupère une méthode protégée d'une classe pour tester/documenter.
* Comment l'utiliser :
* MyClass->foo():
* $cls = new MyClass();
* $foo = self::getProtectedMethode($cls, 'foo');
* $foo->invoke($cls, $...);
* @param object $objet Une instance de votre classe
* @param string $methode Le nom de la méthode protected
* @return ReflectionMethod La méthode demandée
*/
public static function getMethodeProtegee($objet, $nomMethode) {
return self::getMethodePrivee($objet, $nomMethode);
}
}
?>