diff --git a/library/Class/Notice/Xsl.php b/library/Class/Notice/Xsl.php index d2f93527c3e72cfcc921ddc9529c4ddacc763d95..3e8b95570919acbb8e7328a6746ec29aa37c2fc4 100644 --- a/library/Class/Notice/Xsl.php +++ b/library/Class/Notice/Xsl.php @@ -34,6 +34,7 @@ class Class_Notice_Xsl { public function __construct($record, $profile) { $this->_record = $record; $this->_profile = $profile; + $this->_logErrors(); $this->_xsl_file = $this->_getXslFileFromProfile(); } @@ -78,6 +79,16 @@ class Class_Notice_Xsl { } + protected function _logErrors() { + return static::getPhpCommand()->libxml_use_internal_errors(true); + } + + + public function getErrors() { + return static::getPhpCommand()->libxml_get_errors(); + } + + protected function _getXslFileFromProfile() { $settings = $this->_profile->getCfgModulesPreferences('recherche', 'viewnotice', $this->_record->getTypeDoc()); if(!$settings) diff --git a/library/Class/Testing/PhpCommand.php b/library/Class/Testing/PhpCommand.php index 455626d40aaa493f8fd0479a73a86996cc3365f7..8c974a67afca16368b6472bb17c826d6d1b140a0 100644 --- a/library/Class/Testing/PhpCommand.php +++ b/library/Class/Testing/PhpCommand.php @@ -22,6 +22,8 @@ class Class_Testing_PhpCommand extends Class_Testing_FileSystem { public function __construct() { $this->_known_functions = array_merge($this->_known_functions, - ['extension_loaded']); + ['extension_loaded', + 'libxml_use_internal_errors', + 'libxml_get_errors']); } } \ 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 ba8e02b245544c48b3ade723a575c1f399d7d64c..af777b87f938a34e53a70766f73465e68a8aa69f 100644 --- a/library/ZendAfi/View/Helper/Notice/Xsl.php +++ b/library/ZendAfi/View/Helper/Notice/Xsl.php @@ -37,7 +37,8 @@ class ZendAfi_View_Helper_Notice_Xsl extends ZendAfi_View_Helper_BaseHelper { $xslt = new XSLTProcessor(); $xslt->importStylesheet($xsl_doc); - if(!$response = $xslt->transformToXml($xml)) + $response = $xslt->transformToXml($xml); + if(($errors = $xsl->getErrors()) || (!$response)) return $this->_tag('p', $this->_('La transformation du %s en HTML par le fichier %s n\'a pas fonctionné.', $this->view->tagAnchor(Class_Url::absolute($marc_xml), $this->_('marc-xml'), @@ -45,9 +46,27 @@ class ZendAfi_View_Helper_Notice_Xsl extends ZendAfi_View_Helper_BaseHelper { $this->view->tagAnchor(Class_Url::absolute($xsl_file), $this->_('xsl'), ['target' => 'blank'])), - ['class' => 'error']); + ['class' => 'error']) + . $this->_renderXsltErrors($errors); $xsl->unlink($marc_xml); return $response; } + + + protected function _renderXsltErrors($errors) { + $no_error_message = $this->_tag('p', $this->_('Aucune erreur levée par XSLTProcessor')); + if(!$errors) + return $no_error_message; + + if(empty($errors)) + return $no_error_message; + + $html = []; + foreach ($errors as $error) + $html [] = $this->_tag('li', $this->_('Erreur levée par Libxml: %s', $error->message)); + + return $this->_tag('ul', + implode($html)); + } } \ No newline at end of file diff --git a/tests/scenarios/Xsl/XslTest.php b/tests/scenarios/Xsl/XslTest.php index 912288692140bf9aa552d80779e8a500667c6ae0..e5e126a97e1de4dafae207e1bc6f60d6ee212b8b 100644 --- a/tests/scenarios/Xsl/XslTest.php +++ b/tests/scenarios/Xsl/XslTest.php @@ -121,7 +121,13 @@ class XslNoticeajaxDetailDispatchTest extends AbstractControllerTestCase { ->answers(true) ->whenCalled('unlink') - ->answers(true); + ->answers(true) + + ->whenCalled('libxml_use_internal_errors') + ->answers(true) + + ->whenCalled('libxml_get_errors') + ->answers([]); Class_Notice_Xsl::setPhpCommand($php_command);