Subversion Repositories eFlore/Projets.eflore-projets

Rev

Rev 959 | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
520 mathilde 1
<?php
2
 
3
require_once dirname(__FILE__).'/../ServiceEflorePhpUnit.php';
4
 
5
class InformationsBaseflorTest extends ServiceEflorePhpUnit {
6
 
7
	public function __construct() {
8
		$this->projet = 'baseflor';
9
		$this->service = 'informations';
10
	}
11
 
12
 
13
	//++ ------------------------------------Test des ressources -----------------------------++
14
 
15
	public function testRessourceReferentielInconnu() {
16
		$ressources = array('dgoju.nn:73256');
17
		$parametres = array();
790 raphael 18
		$retour = ServiceEflorePhpUnit::consulterBrut($this->service, $this->projet, $ressources, $parametres);
959 raphael 19
		$this->assertEquals("Données introuvables dans la base", $retour, "Il faut renvoyer \"données introuvables\" en cas de référentiel inconnu.");
520 mathilde 20
	}
21
 
22
	public function testRessourceInconnue() {
23
		$ressources = array('inconnue');
24
		$parametres = array();
790 raphael 25
		$retour = ServiceEflorePhpUnit::consulterBrut($this->service, $this->projet, $ressources, $parametres);
520 mathilde 26
		$messageAttendu =
27
				  "Erreur dans l'url de votre requête : </br> La ressource demandée n'existe pas.";
28
		$this->assertEquals($messageAttendu, $retour,
29
							"Il faut indiquer si une ressource est eronnée.");
30
	}
31
 
32
	public function testRessourceNNInconnu() {
33
		$ressources = array('bdtfx.nn:3');
34
		$parametres = array();
790 raphael 35
		$retour = ServiceEflorePhpUnit::consulterBrut($this->service, $this->projet, $ressources, $parametres);
959 raphael 36
		$this->assertEquals("Données introuvables dans la base", $retour, "Il faut indiquer si une requête ne renvoie pas de résultats.");
520 mathilde 37
	}
38
 
39
	//++ ------------------------------------Test des paramètres -----------------------------++
40
 
41
	public function testParametreInconnu() {
42
		$ressourcesList = array(
43
			array('bdtfx.nn:73256'),
44
			array('bdtfx.nn:101128'));
45
		$parametres = array('paramatre' => 'image/jpeg');
46
		foreach ($ressourcesList as $ressources) {
790 raphael 47
			$retour = ServiceEflorePhpUnit::consulterBrut($this->service, $this->projet, $ressources, $parametres);
520 mathilde 48
			$messageAttendu = "Erreur dans les parametres de votre requête :".
49
										" </br> Le paramètre \" paramatre \" n'existe pas.";
50
			$this->assertEquals($messageAttendu, $retour,
783 raphael 51
				"Il faut indiquer si un paramètre est inconnu.");
520 mathilde 52
		}
53
 
54
	}
55
 
56
	public function testParametreCategorieInconnue() {
57
		$ressourcesList = array(
58
			array('bdtfx.nn:73256'),
59
			array('bdtfx.nn:101128'));
60
		$parametres = array('categorie' => 'inventé');
61
		foreach ($ressourcesList as $ressources) {
790 raphael 62
			$retour = ServiceEflorePhpUnit::consulterBrut($this->service, $this->projet, $ressources, $parametres);
788 raphael 63
			$messageAttendu = "Valeur de paramètre inconnue pour 'categorie'. Ce paramètre n'est pas autorisé";
64
			$this->assertContains($messageAttendu, $retour,
65
								"Il faut indiquer si la valeur du paramètre categorie est inconnue pour (" . implode(',', $ressources) . ").");
520 mathilde 66
		}
67
	}
68
 
594 mathilde 69
	public function testParametreNavigationDepartSansLimite() {
520 mathilde 70
		$ressources = array();
594 mathilde 71
		$parametres = array('navigation.depart' => 10);
790 raphael 72
		$retour = ServiceEflorePhpUnit::consulterBrut($this->service, $this->projet, $ressources, $parametres);
594 mathilde 73
		$messageAttendu = "indiquez également la valeur pour le paramètre navigation.limite.";
74
		$this->assertEquals($messageAttendu, $retour,
75
					"Navigation.depart doit être accompagné de navigation.limite ensemble.");
76
 
520 mathilde 77
	}
78
 
79
	public function testParametreDepartSuperieurTotalResultats() {
80
		$ressources = array();
81
		$parametres = array('navigation.depart' => 20000, 'navigation.limite' => 10 );
790 raphael 82
			$retour = ServiceEflorePhpUnit::consulterBrut($this->service, $this->projet, $ressources, $parametres);
520 mathilde 83
			$messageAttendu =
84
				"Erreur : la valeur pour le paramètre navigation.départ est supérieure".
85
				" au nombre total de résultats.";
86
			$this->assertEquals($messageAttendu, $retour,
87
						"Il faut indiquer si la valeur de départ est supérieure au nombre de résultats.");
88
	}
89
 
90
 
91
	public function testParametreNavigationErrone() {
92
		$ressources = array();
93
		$parametresList = array(
94
			array('navigation.depart' => -5, 'navigation.limite' => 10 ),
947 raphael 95
			array('navigation.depart' => 0, 'navigation.limite' => 'abc' ));
520 mathilde 96
		$cles = array('navigation.depart','navigation.limite');
97
		$i = 0 ;
98
		foreach ($parametresList as $parametres) {
790 raphael 99
			$retour = ServiceEflorePhpUnit::consulterBrut($this->service, $this->projet, $ressources, $parametres);
520 mathilde 100
			$messageAttendu = "Erreur : valeur erronnée pour le paramètre {$cles[$i]}.";
101
			$this->assertEquals($messageAttendu, $retour,
102
						"il faut indiquer lorsque qu'un des paramètres de navigation a une valeur impossible.");
103
			$i++;
104
		}
105
	}
106
 
107
	public function testParametreRetourFormatErrone() {
108
		$ressourcesList = array(
109
			array('bdtfx.nn:73256'),
110
			array('bdtfx.nn:101128'));
111
		$parametres = array('retour.format' => 'pdf');
112
		foreach ($ressourcesList as $ressources) {
790 raphael 113
			$retour = ServiceEflorePhpUnit::consulterBrut($this->service, $this->projet, $ressources, $parametres);
788 raphael 114
			$messageAttendu = "Valeur de paramètre inconnue pour 'retour.format'. Ce paramètre n'est pas autorisé";
115
			$this->assertContains($messageAttendu, $retour,
520 mathilde 116
							"il faut indiquer lorsque que le paramètre retour.format a une valeur impossible.");
117
		}
118
	}
119
 
120
	public function testParametreVersionProjetInconnu() {
121
		$ressourcesList = array(
122
			array('bdtfx.nn:73256'),
123
			array('bdtfx.nn:101128'));
124
		$parametres = array('version.projet' => 'dhgkg22');
125
		foreach ($ressourcesList as $ressources){
790 raphael 126
			$retour = ServiceEflorePhpUnit::consulterBrut($this->service, $this->projet, $ressources, $parametres);
520 mathilde 127
			$messageAttendu = "Erreur : La version est inconnue.";
128
			$this->assertEquals($messageAttendu, $retour,
947 raphael 129
									"Il faut indiquer si la valeur du paramètre version.projet est inconnue.");
520 mathilde 130
		}
131
	}
132
 
133
	//++ ------------------------------------Test du retour json correct -----------------------------++
134
 
135
	//++ ---Informations ----++
136
 
137
	public function testJsonBienFormeInformations() {
138
		$ressources = array();
139
		$parametres = array('navigation.depart' => 10, 'navigation.limite' => 15);
790 raphael 140
			$url = ServiceEflorePhpUnit::creerUrl($this->service, $ressources, $parametres);
141
			$retour = $this->consulterJson($this->service, $this->projet, $ressources, $parametres);
520 mathilde 142
			$this->assertArrayHasKey('entete', $retour, "Le json ne contient pas d'attribut : entete. Voir : $url");
143
			$this->assertArrayHasKey('resultats', $retour, "Le json ne contient pas d'attribut : resultat. Voir : $url");
947 raphael 144
			$this->verifierJsonEnteteBienFormeInformations($retour, $ressources, $parametres);
520 mathilde 145
	}
146
 
947 raphael 147
	private function verifierJsonEnteteBienFormeInformations($retour, $ressources, $parametres) {
520 mathilde 148
		//depart
149
		$this->assertArrayHasKey('depart', $retour['entete'],
150
					"L'en-tête ne contient pas d'attribut : depart ");
151
		$this->assertEquals($retour['entete']['depart'], $parametres['navigation.depart'],
152
					"La valeur de départ est incorrecte dans l'en-tête.");
153
		//limite
154
		$this->assertArrayHasKey('limite', $retour['entete'],
155
					"L'en-tête ne contient pas d'attribut : limite");
156
		$this->assertEquals($retour['entete']['limite'], $parametres['navigation.limite'],
157
					"La valeur de limite est incorrecte dans l'en-tête.");
158
		//total
159
		$this->assertArrayHasKey('total', $retour['entete'],
160
					"L'en-tête ne contient pas d'attribut : total ");
161
		$this->assertNotEquals('', $retour['entete']['total'],
162
							"La valeur de total est vide dans l'en-tête.");
163
		//href
164
		$this->assertArrayHasKey('href.suivant', $retour['entete'],
165
					"L'en-tête ne contient pas d'attribut : href.suivant ");
166
		$this->assertArrayHasKey('href.precedent', $retour['entete'],
167
							"L'en-tête ne contient pas d'attribut : href.precedent ");
168
		$parametres_url =
169
		array('navigation.depart' => ($retour['entete']['limite']+$retour['entete']['depart']),
170
						 'navigation.limite' => $retour['entete']['limite'] );
790 raphael 171
		$urlsuivant = ServiceEflorePhpUnit::creerUrl($this->service, $ressources, $parametres_url);
520 mathilde 172
		$this->assertEquals($urlsuivant, $retour['entete']['href.suivant'],
173
												"L' url $urlsuivant de l'entete est incorrecte.");
174
	}
175
 
176
	public function testJsonResultatsHrefInformations() {
177
		$ressources = array();
178
		$parametres = array('navigation.depart' => 370, 'navigation.limite' => 5);
790 raphael 179
		$url = ServiceEflorePhpUnit::creerUrl($this->service, $ressources, $parametres);
180
		$retour = $this->consulterJson($this->service, $this->projet, $ressources, $parametres);
783 raphael 181
		foreach ($retour['resultats'] as $id => $valeurs) {
182
			if (!$valeurs['num_nomen']) {
183
				$this->assertArrayNotHasKey('href', $valeurs,
520 mathilde 184
							"Il ne doit pas avoir de lien s'il n'y a pas de numéro nomenclatural (=0). Voir $url ");
185
			}
186
		}
187
	}
188
 
189
	public function testJsonNombreLimiteDemande() {
190
		$ressources = array();
947 raphael 191
        $parametres = array();
520 mathilde 192
		$parametresList = array('navigation.depart' => 10, 'navigation.limite' => 15 );
790 raphael 193
			$url = ServiceEflorePhpUnit::creerUrl($this->service, $ressources, $parametres);
194
			$retour = $this->consulterJson($this->service, $this->projet, $ressources, $parametres);
520 mathilde 195
			$this->assertLessThanOrEqual(15, count($retour),
196
				"Le json renvoie un nombre de résultats trop important : entete. Voir : $url");
197
	}
198
 
199
	//++ ---Informations.nn ----++
200
 
201
	public function testJsonInformationsNN_min() {
202
		$ressourcesList = array(
203
			array('bdtfx.nn:73256'),
204
			array('bdtfx.nn:101128'));
205
		$parametres = array('retour.format' => 'min' );
206
		foreach ($ressourcesList as $ressources) {
790 raphael 207
			$retour = $this->consulterJson($this->service, $this->projet, $ressources, $parametres);
520 mathilde 208
			$this->assertArrayNotHasKey('type_bio.code',$retour,
209
				"Le champs 'type_bio.code' ne doit pas être présent si retour.format=min. ");
210
			$this->assertArrayNotHasKey('type_bio.libelle',$retour,
211
				"Le champs 'type_bio.libelle' ne doit pas être présent si retour.format=min.");
212
			$this->assertArrayNotHasKey('type_bio.detail',$retour,
213
				"Le champs 'type_bio.detail' ne doit pas être présent si retour.format=min.");
958 raphael 214
			$champs = array_keys(Outils::recupererTableauConfig('Paramètres.champs_ontologiques'));
520 mathilde 215
			foreach ($champs as $chps) {
216
				$this->assertArrayNotHasKey($chps.'.libelle', $retour,
217
					"Le champs '{$chps}.libelle' ne doit pas être présent si retour.format=min.");
218
				$this->assertArrayNotHasKey($chps.'.code', $retour,
219
					"Le champs '{$chps}.code' ne doit pas être présent si retour.format=min.");
220
				$this->assertArrayNotHasKey($chps.'.href', $retour,
221
					"Le champs '{$chps}.href' ne doit pas être présent si retour.format=min.");
222
			}
223
			foreach ($champs as $chps) {
224
				$this->assertArrayNotHasKey($chps.'_min.libelle', $retour,
225
								"Le champs '{$chps}_min.libelle' ne doit pas être présent si retour.format=min.");
226
				$this->assertArrayNotHasKey($chps.'_min.code', $retour,
227
								"Le champs '{$chps}_min.code' ne doit pas être présent si retour.format=min.");
228
				$this->assertArrayNotHasKey($chps.'_min.href', $retour,
229
								"Le champs '{$chps}_min.href' ne doit pas être présent si retour.format=min.");
230
				$this->assertArrayNotHasKey($chps.'_max.libelle', $retour,
231
								"Le champs '{$chps}_max.libelle' ne doit pas être présent si retour.format=min.");
232
				$this->assertArrayNotHasKey($chps.'_max.code', $retour,
233
								"Le champs '{$chps}_max.code' ne doit pas être présent si retour.format=min.");
234
				$this->assertArrayNotHasKey($chps.'_max.href', $retour,
235
								"Le champs '{$chps}_max.href' ne doit pas être présent si retour.format=min.");
236
			}
237
 
238
		}
239
	}
240
 
241
 
242
	public function testJsonInformationsNNBasefor_max() {
947 raphael 243
        $retour = $this->consulterJson($this->service, $this->projet, ['bdtfx.nn:73256'], ['retour.format' => 'max', 'categorie' => 'description']);
244
        $this->verifierParametresDescription_max($retour);
245
 
246
        $retour = $this->consulterJson($this->service, $this->projet, ['bdtfx.nn:73256'], ['retour.format' => 'max', 'categorie' => 'ecologie']);
247
        $this->verifierParametresEcologie_max($retour, 'baseflor');
520 mathilde 248
	}
249
 
250
	public function testJsonInformationsNNRangSup_max() {
251
		$ressources = array('bdtfx.nn:101128');
252
		$parametres = array('retour.format' => 'max' , 'categorie' => 'ecologie');
790 raphael 253
			$retour = $this->consulterJson($this->service, $this->projet, $ressources, $parametres);
520 mathilde 254
			if ($parametres['categorie'] == 'description') {
255
				$this->verifierParametresDescription_max();
256
			} else {
257
				$this->verifierParametresEcologie_max($retour, 'rangSup');
258
			}
259
	}
260
 
261
	private function verifierParametresDescription_max($retour) {
262
		$this->assertArrayHasKey('type_bio.code',$retour,
947 raphael 263
									"Le champs 'type_bio.code' doit être présent si retour.format=max. ");
520 mathilde 264
		$this->assertArrayHasKey('type_bio.libelle',$retour,
947 raphael 265
									"Le champs 'type_bio.libelle' doit être présent si retour.format=max.");
520 mathilde 266
		$this->assertArrayHasKey('type_bio.detail',$retour,
947 raphael 267
									"Le champs 'type_bio.detail' doit être présent si retour.format=max.");
520 mathilde 268
	}
269
 
270
	private function verifierParametresEcologie_max($retour,$type) {
958 raphael 271
		$champs = array_keys(Outils::recupererTableauConfig('Paramètres.champs_ontologiques'));
520 mathilde 272
		if ($type == 'baseflor') {
273
			foreach ($champs as $chps) {
274
				$this->assertArrayHasKey($chps.'.libelle', $retour,
947 raphael 275
													"Le champs '{$chps}.libelle' doit être présent si retour.format=max.");
520 mathilde 276
				$this->assertArrayHasKey($chps.'.code', $retour,
947 raphael 277
													"Le champs '{$chps}.code' doit	 être présent si retour.format=max.");
520 mathilde 278
				$this->assertArrayHasKey($chps.'.href', $retour,
947 raphael 279
													"Le champs '{$chps}.href' doit	 être présent si retour.format=max.");
520 mathilde 280
			}
281
		} elseif ($type == 'rangSup') {
282
			foreach ($champs as $chps) {
283
				$this->assertArrayHasKey($chps.'_min.libelle', $retour,
947 raphael 284
											"Le champs '{$chps}_min.libelle' doit être présent si retour.format=max.");
520 mathilde 285
				$this->assertArrayHasKey($chps.'_min.code', $retour,
947 raphael 286
											"Le champs '{$chps}_min.code' doit être présent si retour.format=max.");
520 mathilde 287
				$this->assertArrayHasKey($chps.'_min.href', $retour,
947 raphael 288
											"Le champs '{$chps}_min.href' doit être présent si retour.format=max.");
520 mathilde 289
				$this->assertArrayHasKey($chps.'_max.libelle', $retour,
947 raphael 290
											"Le champs '{$chps}_max.libelle' doit être présent si retour.format=max.");
520 mathilde 291
				$this->assertArrayHasKey($chps.'_max.code', $retour,
947 raphael 292
											"Le champs '{$chps}_max.code' doit être présent si retour.format=max.");
520 mathilde 293
				$this->assertArrayHasKey($chps.'_max.href', $retour,
947 raphael 294
											"Le champs '{$chps}_max.href' doit être présent si retour.format=max.");
520 mathilde 295
			}
296
		}
297
	}
298
 
947 raphael 299
	//++ ------------------------------------Test du champs type biologique	 -----------------------------++
520 mathilde 300
 
555 mathilde 301
	//TEST sur différents cas typique de 'type_bio.libelle'
554 mathilde 302
	public function testJsonTypeBioOntologies() {
303
		$ressourcesList = array(array("bdtfx.nn:73256"),array("bdtfx.nn:70441"),array("bdtfx.nn:62911"),array("bdtfx.nn:72496"),
304
							array("bdtfx.nn:6446"),array("bdtfx.nn:8373"), array("bdafx.nn:35574"), array("bdtfx.nn:62443"),
305
							array("bdtfx.nn:62442"));
306
		$parametres = array();
947 raphael 307
		$resultats_attendus = array ('Grhi-aqua' => 'Géophytes (>= 1m) à rhizome (plantes aquatiques) ' ,
308
				'test-aqua-car' => 'Thérophytes (< 1m) estivaux	 (plantes aquatiques, carnivores) ',
554 mathilde 309
				'grhi' => 'Géophytes (< 1m) à rhizome ',
310
				'hsto(test)' => 'Hémicryptophytes (< 1m) stolonifères , Thérophytes (< 1m) estivaux ',
947 raphael 311
				'Hsto-lia(Grhi-lia)' => 'Hémicryptophytes (>= 1m) stolonifères	(lianes) , Géophytes (>= 1m) à rhizome (lianes) ',
554 mathilde 312
				'Cfru(b-cad)' => 'Chaméphytes (>= 1m) frutescents , Nanophanérophytes (2 à 4m) (caducifoliées) ',
947 raphael 313
				'test-aqua(heri)' => 'Thérophytes (< 1m) estivaux (plantes aquatiques) , Hémicryptophytes (< 1m) érigé ',
314
				'hbis(hsto,test)-suc' => 'Hémicryptophytes (< 1m) bisannuels (succulentes) , Hémicryptophytes (< 1m) stolonifères, Thérophytes (< 1m) estivaux ',
315
				'hbis(hsto)-suc' => 'Hémicryptophytes (< 1m) bisannuels	 (succulentes) , Hémicryptophytes (< 1m) stolonifères ');
554 mathilde 316
		foreach ($ressourcesList as $ressources) {
790 raphael 317
			$retour = $this->consulterJson($this->service, $this->projet, $ressources, $parametres);
554 mathilde 318
			$code = $retour['type_bio.code'];
319
			$this->assertEquals($resultats_attendus[$code], $retour['type_bio.libelle'],
320
										"le traitement de l'ontologie pour les types biologiques est erroné pour $ressources[0] . ");
321
		}
322
	}
825 raphael 323
 
324
	public function testRelationsCatminat() {
325
		$ressources = array('bdtfx.nn:5641', 'relations', 'catminat');
947 raphael 326
		$parametres = array();
825 raphael 327
		$retour = $this->consulterJson($this->service, $this->projet, $ressources, $parametres);
328
 
329
		// valeurs standards
330
		$this->assertArrayHasKey('cle',$retour, "Le champ 'cle' doit être présent.");
331
		$this->assertEquals('1693',$retour['cle'], "Le champ 'cle' est erroné.");
332
 
333
		$this->assertArrayHasKey('num_nomen',$retour, "Le champ 'num_nomen' doit être présent.");
334
		$this->assertEquals('5641',$retour['num_nomen'], "Le champ 'num_nomen' est erroné.");
335
 
336
		$this->assertArrayHasKey('bdnt',$retour, "Le champ 'bdnt' doit être présent.");
337
		$this->assertEquals('bdtfx',$retour['bdnt'], "Le champ 'bdnt' est erroné.");
338
 
339
		// valeurs écologiques, test libelle
520 mathilde 340
 
825 raphael 341
		$this->assertArrayHasKey('ve_texture_sol_min.libelle',$retour, "Le champ 've_texture_sol_min.libelle' doit être présent.");
342
		$this->assertEquals('intermédiaire',$retour['ve_texture_sol_min.libelle'], "Le champ 've_texture_sol_min.libelle' est erroné.");
343
 
344
		$this->assertArrayHasKey('ve_humidite_atmos_min.code',$retour, "Le champ 've_humidite_atmos_min.code' doit être présent.");
345
		$this->assertEquals('8',$retour['ve_humidite_atmos_min.code'], "Le champ 've_texture_sol_min.libelle' est erroné.");
346
 
347
		// climat
348
		$this->assertArrayHasKey('graphique_climat',$retour, "Le champ 'graphique_climat' doit être présent.");
349
		$this->assertArrayHasKey('libelle',$retour['graphique_climat'], "Le champ 'graphique_climat > libelle' doit être présent.");
350
		$this->assertArrayHasKey('href',$retour['graphique_climat'], "Le champ 'graphique_climat > href' doit être présent.");
351
		$this->assertEquals('climat',$retour['graphique_climat']['libelle'], "Le champ 'graphique_climat > href' doit être présent.");
352
	}
353
 
354
	// TODO = ajouter un test pour Informations/id/Relations/catminat?navigation.limite=500&navigation.depart=0
520 mathilde 355
}
356
?>