From 075f277a2029131affe66c9032d46db95bce765a Mon Sep 17 00:00:00 2001
From: pbarroca <pbarroca@afi-sa.fr>
Date: Wed, 19 Mar 2014 16:00:13 +0100
Subject: [PATCH] Make test not depends on real CosmoVars

---
 library/Class/Notice.php                      | 32 +++++++++-------
 .../controllers/NoticeAjaxControllerTest.php  | 37 +++++++++++--------
 2 files changed, 40 insertions(+), 29 deletions(-)

diff --git a/library/Class/Notice.php b/library/Class/Notice.php
index ec70b173e67..5624737e8e3 100644
--- a/library/Class/Notice.php
+++ b/library/Class/Notice.php
@@ -1591,30 +1591,34 @@ class Class_Notice extends Storm_Model_Abstract {
 		if (isset($result[0]))	{
 			// black list
 			$trav = Class_CosmoVar::get('black_list_856');
-			if (trim($trav)) $black_list = explode(";", $trav);
+			$black_list = (trim($trav)) ? explode(';', $trav) : [];
 
 			// controle url pour target
 			$target = Class_CosmoVar::get('url_site');
 			$trav = explode('/', $target);
 			$ctrl_target = array_pop($trav);
-			if (!trim($ctrl_target)) $ctrl_target = array_pop($trav);
+			if (!trim($ctrl_target)) 
+				$ctrl_target = array_pop($trav);
 
 			// tableau des liens
-			foreach ($result as $item)
-			{
+			foreach ($result as $item) {
 				$controle = true;
-				if ($black_list)
-				{
-					foreach ($black_list as $mot)
-					{
-						if (stripos($item, $mot) !== false)
-						{ $controle = false; break; }
+				if ($black_list) {
+					foreach ($black_list as $mot) {
+						if (stripos($item, $mot) !== false) {
+							$controle = false; 
+							break; 
+						}
 					}
 				}
-				if ($controle == true)
-				{
-					if (substr(strtoupper($item), 0, 4) != "HTTP") $item = "http://" . $item;
-					if (strpos($item, $ctrl_target) === false) $target = 'target="_blank"'; else $target="";
+
+				if ($controle == true) {
+					if (substr(strtoupper($item), 0, 4) != 'HTTP') 
+						$item = 'http://' . $item;
+
+					$target = (strpos($item, $ctrl_target) === false) 
+						? 'target="_blank"' : ''; 
+
 					$lien[] = '<a href="' . trim($item) . '" ' . $target . ">" . trim($item) . '</a>';
 				}
 			}
diff --git a/tests/application/modules/opac/controllers/NoticeAjaxControllerTest.php b/tests/application/modules/opac/controllers/NoticeAjaxControllerTest.php
index 2dd2533aaf0..d851e82af21 100644
--- a/tests/application/modules/opac/controllers/NoticeAjaxControllerTest.php
+++ b/tests/application/modules/opac/controllers/NoticeAjaxControllerTest.php
@@ -58,7 +58,7 @@ class NoticeAjaxControllerNonRegressionTest extends AbstractControllerTestCase {
 
 
 
- class NoticeAjaxControllerNoticeWithGamUrlTestCase extends AbstractControllerTestCase {
+class NoticeAjaxControllerNoticeWithGamUrlTestCase extends AbstractControllerTestCase {
 	protected $_wesley;
 
 	public function setUp() {
@@ -67,18 +67,20 @@ class NoticeAjaxControllerNonRegressionTest extends AbstractControllerTestCase {
 		Class_Profil::getCurrentProfil()
 			->setCfgModules(['recherche' => ['resultatsimple' => ['liste_codes' => "TANECRG"]]]);
 
+		$this->_wesley = $this->fixture(
+			'Class_Notice',
+			['id' => 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']);
 
-		$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);
 
@@ -86,16 +88,21 @@ class NoticeAjaxControllerNonRegressionTest extends AbstractControllerTestCase {
 			->whenCalled('fetchOne')
 			->with("select valeur from variables where clef='black_list_856'")
 			->answers('electre');
+
+		$this->fixture('Class_CosmoVar', ['id' => 'types_docs',
+																			'liste' => "1:cd\r\n200:non identifié\r\n201:livres\r\n202:bd"]);
 	}
 
+
 	/** @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