Subversion Repositories eFlore/Applications.eflore-consultation

Rev

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

<?php
include_once dirname(__FILE__).'/../ResultatFormateurInitialisation.php';

class DeterminationVernaFormateurTest extends ResultatFormateurInitialisation {

        public function testerFormater() {
                $Formateur = $this->initialiserDeterminationVernaFormateur();

                $Formateur->formater();
                $infos = $Formateur->getTplInfos();

                $this->assertArrayHasKey('noms', $infos, print_r($infos, true));
                foreach ($infos['noms'] as $id => $nom) {
                        $this->assertTrue(is_int($id), "L'id '$id' doit être un nombre entier.");
                        $this->assertCount(3, $nom);
                        $this->assertArrayHasKey('nomSci', $infos['noms'][$id], print_r($infos, true));
                        $this->assertArrayHasKey('urlFiche', $infos['noms'][$id], print_r($infos, true));
                        $urlFicheAttendue = sprintf(ConsultationEflorePhpUnit::TPL_URL_FICHE, $id);
                        $this->assertEquals($urlFicheAttendue, $infos['noms'][$id]['urlFiche'], print_r($infos, true));
                        if (array_key_exists('nomVerna', $infos['noms'][$id])) {
                                $nomsVernas = $infos['noms'][$id]['nomVerna'];
                                $this->assertTrue(is_array($nomsVernas));
                                foreach ($nomsVernas as $nomVerna) {
                                        $this->assertCount(2, $nomVerna, print_r($nomVerna, true));
                                        $this->assertArrayHasKey('nn', $nomVerna, print_r($nomVerna, true));
                                        $this->assertTrue(is_int($nomVerna['nn']), "La valeur nn (num_nom) '{$nomVerna['nn']}' doit être un nombre entier.");
                                        $this->assertArrayHasKey('nom_vernaculaire', $nomVerna, print_r($nomVerna, true));
                                }
                        }
                }

                $this->assertArrayHasKey('imagesUrls', $infos, print_r($infos, true));
                $this->assertTrue(is_array($infos['imagesUrls']), "'imagesUrls' doit être un tableau");
                $this->assertArrayHasKey('51299', $infos['imagesUrls'], print_r($infos['imagesUrls'], true));
                $this->assertArrayHasKey('18669', $infos['imagesUrls'], print_r($infos['imagesUrls'], true));
                foreach ($infos['imagesUrls'] as $imgUrl) {
                        $this->assertTrue(is_array($imgUrl), "Chaque taxon doit avoir un tableau d'url d'images");
                        foreach ($imgUrl as $url) {
                                $this->assertRegExp('/^http:\/\/www\.tela-botanica\.org\/appli:cel-img:[0-9]{9}CS\.jpg$/', $url);
                        }
                }
        }
        
        public function testerSurligner() {
                $Formateur = $this->initialiserDeterminationVernaFormateur();

                $Formateur->formater();
                $Formateur->surligner();
                $infos = $Formateur->getTplInfos();

                $this->assertArrayHasKey('noms', $infos, print_r($infos, true));
                foreach ($infos['noms'] as $nom) {
                        foreach ($nom['nomVerna'] as $id => $nomVerna) {
                                $this->assertArrayHasKey('nom_vernaculaire', $nomVerna, print_r($nomVerna, true));
                                $this->assertContains('<span class="surlignage">Muguet</span>', $nomVerna['nom_vernaculaire'], print_r($infos, true));
                        }
                }
        }

        private function initialiserDeterminationVernaFormateur($masque = 'Muguet') {
                $parametres = $this->getParametres('determination', $masque);
                $resultats = $this->getResultatsPourMasque($masque);
                $surligneur = $this->getSurligneur();
                $trieur = $this->getTrieur();
                $appsUrls = $this->getAppUrls();
                $images = $this->getImagesService();
                return new DeterminationVernaFormateur($parametres, $resultats, $surligneur, $trieur, $appsUrls, null, $images);
        }
        
        protected function getResultatsPourMasque($masque) {
                $resultatsJson = file_get_contents(dirname(__FILE__).'/../resultats_verna.json');
                $resultats = json_decode($resultatsJson, true);
                return $resultats[$masque];
        }

        private function getImagesService() {
                $retour = Array ( 
                        'bdtfx.51299' => Array ( 
                                '0' => 'http://www.tela-botanica.org/appli:cel-img:000007275CS.jpg', 
                                '1' => 'http://www.tela-botanica.org/appli:cel-img:000007276CS.jpg', 
                                '2' => 'http://www.tela-botanica.org/appli:cel-img:000007277CS.jpg', 
                                '3' => 'http://www.tela-botanica.org/appli:cel-img:000007278CS.jpg',
                                '4' => 'http://www.tela-botanica.org/appli:cel-img:000007279CS.jpg', 
                                '5' => 'http://www.tela-botanica.org/appli:cel-img:000021076CS.jpg' ),
                        'bdtfx.18669' => Array ( 
                                '0' => 'http://www.tela-botanica.org/appli:cel-img:000009085CS.jpg', 
                                '1' => 'http://www.tela-botanica.org/appli:cel-img:000009086CS.jpg', 
                                '2' => 'http://www.tela-botanica.org/appli:cel-img:000018652CS.jpg', 
                                '3' => 'http://www.tela-botanica.org/appli:cel-img:000018757CS.jpg', 
                                '4' => 'http://www.tela-botanica.org/appli:cel-img:000018862CS.jpg', 
                                '5' => 'http://www.tela-botanica.org/appli:cel-img:000018865CS.jpg', 
                                '6' => 'http://www.tela-botanica.org/appli:cel-img:000032690CS.jpg' ), 
                        'bdtfx.29125' => Array ( 
                                '0' => 'http://www.tela-botanica.org/appli:cel-img:000010721CS.jpg', 
                                '1' => 'http://www.tela-botanica.org/appli:cel-img:000010722CS.jpg', 
                                '2' => 'http://www.tela-botanica.org/appli:cel-img:000013077CS.jpg', 
                                '3' => 'http://www.tela-botanica.org/appli:cel-img:000024697CS.jpg', 
                                '4' => 'http://www.tela-botanica.org/appli:cel-img:000024719CS.jpg', 
                                '5' => 'http://www.tela-botanica.org/appli:cel-img:000024729CS.jpg' ), 
                        'bdtfx.7310' => Array ( 
                                '0' => 'http://www.tela-botanica.org/appli:cel-img:000013740CS.jpg', 
                                '1' => 'http://www.tela-botanica.org/appli:cel-img:000013741CS.jpg' ), 
                        'bdtfx.18716' => Array ( 
                                '0' => 'http://www.tela-botanica.org/appli:cel-img:000021069CS.jpg', 
                                '1' => 'http://www.tela-botanica.org/appli:cel-img:000021071CS.jpg', 
                                '2' => 'http://www.tela-botanica.org/appli:cel-img:000033834CS.jpg', 
                                '3' => 'http://www.tela-botanica.org/appli:cel-img:000033835CS.jpg' ), 
                        'bdtfx.51311' => Array ( 
                                '0' => 'http://www.tela-botanica.org/appli:cel-img:000021070CS.jpg', 
                                '1' => 'http://www.tela-botanica.org/appli:cel-img:000021078CS.jpg' ), 
                        'bdtfx.51306' => Array ( 
                                '0' => 'http://www.tela-botanica.org/appli:cel-img:000021072CS.jpg', 
                                '1' => 'http://www.tela-botanica.org/appli:cel-img:000021075CS.jpg', 
                                '2' => 'http://www.tela-botanica.org/appli:cel-img:000021080CS.jpg' ), 
                        'bdtfx.40679' => Array ( 
                                '0' => 'http://www.tela-botanica.org/appli:cel-img:000021073CS.jpg', 
                                '1' => 'http://www.tela-botanica.org/appli:cel-img:000021074CS.jpg', 
                                '2' => 'http://www.tela-botanica.org/appli:cel-img:000021077CS.jpg', 
                                '3' => 'http://www.tela-botanica.org/appli:cel-img:000021079CS.jpg' ), 
                        'bdtfx.60062' => Array ( 
                                '0' => 'http://www.tela-botanica.org/appli:cel-img:000025283CS.jpg', 
                                '1' => 'http://www.tela-botanica.org/appli:cel-img:000025308CS.jpg', 
                                '2' => 'http://www.tela-botanica.org/appli:cel-img:000025309CS.jpg' ) );

                $Images = $this->getMock('Images', array('getUrlsImagesParIdsNoms'), array(), '', false);
                $Images->expects($this->any())
                        ->method('getUrlsImagesParIdsNoms')
                        ->will($this->returnValue($retour));
                return $Images;
        }
}
?>