From 5ad0260b08c918b07fbba657497ae43bf9072221 Mon Sep 17 00:00:00 2001
From: efalcy <efalcy@afi-sa.fr>
Date: Tue, 1 Sep 2015 18:10:14 +0200
Subject: [PATCH] dev #27625 : nanook , display responsability on 7** $6

---
 library/Class/Notice.php                    | 22 ++++--
 tests/library/Class/DecodageUnimarcTest.php | 75 +++++++++++++++++++++
 2 files changed, 93 insertions(+), 4 deletions(-)

diff --git a/library/Class/Notice.php b/library/Class/Notice.php
index 110ed7e45f9..480ba88ba32 100644
--- a/library/Class/Notice.php
+++ b/library/Class/Notice.php
@@ -1136,14 +1136,28 @@ class Class_Notice extends Storm_Model_Abstract {
     $auteur = new stdClass();
     $auteur->nom = $auteur->prenom = $auteur->fonction = $auteur->fonction_pergame = '';
     foreach ($data as $item) {
-      if ($item['code'] == 'a')
+      if ($item['code'] == 'a') {
         $auteur->nom = trim($item['valeur']);
-      elseif ($item['code'] == 'b')
+        continue;
+      }
+      if ($item['code'] == 'b') {
         $auteur->prenom = trim($item['valeur']);
-      elseif ($item['code'] == '4')
+        continue;
+      }
+
+      if ($item['code'] == '4') {
         $auteur->fonction = trim($item['valeur']);
-      elseif ($item['code'] == 'g')
+        continue;
+      }
+
+      if  ($item['code'] == 'g' && !$auteur->fonction_pergame) {
+        $auteur->fonction_pergame = trim($item['valeur']);
+        continue;
+      }
+      if ($item['code'] == '6') {
         $auteur->fonction_pergame = trim($item['valeur']);
+      }
+
     }
     return $auteur;
   }
diff --git a/tests/library/Class/DecodageUnimarcTest.php b/tests/library/Class/DecodageUnimarcTest.php
index 5eb8c008dd7..7359b410789 100644
--- a/tests/library/Class/DecodageUnimarcTest.php
+++ b/tests/library/Class/DecodageUnimarcTest.php
@@ -310,4 +310,79 @@ class DecodageUnimarcConcertoAuteursTest extends PHPUnit_Framework_TestCase {
 
 }
 
+
+class DecodageUnimarcDVDUnHerosTresDiscretTest extends Storm_Test_ModelTestCase {
+  public function setUp() {
+    parent::setUp();
+    Class_CodifAuteurFonction::beVolatile();
+    Class_CodifAuteur::beVolatile();
+
+    $this->fixture('Class_CodifLangue',
+                   ['id' => 23,
+                    'libelle' => '']);
+    foreach ($this->createAuthors() as $author) {
+      $author_db=$this->fixture('Class_CodifAuteur',
+                                ['id' => $author[0],
+                                 'libelle' => $author[1]
+                                ]);
+      Storm_Test_ObjectWrapper::onLoaderOfModel('Class_CodifAuteur')
+        ->whenCalled('findFirstBy')
+        ->with(['where' => "MATCH(formes) AGAINST('".$author[2]."' IN BOOLEAN MODE)"])
+        ->answers($author_db);
+
+
+    }
+
+    $unimarc=file_get_contents(realpath(dirname(__FILE__)).'../../../fixtures/audiard_herosdiscret.uni');
+    $this->audiard = $this->fixture('Class_Notice',
+                                    ['id' => 10,
+                                     'unimarc' => $unimarc,
+                                     'exemplaires' => []]);
+    $this->_authors = $this->audiard->getAuteursUnimarc(false, true);
+  }
+
+  protected function createAuthors() {
+    return [[1,'Jacques Audiard','AUDIARDxJACQUES'],
+            [2,'Alexandre Desplat', 'DESPLATxALEXANDRE'],
+            [3, 'Jean-François Deniau', 'DENIAUxJEANxFRANCOIS'],
+            [4, 'Mathieu Kassovitz', 'KASSOVITZxMATHIEU'],
+            [5, 'Anouk Grinberg', 'GRINBERGxANOUK'],
+            [6,'Sandrine Kiberlain' , 'KIBERLAINxSANDRINE'],
+            [8,'Albert Dupontel' , 'DUPONTELxALBERT'],
+            [7,'Alain Le Henry' , 'LExHENRYxALAIN']];
+  }
+  /**
+   * @dataProvider expectedAuthors
+   * @test
+   */
+  public function getAuthorUnimarcShouldReturnExpectedAuthors($id, $label, $rebound_code, $author_index) {
+    $author = $this->_authors[$author_index];
+
+
+    $this->assertEquals($id, $author->getId());
+    $this->assertEquals($label, $author->getLabel());
+    $this->assertEquals(['controller' => 'recherche',
+                         'action' => 'simple',
+                         'code_rebond' => $rebound_code,
+                         'facettes' => null,
+                         'facette' => null,
+                         'serie' => null,
+                         'page' => null],
+                        $author->getUrlParams());
+  }
+
+
+  public function expectedAuthors() {
+    return [
+            [1, 'Jacques Audiard (Metteur en scène ou réalisateur)', 'A1', 0],
+            [2, 'Alexandre Desplat (Compositeur)', 'A2', 1],
+            [3, 'Jean-François Deniau (Auteur)', 'A3', 2],
+            [4, 'Mathieu Kassovitz (Acteur)', 'A4', 3],
+            [5, 'Anouk Grinberg (Acteur)','A5', 4],
+            [6, 'Sandrine Kiberlain (Acteur)' , 'A6', 5],
+            [8, 'Albert Dupontel (Acteur)' , 'A8', 7],
+            [7, 'Alain Le Henry (Intervenant)' , 'A7', 9]];
+  }
+
+}
 ?>
\ No newline at end of file
-- 
GitLab