/trunk/tests/metier/EfloreTest.php |
---|
New file |
0,0 → 1,20 |
<?php |
require_once dirname(__FILE__).'/../ConsultationEflorePhpUnit.php'; |
class EfloreTest extends ConsultationEflorePhpUnit { |
public function testFormulerUrl() { |
$ressources = array('bdtfx', 'noms'); |
$parametres = array('masque' => 'acer', 'recherche' => 'stricte', 'ns.format' => 'htm'); |
$url = $this->creerUrl($ressources, $parametres); |
$eflore = $this->getMock('Eflore'); |
$formaterUrl = self::getMethodeProtegee($eflore, 'formaterUrl'); |
$tpl = 'http://localhost/service:eflore:0.1/{projet}/noms?masque={valeur}&recherche={type}&ns.format=htm'; |
$param = array('projet' => 'bdtfx' ,'valeur' => 'acer', 'type' => 'stricte'); |
$urlf = $formaterUrl->invoke($eflore, $tpl, $param); |
$this->assertEquals($url, $urlf); |
} |
} |
?> |
/trunk/tests/metier/NomsTest.php |
---|
New file |
0,0 → 1,26 |
<?php |
require_once dirname(__FILE__).'/../ConsultationEflorePhpUnit.php'; |
class NomsTest extends ConsultationEflorePhpUnit { |
public function testRechercheEtendue() { |
Registre::set('parametres.referentiel', 'bdtfx'); |
$cheminRacine = realpath(dirname(__FILE__).'/../configurations/').'/'; |
Config::charger($cheminRacine.'config.ini'); |
$noms = new Noms(); |
$resultats = $noms->getRechercheEtendue('aceras'); |
$this->assertNotEmpty($resultats); |
$this->assertEquals('15', $resultats['entete']['total']); |
} |
public function testRechercheFloue() { |
Registre::set('parametres.referentiel', 'bdtfx'); |
$cheminRacine = realpath(dirname(__FILE__).'/../configurations/').'/'; |
Config::charger($cheminRacine.'config.ini'); |
$noms = new Noms(); |
$resultats = $noms->getRechercheFloue('aceras'); |
$this->assertNotEmpty($resultats); |
$this->assertEquals('27', $resultats['entete']['total']); |
} |
} |
?> |
/trunk/tests/metier/TaxonsTest.php |
---|
New file |
0,0 → 1,68 |
<?php |
require_once dirname(__FILE__).'/../ConsultationEflorePhpUnit.php'; |
class TaxonsTest extends ConsultationEflorePhpUnit { |
public function testStatsInitialesFamille() { |
Registre::set('parametres.referentiel', 'bdtfx'); |
$cheminRacine = realpath(dirname(__FILE__).'/../configurations/').'/'; |
Config::charger($cheminRacine.'config.ini'); |
$noms = new Taxons(); |
$resultats = $noms->getStatsInitialesFamille(); |
$this->assertNotEmpty($resultats); |
$this->assertEquals('24', $resultats['A']); |
} |
public function testStatsInitialesGenre() { |
Registre::set('parametres.referentiel', 'bdtfx'); |
$cheminRacine = realpath(dirname(__FILE__).'/../configurations/').'/'; |
Config::charger($cheminRacine.'config.ini'); |
$noms = new Taxons(); |
$resultats = $noms->getStatsInitialesGenre(); |
$this->assertNotEmpty($resultats); |
$this->assertEquals('9', $resultats['U']); |
} |
public function testListeFamilleParInitiale() { |
Registre::set('parametres.referentiel', 'bdtfx'); |
$cheminRacine = realpath(dirname(__FILE__).'/../configurations/').'/'; |
Config::charger($cheminRacine.'config.ini'); |
$noms = new Taxons(); |
$resultats = $noms->getListeFamilleParInitiale('U'); |
$this->assertNotEmpty($resultats); |
$this->assertCount(2, $resultats); |
} |
public function testListeGenreParInitiale() { |
Registre::set('parametres.referentiel', 'bdtfx'); |
$cheminRacine = realpath(dirname(__FILE__).'/../configurations/').'/'; |
Config::charger($cheminRacine.'config.ini'); |
$noms = new Taxons(); |
$resultats = $noms->getListeGenreParInitiale('U'); |
$this->assertNotEmpty($resultats); |
$this->assertNotEmpty($resultats[84640]); |
$this->assertCount(9, $resultats); |
} |
public function testRechercheEtendue() { |
Registre::set('parametres.referentiel', 'bdtfx'); |
$cheminRacine = realpath(dirname(__FILE__).'/../configurations/').'/'; |
Config::charger($cheminRacine.'config.ini'); |
$noms = new Taxons(); |
$resultats = $noms->getRechercheEtendue('acer'); |
$this->assertNotEmpty($resultats); |
$this->assertEquals('50', $resultats['entete']['total']); |
} |
public function testRechercheFloue() { |
Registre::set('parametres.referentiel', 'bdtfx'); |
$cheminRacine = realpath(dirname(__FILE__).'/../configurations/').'/'; |
Config::charger($cheminRacine.'config.ini'); |
$noms = new Taxons(); |
$resultats = $noms->getRechercheFloue('aceras'); |
$this->assertNotEmpty($resultats); |
$this->assertEquals('25', $resultats['entete']['total']); |
} |
} |
?> |
/trunk/tests/metier/NomsVernaculairesTest.php |
---|
New file |
0,0 → 1,26 |
<?php |
require_once dirname(__FILE__).'/../ConsultationEflorePhpUnit.php'; |
class NomsVernaculairesTest extends ConsultationEflorePhpUnit { |
public function testRechercheEtendue() { |
Registre::set('parametres.referentiel', 'nvjfl'); |
$cheminRacine = realpath(dirname(__FILE__).'/../configurations/').'/'; |
Config::charger($cheminRacine.'config.ini'); |
$noms = new NomsVernaculaires(); |
$resultats = $noms->getRechercheEtendue('abricotier'); |
$this->assertNotEmpty($resultats); |
$this->assertEquals('3', $resultats['entete']['total']); |
} |
public function testRechercheFloue() { |
Registre::set('parametres.referentiel', 'nvjfl'); |
$cheminRacine = realpath(dirname(__FILE__).'/../configurations/').'/'; |
Config::charger($cheminRacine.'config.ini'); |
$noms = new NomsVernaculaires(); |
$resultats = $noms->getRechercheFloue('abricotier'); |
$this->assertNotEmpty($resultats); |
$this->assertEquals('5', $resultats['entete']['total']); |
} |
} |
?> |
/trunk/tests/ConsultationEflorePhpUnit.php |
---|
New file |
0,0 → 1,151 |
<?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 ConsultationEflorePhpUnit extends PHPUnit_Framework_TestCase { |
//+------------------------------------------------------------------------------------------------------+ |
// Intialisation |
public static function setUpBeforeClass() { |
error_reporting(E_ALL); |
self::chargerFramework(); |
// Enregistrement en première position des autoload de la méthode gérant les classes des services |
spl_autoload_register(array(get_class(), 'chargerClasseAuto')); |
} |
public static function chargerClasseAuto($classe) { |
echo $classe."\n"; |
if (class_exists($classe)) { |
return null; |
} |
$cheminBase = realpath(__DIR__.'/../metier/api_0.1').'/'; |
$cheminsTests = __DIR__.'/'; |
$chemins = array($cheminBase, $cheminsTests); |
foreach ($chemins as $chemin) { |
$chemin = $chemin.$classe.'.php'; |
echo $chemin."\n"; |
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 consulterJson($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); |
$projets = new Projets(); |
$retourJson = $projets->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 = 'http://localhost/service:eflore:0.1'.$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); |
} |
} |
?> |