Subversion Repositories eFlore/Projets.eflore-projets

Compare Revisions

Ignore whitespace Rev 862 → Rev 863

/trunk/services/tests/0.1/coste/CosteNomsTest.php
177,7 → 177,30
$this->assertEquals(1, $retour['entete']['total'], "L'attribut 'total' devrait avoir la valeur 1. Voir : $url");
}
 
// le webservice permet de définir la clef d'index choisir: par num_nom de coste ou num_nom de bdtfx
public function testIndex() {
$url = ServiceEflorePhpUnit::creerUrl(self::$S, NULL, array("masque.famille" => "Sapindaceae"));
$retour = $this->consulterJson(self::$S, self::$P, NULL, array("masque.famille" => "Sapindaceae"));
$e = array(1030,1027,1026,1028,1036,1025);
$r = array_keys($retour['resultats']);
sort($r);sort($e);
$this->assertEquals($e, $r, "Erreur des l'index des résultats. Voir : $url");
 
$url = ServiceEflorePhpUnit::creerUrl(self::$S, NULL, array("masque.famille" => "Sapindaceae", "retour.indexBy" => "bdtfx"));
$retour = $this->consulterJson(self::$S, self::$P, NULL, array("masque.famille" => "Sapindaceae", "retour.indexBy" => "bdtfx"));
$e = array(182,1053,74934,210,141,199);
$r = array_keys($retour['resultats']);
sort($r);sort($e);
$this->assertEquals($e, $r, "Erreur des l'index des résultats. Voir : $url");
 
// le taxon coste:nn:183 ne correspond à ce jour (2013/09/04) à aucun taxon bdtfx
// l'indexation par bdtfx doit donc absolument échouer
$url = ServiceEflorePhpUnit::creerUrl(self::$S, array(183), array("retour.indexBy" => "bdtfx"));
$retour = $this->consulterBrut(self::$S, self::$P, array(183), array("retour.indexBy" => "bdtfx"));
$this->assertContains("error", $retour, "L'indexation par bdtfx doit retourner une erreur en cas de bdtfx.num_nom NULL. Voir : $url");
}
 
 
// commons
public function commonTestHeader($retour, $url) {
$this->assertNotEmpty($retour, 'données absentes');
/trunk/services/modules/0.1/coste/Textes.php
35,18 → 35,19
// SELECT MAX(num_nom) FROM bdtfx_v1_02;
define('_COSTE_TEXTE_MAX_BDTFX_NN', 103386 + 10000);
 
/*restore_error_handler();
error_reporting(E_ALL);*/
/* restore_error_handler();
error_reporting(E_ALL); */
class Textes {
// paramètres autorisés
static $allow_params = array(
'txt.format', 'retour.format', 'retour.champs',
'txt.format', 'retour.format', 'retour.champs', 'retour.indexBy',
'recherche',
'masque.ns', 'masque.txt', 'masque.page', 'masque.tome', 'masque.famille', 'masque.nt',
'masque.titre', // masque sur titre de la page wiki correspondante (page "clef" OR page "description")
'navigation.depart', 'navigation.limite');
// et valeurs par défaut
static $default_params = array('txt.format' => 'txt', 'retour.format' => 'max', 'recherche' => 'stricte',
static $default_params = array('txt.format' => 'txt', 'retour.format' => 'max', 'retour.indexBy' => 'coste',
'recherche' => 'stricte',
'retour.champs' => 'titre,texte,determination,tag',
'navigation.depart' => 0, 'navigation.limite' => 50);
 
162,10 → 163,13
$matches = intval($matches['total']);
}
 
// reformate les résultats pour les indexer par coste:nn
// reformate les résultats pour les indexer par coste:nn par défaut
// cependant le paramètre retour.indexBy permet de choisir une indexation par num_nom de bdtfx
$clef_index = $params['retour.indexBy'] == 'coste' ? 'coste:nn' : 'bdtfx:nn';
$res2 = array();
foreach($res as $v) {
$res2[$v['coste:nn']] = $v;
if(!$v[$clef_index]) throw new Exception('format error: index NULL, use retour.indexBy=coste', 400);
$res2[$v[$clef_index]] = $v;
}
 
// l'appelant s'occupera du json_encode()
373,6 → 377,7
$p = array_intersect_key($params, array_flip(self::$allow_params));
self::unsetIfInvalid($p, 'txt.format', array('txt', 'htm'));
self::unsetIfInvalid($p, 'retour.format', array('min','max'));
self::unsetIfInvalid($p, 'retour.indexBy', array('coste', 'bdtfx'));
self::unsetIfInvalid($p, 'recherche', array('stricte','etendue','floue'));
 
if(isset($params['masque.ns'])) $p['masque.ns'] = trim($params['masque.ns']);