Subversion Repositories eFlore/Applications.del

Rev

Rev 1372 | Go to most recent revision | Details | 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);
22
 
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
 
28
	public function hasKeys($arr, $keys, $url) {
29
		foreach($keys as $k) {
30
			$this->assertArrayHasKey($k, $arr, "attribut {$k} manquant. Voir : $url");
31
		}
32
	}
33
 
34
	public function hasKeysAndNotEmpty($arr, $keys, $url) {
35
		foreach($keys as $k) {
36
			$this->assertArrayHasKey($k, $arr, "attribut {$k} manquant. Voir : $url");
37
			$this->assertNotEmpty($arr[$k], "attribut {$k} vide. Voir : $url");
38
		}
39
	}
40
}