From f83cd4f88ebc3b306733969b4a6d70842a7aac4b Mon Sep 17 00:00:00 2001
From: gloas <gloas@afi-sa.fr>
Date: Tue, 5 Feb 2019 15:43:55 +0100
Subject: [PATCH] dev #64573 fix reading widget settings + fix html 5 when not
 logged

---
 .../Intonation/Library/Widget/Login/View.php  | 70 ++++++++-----------
 .../Intonation/Library/Widget/Search/View.php | 40 +++++------
 tests/scenarios/Templates/TemplatesTest.php   | 17 +++--
 3 files changed, 63 insertions(+), 64 deletions(-)

diff --git a/library/templates/Intonation/Library/Widget/Login/View.php b/library/templates/Intonation/Library/Widget/Login/View.php
index addbde98dc4..5df8559ab88 100644
--- a/library/templates/Intonation/Library/Widget/Login/View.php
+++ b/library/templates/Intonation/Library/Widget/Login/View.php
@@ -44,15 +44,12 @@ class Intonation_Library_Widget_Login_View extends Zendafi_View_Helper_Accueil_B
 
 
   protected function _getRenderStrategy() {
-    $preferences = $this->_settings->getPreferences();
+    $form_style = $this->_settings->getIntonationFormStyle();
 
-    if(!isset($preferences['IntonationFormStyle']))
-      return new IntonationLoginRenderDefault($this->view, $this->_settings, $this->_user);
-
-    if('inline' == $preferences['IntonationFormStyle'])
+    if('inline' == $form_style)
       return new IntonationLoginRenderInline($this->view, $this->_settings, $this->_user);
 
-    if('toggle' == $preferences['IntonationFormStyle'])
+    if('toggle' == $form_style)
       return new IntonationLoginRenderToggle($this->view, $this->_settings, $this->_user);
 
     return new IntonationLoginRenderDefault($this->view, $this->_settings, $this->_user);
@@ -90,12 +87,15 @@ class IntonationLoginRenderAbstract {
 
 
   protected function _getLoginForm() {
-    $preferences = $this->_settings->getPreferences();
-    $form_options = $this->_settings->getFormOptions();
-    $data = $form_options['data'];
+    $options = [];
 
-    $form = ZendAfi_Form_Login::newWithOptions($form_options);
+    foreach($this->_settings->toArray() as $key => $value)
+      if (is_string($value) || is_int($value))
+        $options [Storm_Inflector::underscorize($key)] = $value;
 
+    $form = ZendAfi_Form_Login::newWithOptions(['data' => $options]);
+    $form->setAction($this->_view->url(['controller' => 'auth',
+                                        'action' => 'login'], null, true));
     $form->removeElement('loginlink');
     $form->removeElement('lostpass');
     $form->removeElement('register');
@@ -107,27 +107,23 @@ class IntonationLoginRenderAbstract {
 
 
   protected function _getLinks() {
-    $preferences = $this->_settings->getPreferences();
-    $form_options = $this->_settings->getFormOptions();
-    $data = $form_options['data'];
-
+    return [];
     $html = [$this->_view->tagAnchor(['controller' => 'auth',
                                       'action' => 'lostpass'],
-                                     $data['lien_mot_de_passe_oublie'],
-                                     ['label' => $data['lien_mot_de_passe_oublie']])];
+                                     $this->_settings->getLienMotDePasseOublie(),
+                                     ['label' => $this->_settings->getLienMotDePasseOublie()])];
 
-    if (Class_AdminVar::isEnregUtilAllowed() && $data['lien_creer_compte'])
+    if (Class_AdminVar::isEnregUtilAllowed() && ($create_account = $this->_settings->getLienCreerCompte()))
       $html [] = $this->_view->tagAnchor(['controller' => 'auth',
                                           'action' => 'register'],
-                                         $data['lien_creer_compte'],
-                                         ['label' => $data['lien_creer_compte']]);
-
+                                         $create_account,
+                                         ['label' => $create_account]);
 
-    if(isset($data['pre_registration']) && $data['pre_registration'])
+    if($pre_registration = $this->_settings->getPreRegistration())
       $html [] = $this->_view->tagAnchor(['controller' => 'auth',
                                           'action' => 'pre-registration'],
-                                         $data['pre_registration'],
-                                         ['label' => $data['pre_registration']]);
+                                         $pre_registration,
+                                         ['label' => $pre_registration]);
 
     return array_filter($html);
   }
@@ -178,18 +174,17 @@ class IntonationLoginRenderDefault extends IntonationLoginRenderAbstract {
 
   public function renderLogged() {
     $user = $this->_user;
-    $preferences = $this->_settings->getPreferences();
 
     $html = [$this->_view->tag('p',
-                               $preferences['message_connecte'] . ' ' . $this->_view->abonne_NamesOrLogin($user))];
+                               $this->_settings->getMessageConnecte() . ' ' . $this->_view->abonne_NamesOrLogin($user))];
 
     $user_url =  $this->_view->url(['controller' => 'abonne',
                                     'action' => 'fiche',
-                                    'id_profil' => $preferences['profil_redirect'] > 0 ? $preferences['profil_redirect'] : Class_Profil::getCurrentProfil()->getId()],
+                                    'id_profil' => $this->_settings->getProfilRedirect() > 0 ? $this->_settings->getProfilRedirect() : Class_Profil::getCurrentProfil()->getId()],
                                    null, true);
 
     $links = [$this->_view->tagAnchor($user_url,
-                                      $preferences['lien_compte'],
+                                      $this->_settings->getLienCompte(),
                                       ['title' => $this->_('Accéder à l\'interface de gestion de %s.', $user->getNomComplet()),
                                        'class' => 'account-link'])];
 
@@ -203,7 +198,7 @@ class IntonationLoginRenderDefault extends IntonationLoginRenderAbstract {
     if($notifications = $this->_view->renderNotifications($user))
       $links = array_merge($links, $notifications);
 
-    $links [] = $this->_view->tag('a', $preferences['lien_deconnection'],
+    $links [] = $this->_view->tag('a', $this->_settings->getLienDeconnection(),
                                   ['title' => $this->_('Se déconnecter de la session %s', $user->getNomComplet()),
                                    'href' => $this->_view->url(['controller'=>'auth',
                                                                 'action'=>'logout'],
@@ -232,11 +227,10 @@ class IntonationLoginRenderDefault extends IntonationLoginRenderAbstract {
 class IntonationLoginRenderInline extends IntonationLoginRenderAbstract {
   public function renderLogged() {
     $user = $this->_user;
-    $preferences = $this->_settings->getPreferences();
 
     $user_url =  $this->_view->url(['controller' => 'abonne',
                                     'action' => 'fiche',
-                                    'id_profil' => $preferences['profil_redirect'] > 0 ? $preferences['profil_redirect'] : Class_Profil::getCurrentProfil()->getId()],
+                                    'id_profil' => $this->_settings->getProfilRedirect() > 0 ? $this->_settings->getProfilRedirect() : Class_Profil::getCurrentProfil()->getId()],
                                    null, true);
 
     $links = [$this->_view->button((new Class_Entity())
@@ -245,7 +239,7 @@ class IntonationLoginRenderInline extends IntonationLoginRenderAbstract {
                                    ->setAttribs(['title' => $this->_('Accéder à l\'interface de gestion de %s.', $user->getNomComplet()),
                                                  'class' => 'btn btn-sm btn-primary'])),
               $this->_view->button((new Class_Entity())
-                                   ->setText($preferences['lien_deconnection'])
+                                   ->setText($this->_settings->getLienDeconnection())
                                    ->setAttribs(['class' => 'btn btn-sm btn-link',
                                                  'title' => $this->_('Se déconnecter de la session %s', $user->getNomComplet())])
                                    ->setUrl($this->_view->url(['controller'=>'auth',
@@ -299,12 +293,11 @@ class IntonationLoginRenderToggle extends IntonationLoginRenderAbstract {
   public function renderLogin() {
     $html = parent::renderLogin();
     $user = $this->_user;
-    $preferences = $this->_settings->getPreferences();
 
-    $id = Storm_Inflector::camelize($preferences['id_module'] . $preferences['titre']);
+    $id = Storm_Inflector::camelize($this->_settings->getIdModule() . $this->_settings->getTitre());
     return $this->_view->tag('div',
                              $this->_view->tag('button',
-                                               $preferences['titre'],
+                                               $this->_settings->getTitre(),
                                                ['id' => $id,
                                                 'data-toggle' => 'dropdown',
                                                 'aria-haspopup' => 'true',
@@ -321,11 +314,10 @@ class IntonationLoginRenderToggle extends IntonationLoginRenderAbstract {
 
   public function renderLogged() {
     $user = $this->_user;
-    $preferences = $this->_settings->getPreferences();
 
     $user_url =  $this->_view->url(['controller' => 'abonne',
                                     'action' => 'fiche',
-                                    'id_profil' => $preferences['profil_redirect'] > 0 ? $preferences['profil_redirect'] : Class_Profil::getCurrentProfil()->getId()],
+                                    'id_profil' => $this->_settings->getProfilRedirect() > 0 ? $this->_settings->getProfilRedirect() : Class_Profil::getCurrentProfil()->getId()],
                                    null, true);
 
     $links = [$this->_view->button((new Class_Entity())
@@ -334,7 +326,7 @@ class IntonationLoginRenderToggle extends IntonationLoginRenderAbstract {
                                    ->setAttribs(['title' => $this->_('Accéder à l\'interface de gestion de %s.', $user->getNomComplet()),
                                                  'class' => 'btn btn-sm btn-primary'])),
               $this->_view->button((new Class_Entity())
-                                   ->setText($preferences['lien_deconnection'])
+                                   ->setText($this->_settings->getLienDeconnection())
                                    ->setAttribs(['class' => 'btn btn-sm btn-link',
                                                  'title' => $this->_('Se déconnecter de la session %s', $user->getNomComplet())])
                                    ->setUrl($this->_view->url(['controller'=>'auth',
@@ -363,11 +355,11 @@ class IntonationLoginRenderToggle extends IntonationLoginRenderAbstract {
                                                $this->_getLinksListAttribs()),
                               ['class' => 'align-self-center']);
 
-    $id = Storm_Inflector::camelize($preferences['id_module'] . $preferences['titre_connecte']);
+    $id = Storm_Inflector::camelize($this->_settings->getIdModule() . $this->_settings->getTitreConnecte());
 
     return $this->_view->tag('div',
                              $this->_view->tag('button',
-                                               $preferences['titre_connecte'],
+                                               $this->_settings->getTitreConnecte(),
                                                ['id' => $id,
                                                 'data-toggle' => 'dropdown',
                                                 'aria-haspopup' => 'true',
diff --git a/library/templates/Intonation/Library/Widget/Search/View.php b/library/templates/Intonation/Library/Widget/Search/View.php
index dc62efd308c..96a28ff443a 100644
--- a/library/templates/Intonation/Library/Widget/Search/View.php
+++ b/library/templates/Intonation/Library/Widget/Search/View.php
@@ -68,7 +68,7 @@ abstract class IntonationSearchRenderAbstract {
     $this->_view = $view;
     $this->_settings = $settings;
     $this->_user = $user;
-    $this->_id = $settings->getid_module();
+    $this->_id = $settings->getIdModule();
   }
 
 
@@ -77,10 +77,10 @@ abstract class IntonationSearchRenderAbstract {
                    'controller' => 'recherche',
                    'action' => 'simple'];
 
-    if ($doc_type = $this->_settings->gettype_doc())
+    if ($doc_type = $this->_settings->getTypeDoc())
       $action_url['facette'] = Class_TypeDoc::CODE_FACETTE . $doc_type;
 
-    if ($profile_id_redirect = $this->_settings->getprofil_redirect())
+    if ($profile_id_redirect = $this->_settings->getProfilRedirect())
       $action_url['id_profil'] = $profile_id_redirect;
 
     $action_url = $this->_view->url($action_url, null, true);
@@ -95,17 +95,17 @@ abstract class IntonationSearchRenderAbstract {
     $form
       ->addElement('hidden',
                    'tri',
-                   ['value' => $this->_settings->gettri()])
+                   ['value' => $this->_settings->getTri()])
 
       ->addElement('search',
                    'expressionRecherche' . $this->_id,
-                   ['label' => $this->_settings->getmessage(),
+                   ['label' => $this->_settings->getMessage(),
                     'class' => 'expressionRecherche',
-                    'placeholder' => $this->_settings->getplaceholder()])
+                    'placeholder' => $this->_settings->getPlaceholder()])
 
       ->addElement('submit',
                    'search_submit',
-                   ['label' => $this->_settings->getsearch_button(),
+                   ['label' => $this->_settings->getSearchButton(),
                     'onclick' => '$(this).parents(\'form\').submit()',
                     'order' => 10]);
 
@@ -127,14 +127,14 @@ abstract class IntonationSearchRenderAbstract {
     $form = new ZendAfi_Form;
     $elements = [];
 
-    if ($this->_settings->getselect_doc())
+    if ($this->_settings->getSelectDoc())
       $elements [] =
         $form->createElement('select',
                              'custom_multifacets_doctype',
                              ['label' => $this->_('Type de document'),
                               'multiOptions' => Class_TypeDoc::getMultiOptionsFacets()]);
 
-    if ($this->_settings->getselect_annexe())
+    if ($this->_settings->getSelectAnnexe())
       $elements [] =
         $form->createElement('select',
                              'custom_multifacets_annexe',
@@ -147,7 +147,7 @@ abstract class IntonationSearchRenderAbstract {
 
 
   protected function _createDomainElement($elements) {
-    if (!$domain_ids = trim($this->_settings->getdomain_ids()))
+    if (!$domain_ids = trim($this->_settings->getDomainIds()))
       return $elements;
 
     if (!$domain_ids = array_filter(explode('-', $domain_ids), 'is_numeric'))
@@ -159,7 +159,7 @@ abstract class IntonationSearchRenderAbstract {
     $form = $this->_getMainForm();
 
     $elements [] = (Class_Systeme_ModulesAccueil_RechercheSimple::DOMAIN_SELECT_SELECT
-        == $this->_settings->getdomain_select_style())
+        == $this->_settings->getDomainSelectStyle())
       ? $form->createElement('select',
                              'custom_multifacets_domains',
                              ['label' => $this->_('Domaine de recherche'),
@@ -178,7 +178,7 @@ abstract class IntonationSearchRenderAbstract {
 
 
   protected function _isAdvancedSearchEnabled() {
-    return in_array($this->_settings->getrecherche_avancee(), ['on', 1, '1'], true);
+    return in_array($this->_settings->getRechercheAvancee(), ['on', 1, '1'], true);
   }
 
 
@@ -240,7 +240,7 @@ class IntonationSearchRenderDefault extends IntonationSearchRenderAbstract {
 
 class IntonationSearchRenderToggle extends IntonationSearchRenderDefault {
   public function render() {
-    return $this->_renderToggle(parent::render(), $this->_settings->getmessage());
+    return $this->_renderToggle(parent::render(), $this->_settings->getMessage());
   }
 }
 
@@ -259,15 +259,13 @@ class IntonationSearchRenderInline extends IntonationSearchRenderAbstract {
       ? $this->_renderAdvancedSearch()
       : '';
 
-    $form = $this
-      ->_getMainForm()
-      ->addElement('custom',
-                   'custom_advanced_search',
-                   ['render' => function() use ($advanced_search,
-                                                $optional_form_elements)
-                     {
-                       $html = implode($optional_form_elements) . $advanced_search;
+    $form = $this->_getMainForm();
 
+    if ($html = implode($optional_form_elements) . $advanced_search)
+      $form->addElement('custom',
+                        'custom_advanced_search',
+                        ['render' => function() use ($html)
+                     {
                        return $this->_renderToggle($html);
                      }]);
 
diff --git a/tests/scenarios/Templates/TemplatesTest.php b/tests/scenarios/Templates/TemplatesTest.php
index a869ebabe91..648e57c92e5 100644
--- a/tests/scenarios/Templates/TemplatesTest.php
+++ b/tests/scenarios/Templates/TemplatesTest.php
@@ -441,7 +441,6 @@ class TemplatesDispatchIntonationTest extends TemplatesIntonationTestCase {
 
 
 
-
 class TemplatesDispatchEditMenuHTest extends TemplatesIntonationTestCase {
 
   public function setUp() {
@@ -953,12 +952,10 @@ class TemplatesEditHistoricTest extends TemplatesEnabledTestCase {
 
 
 
-class TemplatesLoginWidgetTest extends TemplatesIntonationTestCase {
-  protected $_storm_default_to_volatile = false;
+class TemplatesNotLoggedTestDispatchIntonationTest extends TemplatesIntonationTestCase {
 
   public function setUp() {
     parent::setUp();
-
     Class_Profil::find(72)->setAccessLevel(-1)->save();
     ZendAfi_Auth::getInstance()->clearIdentity();
     $this->dispatch('/opac/index/index/id_profil/72', true);
@@ -981,6 +978,18 @@ class TemplatesLoginWidgetTest extends TemplatesIntonationTestCase {
   public function formSubmitShouldBeLastFormElement() {
     $this->assertXPath('//form//div[contains(@class,"form-group")]/following-sibling::input[@type="submit"]');
   }
+
+
+  /** @test */
+  public function pageShouldBeHtml5Valid() {
+    $this->assertHTML5();
+  }
+
+
+  /** @test */
+  public function pageShouldBeAccessible() {
+    $this->assertAccessible($this->_response->getBody());
+  }
 }
 
 
-- 
GitLab