Subversion Repositories eFlore/Applications.del

Compare Revisions

Ignore whitespace Rev 1360 → Rev 1361

/trunk/services/tests/0.1/observations/ObservationsTest.php
New file
0,0 → 1,40
<?php
require_once __DIR__ . '/../ServiceDelPhpUnit.php';
error_reporting(E_ALL);
 
class ObservationsTest extends ServiceDelPhpUnit {
//static function creerUrl($service, $ressources, $parametres = NULL) {
public function testNonExistant() {
$url = $this->creerUrl('observations');
$i = new Observations();
$retour = $this->consulterDirectJson($i->consulter([0], []),
$url);
// TODO: en-tĂȘte malgrĂ© tout ?
$this->assertEmpty($retour, "Le json doit retourner un tableau vide. Voir : $url");
}
 
public function testExistant() {
$url = $this->creerUrl('observations');
$i = new Observations();
$retour = $this->consulterDirectJson($i->consulter([1043942], []),
$url);
 
$this->hasKeysAndNotEmpty($retour, ['auteur.id', 'auteur.nom', 'date_transmission', 'observateur', 'id_observation'], $url);
$this->hasKeys($retour, ['auteur.nom'], $url);
$this->assertArrayHasKey('auteur.id', $retour, "attribut auteur.id manquant. Voir : $url");
}
 
public function hasKeys($arr, $keys, $url) {
foreach($keys as $k) {
$this->assertArrayHasKey($k, $arr, "attribut {$k} manquant. Voir : $url");
}
}
 
public function hasKeysAndNotEmpty($arr, $keys, $url) {
foreach($keys as $k) {
$this->assertArrayHasKey($k, $arr, "attribut {$k} manquant. Voir : $url");
$this->assertNotEmpty($arr[$k], "attribut {$k} vide. Voir : $url");
}
}
}