Subversion Repositories eFlore/Projets.eflore-projets

Rev

Rev 258 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
258 jpm 1
<?php
2
require_once dirname(__FILE__).'/../ServiceEflorePhpUnit.php';
3
 
4
class ChorodepCartesTest extends ServiceEflorePhpUnit {
5
 
6
	private $retour = '';
7
	private $svg = '';
8
 
9
	public function __construct() {
10
		$this->projet = 'chorodep';
11
		$this->service = 'cartes';
12
	}
13
 
14
	public function setUp() {
15
		$this->retour = '';
16
		$this->svg = '';
17
	}
18
 
19
	public function testCarteGenerique() {
20
		$ressources = array();
21
		$parametres = array('version.projet' => '2012.01');
22
 
790 raphael 23
		$this->retour = ServiceEflorePhpUnit::consulterBrut($this->service, $this->projet, $ressources, $parametres);
258 jpm 24
 
25
		$this->verifierPresenceMessage("A implémenter : carte proportionnelle ensemble des infos");
26
	}
27
 
28
	public function testCarteGeneriqueLegende() {
29
		$ressources = array('legende');
30
		$parametres = array('version.projet' => '2012.01');
31
 
790 raphael 32
		$this->retour = ServiceEflorePhpUnit::consulterBrut($this->service, $this->projet, $ressources, $parametres);
258 jpm 33
 
34
		$this->verifierPresenceMessage("A implémenter : légende carte proportionnelle ensemble des infos");
35
	}
36
 
37
	public function testErreurRessource1() {
38
		$ressources = array('ressource1Erreur');
39
		$parametres = array('version.projet' => '2012.01');
40
 
790 raphael 41
		$this->retour = ServiceEflorePhpUnit::consulterBrut($this->service, $this->projet, $ressources, $parametres);
258 jpm 42
 
43
		$this->verifierPresenceMessage("La ressource n°1 '{$ressources[0]} indiquée n'est pas valable.");
44
	}
45
 
46
	public function testCarteSvgIdentifiants() {
47
		$ressourcesListe = array(
48
			array('3237'),
49
			array('nn:3237'),
50
			array('bdtfx.nn:3237')
51
		);
52
		$parametres = array('version.projet' => '2012.01',
53
			'retour' => 'image/svg+xml');
54
 
55
		foreach ($ressourcesListe as $ressources) {
790 raphael 56
			$this->retour = ServiceEflorePhpUnit::consulterBrut($this->service, $this->projet, $ressources, $parametres);
258 jpm 57
 
58
			$this->chargerXml();
59
			$this->etreSvg();
60
			$this->verifierDepartementsPresence(array(63, 81));
61
		}
62
	}
63
 
64
	public function testCarteSvgPlusieursLegendes() {
65
		$ressources = array('bdtfx.nn:71574');
66
		$parametres = array('version.projet' => '2012.01',
67
				'retour' => 'image/svg+xml');
68
 
790 raphael 69
		$this->retour = ServiceEflorePhpUnit::consulterBrut($this->service, $this->projet, $ressources, $parametres);
258 jpm 70
 
71
		$this->chargerXml();
72
		$this->etreSvg();
73
		$this->verifierDepartementsPresence(array('02', '07', '57', '67', '88', '68', '90', '25', '21', '39', '01', '74', '73', '38', '46', '83'));
74
		$this->verifierDepartementsPresenceAConfirmer(array('62', '71'));
75
		$this->verifierDepartementsDisparu(array('70'));
76
		$this->verifierDepartementsErreur(array('06'));
77
	}
78
 
79
	private function verifierPresenceMessage($messageAttendu) {
80
		$this->assertEquals($messageAttendu, $this->retour);
81
	}
82
 
83
	private function chargerXml() {
84
		$this->svg = new DOMDocument();
85
		$chargement = $this->svg->loadXML($this->retour);
86
		$this->assertTrue($chargement);
87
	}
88
 
89
	private function etreSvg() {
90
		$racineElement = $this->svg->documentElement;
91
		$this->assertEquals('svg', $racineElement->tagName);
92
	}
93
	private function verifierDepartementsPresence($departements) {
94
		$this->verifierReglesCssCouleur('A0FF7D', $departements);
95
	}
96
 
97
	private function verifierDepartementsPresenceAConfirmer($departements) {
98
		$this->verifierReglesCssCouleur('FFFF32', $departements);
99
	}
100
 
101
	private function verifierDepartementsDouteux($departements) {
102
		$this->verifierReglesCssCouleur('FFCB30', $departements);
103
	}
104
 
105
	private function verifierDepartementsDisparu($departements) {
106
		$this->verifierReglesCssCouleur('F88017', $departements);
107
	}
108
 
109
	private function verifierDepartementsErreur($departements) {
110
		$this->verifierReglesCssCouleur('FF2850', $departements);
111
	}
112
 
113
	private function verifierDepartementsErreurAConfirmer($departements) {
114
		$this->verifierReglesCssCouleur('9F0016', $departements);
115
	}
116
 
117
	private function verifierReglesCssCouleur($couleur, $departements) {
118
		sort($departements);
119
		$cssRegles = $this->getListeReglesCss($departements);
120
		$cssAttendu = "$cssRegles{\nfill:#$couleur;\n}";
121
 
122
		$cssPresent = $this->svg->getElementsByTagName('style')->item(0)->nodeValue;
123
 
124
		$this->assertContains($cssAttendu, $cssPresent);
125
	}
126
 
127
	private function getListeReglesCss($departements) {
128
		foreach ($departements as $id => $val) {
129
			$departements[$id] = '.departement'.$val;
130
		}
131
		$cssRegle = implode(', ', $departements);
132
		return $cssRegle;
133
	}
134
}
135
?>