Subversion Repositories eFlore/Projets.eflore-projets

Rev

Rev 855 | Rev 859 | Go to most recent revision | Details | Compare with Previous | 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");
21
		$this->commonTest($retour, $url);
22
		// tag peut peut-être varier à travers les décennies ?
23
		// testRechercheTag ?
24
		$this->assertArrayHasKey('tag', $retour['resultats']['182'], "Le json [182] ne contient pas d'élément tag. Voir : $url");
25
		$this->assertContains("HYBRIDA", $retour['resultats']['182']['texte'], "error: ['resultats']['182']['texte']. Voir : $url");
26
	}
27
 
28
	public function testBdtfxRessource() {
856 raphael 29
		$url = ServiceEflorePhpUnit::creerUrl(self::$S, array("bdtfx.nn:182"));
30
		$retour = $this->consulterJson(self::$S, self::$P, array("bdtfx.nn:182"));
855 raphael 31
		$this->commonTestHeader($retour, $url);
32
		$this->assertEquals(1, $retour['entete']['total'], "L'attribut 'total' devrait avoir la valeur 1. Voir : $url");
33
		$this->commonTest($retour, $url);
34
		$this->assertArrayHasKey('tag', $retour['resultats']['182'], "Le json [182] ne contient pas d'élément tag. Voir : $url");
35
		$this->assertContains("HYBRIDA", $retour['resultats']['182']['texte'], "error: ['resultats']['182']['texte']. Voir : $url");
36
	}
37
 
38
	public function testNonExistantRessource() {
856 raphael 39
		$url = ServiceEflorePhpUnit::creerUrl(self::$S, array("-182"));
40
		$retour = $this->consulterBrut(self::$S, self::$P, array("-182"));
855 raphael 41
		$this->assertEquals("not supported", $retour, "error. Voir : $url");
42
	}
43
 
44
	// les critères se cumulent
45
	public function testRessourceEtMasque() {
856 raphael 46
		$url = ServiceEflorePhpUnit::creerUrl(self::$S, array(182), array("masque.ns" => "ABC"));
47
		$retour = $this->consulterJson(self::$S, self::$P, array(182), array("masque.ns" => "ABC"));
855 raphael 48
		$this->commonTestHeader($retour, $url);
49
		$this->assertEquals(0, $retour['entete']['total'], "L'attribut 'total' devrait avoir la valeur 0. Voir : $url");
50
	}
51
 
52
	public function testRessourceFormatHTML() {
856 raphael 53
		$url = ServiceEflorePhpUnit::creerUrl(self::$S, array(182), array('txt.format' => 'htm'));
54
		$retour = $this->consulterJson(self::$S, self::$P, array(182), array('txt.format' => 'htm'));
855 raphael 55
		$this->assertContains("span class", $retour['resultats']['182']['titre'], "error: ['resultats']['182']['titre']. Voir : $url");
56
	}
57
 
58
	public function testRessourceChamps() {
856 raphael 59
		$url = ServiceEflorePhpUnit::creerUrl(self::$S, array(182), array('retour.champs' => 'titre,tome,page,famille'));
60
		$retour = $this->consulterJson(self::$S, self::$P, array(182), array('retour.champs' => 'titre,tome,page,famille'));
855 raphael 61
		$this->assertEquals(1, count($retour['resultats']), "error: ['resultats']['182']. Voir : $url");
62
		$this->assertArrayHasKey("num_nom", $retour['resultats']['182'], "error: ['resultats']['182'], clef num_nom. Voir : $url");
63
		$this->assertArrayHasKey("titre", $retour['resultats']['182'], "error: ['resultats']['182'], clef titre. Voir : $url");
64
		$this->assertArrayHasKey("tome", $retour['resultats']['182'], "error: ['resultats']['182'], clef tome. Voir : $url");
65
		$this->assertArrayHasKey("page", $retour['resultats']['182'], "error: ['resultats']['182'], clef page. Voir : $url");
66
		$this->assertArrayHasKey("famille", $retour['resultats']['182'], "error: ['resultats']['182'], clef famille. Voir : $url");
67
		$this->assertEquals("1", $retour['resultats']['182']['tome'], "error: ['resultats']['182']['tome']. Voir : $url");
68
		$this->assertEquals("62", $retour['resultats']['182']['page'], "error: ['resultats']['182']['page']. Voir : $url");
69
		$this->assertEquals("Sapindaceae", $retour['resultats']['182']['famille'], "error: ['resultats']['182']['famille']. Voir : $url");
70
	}
71
 
72
 
73
	public function testRechercheNS() {
856 raphael 74
		$url = ServiceEflorePhpUnit::creerUrl(self::$S, NULL, array("masque.ns" => "Roemeria", "recherche" => "etendue"));
75
		$retour = $this->consulterJson(self::$S, self::$P, NULL, array("masque.ns" => "Roemeria", "recherche" => "etendue"));
855 raphael 76
		$this->commonTestHeader($retour, $url);
77
		$this->assertEquals(3, $retour['entete']['total'], "L'attribut 'total' devrait avoir la valeur 3. Voir : $url");
78
		$this->commonTest($retour, $url);
79
	}
80
 
81
 
82
	public function testRechercheTXT() {
856 raphael 83
		$url = ServiceEflorePhpUnit::creerUrl(self::$S, NULL, array("masque.txt" => "Nancy"));
84
		$retour = $this->consulterJson(self::$S, self::$P, NULL, array("masque.txt" => "Nancy"));
855 raphael 85
		$this->assertEquals(2, $retour['entete']['total'], "L'attribut 'total' devrait avoir la valeur 2. Voir : $url");
86
		$this->assertArrayHasKey("1774", $retour['resultats'], "error: ['resultats']['1774']. Voir : $url");
87
		$this->assertArrayHasKey("1775", $retour['resultats'], "error: ['resultats']['1775']. Voir : $url");
88
 
856 raphael 89
		$url = ServiceEflorePhpUnit::creerUrl(self::$S, NULL, array("masque.txt" => "Nancy", "recherche" => "floue"));
90
		$retour = $this->consulterJson(self::$S, self::$P, NULL, array("masque.txt" => "Nancy", "recherche" => "floue"));
855 raphael 91
		$this->assertEquals(2, $retour['entete']['total'], "L'attribut 'total' devrait avoir la valeur 2. Voir : $url");
92
		$this->assertArrayHasKey("1774", $retour['resultats'], "error: ['resultats']['1774']. Voir : $url");
93
		$this->assertArrayHasKey("1775", $retour['resultats'], "error: ['resultats']['1775']. Voir : $url");
94
 
856 raphael 95
		$url = ServiceEflorePhpUnit::creerUrl(self::$S, NULL, array("masque.txt" => "Nancy", "masque.tome" => 2));
96
		$retour = $this->consulterJson(self::$S, self::$P, NULL, array("masque.txt" => "Nancy", "masque.tome" => 2));
855 raphael 97
		$this->assertEquals(1, $retour['entete']['total'], "L'attribut 'total' devrait avoir la valeur 1. Voir : $url");
98
		$this->assertArrayHasKey("1774", $retour['resultats'], "error: ['resultats']['1774']. Voir : $url");
99
 
856 raphael 100
		$url = ServiceEflorePhpUnit::creerUrl(self::$S, NULL, array("masque.txt" => "Nancy", "masque.page" => 0));
101
		$retour = $this->consulterJson(self::$S, self::$P, NULL, array("masque.txt" => "Nancy", "masque.page" => 0));
855 raphael 102
		$this->assertEquals(1, $retour['entete']['total'], "L'attribut 'total' devrait avoir la valeur 1. Voir : $url");
103
		$this->assertArrayHasKey("1775", $retour['resultats'], "error: ['resultats']['1775']. Voir : $url");
104
	}
105
 
106
 
107
	// par compatibilité, "titre" signifie une recherche sur "tag" (le titre de la page wiki de la description
108
	// ou des clefs de détermination)
109
	public function testRechercheTag() {
856 raphael 110
		$url = ServiceEflorePhpUnit::creerUrl(self::$S, NULL, array("masque.titre" => "Esp0131RoemeriaViolacea"));
111
		$retour = $this->consulterJson(self::$S, self::$P, NULL, array("masque.titre" => "Esp0131RoemeriaViolacea"));
855 raphael 112
		$this->commonTestHeader($retour, $url);
113
		$this->assertEquals(2, $retour['entete']['total'], "L'attribut 'total' devrait avoir la valeur 2. Voir : $url");
114
		$this->commonTest($retour, $url);
115
		$this->assertArrayHasKey('tag', $retour['resultats']['182'], "Le json [182] ne contient pas d'élément tag. Voir : $url");
116
		$this->assertEquals("Esp0131RoemeriaViolacea", $retour['resultats']['182']['tag'], "error: ['resultats']['182']['tag']. Voir : $url");
117
	}
118
 
119
	public function testRechercheFamille() {
120
		// unknown famille
856 raphael 121
		$url = ServiceEflorePhpUnit::creerUrl(self::$S, NULL, array("masque.famille" => "ABC"));
122
		$retour = $this->consulterJson(self::$S, self::$P, NULL, array("masque.famille" => "ABC"));
855 raphael 123
		$this->assertEquals(0, $retour['entete']['total'], "L'attribut 'total' devrait avoir la valeur 0. Voir : $url");
124
 
125
		// par famille, mais pas de recherche étendue pour ça
856 raphael 126
		$url = ServiceEflorePhpUnit::creerUrl(self::$S, NULL, array("masque.famille" => "Sapind"));
127
		$retour = $this->consulterJson(self::$S, self::$P, NULL, array("masque.famille" => "Sapind"));
855 raphael 128
		$this->assertEquals(0, $retour['entete']['total'], "L'attribut 'total' devrait avoir la valeur 0. Voir : $url");
129
 
856 raphael 130
		$url = ServiceEflorePhpUnit::creerUrl(self::$S, array(182), array("masque.famille" => "Sapindaceae"));
131
		$retour = $this->consulterJson(self::$S, self::$P, array(182), array("masque.famille" => "Sapindaceae"));
855 raphael 132
		$this->assertEquals(1, $retour['entete']['total'], "L'attribut 'total' devrait avoir la valeur 1. Voir : $url");
133
 
856 raphael 134
		$url = ServiceEflorePhpUnit::creerUrl(self::$S, array(182), array("masque.famille" => "Sapind%"));
135
		$retour = $this->consulterJson(self::$S, self::$P, array(182), array("masque.famille" => "Sapind%"));
855 raphael 136
		$this->assertEquals(1, $retour['entete']['total'], "L'attribut 'total' devrait avoir la valeur 1. Voir : $url");
137
 
856 raphael 138
		$url = ServiceEflorePhpUnit::creerUrl(self::$S, array(182), array("masque.famille" => "S_pindaceae"));
139
		$retour = $this->consulterJson(self::$S, self::$P, array(182), array("masque.famille" => "S_pindaceae"));
855 raphael 140
		$this->assertEquals(1, $retour['entete']['total'], "L'attribut 'total' devrait avoir la valeur 1. Voir : $url");
141
	}
142
 
143
 
144
	// commons
145
	public function commonTestHeader($retour, $url) {
146
		$this->assertNotEmpty($retour, 'données absentes');
147
		$this->assertArrayHasKey('total', $retour['entete'], "Le json ne contient pas d'attribut : total. Voir : $url");
148
	}
149
 
150
 
151
	public function commonTest($retour, $url) {
152
		$this->assertArrayHasKey('182', $retour['resultats'], "Le json ne contient pas d'élément 182. Voir : $url");
153
		$this->assertArrayHasKey('titre', $retour['resultats']['182'], "Le json [182] ne contient pas d'élément titre. Voir : $url");
154
		$this->assertArrayHasKey('num_nom', $retour['resultats']['182'], "Le json [182] ne contient pas d'élément num_nom. Voir : $url");
155
		$this->assertEquals("Roemeria violacea", $retour['resultats']['182']['titre'], "error: ['resultats']['182']['titre']. Voir : $url");
156
		$this->assertEquals("182", $retour['resultats']['182']['num_nom'], "error: ['resultats']['182']['num_nom']. Voir : $url");
157
	}
158
 
159
}