From f1367143eba0a244caecbc58ecc4d63dcf15db60 Mon Sep 17 00:00:00 2001
From: Patrick Barroca <pbarroca@afi-sa.fr>
Date: Wed, 13 Jun 2018 09:19:02 +0200
Subject: [PATCH] dev #75882 fix failures + add tests

---
 library/Class/CodifAuteur.php                 |   4 +
 .../Action/Helper/AbstractListViewMode.php    |   6 +-
 .../Action/Helper/AuthorListViewMode.php      |  20 +++
 .../Helper/CodificationListViewMode.php       |  17 +++
 .../AuthorBrowser/AuthorBrowserTest.php       | 116 ++++++++++++++++++
 .../CodificationBrowserTest.php               |  30 -----
 tests/scenarios/Thesauri/ThesauriTest.php     |   2 +
 7 files changed, 160 insertions(+), 35 deletions(-)
 create mode 100644 tests/scenarios/AuthorBrowser/AuthorBrowserTest.php

diff --git a/library/Class/CodifAuteur.php b/library/Class/CodifAuteur.php
index 751802c3221..4c1d8d187cb 100644
--- a/library/Class/CodifAuteur.php
+++ b/library/Class/CodifAuteur.php
@@ -119,4 +119,8 @@ class Class_CodifAuteur extends Storm_Model_Abstract {
                                           'mots_renvois' => '',
                                           'id_bnf' => '',
                                           'date_creation' => ''];
+
+  public function getCategorie() {
+    return;
+  }
 }
\ No newline at end of file
diff --git a/library/ZendAfi/Controller/Action/Helper/AbstractListViewMode.php b/library/ZendAfi/Controller/Action/Helper/AbstractListViewMode.php
index 55eb4afe4aa..28c8b8a86e8 100644
--- a/library/ZendAfi/Controller/Action/Helper/AbstractListViewMode.php
+++ b/library/ZendAfi/Controller/Action/Helper/AbstractListViewMode.php
@@ -45,10 +45,6 @@ abstract class ZendAfi_Controller_Action_Helper_AbstractListViewMode extends Zen
     if ($this->isSearching())
       return;
 
-    $labelWithCount = function($model, $attrib) {
-      return $this->_renderCategory($model, $attrib);
-    };
-
     $description = (new Class_TableDescription('categories_' . get_class($this->getModel())));
     return $this->_describeCategoriesIn($description)
                 ->addRowAction(function($model)
@@ -199,7 +195,7 @@ abstract class ZendAfi_Controller_Action_Helper_AbstractListViewMode extends Zen
   }
 
 
-  protected function getItems() {
+  public function getItems() {
     return [];
   }
 
diff --git a/library/ZendAfi/Controller/Action/Helper/AuthorListViewMode.php b/library/ZendAfi/Controller/Action/Helper/AuthorListViewMode.php
index ebfe1feb1ab..0c751f4a895 100644
--- a/library/ZendAfi/Controller/Action/Helper/AuthorListViewMode.php
+++ b/library/ZendAfi/Controller/Action/Helper/AuthorListViewMode.php
@@ -21,6 +21,8 @@
 
 
 class ZendAfi_Controller_Action_Helper_AuthorListViewMode extends ZendAfi_Controller_Action_Helper_AbstractListViewMode {
+
+
   public function authorListViewMode($params) {
     $this->_params = $params;
     return $this;
@@ -32,6 +34,24 @@ class ZendAfi_Controller_Action_Helper_AuthorListViewMode extends ZendAfi_Contro
   }
 
 
+  protected function _describeCategoriesIn($description) {
+    return $description;
+  }
+
+
+  protected function _describeItemsIn($description) {
+    return $description
+      ->addColumn($this->_('Nom prénom'), ['attribute' => 'libelle',
+                                          'callback' => function($model, $attrib)
+                                          {
+                                            return $this->_renderItem($model, $attrib);
+                                          }])
+      ->addColumn($this->_('Code facette'), ['attribute' => 'facet_code',
+                                             'sort_attribute' => 'id_auteur'])
+      ->setSorterServer();
+  }
+
+
   public function getBreadcrumb() {
     return [['url' => ['module' => 'admin',
                        'controller' => 'codification-browser',
diff --git a/library/ZendAfi/Controller/Action/Helper/CodificationListViewMode.php b/library/ZendAfi/Controller/Action/Helper/CodificationListViewMode.php
index b92a7a6df55..d70b4010a5d 100644
--- a/library/ZendAfi/Controller/Action/Helper/CodificationListViewMode.php
+++ b/library/ZendAfi/Controller/Action/Helper/CodificationListViewMode.php
@@ -21,6 +21,8 @@
 
 
 class ZendAfi_Controller_Action_Helper_CodificationListViewMode extends ZendAfi_Controller_Action_Helper_AbstractListViewMode {
+
+
   public function codificationListViewMode($params) {
     $this->_params = $params;
     return $this;
@@ -32,6 +34,21 @@ class ZendAfi_Controller_Action_Helper_CodificationListViewMode extends ZendAfi_
   }
 
 
+  protected function _describeCategoriesIn($description) {
+    return $description
+      ->addColumn($this->_('Codification'), ['attribute' => 'libelle',
+                                             'callback' => function($model, $attrib)
+                                             {
+                                               return $this->_renderCategory($model, $attrib);
+                                             }]);
+  }
+
+
+  protected function _describeItemsIn($description) {
+    return $description;
+  }
+
+
   public function getBreadcrumb() {
     return [['url' => ['module' => 'admin',
                       'controller' => 'codification-browser',
diff --git a/tests/scenarios/AuthorBrowser/AuthorBrowserTest.php b/tests/scenarios/AuthorBrowser/AuthorBrowserTest.php
new file mode 100644
index 00000000000..b3c689b5daa
--- /dev/null
+++ b/tests/scenarios/AuthorBrowser/AuthorBrowserTest.php
@@ -0,0 +1,116 @@
+<?php
+/**
+ * Copyright (c) 2012-2017, Agence Française Informatique (AFI). All rights reserved.
+ *
+ * BOKEH is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU AFFERO GENERAL PUBLIC LICENSE as published by
+ * the Free Software Foundation.
+ *
+ * There are special exceptions to the terms and conditions of the AGPL as it
+ * is applied to this software (see README file).
+ *
+ * BOKEH is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU AFFERO GENERAL PUBLIC LICENSE for more details.
+ *
+ * You should have received a copy of the GNU AFFERO GENERAL PUBLIC LICENSE
+ * along with BOKEH; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301  USA
+ */
+
+
+abstract class AuthorBrowserTestCase extends Admin_AbstractControllerTestCase {
+  protected
+    $_storm_default_to_volatile = true,
+    $_erroc;
+
+
+  public function setUp() {
+    parent::setUp();
+
+    $this->_erroc = $this->fixture('Class_CodifAuteur',
+                                   ['id' => 15,
+                                    'libelle' => 'Erroc']);
+  }
+}
+
+
+
+
+class AuthorBrowserIndexDispatchTest extends AuthorBrowserTestCase {
+
+  public function setUp() {
+    parent::setUp();
+    $this->dispatch('/admin/author-browser', true);
+  }
+
+
+  /** @test */
+  public function linkToCodificationBrowserShouldBePresent() {
+    $this->assertXPathContentContains('//a[@href="/admin/codification-browser"]', 'Racine');
+  }
+
+
+  /** @test */
+  public function linkToSearchWithFacetA15ShouldBePresent() {
+    $this->assertXPath('//td//a[contains(@href, "/recherche/simple/facette/A15")]');
+  }
+}
+
+
+
+
+class AuthorBrowserSearchTest extends AuthorBrowserTestCase {
+  public function setUp() {
+    parent::setUp();
+    $_SERVER['HTTP_REFERER'] = 'http://test.org/admin/author-browser/index';
+  }
+
+
+  /** @test */
+  public function searchShouldRedirect() {
+    $this->postDispatch('/admin/author-browser/index',
+                        ['title_search' => 'Erroc']);
+    $this->assertRedirectTo('/admin/author-browser/index/title_search/Erroc/page/1/order/libelle');
+  }
+
+
+  /** @test */
+  public function redirectedShouldDisplayResult() {
+    $this->onLoaderOfModel('Class_CodifAuteur')
+
+         ->whenCalled('findAllBy')
+         ->with(['where' => "(libelle like '%Erroc%') or (id_auteur like '%Erroc%')",
+                 'order' => "libelle",
+                 'limitPage' => ["1", 25]])
+         ->answers([$this->_erroc])
+
+         ->whenCalled('countBy')
+         ->with(['where' => "(libelle like '%Erroc%') or (id_auteur like '%Erroc%')",
+                 'order' => "libelle"])
+         ->answers(1)
+
+         ->beStrict();
+
+    $this->dispatch('/admin/author-browser/index/title_search/Erroc/page/1/order/libelle', true);
+    $this->assertXpathContentContains('//table', 'Erroc');
+  }
+}
+
+
+
+
+class AuthorBrowserIndexOrderTest extends AuthorBrowserTestCase {
+
+  public function setUp() {
+    parent::setUp();
+    $this->dispatch('/admin/author-browser/index/order/id_auteur', true);
+  }
+
+
+  /** @test */
+  public function codeFacetOrderLinkShouldDesc() {
+    $this->assertXpathContentContains('//table//a[contains(@href, "order/id_auteur+desc")]', 'Code facette');
+  }
+}
\ No newline at end of file
diff --git a/tests/scenarios/CodificationBrowser/CodificationBrowserTest.php b/tests/scenarios/CodificationBrowser/CodificationBrowserTest.php
index bb4d588376e..9210835c9e8 100644
--- a/tests/scenarios/CodificationBrowser/CodificationBrowserTest.php
+++ b/tests/scenarios/CodificationBrowser/CodificationBrowserTest.php
@@ -47,34 +47,4 @@ class CodificationBrowserIndexDispatchTest extends Admin_AbstractControllerTestC
   public function authorsShouldBeInTable() {
     $this->assertXPathContentContains('//td//a[@href="/admin/author-browser"]', 'Auteurs');
   }
-}
-
-
-
-
-class CodificationBrowserAuthorIndexDispatchTest extends Admin_AbstractControllerTestCase {
-  protected $_storm_default_to_volatile = true;
-
-
-  public function setUp() {
-    parent::setUp();
-
-    $this->fixture('Class_CodifAuteur',
-                   ['id' => 15,
-                    'libelle' => 'Erroc']);
-
-    $this->dispatch('/admin/author-browser', true);
-  }
-
-
-  /** @test */
-  public function linkToCodificationBrowserShouldBePresent() {
-    $this->assertXPathContentContains('//a[@href="/admin/codification-browser"]', 'Racine');
-  }
-
-
-  /** @test */
-  public function linkToSearchWithFacetA15ShouldBePresent() {
-    $this->assertXPath('//td//a[contains(@href, "/recherche/simple/facette/A15")]');
-  }
 }
\ No newline at end of file
diff --git a/tests/scenarios/Thesauri/ThesauriTest.php b/tests/scenarios/Thesauri/ThesauriTest.php
index 194b5d0da79..79c5ec20a37 100644
--- a/tests/scenarios/Thesauri/ThesauriTest.php
+++ b/tests/scenarios/Thesauri/ThesauriTest.php
@@ -140,6 +140,8 @@ class ThesauriIndexChildrenTest extends ThesauriTestCase {
 }
 
 
+
+
 class ThesauriIndexChildrenSearchTest extends ThesauriTestCase {
   public function setUp() {
     parent::setUp();
-- 
GitLab