From d9665c23b6eb6bd2f259279f123844da09b0b4bf Mon Sep 17 00:00:00 2001 From: Laurent Laffont <llaffont@afi-sa.fr> Date: Fri, 13 Nov 2020 17:03:29 +0100 Subject: [PATCH] hotline #121599 Templates : menus should not cache content as there's widgets inside --- VERSIONS_HOTLINE/121599 | 1 + .../Intonation/Library/Widget/Nav/View.php | 4 ++ .../Templates/TemplatesWidgetInMenusTest.php | 46 ++++++++++++++++++- 3 files changed, 50 insertions(+), 1 deletion(-) create mode 100644 VERSIONS_HOTLINE/121599 diff --git a/VERSIONS_HOTLINE/121599 b/VERSIONS_HOTLINE/121599 new file mode 100644 index 00000000000..3136bb976ca --- /dev/null +++ b/VERSIONS_HOTLINE/121599 @@ -0,0 +1 @@ + - ticket #121599 : Magasin de thèmes : correction de la boîte de connexion dans un menu qui affiche parfois le nom d'un usager autre que celui qui se connecte \ No newline at end of file diff --git a/library/templates/Intonation/Library/Widget/Nav/View.php b/library/templates/Intonation/Library/Widget/Nav/View.php index f2b1b21cf16..51ef44d806d 100644 --- a/library/templates/Intonation/Library/Widget/Nav/View.php +++ b/library/templates/Intonation/Library/Widget/Nav/View.php @@ -28,6 +28,10 @@ class Intonation_Library_Widget_Nav_View extends Zendafi_View_Helper_Accueil_Bas $_menu_id, $_menu; + public function shouldCacheContent() { + return false; + } + public function getHtml() { $this->titre = $this->_settings->getTitre(); diff --git a/tests/scenarios/Templates/TemplatesWidgetInMenusTest.php b/tests/scenarios/Templates/TemplatesWidgetInMenusTest.php index 9e4912143bb..5668977f960 100644 --- a/tests/scenarios/Templates/TemplatesWidgetInMenusTest.php +++ b/tests/scenarios/Templates/TemplatesWidgetInMenusTest.php @@ -48,7 +48,7 @@ class TemplatesWidgetInMenusNewsletterLoggedOutTest extends TemplatesIntonationT -class TemplatesWidgetLoginInMenuAndInHeaderTestCase extends Admin_AbstractControllerTestCase { +class TemplatesWidgetLoginInMenuAndInHeaderTest extends Admin_AbstractControllerTestCase { protected $_storm_default_to_volatile = true; @@ -56,6 +56,15 @@ class TemplatesWidgetLoginInMenuAndInHeaderTestCase extends Admin_AbstractContro parent::setUp(); Class_AdminVar::set('FEATURES_TRACKING_ENABLE', 0); Class_AdminVar::set('MENU_BOITE', 1); + Class_AdminVar::set('CACHE_ACTIF', 1); + + Storm_Cache::beVolatile(); + + Class_Users::getIdentity() + ->setNom('Tor') + ->setPrenom('Termina') + ->setPassword('2000') + ->assertSave(); $this->_buildTemplateProfil(['id' => 1, 'libelle' => 'My page']) @@ -123,4 +132,39 @@ class TemplatesWidgetLoginInMenuAndInHeaderTestCase extends Admin_AbstractContro public function pageShouldContainsLinkToEditWidgetTwoInDivisionFour() { $this->assertXPath('//header[@data-division="4"]//div[@id="boite_2"]//a[contains(@href, "/admin/widget/edit-widget/id/2/id_profil/1")]'); } + + + /** @test */ + public function loginWidgetInMenuShouldContainsUserFirstNameTermina() { + $this->assertXPathContentContains('//header[@data-division="4"]//div[contains(@class, "navbar")]//div[@id="boite_8-0"]//span[contains(@class, "user_first_name")]', + 'Termina'); + } + + + /** @test */ + public function loginWidgetInMenuShouldNotBeCachedAndContainsPredatorWhenLogged() { + $this->dispatch('/opac/index/index/id_profil/1'); + /* + * OK, there's some wrong stuff here + * put a breakpoint in Intonation_Library_Widget_Nav_View::shoulCacheContent + * inspect $this->_preferences and you will see objects !! deeped into this variable + * So I need to double dispatch in order to reproduce the real problem, it's sad ... + * @see http://forge.afi-sa.fr/issues/121599 + * + */ + $this->_response->setBody(''); + + ZendAfi_Auth::getInstance() + ->logUser(Class_Users::newInstanceWithId(5, + ['login' => 'Predator', + 'nom' => 'Tor', + 'prenom' => 'Preda', + 'password' => '2000'])); + + $this->dispatch('/opac/index/index/id_profil/1'); + $this->assertXPathContentContains('//header[@data-division="4"]//div[contains(@class, "navbar")]//div[@id="boite_8-0"]//span[contains(@class, "user_first_name")]', + 'Preda'); + } + + } -- GitLab