diff --git a/library/Class/FileManager.php b/library/Class/FileManager.php index 1499d5f9ae28f24e8efa1f6c5b454dd40ea260d2..5a4076dcda65063e07e7dc432878d39a54104800 100644 --- a/library/Class/FileManager.php +++ b/library/Class/FileManager.php @@ -22,7 +22,10 @@ class Class_FileManager extends Class_Entity { use Trait_Translator; - protected static $_file_system; + protected static + $_file_system, + $_open_bar = false; + const REGEX_NAME = '/^[a-z0-9][a-z0-9_\-\.]+$/i'; protected $_attribs = ['Id' => '', 'Realpath' => '', @@ -207,6 +210,9 @@ class Class_FileManager extends Class_Entity { public static function userHasRightOnPath($path) { + if(static::isOpenBar()) + return true; + if (!$user = Class_Users::getIdentity()) return false; @@ -226,6 +232,21 @@ class Class_FileManager extends Class_Entity { } + public static function isOpenBar() { + return static::$_open_bar; + } + + + public static function beOpenBar() { + return static::$_open_bar = true; + } + + + public static function reset() { + static::$_open_bar = false; + } + + public static function createImage($path, $content) { return static::getFileSystem()->createImage($path, $content); } diff --git a/library/Class/Notice/Xsl.php b/library/Class/Notice/Xsl.php index 0c7dc05940e14a4a4a3be693042278e9c7b3e69a..8a27c72ec41b23db082ee9a6b42abcdd91411494 100644 --- a/library/Class/Notice/Xsl.php +++ b/library/Class/Notice/Xsl.php @@ -40,16 +40,13 @@ class Class_Notice_Xsl { public function isEnabled() { - if(!static::getPhpCommand()->extension_loaded('xsl')) - return false; - if(!$this->_record) return false; if(!$this->_profile) return false; - if(!$this->getXslFile()) + if(!$this->getXslFileUrl()) return false; return true; @@ -89,8 +86,8 @@ class Class_Notice_Xsl { } - protected function _getXslFileFromProfile() { - $settings = $this->_profile->getCfgModulesPreferences('recherche', 'viewnotice', $this->_record->getTypeDoc()); + public function getXslFileUrl() { + $settings = $this->_profile->getCfgModulesPreferences('recherche', 'viewnotice', $this->_record->getTypeDoc()); if(!$settings) return; @@ -98,7 +95,18 @@ class Class_Notice_Xsl { return; return array_key_exists(Class_Notice_Xsl::KEY, $settings) - ? Class_FileManager::find($settings[Class_Notice_Xsl::KEY]) + ? $settings[Class_Notice_Xsl::KEY] : null; } + + + public function isActivated() { + return static::getPhpCommand()->extension_loaded('xsl'); + } + + + protected function _getXslFileFromProfile() { + Class_FileManager::beOpenBar(); + return Class_FileManager::find($this->getXslFileUrl()); + } } \ No newline at end of file diff --git a/library/ZendAfi/View/Helper/Notice/Xsl.php b/library/ZendAfi/View/Helper/Notice/Xsl.php index e93e39fed3700f68d956d629e88c39df8bd739da..36c17f27458fe3db7a3e502aebf8a12482eea89a 100644 --- a/library/ZendAfi/View/Helper/Notice/Xsl.php +++ b/library/ZendAfi/View/Helper/Notice/Xsl.php @@ -22,11 +22,18 @@ class ZendAfi_View_Helper_Notice_Xsl extends ZendAfi_View_Helper_BaseHelper { public function Notice_Xsl($xsl) { + if(!$xsl->isActivated()) + return $this->_tag('p', $this->_('L\'extension PHP XSL n\'est pas installée. Merci de contacter votre hébergeur'), ['class' => 'error']); + if(!$xsl_file = $xsl->getXslFile()) - return ''; + return $this->_tag('p', + $this->_('Le fichier xsl n\'a pas pu être chargé : %s', $xsl->getXslFileUrl()), + ['class' => 'error']); if(!$marc_xml = $xsl->getMarcXmlFile()) - return ''; + return $this->_tag('p', + $this->_('Le fichier marc-xml n\'a pas pu être généré'), + ['class' => 'error']); $xsl_doc = new DOMDocument(); $xsl_doc->load($xsl_file->getRealpath()); diff --git a/tests/application/modules/AbstractControllerTestCase.php b/tests/application/modules/AbstractControllerTestCase.php index 8d082ec22b9ab0b5ed55684886d7bc1ccc8ee2ae..cdf885fb3e442079d5f2431c71161dee57d29042 100644 --- a/tests/application/modules/AbstractControllerTestCase.php +++ b/tests/application/modules/AbstractControllerTestCase.php @@ -193,6 +193,7 @@ abstract class AbstractControllerTestCase extends Zend_Test_PHPUnit_ControllerTe Class_AdminVar::set('NOM_DOMAINE', ''); Class_Log::resetInstance(); Class_WebService_BibNumerique_Vignette::resetInstance(); + Class_FileManager::reset(); } diff --git a/tests/scenarios/Xsl/XslTest.php b/tests/scenarios/Xsl/XslTest.php index b9e15fdfd3c698b2b00b4814b7927e4a393af5e1..c7ecfac81bf63ea5811c94c33060483702631e2d 100644 --- a/tests/scenarios/Xsl/XslTest.php +++ b/tests/scenarios/Xsl/XslTest.php @@ -118,7 +118,13 @@ class XslNoticeajaxDetailDispatchTest extends AbstractControllerTestCase { public function setUp() { parent::setUp(); - $disk = $this->mock(); + $disk = $this->mock() + ->whenCalled('directoryAt') + ->answers(null) + + ->whenCalled('fileAt') + ->answers((new Class_FileManager) + ->setRealpath('tests/scenarios/Xsl/record_description.xsl')); Class_FileManager::setFileSystem($disk); @@ -163,4 +169,42 @@ class XslNoticeajaxDetailDispatchTest extends AbstractControllerTestCase { public function shouldDisplayMarcWithXslt() { $this->assertContains('<strong>Numéro de notice Koha : </strong>2774</li><br><li>', $this->_response->getBody()); } +} + + + + +class XslNoticeajaxDetailDispatchWithoutXSLTest extends AbstractControllerTestCase { + protected $_storm_default_to_volatile = true; + + public function setUp() { + parent::setUp(); + $php_command = $this->mock() + ->whenCalled('extension_loaded') + ->answers(false) + + ->whenCalled('libxml_use_internal_errors') + ->answers(true); + + Class_Notice_Xsl::setPhpCommand($php_command); + + $profile = Class_Profil::getCurrentProfil(); + $profile->setCfgModulesPreferences(['xslt' => 'tests/scenarios/Xsl/record_description.xsl'], + 'recherche', + 'viewnotice', + '1'); + $profile->save(); + + $this->fixture('Class_Notice', + ['id' => 5, + 'type_doc' => 1]); + + $this->dispatch('/opac/noticeajax/detail/id_notice/5', true); + } + + + /** @test */ + public function plzInstallXSLErrorShouldBeDisplay() { + $this->assertXPathContentContains('//p', "L'extension PHP XSL"); + } } \ No newline at end of file