From 75fee0924cb22c032b93c5826a0070fc7bd87abf Mon Sep 17 00:00:00 2001
From: llaffont <llaffont@git-test.afi-sa.fr>
Date: Mon, 15 Apr 2013 13:59:17 +0000
Subject: [PATCH] Editeur CSS: contourne le cache navigateur

---
 .../modules/opac/views/scripts/head.phtml     | 12 ++--
 .../opac/controllers/IndexControllerTest.php  | 61 ++++++++++++++++---
 2 files changed, 59 insertions(+), 14 deletions(-)

diff --git a/application/modules/opac/views/scripts/head.phtml b/application/modules/opac/views/scripts/head.phtml
index f18b81e2dc7..b383c24fa91 100644
--- a/application/modules/opac/views/scripts/head.phtml
+++ b/application/modules/opac/views/scripts/head.phtml
@@ -36,17 +36,21 @@ $head_scripts = Class_ScriptLoader::newInstance()
 if (file_exists(PATH_SKIN.'/css/bib.css'))
 	$head_scripts->addSkinStyleSheet('bib');
 
-if ($this->header_css)
-	$head_scripts->addStyleSheet($this->header_css, ['id' => 'profil_css']);
-
 if ($this->header_js)
 	$head_scripts->addJQueryReady('$.getScript("'.$this->header_js.'")');
 
-if (Class_Users::isCurrentUserAdmin() && Class_AdminVar::isCssEditorEnabled())
+xdebug_break();
+if (Class_Users::isCurrentUserAdmin() && Class_AdminVar::isCssEditorEnabled()) {
 	$head_scripts
 		->loadAmber(true)
 		->addAmberPackage('AFI-OPAC');
 
+	$this->header_css .= '?cache='.md5(time());
+}
+
+if ($this->header_css) 
+	$head_scripts->addStyleSheet($this->header_css, ['id' => 'profil_css']);
+
 if ($this->accessibilite_on) {  //Feuilles de styles pour les déficiences visuelles
 	$head_scripts
 		->addOPACStyleSheet('blanc_sur_noir', array('rel' => 'alternate stylesheet',
diff --git a/tests/application/modules/opac/controllers/IndexControllerTest.php b/tests/application/modules/opac/controllers/IndexControllerTest.php
index 2f103b2966f..98f22ec61bb 100644
--- a/tests/application/modules/opac/controllers/IndexControllerTest.php
+++ b/tests/application/modules/opac/controllers/IndexControllerTest.php
@@ -37,6 +37,7 @@ class IndexControllerAsInviteTest extends AbstractControllerTestCase {
 		$this->assertNotXPathContentContains('//script', 'AFI-OPAC.js');
 	}
 
+
 	/** @test */
 	public function linkToConfigurePageShouldNotBeInFooter() {
 		$this->dispatch('/?id_profil=1');
@@ -46,32 +47,72 @@ class IndexControllerAsInviteTest extends AbstractControllerTestCase {
 
 
 
-class IndexControllerAsAdminTest extends AbstractControllerTestCase {
+abstract class IndexControllerAsAdminTestCase extends AbstractControllerTestCase {
 	protected function _loginHook($account) {
 		$account->ROLE_LEVEL = ZendAfi_Acl_AdminControllerRoles::ADMIN_PORTAIL;
 	}
 
-	/** @test */
-	public function withCssEditorEnabledShouldLoadIt() {
-		Class_AdminVar::newInstanceWithID('CSS_EDITOR')->setValeur(1);
-		$this->dispatch('/');
-		$this->assertXPathContentContains('//script', 'AFI-OPAC.js');
+
+	public function setUp() {
+		parent::setUp();
+
+		Class_Profil::newInstanceWithId(1, ['header_css' => 'mycss.css']);
+	}
+}
+
+
+
+
+class IndexControllerAsAdminWithoutCssEditor extends IndexControllerAsAdminTestCase {
+	public function setUp() {
+		parent::setUp();
+
+		Class_AdminVar::newInstanceWithID('CSS_EDITOR', ['valeur' => 0]);
+		$this->dispatch('/?id_profil=1');
 	}
 
 
 	/** @test */
-	public function withCssEditorDisabledShouldNotLoadIt() {
-		Class_AdminVar::newInstanceWithID('CSS_EDITOR')->setValeur(0);
-		$this->dispatch('/');
+	public function cssEditorShouldNotBeLoaded() {
 		$this->assertNotXPathContentContains('//script', 'AFI-OPAC.js');
 	}
 
+	
+	/** @test */
+	public function headerCssShouldBeMyCss() {
+		$this->assertXPath('//link[contains(@href, "mycss.css")][not(contains(@href, "?cache="))]');
+	}
+
 
 	/** @test */
 	public function linkToConfigurePageShouldBeInFooter() {
-		$this->dispatch('/?id_profil=1');
 		$this->assertXPath('//div[@class="footer"]//a[@class="edit_profil"][contains(@href, "admin/profil/accueil/id_profil/1")]');
 	}
 }
 
+
+
+
+class IndexControllerAsAdminWithCSSEditorTest extends IndexControllerAsAdminTestCase {
+	public function setUp() {
+		parent::setUp();
+
+		Class_AdminVar::newInstanceWithID('CSS_EDITOR', ['valeur' => 1]);
+		$this->dispatch('/?id_profil=1');
+	}
+
+
+	/** @test */
+	public function cssEditorShouldBeLoaded() {
+		$this->assertXPathContentContains('//script', 'AFI-OPAC.js');
+	}
+
+
+	/** @test */
+	public function headerCssShouldBeMyCssWithCacheWorkaround() {
+		$this->assertXPath('//link[contains(@href, "mycss.css")][contains(@href, "?cache=")]');
+	}
+
+}
+
 ?>
-- 
GitLab