Subversion Repositories eFlore/Applications.del

Rev

Rev 1361 | 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);
                return; // TODO
                $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 testMasque() {
                $url = $this->creerUrl('observations');
                $i = new Observations();
                $retour = $this->consulterDirectJson($i->consulter([], ['navigation.depart'=>0,'navigation.limite'=>12,'ordre'=>'asc','masque'=>'G']),
                                                                                        $url);
                $expected = unserialize(file_get_contents("masque=G.data.json"));
                ksort($expected);
                ksort($retour);
                $this->assertEquals($expected['resultats'], $retour['resultats'], "JSON error, $url");
        }

        public function testMasqueEtType() {
                $url = $this->creerUrl('observations');
                $i = new Observations();
                $retour = $this->consulterDirectJson($i->consulter([], ['navigation.depart'=>0,'navigation.limite'=>12,'ordre'=>'asc','masque'=>'G','masque.type'=>'endiscussion']),
                                                                                        $url);
                $expected = unserialize(file_get_contents("masque=G-masque.type=endiscussion.data.json"));
                ksort($expected);
                ksort($retour);
                $this->assertEquals($expected['resultats'], $retour['resultats'], "JSON error, $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");
                }
        }
}