Subversion Repositories eFlore/Projets.eflore-projets

Rev

Rev 7 | Rev 96 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 7 Rev 17
Line 1... Line 1...
1
<?php
1
<?php
2
class BdtfxNomsTest extends PHPUnit_Framework_TestCase {
2
class BdtfxNomsTest extends ServicesTestsOutils {
-
 
3
 
-
 
4
	public function __construct() {
-
 
5
		$this->projet = 'bdtfx';
-
 
6
		$this->service = 'noms';
-
 
7
	}
Line 3... Line 8...
3
 
8
 
4
	public function testVersionPrecise() {
9
	public function testVersionPrecise() {
5
		$ressources = array('v1.01');
10
		$ressources = array('v1.01');
6
		$parametres = array();
11
		$parametres = array();
Line 193... Line 198...
193
		$this->assertArrayHasKey('resultat', $retour, "Le json ne contient pas d'attribut : resultat.\nVoir : $url");
198
		$this->assertArrayHasKey('resultat', $retour, "Le json ne contient pas d'attribut : resultat.\nVoir : $url");
194
		$attendu = '<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>]';
199
		$attendu = '<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>]';
195
		$message = "Le tableau du résultat 182 doit contenir un champ 'nom_sci' avec pour valeur '$attendu'. Voir : $url";
200
		$message = "Le tableau du résultat 182 doit contenir un champ 'nom_sci' avec pour valeur '$attendu'. Voir : $url";
196
		$this->assertEquals($attendu, $retour['resultat']['182']['nom_sci'], $message);
201
		$this->assertEquals($attendu, $retour['resultat']['182']['nom_sci'], $message);
197
	}
202
	}
198
 
-
 
199
	//+------------------------------------------------------------------------------------------------------+
-
 
200
	// Refactorisation
-
 
201
	private function consulterJson($ressources, $parametres) {
-
 
202
		$retourJson = $this->consulterBrut($ressources, $parametres);
-
 
203
		$retour = json_decode($retourJson, true);
-
 
204
		$this->assertEquals(JSON_ERROR_NONE, json_last_error(), "Le json contient des erreurs qui bloquent le décodage. Voir : $url");
-
 
205
		return $retour;
-
 
206
	}
-
 
207
 
-
 
208
	private function consulterBrut($ressources, $parametres) {
-
 
209
		array_unshift($ressources, 'noms');
-
 
210
		array_unshift($ressources, 'bdtfx');
-
 
211
		$projets = new Projets();
-
 
212
		$retourJson = $projets->consulter($ressources, $parametres);
-
 
213
		return $retourJson;
-
 
214
	}
-
 
215
 
-
 
216
	private function creerUrl($ressources, $parametres) {
-
 
217
		$version = '';
-
 
218
		$ressourcesUrl = array();
-
 
219
		foreach ($ressources as $ressource) {
-
 
220
			if (preg_match('/^(v[0-9]+\.[0-9]+|[*+])$/', $ressource)) {
-
 
221
				$version = $ressource.'/';
-
 
222
			} else {
-
 
223
				$ressourcesUrl[] = $ressource;
-
 
224
			}
-
 
225
		}
-
 
226
		$ressourcesUrl = count($ressourcesUrl) > 0 ? '/'.implode('/', $ressourcesUrl) : '';
-
 
227
 
-
 
228
		$parametresUrl = '';
-
 
229
		if (count($parametres) > 0) {
-
 
230
			foreach ($parametres as $cle => $valeur) {
-
 
231
				$parametresUrl[] = $cle.'='.rawurlencode($valeur);
-
 
232
			}
-
 
233
			$parametresUrl = '?'.implode('&', $parametresUrl);
-
 
234
		}
-
 
235
		$url = Config::get('url_service').'/'.$version.'noms'.$ressourcesUrl.$parametresUrl;
-
 
236
		return $url;
-
 
237
	}
-
 
238
}
203
}
239
?>
204
?>
240
205