diff --git a/VERSIONS_HOTLINE/33429 b/VERSIONS_HOTLINE/33429 new file mode 100644 index 0000000000000000000000000000000000000000..0882c326044cb1614e64598e7a14dc65ac0b4dbd --- /dev/null +++ b/VERSIONS_HOTLINE/33429 @@ -0,0 +1 @@ + - ticket #33429 : Cosmogramme : correction de la génération de vignettes des pseudo-notices dans le contexte de l'intégration automatique \ No newline at end of file diff --git a/library/Class/Profil.php b/library/Class/Profil.php index 2d5d9a3853e85bf212f1e97ae497a7324af43d8b..8495ddf1c0d53b7e2361ffa71fdcda4923b10e59 100644 --- a/library/Class/Profil.php +++ b/library/Class/Profil.php @@ -137,12 +137,14 @@ class Class_Profil extends Storm_Model_Abstract { * @return Class_Profil */ public static function getCurrentProfil() { - if (!isset(self::$_current_profil)) { - if (!$id_profil = Zend_Registry::get('session')->id_profil) - $id_profil = 1; - self::$_current_profil = self::getLoader()->find($id_profil); - } - return self::$_current_profil; + if (isset(self::$_current_profil)) + return self::$_current_profil; + + if (!Zend_Registry::isRegistered('session') + || (!$id_profil = Zend_Registry::get('session')->id_profil)) + $id_profil = 1; + + return self::$_current_profil = self::getLoader()->find($id_profil); } diff --git a/tests/library/Class/ProfilTest.php b/tests/library/Class/ProfilTest.php index 4e4f13d2f671dbc7aa1ab1512dc21a722b97c64f..4e90e0d108410b19dd2f8f1573bbe276202c9082 100644 --- a/tests/library/Class/ProfilTest.php +++ b/tests/library/Class/ProfilTest.php @@ -20,6 +20,8 @@ */ class ProfilVideTest extends ModelTestCase { + protected $_storm_default_to_volatile = true; + public function setUp() { parent::setup(); $this->profil_vide = new Class_Profil(); @@ -58,7 +60,7 @@ class ProfilVideTest extends ModelTestCase { public function profilZonesTitreShouldReturn200_E_H_I() { $this->assertEquals( ['200$e', '200$h', '200$i'], - Class_Profil::getCurrentProfil()->getZonesTitre()); + $this->profil_vide->getZonesTitre()); } @@ -71,6 +73,8 @@ class ProfilVideTest extends ModelTestCase { class ProfilJeunesseAstrolabeTest extends ModelTestCase { + protected $_storm_default_to_volatile = true; + public function setUp() { $this->fixture('Class_AdminVar', ['clef' => 'NOM_DOMAINE', 'id' => 'NOM_DOMAINE', @@ -81,77 +85,65 @@ class ProfilJeunesseAstrolabeTest extends ModelTestCase { 'preferences' => []]], 'options' => []]; - $this->profil_astro = Class_Profil::getLoader() - ->newInstanceWithId(7) - ->setIdSite(12) - ->setLibelle("Jeunesse") - ->setSkin('astrolabe') - ->setCfgMenus(array()) - ->setHeaderCss('afi-opac3/userfiles/jeunesse.css') - ->setCfgAccueil($cfg_accueil); + $this->profil_astro = $this->fixture('Class_Profil', + ['id' => 7, + 'id_site' => 12, + 'libelle' => 'Jeunesse', + 'skin' => 'astrolabe', + 'cfg_menus' => [], + 'header_css' => 'afi-opac3/userfiles/jeunesse.css', + 'cfg_accueil' => $cfg_accueil]); - $this->bib_melun = Class_Bib::getLoader() - ->newInstanceWithId(12) - ->setLibelle('Melun'); + $this->bib_melun = $this->fixture('Class_Bib', + ['id' => 12, + 'libelle' => 'Melun']); + $this->onLoaderOfModel('Class_Profil') + ->whenCalled('findAllBy') + ->answers([]); - Storm_Test_ObjectWrapper - ::onLoaderOfModel('Class_Profil') - ->whenCalled('findAllBy') - ->answers(array()); - - Class_Profil::setFileWriter(Storm_Test_ObjectWrapper::mock()->whenCalled('fileExists')->answers(true)); + Class_Profil::setFileWriter($this->mock()->whenCalled('fileExists')->answers(true)); } /** @test */ public function profilUrlShouldReturnBokehDotOrg() { - $this->assertEquals('http://bokeh.org/index/index?id_profil=7', Class_Profil::find(7)->getUrl()); + $this->assertEquals('http://bokeh.org/index/index?id_profil=7', + Class_Profil::find(7)->getUrl()); } /** @test */ public function getCfgMenuAsArrayShouldReturnDefaultMenus() { - $this->assertEquals(array( - 'H' => array( - "libelle" => "Menu horizontal", - "picto" => "vide.gif", - 'menus' => array()), - 'V' => array( - "libelle" => "Menu vertical", - "picto" => "vide.gif", - 'menus' => array())), + $this->assertEquals(['H' => ["libelle" => "Menu horizontal", + "picto" => "vide.gif", + 'menus' => []], + 'V' => ["libelle" => "Menu vertical", + "picto" => "vide.gif", + 'menus' => []]], $this->profil_astro->getCfgMenusAsArray()); } /** @test */ public function shouldAddMenuHorizontalIfNotExists() { - $this->profil_astro->setCfgMenus( array( - 'V' => array( - "libelle" => "Les news", - "picto" => "home.gif", - "menus" => array()), - - '4' => array( - "libelle" => "Mon menu", - "picto" => "home.png", - "menus" => array()))); - - $this->assertEquals(array( - 'H' => array( - "libelle" => "Menu horizontal", - "picto" => "vide.gif", - "menus" => array()), - 'V' => array( - "libelle" => "Les news", - "picto" => "home.gif", - "menus" => array()), - - '4' => array( - "libelle" => "Mon menu", - "picto" => "home.png", - "menus" => array())), + $this->profil_astro + ->setCfgMenus(['V' => ["libelle" => "Les news", + "picto" => "home.gif", + "menus" => []], + '4' => ["libelle" => "Mon menu", + "picto" => "home.png", + "menus" => []]]); + + $this->assertEquals(['H' => ["libelle" => "Menu horizontal", + "picto" => "vide.gif", + "menus" => []], + 'V' => ["libelle" => "Les news", + "picto" => "home.gif", + "menus" => []], + '4' => ["libelle" => "Mon menu", + "picto" => "home.png", + "menus" => []]], $this->profil_astro->getCfgMenusAsArray()); } @@ -165,7 +157,8 @@ class ProfilJeunesseAstrolabeTest extends ModelTestCase { /** @test */ public function astroHeaderCssShouldBeJeunesse() { - $this->assertEquals('afi-opac3/userfiles/jeunesse.css', $this->profil_astro->getHeaderCss()); + $this->assertEquals('afi-opac3/userfiles/jeunesse.css', + $this->profil_astro->getHeaderCss()); } @@ -232,7 +225,7 @@ class ProfilJeunesseAstrolabeTest extends ModelTestCase { /** @test */ public function toArrayShouldContainsTitreSiteMediathequeAstrolabe() { $attributes = $this->profil_astro->toArray(); - $this->assertEquals("", $attributes['titre_site']); + $this->assertEquals('', $attributes['titre_site']); } @@ -280,7 +273,7 @@ class ProfilJeunesseAstrolabeTest extends ModelTestCase { /** @test */ public function updateAttributesWithBoiteLoginTrueShouldAddIt() { - $this->profil_astro->updateAttributes(array('boite_login_in_banniere' => true)); + $this->profil_astro->updateAttributes(['boite_login_in_banniere' => true]); $this->assertTrue($this->profil_astro->getBoiteLoginInBanniere()); } @@ -293,19 +286,14 @@ class ProfilJeunesseAstrolabeTest extends ModelTestCase { /** @test */ public function getSubProfilsShouldReturnEmptyArray() { - $this->assertEquals(array(), - $this->profil_astro->getSubProfils()); - return Class_Profil::getLoader(); - + $this->assertEquals([], $this->profil_astro->getSubProfils()); } - /** - * @depends getSubProfilsShouldReturnEmptyArray - * @test - */ - public function profilLoaderShouldHaveFindAllByCalledWithParentIdOfAstrolabe($loader) { - $param = $loader->getFirstAttributeForLastCallOn('findAllBy'); + /** @test */ + public function profilLoaderShouldHaveFindAllByCalledWithParentIdOfAstrolabe() { + $this->profil_astro->getSubProfils(); + $param = Class_Profil::getFirstAttributeForLastCallOn('findAllBy'); $this->assertEquals('parent_profil', $param['role']); $this->assertEquals($this->profil_astro->toArray(), @@ -323,7 +311,8 @@ class ProfilJeunesseAstrolabeTest extends ModelTestCase { -class PageBdAstrolabeTest extends Storm_Test_ModelTestCase { +class PageBdAstrolabeTest extends ModelTestCase { + protected $_storm_default_to_volatile = true; protected $page_bd; protected $profil_astro; protected $bib_melun; @@ -340,38 +329,33 @@ class PageBdAstrolabeTest extends Storm_Test_ModelTestCase { 'preferences' => ['titre'=>'Connection']]], 'options' => []]; - $this->profil_astro = Class_Profil::getLoader() - ->newInstanceWithId(7) - ->setIdSite(12) - ->setLibelle("Jeunesse") - ->setSkin('astrolabe') - ->setCfgMenus(array()) - ->setHeaderCss('afi-opac3/userfiles/jeunesse.css') - ->setCfgAccueil($cfg_accueil); - - $this->bib_melun = Class_Bib::getLoader() - ->newInstanceWithId(12) - ->setLibelle('Melun'); - - Storm_Test_ObjectWrapper - ::onLoaderOfModel('Class_Profil') - ->whenCalled('findAllBy') - ->answers(array()); - - Class_Profil::setFileWriter( - Storm_Test_ObjectWrapper::mock() - ->whenCalled('fileExists') - ->answers(true)); - - $this->page_bd = Class_Profil::getLoader() - ->newInstanceWithId(6, - ['parent_id' => $this->profil_astro->getId(), - 'id_site' => 12, - 'libelle' => 'Bdd', - 'cfg_menus' => [], - 'cfg_accueil' => [], - 'page_css' => 'afi-opac3/userfiles/bd_jeunesse.css']); - + $this->profil_astro = $this->fixture('Class_Profil', + ['id' => 7, + 'id_site' => 12, + 'libelle' => 'Jeunesse', + 'skin' => 'astrolabe', + 'cfg_menus' => [], + 'header_css' => 'afi-opac3/userfiles/jeunesse.css', + 'cfg_accueil' => $cfg_accueil]); + + $this->bib_melun = $this->fixture('Class_Bib', + ['id' => 12, + 'libelle' => 'Melun']); + + $this->onLoaderOfModel('Class_Profil') + ->whenCalled('findAllBy') + ->answers([]); + + Class_Profil::setFileWriter($this->mock()->whenCalled('fileExists')->answers(true)); + + $this->page_bd = $this->fixture('Class_Profil', + ['id' => 6, + 'parent_id' => $this->profil_astro->getId(), + 'id_site' => 12, + 'libelle' => 'Bdd', + 'cfg_menus' => [], + 'cfg_accueil' => [], + 'page_css' => 'afi-opac3/userfiles/bd_jeunesse.css',]); $this->profil_astro->setSubProfils([$this->page_bd]); } @@ -1601,8 +1585,4 @@ class ProfilIsPortalTest extends Storm_Test_ModelTestCase { public function profilWithIdSevenStringShouldNotBePortal() { $this->assertFalse($this->fixture('Class_Profil', ['id' => '7'])->isPortail()); } - -} - - -?> \ No newline at end of file +} \ No newline at end of file