From b6fae8b71d8dc662db6004e1c527af1233c36cf0 Mon Sep 17 00:00:00 2001
From: Henri-Damien LAURENT <hdlaurent@afi-sa.fr>
Date: Wed, 31 Aug 2022 22:51:57 +0200
Subject: [PATCH] hotline#160288 : ensure tests

---
 VERSIONS_HOTLINE/160288                       |  1 +
 .../Controller/Plugin/Manager/Article.php     |  3 +-
 .../Plugin/ResourceDefinition/Article.php     |  1 -
 .../admin/controllers/CmsControllerTest.php   | 98 +++++++++++++++++++
 4 files changed, 101 insertions(+), 2 deletions(-)
 create mode 100644 VERSIONS_HOTLINE/160288

diff --git a/VERSIONS_HOTLINE/160288 b/VERSIONS_HOTLINE/160288
new file mode 100644
index 00000000000..931913a3ed2
--- /dev/null
+++ b/VERSIONS_HOTLINE/160288
@@ -0,0 +1 @@
+ - correctif #160288 : Articles : La modification par lot des articles procède à leur indexation.
\ No newline at end of file
diff --git a/library/ZendAfi/Controller/Plugin/Manager/Article.php b/library/ZendAfi/Controller/Plugin/Manager/Article.php
index 2d771c9fbf7..04cc55b5568 100644
--- a/library/ZendAfi/Controller/Plugin/Manager/Article.php
+++ b/library/ZendAfi/Controller/Plugin/Manager/Article.php
@@ -164,11 +164,12 @@ class ZendAfi_Controller_Plugin_Manager_Article extends ZendAfi_Controller_Plugi
       $this->updateConfigBoiteNews($id_module,$article);
     $this->_notifyArticleChanged($article);
 
+    $article->index();
+
     $this->withOtherPluginsDo(function($plugin) use($article)
                               {
                                 $plugin->notifyAfterSave($article);
                               });
-
     return $this;
   }
 
diff --git a/library/ZendAfi/Controller/Plugin/ResourceDefinition/Article.php b/library/ZendAfi/Controller/Plugin/ResourceDefinition/Article.php
index 15b6874f120..f8c5f0bb88f 100644
--- a/library/ZendAfi/Controller/Plugin/ResourceDefinition/Article.php
+++ b/library/ZendAfi/Controller/Plugin/ResourceDefinition/Article.php
@@ -34,7 +34,6 @@ class ZendAfi_Controller_Plugin_ResourceDefinition_Article
                            'successful_delete' => $this->_('Article "%s" supprimé')],
 
             'actions' => ['add' => ['title' => $this->_("Ajouter un article")]],
-            'after_edit' => function ($model) { $model->index(); }
     ];
   }
 
diff --git a/tests/application/modules/admin/controllers/CmsControllerTest.php b/tests/application/modules/admin/controllers/CmsControllerTest.php
index 219782a6377..4e906c3f0b0 100644
--- a/tests/application/modules/admin/controllers/CmsControllerTest.php
+++ b/tests/application/modules/admin/controllers/CmsControllerTest.php
@@ -125,6 +125,9 @@ abstract class CmsControllerTestCase extends Admin_AbstractControllerTestCase {
                                               'libelle' => 'Histoire',
                                               'sous_domaines' => [$this->domaine_art]]);
 
+    $this->domaine_musique = $this->fixture('Class_Catalogue',
+                                            ['id' => 12, 'libelle' => 'Musique']);
+
     $domaine_a_la_une = $this->fixture('Class_Catalogue',
                                        ['id' => 66, 'libelle' => 'A la Une']);
     $this->fixture('Class_Catalogue',
@@ -3179,3 +3182,98 @@ class CmsControllerEditArticleWithQueryTest extends CmsControllertestCase {
     $this->assertXPath('//form[@action="/admin/cms/edit/id/4"]');
   }
 }
+
+
+
+class CmsControllerEditArticleUnindexTest extends CmsControllertestCase {
+
+  public function setup() {
+    parent::setup();
+    Class_Article::find(4)
+      ->setVisible(true)
+      ->setDebut('')
+      ->setFin('')
+      ->setIndexation(1)
+      ->setStatus(Class_Article::STATUS_VALIDATED)
+      ->save();
+    Class_Article::find(4)
+      ->index();
+
+    $this->_admin_bib->beAdminPortail()->save();
+
+    $datas = [
+              'titre' => 'Erik Truffaz - Ladyland quartet en concert',
+              'debut' => '',
+              'fin' => '',
+              'events_debut' => '',
+              'events_fin' => '',
+              'auteur' => Class_Users::newInstanceWithId(1, ['login' => 'tom']),
+              'id_cat' => 34,
+              'indexation' => '',
+              'contenu' => 'Ici: <img src="../../images/bonlieu.jpg" />',
+              'description' => 'Affiche: <img src="http://localhost' . BASE_URL . '/images/concert.jpg" />',
+              'status' => Class_Article::STATUS_VALIDATED,
+    ];
+
+    $this->postDispatch('/admin/cms/edit/id_bib/0/id/4/id_cat/34',
+                        $datas);
+  }
+
+
+  /** @test */
+  public function NoticesShouldBeEmpty() {
+    $this->assertEmpty(Class_Notice::findAllBy([]));
+  }
+}
+
+
+
+
+class CmsControllerEditMultipleArticleUnindexTest extends CmsControllertestCase {
+
+  public function setup() {
+    parent::setup();
+    Class_Article::find(4)
+      ->setVisible(true)
+      ->setDebut('')
+      ->setFin('')
+      ->setIndexation(1)
+      ->setStatus(Class_Article::STATUS_VALIDATED)
+      ->save();
+    Class_Article::find(4)
+      ->index();
+    Zend_Registry::get('session')->selected_items = ['article' => [4]];
+
+
+    $this->_admin_bib->beAdminPortail()->save();
+
+    $datas = [
+              'titre' => 'Erik Truffaz - Ladyland quartet en concert',
+              'debut' => '',
+              'fin' => '',
+              'events_debut' => '',
+              'events_fin' => '',
+              'auteur' => Class_Users::newInstanceWithId(1, ['login' => 'tom']),
+              'id_cat' => 34,
+              'indexation' => '',
+              'contenu' => 'Ici: <img src="../../images/bonlieu.jpg" />',
+              'description' => 'Affiche: <img src="http://localhost' . BASE_URL . '/images/concert.jpg" />',
+              'status' => Class_Article::STATUS_VALIDATED,
+    ];
+
+    $this->postDispatch('/admin/cms/edit-multiple',
+                        $datas);
+  }
+
+
+  public function tearDown() {
+    Zend_Registry::get('session')->selected_items = [];
+    parent::tearDown();
+  }
+
+
+  /** @test */
+  public function NoticesShouldBeEmpty() {
+    $this->assertEmpty(Class_Notice::findAllBy([]));
+  }
+}
-- 
GitLab