Subversion Repositories eFlore/Applications.del

Rev

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

Rev Author Line No. Line
1361 raphael 1
<?php
2
require_once __DIR__ . '/../ServiceDelPhpUnit.php';
3
error_reporting(E_ALL);
4
 
5
class ObservationsTest extends ServiceDelPhpUnit {
6
	//static function creerUrl($service, $ressources, $parametres = NULL) {
7
 
8
	public function testNonExistant() {
9
		$url = $this->creerUrl('observations');
10
		$i = new Observations();
11
		$retour = $this->consulterDirectJson($i->consulter([0], []),
12
											$url);
13
		// TODO: en-tête malgré tout ?
14
		$this->assertEmpty($retour, "Le json doit retourner un tableau vide. Voir : $url");
15
	}
16
 
17
	public function testExistant() {
18
		$url = $this->creerUrl('observations');
19
		$i = new Observations();
20
		$retour = $this->consulterDirectJson($i->consulter([1043942], []),
21
											$url);
1372 raphael 22
		return; // TODO
1361 raphael 23
		$this->hasKeysAndNotEmpty($retour, ['auteur.id', 'auteur.nom', 'date_transmission', 'observateur', 'id_observation'], $url);
24
		$this->hasKeys($retour, ['auteur.nom'], $url);
25
		$this->assertArrayHasKey('auteur.id', $retour, "attribut auteur.id manquant. Voir : $url");
26
	}
27
 
1372 raphael 28
	public function testMasque() {
29
		$url = $this->creerUrl('observations');
30
		$i = new Observations();
31
		$retour = $this->consulterDirectJson($i->consulter([], ['navigation.depart'=>0,'navigation.limite'=>12,'ordre'=>'asc','masque'=>'G']),
32
											$url);
33
		$expected = unserialize(file_get_contents("masque=G.data.json"));
34
		ksort($expected);
35
		ksort($retour);
36
		$this->assertEquals($expected['resultats'], $retour['resultats'], "JSON error, $url");
37
	}
38
 
39
	public function testMasqueEtType() {
40
		$url = $this->creerUrl('observations');
41
		$i = new Observations();
42
		$retour = $this->consulterDirectJson($i->consulter([], ['navigation.depart'=>0,'navigation.limite'=>12,'ordre'=>'asc','masque'=>'G','masque.type'=>'endiscussion']),
43
											$url);
44
		$expected = unserialize(file_get_contents("masque=G-masque.type=endiscussion.data.json"));
45
		ksort($expected);
46
		ksort($retour);
47
		$this->assertEquals($expected['resultats'], $retour['resultats'], "JSON error, $url");
48
	}
49
 
50
 
51
 
1361 raphael 52
	public function hasKeys($arr, $keys, $url) {
53
		foreach($keys as $k) {
54
			$this->assertArrayHasKey($k, $arr, "attribut {$k} manquant. Voir : $url");
55
		}
56
	}
57
 
58
	public function hasKeysAndNotEmpty($arr, $keys, $url) {
59
		foreach($keys as $k) {
60
			$this->assertArrayHasKey($k, $arr, "attribut {$k} manquant. Voir : $url");
61
			$this->assertNotEmpty($arr[$k], "attribut {$k} vide. Voir : $url");
62
		}
63
	}
64
}