From 8dcc9517482b48741a10cc1c9807e1af566de96c Mon Sep 17 00:00:00 2001
From: Laurent Laffont <llaffont@afi-sa.fr>
Date: Tue, 11 Dec 2018 14:37:39 +0100
Subject: [PATCH] dev #81899 search author by name

---
 FEATURES/81899                                | 12 ++---
 .../opac/controllers/AuthorController.php     | 17 ++++++-
 tests/scenarios/AuthorPage/AuthorPageTest.php | 48 +++++++++++++++----
 3 files changed, 61 insertions(+), 16 deletions(-)

diff --git a/FEATURES/81899 b/FEATURES/81899
index 59c32a9d080..3c01eba3219 100644
--- a/FEATURES/81899
+++ b/FEATURES/81899
@@ -1,10 +1,10 @@
         '81899' =>
-            ['Label' => $this->_('[Pairing] Fiche auteur'),
-             'Desc' => '',
-             'Image' => '',
+            ['Label' => $this->_('Fiche auteur'),
+             'Desc' => $this->_('La fiche auteur permet de mettre en avant différents axes de découverte du fonds à partir d'un auteur'),
+             'Image' => 'http://wiki.bokeh-library-portal.org/images/thumb/f/f4/Author_page.png/502px-Author_page.png',
              'Video' => '',
-             'Category' => '',
+             'Category' => $this->_('Recherche'),
              'Right' => function($feature_description, $user) {return true;},
-             'Wiki' => '',
-             'Test' => '',
+             'Wiki' => 'http://wiki.bokeh-library-portal.org/index.php?title=Fiche_auteur',
+             'Test' => '/author/view/named/molière',
              'Date' => '2018-11-19'],
\ No newline at end of file
diff --git a/application/modules/opac/controllers/AuthorController.php b/application/modules/opac/controllers/AuthorController.php
index 7018b473f87..365314c53f9 100644
--- a/application/modules/opac/controllers/AuthorController.php
+++ b/application/modules/opac/controllers/AuthorController.php
@@ -20,12 +20,14 @@
  */
 
 class AuthorController extends ZendAfi_Controller_Action {
-    public function viewAction() {
+  public function viewAction() {
     Class_ScriptLoader::getInstance()
       ->addOPACScript('author_sheet.js')
       ->addJQueryReady('$("div.author").authorSheet()');
 
-    $author = Class_CodifAuteur::find($this->_getParam('id'));
+    if (!$author = $this->_findAuthor())
+      throw new Zend_Controller_Action_Exception($this->view->_('Désolé, cette page n\'existe pas'), 404);
+
     $search_result = $this->_findRecordsForAuthor($author);
     $all_records = $this->_sortRecordsFrom($search_result,
                                            $author->getFacetCode());
@@ -41,6 +43,17 @@ class AuthorController extends ZendAfi_Controller_Action {
   }
 
 
+  protected function _findAuthor() {
+    if ($id = (int)$this->_getParam('id'))
+      return Class_CodifAuteur::find($id);
+
+    if ($name = $this->_getParam('named'))
+      return Class_CodifAuteur::findWithFullName($name);
+
+    return null;
+  }
+
+
   protected function  _findRecordsForAuthor($author) {
     $author_code = $author->getFacetCode();
 
diff --git a/tests/scenarios/AuthorPage/AuthorPageTest.php b/tests/scenarios/AuthorPage/AuthorPageTest.php
index 0c982d364fe..d40f9ef8b1b 100644
--- a/tests/scenarios/AuthorPage/AuthorPageTest.php
+++ b/tests/scenarios/AuthorPage/AuthorPageTest.php
@@ -77,16 +77,8 @@ abstract class AuthorPageTestCase extends AbstractControllerTestCase {
                                       [9, 'A2408 M6'],
                                       [10, 'A2408 A3']]);
     Zend_Registry::set('sql', $this->mock_sql);
-  }
-}
-
-
 
 
-class AuthorPageViewTest extends AuthorPageTestCase {
-  public function setUp() {
-    parent::setUp();
-
     Class_CosmoVar::newInstanceWithId('url_services')->setValeur('http://cache.org');
     Class_WebService_AllServices::setHttpClient($http_client = $this->mock());
 
@@ -102,9 +94,16 @@ class AuthorPageViewTest extends AuthorPageTestCase {
                              'vignette' => 'http://images.fr/hugo_thumb.jpg',
                              'image' => 'http://images.fr/hugo_big.jpg']))
       ->beStrict();
+  }
+}
+
 
 
 
+class AuthorPageViewByIdTest extends AuthorPageTestCase {
+  public function setUp() {
+    parent::setUp();
+
     $this->dispatch('/author/view/id/2408');
   }
 
@@ -220,6 +219,39 @@ class AuthorPageViewTest extends AuthorPageTestCase {
 
 
 
+class AuthorPageViewByNameTest extends AuthorPageTestCase {
+  /** @test */
+  public function searchVictorHugoShouldShowVictorHugo() {
+    Storm_Test_ObjectWrapper::onLoaderOfModel('Class_CodifAuteur')
+      ->whenCalled('findWithFullName')
+      ->with('Victor Hugo')
+      ->answers(Class_CodifAuteur::find(2408));
+
+    $this->dispatch('/author/view/named/Victor+Hugo');
+
+    $this->assertXPathContentContains('//h1', 'Victor Hugo', $this->_response->getBody());
+  }
+
+
+  /** @test */
+  public function searchUnknownShouldDisplay404() {
+    Storm_Test_ObjectWrapper::onLoaderOfModel('Class_CodifAuteur')
+        ->whenCalled('findWithFullName')
+        ->answers(null);
+
+    try {
+      $this->dispatch('/author/view/named/Unknown');
+    }  catch(Zend_Controller_Action_Exception $e) {
+      $this->assertEquals(404, $e->getCode());
+      return;
+    }
+    $this->fail('should raise error 404 not found');
+  }
+}
+
+
+
+
 class AuthorPageViewRecordDetailTest extends AuthorPageTestCase {
   public function setUp() {
     parent::setUp();
-- 
GitLab