Skip to content
Snippets Groups Projects
Commit 786da038 authored by Ghislain Loas's avatar Ghislain Loas
Browse files

dev #73871 upgrade error handling

parent 0432ccfb
Branches
Tags
5 merge requests!2660Master,!2616Dev#73871 minsoc xlst etape 2 association fichier xslt,!2601Dev#73871 minsoc xlst etape 2 association fichier xslt,!2597Dev#73871 minsoc xlst etape 2 association fichier xslt,!2589Dev#73871 minsoc xlst etape 2 association fichier xslt
Pipeline #3874 failed with stage
in 16 minutes and 40 seconds
......@@ -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);
}
......
......@@ -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
......@@ -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());
......
......@@ -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();
}
......
......@@ -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
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment