Subversion Repositories eFlore/Projets.eflore-projets

Rev

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

Rev 206 Rev 216
Line 1... Line 1...
1
<?php
1
<?php
2
require_once dirname(__FILE__).'/../ServicePhpUnit.php';
2
require_once dirname(__FILE__).'/../ServicePhpUnit.php';
Line 3... Line 3...
3
 
3
 
Line -... Line 4...
-
 
4
class NomsServiceBdtfxTest extends ServicePhpUnit {
4
class NomDetailsBdtfxTest extends ServicePhpUnit {
5
 
5
 
6
	private $retour = '';
6
	private $nomDetailSqueletteUrl = 'http://localhost/service:eflore:0.2/bdtfx/noms/%s';
7
	private $nomDetailSqueletteUrl = 'http://localhost/service:eflore:0.2/bdtfx/noms/%s';
7
	private $ontologieHrefTpl = 'http://localhost/service:eflore:0.2/bdnt/ontologies/rangTaxo:%s';
8
	private $ontologieHrefTpl = 'http://localhost/service:eflore:0.2/bdnt/ontologies/rangTaxo:%s';
8
	private $champsProjet = array(
9
	private $champsProjet = array(
9
		'presence_Ga' => 'presence_Ga.code',
10
		'presence_Ga' => 'presence_Ga.code',
Line 10... Line 11...
10
		'presence_Co' => 'presence_Co.code'
11
		'presence_Co' => 'presence_Co.code'
11
		);
12
		);
12
 
13
 
13
	public function __construct() {
-
 
14
		$this->projet = 'bdtfx';
14
	public function __construct() {
Line 15... Line 15...
15
		$this->service = 'noms';
15
		$this->projet = 'bdtfx';
16
		$this->classeTestee = 'NomDetailsGenerique';
16
		$this->service = 'noms';
17
	}
17
	}
18
 
18
 
19
	public function initialiserService(NomsListe $service) {
19
	public function initialiserService(NomsListe $service) {
Line -... Line 20...
-
 
20
		$service->setDetailsHrefTpl($this->nomDetailSqueletteUrl);
-
 
21
		$service->setOntologieHrefTpl($this->ontologieHrefTpl);
-
 
22
		$service->setChampsProjet($this->champsProjet);
-
 
23
	}
-
 
24
 
-
 
25
	public function testVersionPrecise() {
-
 
26
		$ressources = array();
-
 
27
		$parametres = array('version.projet' => '1.01', 'recherche' => 'etendue', 'masque' => 'acer');
-
 
28
 
-
 
29
		$this->retour = $this->consulter($ressources, $parametres);
-
 
30
 
-
 
31
		$this->verifierStructureListe();
-
 
32
		$this->verifierMasque('nom_sci=acer%');
-
 
33
		$this->verifierTotal(156);
-
 
34
		$this->verifierNbreResultats(100);
-
 
35
	}
-
 
36
 
-
 
37
	public function testNomsVersionMultiple() {
-
 
38
		$ressources = array();
-
 
39
		$parametres = array('version.projet' => '*', 'recherche' => 'etendue', 'masque' => 'acer');
-
 
40
 
-
 
41
		$this->retour = $this->consulterBrut($ressources, $parametres);
-
 
42
 
-
 
43
		$this->verifierPresenceMessage("L'affichage de plusieurs versions ne fonctionne que pour les ressources de type /ressources/#id");
-
 
44
	}
-
 
45
 
-
 
46
	public function testVersionInexistante() {
-
 
47
		$ressources = array();
-
 
48
		$parametres = array('version.projet' => '99.00');
-
 
49
 
-
 
50
		$this->retour = $this->consulterBrut($ressources, $parametres);
-
 
51
 
-
 
52
		$this->verifierPresenceMessage("La version '99.00' n'est pas disponible pour le projet 'bdtfx' !");
-
 
53
	}
-
 
54
 
-
 
55
	public function testAucunResultat() {
-
 
56
		$ressources = array();
-
 
57
		$parametres = array(
-
 
58
					'version.projet' => '1.01',
-
 
59
					'recherche' => 'stricte',
-
 
60
					'masque' => 'Axer');
-
 
61
 
-
 
62
		$this->retour = $this->consulterBrut($ressources, $parametres);
-
 
63
 
-
 
64
		$this->verifierPresenceMessage("Aucun résultat ne correspond a votre requête !");
-
 
65
	}
-
 
66
 
-
 
67
	public function testRechercheStricte() {
-
 
68
		$ressources = array();
-
 
69
		$parametres = array(
-
 
70
				'version.projet' => '1.01',
-
 
71
				'recherche' => 'stricte',
-
 
72
				'masque' => 'Acer');
-
 
73
 
-
 
74
		$this->retour = $this->consulter($ressources, $parametres);
-
 
75
 
-
 
76
		$this->verifierStructureListe();
-
 
77
		$this->verifierMasque('nom_sci=Acer');
-
 
78
		$this->verifierTotal(1);
-
 
79
		$this->verifierNbreResultats(1);
-
 
80
	}
-
 
81
 
-
 
82
	public function testResultatChamps() {
-
 
83
		$ressources = array();
-
 
84
		$parametres = array(
-
 
85
				'version.projet' => '1.01',
-
 
86
				'recherche' => 'stricte',
-
 
87
				'masque.nn' => '182');
-
 
88
 
-
 
89
		$this->retour = $this->consulter($ressources, $parametres);
-
 
90
 
-
 
91
		$this->verifierStructureListe();
-
 
92
		$this->verifierMasque('num_nom=182');
-
 
93
		$this->verifierTotal(1);
-
 
94
		$this->verifierNbreResultats(1);
-
 
95
		$this->verifierLigneResultatsStructure(182);
-
 
96
		$this->verifierResultatsLigneAttributValeur(182, 'retenu', true);
-
 
97
		$this->verifierResultatsLigneAttributValeur(182, 'nom_sci', 'Acer monspessulanum');
-
 
98
	}
-
 
99
 
-
 
100
	public function testMasqueSg() {
-
 
101
		$ressources = array();
-
 
102
		$parametres = array(
-
 
103
				'version.projet' => '1.01',
-
 
104
				'recherche' => 'stricte',
-
 
105
				'masque.sg' => 'Asteraceae');
-
 
106
 
-
 
107
		$this->retour = $this->consulter($ressources, $parametres);
-
 
108
 
-
 
109
		$this->verifierStructureListe();
-
 
110
		$this->verifierMasque('nom_supra_generique=Asteraceae');
-
 
111
		$this->verifierTotal(1);
-
 
112
		$this->verifierNbreResultats(1);
-
 
113
	}
-
 
114
 
-
 
115
	public function testMasqueGenSpSspAuAn() {
-
 
116
		$ressources = array();
-
 
117
		$parametres = array(
-
 
118
				'version.projet' => '1.01',
-
 
119
				'recherche' => 'stricte',
-
 
120
				'masque.gen' => 'Allium',
-
 
121
				'masque.sp' => 'carinatum',
-
 
122
				'masque.ssp' => 'consimile',
-
 
123
				'masque.au' => 'Gren.',
-
 
124
				'masque.an' => '1855');
-
 
125
 
-
 
126
		$this->retour = $this->consulter($ressources, $parametres);
-
 
127
 
-
 
128
		$this->verifierStructureListe();
-
 
129
		$this->verifierMasque('genre=Allium&epithete_sp=carinatum&epithete_infra_sp=consimile&auteur=Gren.&annee=1855');
-
 
130
		$this->verifierTotal(1);
-
 
131
		$this->verifierNbreResultats(1);
-
 
132
	}
-
 
133
 
-
 
134
	public function testMasqueNn() {
-
 
135
		$ressources = array();
-
 
136
		$parametres = array(
-
 
137
				'version.projet' => '1.01',
-
 
138
				'recherche' => 'stricte',
-
 
139
				'masque.nn' => '182');
-
 
140
 
-
 
141
		$this->retour = $this->consulter($ressources, $parametres);
-
 
142
 
-
 
143
		$this->verifierStructureListe();
-
 
144
		$this->verifierMasque('num_nom=182');
-
 
145
		$this->verifierTotal(1);
-
 
146
		$this->verifierNbreResultats(1);
-
 
147
		$this->verifierLigneResultatsStructure(182);
-
 
148
	}
-
 
149
 
-
 
150
	public function testMasqueRg() {
-
 
151
		$ressources = array();
-
 
152
		$parametres = array(
-
 
153
				'version.projet' => '1.01',
-
 
154
				'recherche' => 'stricte',
-
 
155
				'masque.rg' => '180');
-
 
156
 
-
 
157
		$this->retour = $this->consulter($ressources, $parametres);
-
 
158
 
-
 
159
		$this->verifierStructureListe();
-
 
160
		$this->verifierMasque('rang=180');
-
 
161
		$this->verifierTotal(210);
-
 
162
	}
-
 
163
 
-
 
164
	// TODO : à implémenter!
-
 
165
	/*
-
 
166
	 public function testNomsIdVersionMultiple() {
-
 
167
	$ressources = array('71711');
-
 
168
	$parametres = array('version.projet' => '*');
-
 
169
 
-
 
170
	$retour = $this->consulter($ressources, $parametres);
-
 
171
	$this->assertArrayHasKey('bdtfx_v1_01', $retour, "Le json ne contient pas d'attribut : bdtfx_v1_01.");
-
 
172
	$this->assertArrayHasKey('bdtfx_v1_02', $retour, "Le json ne contient pas d'attribut : bdtfx_v1_02.");
-
 
173
	$this->assertEquals('71711', $retour['bdtfx_v1_01']['id'], "'bdtfx_v1_01' doit contenir un attribut 'id' avec la valeur '71711'");
-
 
174
	$this->assertEquals('71711', $retour['bdtfx_v1_02']['id'], "'bdtfx_v1_02' doit contenir un attribut 'id' avec la valeur '71711'");
-
 
175
	}*/
-
 
176
 
-
 
177
	// TODO : à implémenter
-
 
178
	/*
-
 
179
	public function testNsStructureTxt() {
-
 
180
		$ressources = array();
-
 
181
		$parametres = array(
-
 
182
				'version.projet' => '1.01',
-
 
183
				'recherche' => 'stricte',
-
 
184
				'masque.nn' => '182',
-
 
185
				'ns.format' => 'txt',
-
 
186
				'ns.structure' => 'au,an,bib,ad');
-
 
187
 
-
 
188
		$this->retour = $this->consulter($ressources, $parametres);
-
 
189
 
-
 
190
		$this->verifierStructureListe();
-
 
191
		$this->verifierMasque('num_nom=182');
-
 
192
		$this->verifierTotal(1);
-
 
193
		$this->verifierNbreResultats(1);
-
 
194
		$this->verifierResultatsLigneAttributValeur(182, 'nom_sci', 'Acer monspessulanum L. [1753, Sp. Pl., éd. 1 : 1056]');
-
 
195
	}*/
-
 
196
 
-
 
197
	// TODO : à implémenter
-
 
198
	/*
-
 
199
	public function testNsStructureHtml() {
-
 
200
		$ressources = array();
-
 
201
		$parametres = array(
-
 
202
				'version.projet' => '1.01',
-
 
203
				'recherche' => 'stricte',
-
 
204
				'masque.nn' => '182',
-
 
205
				'ns.format' => 'htm',
-
 
206
				'ns.structure' => 'au,an,bib,ad');
-
 
207
 
-
 
208
		$this->retour = $this->consulter($ressources, $parametres);
-
 
209
 
-
 
210
		$this->verifierStructureListe();
-
 
211
		$this->verifierMasque('num_nom=182');
-
 
212
		$this->verifierTotal(1);
-
 
213
		$this->verifierNbreResultats(1);
-
 
214
		$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>]';
-
 
215
		$this->verifierResultatsLigneAttributValeur(182, 'nom_sci', $nomSciAttendu);
-
 
216
	}*/
-
 
217
 
-
 
218
	public function testListeNomsAvecParametreRetourChamps() {
-
 
219
		$ressources = array();
-
 
220
		$parametres = array('version.projet' => '1.01',
-
 
221
				'masque' => 'acer',
-
 
222
				'retour.champs' => 'auteur,nom_retenu.*');
-
 
223
 
-
 
224
		$this->retour = $this->consulter($ressources, $parametres);
-
 
225
 
-
 
226
		$this->verifierStructureListe();
-
 
227
		$this->presenceAttributDansResultat(83587, 'auteur');
20
		$service->setDetailsHrefTpl($this->nomDetailSqueletteUrl);
228
		$this->presenceAttributDansResultat(83587, 'nom_retenu.id');
21
		$service->setOntologieHrefTpl($this->ontologieHrefTpl);
229
		$this->presenceAttributDansResultat(83587, 'nom_retenu.href');
22
		$service->setChampsProjet($this->champsProjet);
230
		$this->abscenceAttributDansResultat(83587, 'nom_retenu');
Line 23... Line 231...
23
	}
231
	}
Line 75... Line 283...
75
		$this->assertArrayHasKey('nom_retenu', $retour, 'Présence champ nom_retenu');
283
		$this->assertArrayHasKey('nom_retenu', $retour, 'Présence champ nom_retenu');
76
		$this->assertSame(null, $retour['nom_retenu'], 'Valeur champ nom_retenu = null');
284
		$this->assertSame(null, $retour['nom_retenu'], 'Valeur champ nom_retenu = null');
77
		$this->assertArrayNotHasKey('nom_retenu.href', $retour, 'Abscence champ nom_retenu.href');
285
		$this->assertArrayNotHasKey('nom_retenu.href', $retour, 'Abscence champ nom_retenu.href');
78
	}
286
	}
Line -... Line 287...
-
 
287
 
-
 
288
	private function verifierPresenceMessage($messageAttendu) {
-
 
289
		$this->assertEquals($messageAttendu, $this->retour);
-
 
290
	}
-
 
291
 
-
 
292
	private function verifierStructureListe() {
-
 
293
		$this->assertArrayHasKey('entete', $this->retour, "Présence attribut : entete");
-
 
294
		$this->assertArrayHasKey('masque', $this->retour['entete'], "Présence attribut : entete>masque");
-
 
295
		$this->assertArrayHasKey('depart', $this->retour['entete'], "Présence attribut : entete>depart");
-
 
296
		$this->assertArrayHasKey('limite', $this->retour['entete'], "Présence attribut : entete>limite");
-
 
297
		$this->assertArrayHasKey('total', $this->retour['entete'], "Présence attribut : entete>total");
-
 
298
		$this->assertArrayHasKey('resultats', $this->retour, "Présence attribut : resultats");
-
 
299
	}
-
 
300
 
-
 
301
	private function verifierMasque($masque) {
-
 
302
		$this->assertEquals($masque, $this->retour['entete']['masque'], "Attribut 'entete>masque' = '$masque'");
-
 
303
	}
-
 
304
 
-
 
305
	private function verifierTotal($total) {
-
 
306
		$this->assertSame($total, $this->retour['entete']['total'], "Attribut 'entete>total' = $total");
-
 
307
	}
-
 
308
 
-
 
309
	private function verifierNbreResultats($nbre) {
-
 
310
		$this->assertSame($nbre, count($this->retour['resultats']), "Nbre 'resultats' = 1");
-
 
311
	}
-
 
312
 
-
 
313
	private function verifierLigneResultatsStructure($ligne) {
-
 
314
		$this->assertArrayHasKey($ligne, $this->retour['resultats'], "Presence attribut : resultats>$ligne".print_r($this->retour, true));
-
 
315
		$this->assertArrayHasKey('nom_sci', $this->retour['resultats'][$ligne], "Presence attribut : resultats>$ligne>nom_sci".print_r($this->retour, true));
-
 
316
		$this->assertArrayHasKey('retenu', $this->retour['resultats'][$ligne], "Presence attribut : resultats>$ligne>retenu".print_r($this->retour, true));
-
 
317
		$this->assertArrayHasKey('href', $this->retour['resultats'][$ligne], "Presence attribut : resultats>$ligne>href".print_r($this->retour, true));
-
 
318
	}
-
 
319
 
-
 
320
	private function presenceAttributDansResultat($ligne, $attribut) {
-
 
321
		$this->assertArrayHasKey($attribut, $this->retour['resultats'][$ligne], "Présence attribut : resultats>$ligne>$attribut");
-
 
322
	}
-
 
323
 
-
 
324
	private function abscenceAttributDansResultat($ligne, $attribut) {
-
 
325
		$this->assertArrayNotHasKey($attribut, $this->retour['resultats'][$ligne], "Présence attribut : resultats>$ligne>$attribut");
-
 
326
	}
-
 
327
 
-
 
328
	private function verifierResultatsLigneAttributValeur($ligne, $attribut, $valeur) {
-
 
329
		$this->assertSame($valeur, $this->retour['resultats'][$ligne][$attribut], "Attribut 'resultats>$ligne>$attribut' = $valeur");
79
 
330
	}
80
}
331
}
81
?>
332
?>