From 13d9d367f69c28398e01b992b32e6f2d19d276ef Mon Sep 17 00:00:00 2001
From: efalcy <efalcy@git-test.afi-sa.fr>
Date: Mon, 30 Sep 2013 10:41:40 +0000
Subject: [PATCH] Detail notice : non affichage des liens internet si 856x est
 present dans l'unimarc

---
 library/Class/Notice.php                      | 26 +++++++++++--
 .../controllers/NoticeAjaxControllerTest.php  | 37 +++++++++++++++++++
 2 files changed, 60 insertions(+), 3 deletions(-)

diff --git a/library/Class/Notice.php b/library/Class/Notice.php
index 56232a0717d..e4626923316 100644
--- a/library/Class/Notice.php
+++ b/library/Class/Notice.php
@@ -1555,11 +1555,31 @@ class Class_Notice extends Storm_Model_Abstract {
 // Champ 856$a et 856$u (liens internet)
 // ----------------------------------------------------------------
 	public function get856a()	{
+		xdebug_break();
 		$lien = array();
-		$data = $this->get_subfield(856, "a");
-		$data1 = $this->get_subfield(856, "u");
-		$result = array_merge($data, $data1);
 
+	
+		$blocs = $this->get_subfield(856);
+		$result = [];
+		foreach ($blocs as $bloc) {
+
+			$datas = $this->decoupe_bloc_champ($bloc);
+			$link=null;
+			foreach ($datas as $data) {
+				if ($data['code']=='x') {
+					$link=null;
+					break;
+				}
+				if ($data['code']=='u')
+					$link=$data['valeur'];
+				
+				if ($data['code']=='a')
+					$link=$data['valeur'];
+			}
+			
+			$result[]=$link;
+		}
+		xdebug_break();
 		if (isset($result[0]))	{
 			// black list
 			$trav = fetchOne("select valeur from variables where clef='black_list_856'");
diff --git a/tests/application/modules/opac/controllers/NoticeAjaxControllerTest.php b/tests/application/modules/opac/controllers/NoticeAjaxControllerTest.php
index 471bd5fb585..cb3eb5645cc 100644
--- a/tests/application/modules/opac/controllers/NoticeAjaxControllerTest.php
+++ b/tests/application/modules/opac/controllers/NoticeAjaxControllerTest.php
@@ -60,7 +60,44 @@ class NoticeAjaxControllerNonRegressionTest extends AbstractControllerTestCase {
 
 
 
+ class NoticeAjaxControllerNoticeWithGamUrlTestCase extends AbstractControllerTestCase {
+	protected $_wesley;
 
+	public function setUp() {
+		parent::setUp();
+
+		Class_Profil::getCurrentProfil()
+			->setCfgModules(['recherche' => ['resultatsimple' => ['liste_codes' => "TANECRG"]]]);
+
+
+		$this->_wesley = Class_Notice::newInstanceWithId(1, 
+																												 ['facettes' => 'A1',
+																													'isbn' => '',
+																													'ean' => '',
+																													'type_doc' => 1,
+																													'tome_alpha' => '',
+																													'clef_alpha' => 'Wesley',
+																													'unimarc' => "02502njm0 22007331  450 00100060000007100370000610000410004310100080008412700100009220000450010220000030014721000390015021500090018932700030019834500420020146400030024346400030024646400030024946400030025246400030025546400030025846400030026146400030026446400030026746400030027046400030027346400030027646400030027946400190028246400210030146400160032246400100033846400240034846400250037246400110039746400250040846400290043346400280046246400180049046400150050846400170052368600290054070000320056970000030060170100320060470200400063670200340067670200330071070200380074370200440078170200350082570200360086070200310089671100030092780100220093085601320095293301470108498401320123198500820136398500840144598500790152998500730160898500870168134793100a2784087bHIP-OSelect.com/Polydor  a20130311d2011    u  y0frey0103    ba0 aeng  a53:221 aThe Lost album featuring Watermelon man 1   cUniversal RecordsdRÂeedition 2011  a1 cd1   b0602527840871cdisque compactd7,48 E 1 1 1 1 1 1 1 1 1 1 1 1 1  tWatermelon man  tSweet loneliness  tSecret love  tSeulb  tYou've got a friend  tTransmograpification  tUse me  tGet on the good foot  tEverybody plays the fool  tAlone again (Naturally)  tBack stabbers  tJ.B. shout  tFunky & some  a1.382tJazz funky2PCDM4 1aWesleybFred40006trombone 1 1aThe JB's 40006ens. instr. 1aFarrellbJoe40006saxophone tÂenor 1aStammbMarvin4btr6trompette 1aBrownbCharlie40006guitare 1aCranshawbBob4MBS6basse guitare 1aBreckerbMichael40006saxophone tÂenor 1aBreckerbRandy4btr6trompette 1aCarterbRon4MBS6basse guitare 1aGaddbSteve4PDS6batterie02 0aFRbGAMc201303114 uhttp://www.gamannecy.com//upload/albums/201202/0602527840871_thumb.jpgzFred Wesley / Lost album featuring Watermelon man (The)  3http://www.gamannecy.com//upload/albums/201202/0602527840871_thumb.jpgahttp://www.gamannecy.com//upload/albums/201202/0602527840871_thumb.jpg  ahttp://www.gamannecy.com//upload/albums/201202/0602527840871_thumb.jpgbFred Wesley / Lost album featuring Watermelon man (The)  ahttp://www.gamannecy.com/polysson/201205/01-0602527840871.mp3bWatermelon man  ahttp://www.gamannecy.com/polysson/201205/02-0602527840871.mp3bSweet loneliness  ahttp://www.gamannecy.com/polysson/201205/03-0602527840871.mp3bSecret love  ahttp://www.gamannecy.com/polysson/201205/04-0602527840871.mp3bSeulb  ahttp://www.gamannecy.com/polysson/201205/05-0602527840871.mp3bYou've got a friend",
+																													'annee' => '2000',
+																													'url_vignette' => 'wesley_small.png',
+																													'url_image' => 'wesley.png']);
+		$mock_sql = Storm_Test_ObjectWrapper::on(Zend_Registry::get('sql'));
+		Zend_Registry::set('sql', $mock_sql);
+
+		$mock_sql
+			->whenCalled('fetchOne')
+			->with("select valeur from variables where clef='black_list_856'")
+			->answers('electre');
+	}
+
+	/** @test */
+	public function withNoticeFoundResponseShouldContainsLienInternet() {
+		$this->dispatch('/opac/noticeajax/detail/id_notice/1', true);
+		$this->assertXPathContentContains('//a', 'http://www.gamannecy.com//upload/albums/201202/0602527840871_thumb.jpg', $this->_response->getBody());
+	}
+
+	
+}
 abstract class NoticeAjaxControllerNoticeSouleymaneTestCase extends AbstractControllerTestCase {
 	protected $_souleymane;
 
-- 
GitLab