Subversion Repositories eFlore/Projets.eflore-projets

Rev

Rev 215 | Blame | Last modification | View Log | RSS feed

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

class ParametresTest extends ServicePhpUnit {

        private function initialiser($parametresUrl = array()) {
                $bdd = $this->getMock('Bdd');

                $parametres = new Parametres($parametresUrl, $bdd);
                return $parametres;
        }

        public function testerParametreParDefaut() {
                $parametres = $this->initialiser();

                $this->assertEquals('stricte', $parametres->get('recherche'));
                $this->assertEquals('txt', $parametres->get('ns.format'));
                $this->assertEquals('application/json', $parametres->get('retour'));
                $this->assertEquals('max', $parametres->get('retour.format'));
                $this->assertEquals('fr', $parametres->get('retour.langue'));
                $this->assertEquals('+', $parametres->get('version.projet'));
                $this->assertSame(0, $parametres->get('navigation.depart'));
                $this->assertSame(100, $parametres->get('navigation.limite'));
        }

        public function testerExisterRetourneBouleen() {
                $parametresUrl = array('masque.id' => '12,15,18');

                $parametres = $this->initialiser($parametresUrl);

                $this->assertTrue($parametres->exister('masque.id'));
                $this->assertFalse($parametres->exister('masque'));
                $this->assertTrue($parametres->exister('recherche'));
        }

        public function testerGetRetourneValeur() {
                $parametresUrl = array('masque.id' => '12,15,18');

                $parametres = $this->initialiser($parametresUrl);

                $this->assertEquals('12,15,18', $parametres->get('masque.id'));
        }

        public function testerGetListeRetourneTableau() {
                $parametresUrl = array('masque.id' => '12,15,18');

                $parametres = $this->initialiser($parametresUrl);
                $liste = $parametres->getListe('masque.id');

                $this->assertTrue(is_array($liste));
                $this->assertCount(3, $liste);
                $this->assertContains(12, $liste);
                $this->assertContains(15, $liste);
                $this->assertContains(18, $liste);
        }

        public function testerIterateur() {
                $parametresUrl = array('code1' => 'val1', 'code2' => 'val2', 'code3' => 'val3');

                $parametres = $this->initialiser($parametresUrl);

                $parametres->rewind();
                $code = $parametres->key();
                $valeur = $parametres->current();
                $this->assertEquals('code1', $code);
                $this->assertEquals('val1', $valeur);

                $parametres->next();
                $code = $parametres->key();
                $valeur = $parametres->current();
                $this->assertEquals('code2', $code);
                $this->assertEquals('val2', $valeur);

                $parametres->next();
                $code = $parametres->key();
                $valeur = $parametres->current();
                $this->assertEquals('code3', $code);
                $this->assertEquals('val3', $valeur);

                $parametres->next();
                $this->assertFalse($parametres->valid());

                $parametres->rewind();
                $this->assertTrue($parametres->valid());
                $code = $parametres->key();
                $this->assertEquals('code1', $code);
        }

}