Subversion Repositories eFlore/Projets.eflore-projets

Rev

Rev 258 | Rev 949 | Go to most recent revision | Blame | Compare with Previous | Last modification | View Log | RSS feed

<?php
require_once dirname(__FILE__).'/../ServiceEflorePhpUnit.php';

class ChorodepCartesTest extends ServiceEflorePhpUnit {

        private $retour = '';
        private $svg = '';

        public function __construct() {
                $this->projet = 'chorodep';
                $this->service = 'cartes';
        }

        public function setUp() {
                $this->retour = '';
                $this->svg = '';
        }

        public function testCarteGenerique() {
                $ressources = array();
                $parametres = array('version.projet' => '2012.01');

                $this->retour = ServiceEflorePhpUnit::consulterBrut($this->service, $this->projet, $ressources, $parametres);

                $this->verifierPresenceMessage("A implémenter : carte proportionnelle ensemble des infos");
        }

        public function testCarteGeneriqueLegende() {
                $ressources = array('legende');
                $parametres = array('version.projet' => '2012.01');

                $this->retour = ServiceEflorePhpUnit::consulterBrut($this->service, $this->projet, $ressources, $parametres);

                $this->verifierPresenceMessage("A implémenter : légende carte proportionnelle ensemble des infos");
        }

        public function testErreurRessource1() {
                $ressources = array('ressource1Erreur');
                $parametres = array('version.projet' => '2012.01');

                $this->retour = ServiceEflorePhpUnit::consulterBrut($this->service, $this->projet, $ressources, $parametres);

                $this->verifierPresenceMessage("La ressource n°1 '{$ressources[0]} indiquée n'est pas valable.");
        }

        public function testCarteSvgIdentifiants() {
                $ressourcesListe = array(
                        array('3237'),
                        array('nn:3237'),
                        array('bdtfx.nn:3237')
                );
                $parametres = array('version.projet' => '2012.01',
                        'retour' => 'image/svg+xml');

                foreach ($ressourcesListe as $ressources) {
                        $this->retour = ServiceEflorePhpUnit::consulterBrut($this->service, $this->projet, $ressources, $parametres);

                        $this->chargerXml();
                        $this->etreSvg();
                        $this->verifierDepartementsPresence(array(63, 81));
                }
        }

        public function testCarteSvgPlusieursLegendes() {
                $ressources = array('bdtfx.nn:71574');
                $parametres = array('version.projet' => '2012.01',
                                'retour' => 'image/svg+xml');

                $this->retour = ServiceEflorePhpUnit::consulterBrut($this->service, $this->projet, $ressources, $parametres);

                $this->chargerXml();
                $this->etreSvg();
                $this->verifierDepartementsPresence(array('02', '07', '57', '67', '88', '68', '90', '25', '21', '39', '01', '74', '73', '38', '46', '83'));
                $this->verifierDepartementsPresenceAConfirmer(array('62', '71'));
                $this->verifierDepartementsDisparu(array('70'));
                $this->verifierDepartementsErreur(array('06'));
        }

        private function verifierPresenceMessage($messageAttendu) {
                $this->assertEquals($messageAttendu, $this->retour);
        }

        private function chargerXml() {
                $this->svg = new DOMDocument();
                $chargement = $this->svg->loadXML($this->retour);
                $this->assertTrue($chargement);
        }

        private function etreSvg() {
                $racineElement = $this->svg->documentElement;
                $this->assertEquals('svg', $racineElement->tagName);
        }
        private function verifierDepartementsPresence($departements) {
                $this->verifierReglesCssCouleur('A0FF7D', $departements);
        }

        private function verifierDepartementsPresenceAConfirmer($departements) {
                $this->verifierReglesCssCouleur('FFFF32', $departements);
        }

        private function verifierDepartementsDouteux($departements) {
                $this->verifierReglesCssCouleur('FFCB30', $departements);
        }

        private function verifierDepartementsDisparu($departements) {
                $this->verifierReglesCssCouleur('F88017', $departements);
        }

        private function verifierDepartementsErreur($departements) {
                $this->verifierReglesCssCouleur('FF2850', $departements);
        }

        private function verifierDepartementsErreurAConfirmer($departements) {
                $this->verifierReglesCssCouleur('9F0016', $departements);
        }

        private function verifierReglesCssCouleur($couleur, $departements) {
                sort($departements);
                $cssRegles = $this->getListeReglesCss($departements);
                $cssAttendu = "$cssRegles{\nfill:#$couleur;\n}";

                $cssPresent = $this->svg->getElementsByTagName('style')->item(0)->nodeValue;

                $this->assertContains($cssAttendu, $cssPresent);
        }

        private function getListeReglesCss($departements) {
                foreach ($departements as $id => $val) {
                        $departements[$id] = '.departement'.$val;
                }
                $cssRegle = implode(', ', $departements);
                return $cssRegle;
        }
}
?>