Subversion Repositories eFlore/Projets.eflore-projets

Rev

Go to most recent revision | Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
855 raphael 1
<?php
2
/*
3
 * @copyright 2013 Tela Botanica (accueil@tela-botanica.org)
4
 * @author Raphaël Droz <raphael@tela-botanica.org>
5
 * @license GPL v3 <http://www.gnu.org/licenses/gpl.txt>
6
 * @license CECILL v2 <http://www.cecill.info/licences/Licence_CeCILL_V2-en.txt>
7
 */
8
require_once dirname(__FILE__).'/../ServiceEflorePhpUnit.php';
9
 
10
class CosteNomsTest extends ServiceEflorePhpUnit {
11
 
856 raphael 12
	static $P = "coste";
13
	static $S = "textes";
14
 
855 raphael 15
	// test d'obtention d'information sur num_nom connu
16
	public function testRessource() {
856 raphael 17
		$url = ServiceEflorePhpUnit::creerUrl(self::$S, array(182));
18
		$retour = $this->consulterJson(self::$S, self::$P, array(182));
855 raphael 19
		$this->commonTestHeader($retour, $url);
20
		$this->assertEquals(1, $retour['entete']['total'], "L'attribut 'total' devrait avoir la valeur 1. Voir : $url");
861 raphael 21
		$this->commonTest($retour, $url, 182);
949 raphael 22
		$this->assertEquals(182, $retour['resultats'][182]['coste:nn'], "error: ['resultats'][182]['coste:nn']. Voir : $url");
861 raphael 23
		$this->assertEquals("Roemeria violacea", $retour['resultats'][182]['titre'], "error: ['resultats'][182]['titre']. Voir : $url");
855 raphael 24
		// tag peut peut-être varier à travers les décennies ?
25
		// testRechercheTag ?
861 raphael 26
		$this->assertArrayHasKey('tag', $retour['resultats'][182], "Le json [182] ne contient pas d'élément tag. Voir : $url");
27
		$this->assertContains("HYBRIDA", $retour['resultats'][182]['texte'], "error: ['resultats'][182]['texte']. Voir : $url");
28
		$this->assertEquals(56272, $retour['resultats'][182]['bdtfx:nn'], "error: ['resultats'][182]['titre']. Voir : $url");
855 raphael 29
	}
30
 
31
	public function testBdtfxRessource() {
856 raphael 32
		$url = ServiceEflorePhpUnit::creerUrl(self::$S, array("bdtfx.nn:182"));
33
		$retour = $this->consulterJson(self::$S, self::$P, array("bdtfx.nn:182"));
855 raphael 34
		$this->commonTestHeader($retour, $url);
35
		$this->assertEquals(1, $retour['entete']['total'], "L'attribut 'total' devrait avoir la valeur 1. Voir : $url");
861 raphael 36
		$this->commonTest($retour, $url, 1027);
37
		$this->assertEquals("Acer monspessulanum", $retour['resultats'][1027]['titre'], "error: ['resultats'][1027]['titre']. Voir : $url");
38
		$this->assertArrayHasKey('tag', $retour['resultats'][1027], "Le json [1027] ne contient pas d'élément tag. Voir : $url");
39
		$this->assertContains("Érable de Montpellier", $retour['resultats'][1027]['texte'], "error: ['resultats'][1027]['texte']. Voir : $url");
40
		$this->assertEquals(1027, $retour['resultats'][1027]['coste:nn'], "error: ['resultats'][1027]['coste:nn']. Voir : $url");
41
		$this->assertEquals(182, $retour['resultats'][1027]['bdtfx:nn'], "error: ['resultats'][1027]['coste:nn']. Voir : $url");
855 raphael 42
	}
43
 
859 raphael 44
 
45
	public function testRessources() {
46
		$url = ServiceEflorePhpUnit::creerUrl(self::$S, array("bdtfx.nn:182,abcd,666"));
47
		$retour = $this->consulterJson(self::$S, self::$P, array("bdtfx.nn:182,abcd,666"));
48
		$this->commonTestHeader($retour, $url);
49
		$this->assertEquals(2, $retour['entete']['total'], "L'attribut 'total' devrait avoir la valeur 2. Voir : $url");
861 raphael 50
		$this->commonTest($retour, $url, 1027);
51
		$this->assertEquals("Acer monspessulanum", $retour['resultats'][1027]['titre'], "error: ['resultats'][1027]['titre']. Voir : $url");
52
		$this->assertArrayHasKey('titre', $retour['resultats'][1027], "Le json [1027] ne contient pas d'élément titre. Voir : $url");
53
		$this->assertArrayHasKey('titre', $retour['resultats'][666], "Le json [666] ne contient pas d'élément titre. Voir : $url");
54
		$this->assertEquals("Acer monspessulanum", $retour['resultats'][1027]['titre'], "error: ['resultats'][1027]['titre']. Voir : $url");
55
		$this->assertEquals("Silene reflexa", $retour['resultats'][666]['titre'], "error: ['resultats'][666]['titre']. Voir : $url");
859 raphael 56
 
57
		$url = ServiceEflorePhpUnit::creerUrl(self::$S, array("a,-1,99999"));
58
		$retour = $this->consulterBrut(self::$S, self::$P, array("a,-1,99999"));
59
		$this->assertEquals("not supported", $retour, "error, Voir : $url");
60
	}
61
 
855 raphael 62
	public function testNonExistantRessource() {
856 raphael 63
		$url = ServiceEflorePhpUnit::creerUrl(self::$S, array("-182"));
64
		$retour = $this->consulterBrut(self::$S, self::$P, array("-182"));
855 raphael 65
		$this->assertEquals("not supported", $retour, "error. Voir : $url");
66
	}
67
 
68
	// les critères se cumulent
69
	public function testRessourceEtMasque() {
856 raphael 70
		$url = ServiceEflorePhpUnit::creerUrl(self::$S, array(182), array("masque.ns" => "ABC"));
71
		$retour = $this->consulterJson(self::$S, self::$P, array(182), array("masque.ns" => "ABC"));
855 raphael 72
		$this->commonTestHeader($retour, $url);
73
		$this->assertEquals(0, $retour['entete']['total'], "L'attribut 'total' devrait avoir la valeur 0. Voir : $url");
74
	}
75
 
76
	public function testRessourceFormatHTML() {
856 raphael 77
		$url = ServiceEflorePhpUnit::creerUrl(self::$S, array(182), array('txt.format' => 'htm'));
78
		$retour = $this->consulterJson(self::$S, self::$P, array(182), array('txt.format' => 'htm'));
861 raphael 79
		$this->assertContains("span class", $retour['resultats'][182]['titre'], "error: ['resultats'][182]['titre']. Voir : $url");
855 raphael 80
	}
81
 
82
	public function testRessourceChamps() {
862 raphael 83
		$url = ServiceEflorePhpUnit::creerUrl(self::$S, array(182), array('retour.champs' => 'titre,tome,page,famille,bdtfx:nt'));
84
		$retour = $this->consulterJson(self::$S, self::$P, array(182), array('retour.champs' => 'titre,tome,page,famille,bdtfx:nt'));
897 raphael 85
		$this->assertCount(1, $retour['resultats'], "error: ['resultats'][182]. Voir : $url");
861 raphael 86
		$this->assertArrayHasKey("coste:nn", $retour['resultats'][182], "error: ['resultats'][182], clef coste:nn. Voir : $url");
87
		$this->assertArrayHasKey("titre", $retour['resultats'][182], "error: ['resultats'][182], clef titre. Voir : $url");
88
		$this->assertArrayHasKey("tome", $retour['resultats'][182], "error: ['resultats'][182], clef tome. Voir : $url");
89
		$this->assertArrayHasKey("page", $retour['resultats'][182], "error: ['resultats'][182], clef page. Voir : $url");
90
		$this->assertArrayHasKey("famille", $retour['resultats'][182], "error: ['resultats'][182], clef famille. Voir : $url");
862 raphael 91
		$this->assertArrayHasKey("bdtfx:nt", $retour['resultats'][182], "error: ['resultats'][182], clef bdtfx:nt. Voir : $url");
92
		$this->assertEquals(1, $retour['resultats'][182]['tome'], "error: ['resultats'][182]['tome']. Voir : $url");
93
		$this->assertEquals(62, $retour['resultats'][182]['page'], "error: ['resultats'][182]['page']. Voir : $url");
861 raphael 94
		$this->assertEquals("Papaveraceae", $retour['resultats'][182]['famille'], "error: ['resultats'][182]['famille']. Voir : $url");
862 raphael 95
		$this->assertEquals(4057, $retour['resultats'][182]['bdtfx:nt'], "error: ['resultats'][182]['bdtfx:nt']. Voir : $url");
855 raphael 96
	}
97
 
98
 
99
	public function testRechercheNS() {
856 raphael 100
		$url = ServiceEflorePhpUnit::creerUrl(self::$S, NULL, array("masque.ns" => "Roemeria", "recherche" => "etendue"));
101
		$retour = $this->consulterJson(self::$S, self::$P, NULL, array("masque.ns" => "Roemeria", "recherche" => "etendue"));
855 raphael 102
		$this->commonTestHeader($retour, $url);
103
		$this->assertEquals(3, $retour['entete']['total'], "L'attribut 'total' devrait avoir la valeur 3. Voir : $url");
861 raphael 104
		$this->commonTest($retour, $url, 182);
105
		$this->assertEquals("Roemeria violacea", $retour['resultats'][182]['titre'], "error: ['resultats'][182]['titre']. Voir : $url");
855 raphael 106
	}
107
 
108
 
109
	public function testRechercheTXT() {
856 raphael 110
		$url = ServiceEflorePhpUnit::creerUrl(self::$S, NULL, array("masque.txt" => "Nancy"));
111
		$retour = $this->consulterJson(self::$S, self::$P, NULL, array("masque.txt" => "Nancy"));
855 raphael 112
		$this->assertEquals(2, $retour['entete']['total'], "L'attribut 'total' devrait avoir la valeur 2. Voir : $url");
113
		$this->assertArrayHasKey("1774", $retour['resultats'], "error: ['resultats']['1774']. Voir : $url");
114
		$this->assertArrayHasKey("1775", $retour['resultats'], "error: ['resultats']['1775']. Voir : $url");
115
 
856 raphael 116
		$url = ServiceEflorePhpUnit::creerUrl(self::$S, NULL, array("masque.txt" => "Nancy", "recherche" => "floue"));
117
		$retour = $this->consulterJson(self::$S, self::$P, NULL, array("masque.txt" => "Nancy", "recherche" => "floue"));
855 raphael 118
		$this->assertEquals(2, $retour['entete']['total'], "L'attribut 'total' devrait avoir la valeur 2. Voir : $url");
119
		$this->assertArrayHasKey("1774", $retour['resultats'], "error: ['resultats']['1774']. Voir : $url");
120
		$this->assertArrayHasKey("1775", $retour['resultats'], "error: ['resultats']['1775']. Voir : $url");
121
 
856 raphael 122
		$url = ServiceEflorePhpUnit::creerUrl(self::$S, NULL, array("masque.txt" => "Nancy", "masque.tome" => 2));
123
		$retour = $this->consulterJson(self::$S, self::$P, NULL, array("masque.txt" => "Nancy", "masque.tome" => 2));
855 raphael 124
		$this->assertEquals(1, $retour['entete']['total'], "L'attribut 'total' devrait avoir la valeur 1. Voir : $url");
125
		$this->assertArrayHasKey("1774", $retour['resultats'], "error: ['resultats']['1774']. Voir : $url");
126
 
856 raphael 127
		$url = ServiceEflorePhpUnit::creerUrl(self::$S, NULL, array("masque.txt" => "Nancy", "masque.page" => 0));
128
		$retour = $this->consulterJson(self::$S, self::$P, NULL, array("masque.txt" => "Nancy", "masque.page" => 0));
855 raphael 129
		$this->assertEquals(1, $retour['entete']['total'], "L'attribut 'total' devrait avoir la valeur 1. Voir : $url");
130
		$this->assertArrayHasKey("1775", $retour['resultats'], "error: ['resultats']['1775']. Voir : $url");
131
	}
132
 
133
 
134
	// par compatibilité, "titre" signifie une recherche sur "tag" (le titre de la page wiki de la description
135
	// ou des clefs de détermination)
136
	public function testRechercheTag() {
856 raphael 137
		$url = ServiceEflorePhpUnit::creerUrl(self::$S, NULL, array("masque.titre" => "Esp0131RoemeriaViolacea"));
138
		$retour = $this->consulterJson(self::$S, self::$P, NULL, array("masque.titre" => "Esp0131RoemeriaViolacea"));
855 raphael 139
		$this->commonTestHeader($retour, $url);
140
		$this->assertEquals(2, $retour['entete']['total'], "L'attribut 'total' devrait avoir la valeur 2. Voir : $url");
861 raphael 141
		$this->commonTest($retour, $url, 182);
142
		$this->assertEquals("Roemeria violacea", $retour['resultats'][182]['titre'], "error: ['resultats'][182]['titre']. Voir : $url");
143
		$this->assertArrayHasKey('tag', $retour['resultats'][182], "Le json [182] ne contient pas d'élément tag. Voir : $url");
144
		$this->assertEquals("Esp0131RoemeriaViolacea", $retour['resultats'][182]['tag'], "error: ['resultats'][182]['tag']. Voir : $url");
855 raphael 145
	}
146
 
862 raphael 147
	public function testRechercheNT() {
148
		$url = ServiceEflorePhpUnit::creerUrl(self::$S, NULL, array("masque.nt" => 8523));
149
		$retour = $this->consulterJson(self::$S, self::$P, NULL, array("masque.nt" => 8523));
150
		$this->commonTestHeader($retour, $url);
151
		$this->assertEquals(1, $retour['entete']['total'], "L'attribut 'total' devrait avoir la valeur 1. Voir : $url");
152
		$this->commonTest($retour, $url, 1027);
153
		$this->assertEquals("Acer monspessulanum", $retour['resultats'][1027]['titre'], "error: ['resultats'][182]['titre']. Voir : $url");
154
	}
155
 
855 raphael 156
	public function testRechercheFamille() {
157
		// unknown famille
856 raphael 158
		$url = ServiceEflorePhpUnit::creerUrl(self::$S, NULL, array("masque.famille" => "ABC"));
159
		$retour = $this->consulterJson(self::$S, self::$P, NULL, array("masque.famille" => "ABC"));
855 raphael 160
		$this->assertEquals(0, $retour['entete']['total'], "L'attribut 'total' devrait avoir la valeur 0. Voir : $url");
161
 
162
		// par famille, mais pas de recherche étendue pour ça
856 raphael 163
		$url = ServiceEflorePhpUnit::creerUrl(self::$S, NULL, array("masque.famille" => "Sapind"));
164
		$retour = $this->consulterJson(self::$S, self::$P, NULL, array("masque.famille" => "Sapind"));
855 raphael 165
		$this->assertEquals(0, $retour['entete']['total'], "L'attribut 'total' devrait avoir la valeur 0. Voir : $url");
166
 
861 raphael 167
		$url = ServiceEflorePhpUnit::creerUrl(self::$S, array("bdtfx.nn:182"), array("masque.famille" => "Sapindaceae"));
168
		$retour = $this->consulterJson(self::$S, self::$P, array("bdtfx.nn:182"), array("masque.famille" => "Sapindaceae"));
855 raphael 169
		$this->assertEquals(1, $retour['entete']['total'], "L'attribut 'total' devrait avoir la valeur 1. Voir : $url");
170
 
861 raphael 171
		$url = ServiceEflorePhpUnit::creerUrl(self::$S, array("bdtfx.nn:182"), array("masque.famille" => "Sapind%"));
172
		$retour = $this->consulterJson(self::$S, self::$P, array("bdtfx.nn:182"), array("masque.famille" => "Sapind%"));
855 raphael 173
		$this->assertEquals(1, $retour['entete']['total'], "L'attribut 'total' devrait avoir la valeur 1. Voir : $url");
174
 
861 raphael 175
		$url = ServiceEflorePhpUnit::creerUrl(self::$S, array("bdtfx.nn:182"), array("masque.famille" => "S_pindaceae"));
176
		$retour = $this->consulterJson(self::$S, self::$P, array("bdtfx.nn:182"), array("masque.famille" => "S_pindaceae"));
855 raphael 177
		$this->assertEquals(1, $retour['entete']['total'], "L'attribut 'total' devrait avoir la valeur 1. Voir : $url");
178
	}
179
 
863 raphael 180
	// le webservice permet de définir la clef d'index choisir: par num_nom de coste ou num_nom de bdtfx
181
	public function testIndex() {
182
		$url = ServiceEflorePhpUnit::creerUrl(self::$S, NULL, array("masque.famille" => "Sapindaceae"));
183
		$retour = $this->consulterJson(self::$S, self::$P, NULL, array("masque.famille" => "Sapindaceae"));
184
		$e = array(1030,1027,1026,1028,1036,1025);
185
		$r = array_keys($retour['resultats']);
186
		sort($r);sort($e);
187
		$this->assertEquals($e, $r, "Erreur des l'index des résultats. Voir : $url");
855 raphael 188
 
863 raphael 189
		$url = ServiceEflorePhpUnit::creerUrl(self::$S, NULL, array("masque.famille" => "Sapindaceae", "retour.indexBy" => "bdtfx"));
190
		$retour = $this->consulterJson(self::$S, self::$P, NULL, array("masque.famille" => "Sapindaceae", "retour.indexBy" => "bdtfx"));
191
		$e = array(182,1053,74934,210,141,199);
192
		$r = array_keys($retour['resultats']);
193
		sort($r);sort($e);
194
		$this->assertEquals($e, $r, "Erreur des l'index des résultats. Voir : $url");
195
 
196
		// le taxon coste:nn:183 ne correspond à ce jour (2013/09/04) à aucun taxon bdtfx
197
		// l'indexation par bdtfx doit donc absolument échouer
198
		$url = ServiceEflorePhpUnit::creerUrl(self::$S, array(183), array("retour.indexBy" => "bdtfx"));
199
		$retour = $this->consulterBrut(self::$S, self::$P, array(183), array("retour.indexBy" => "bdtfx"));
200
		$this->assertContains("error", $retour, "L'indexation par bdtfx doit retourner une erreur en cas de bdtfx.num_nom NULL. Voir : $url");
201
	}
202
 
203
 
855 raphael 204
	// commons
205
	public function commonTestHeader($retour, $url) {
206
		$this->assertNotEmpty($retour, 'données absentes');
207
		$this->assertArrayHasKey('total', $retour['entete'], "Le json ne contient pas d'attribut : total. Voir : $url");
208
	}
209
 
210
 
861 raphael 211
	public function commonTest($retour, $url, $id) {
212
		$this->assertArrayHasKey("$id", $retour['resultats'], "Le json ne contient pas d'élément $id. Voir : $url");
213
		$this->assertArrayHasKey('titre', $retour['resultats'][$id], "Le json [$id] ne contient pas d'élément titre. Voir : $url");
214
		$this->assertArrayHasKey('coste:nn', $retour['resultats'][$id], "Le json [$id] ne contient pas d'élément coste:nn. Voir : $url");
215
		$this->assertArrayHasKey('bdtfx:nn', $retour['resultats'][$id], "Le json [$id] ne contient pas d'élément bdtfx:nn. Voir : $url");
855 raphael 216
	}
217
}