Rev 1374 | Go to most recent revision | Blame | Compare with Previous | Last modification | View Log | RSS feed
<?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");
}
}
}