diff --git a/library/Class/FileManager.php b/library/Class/FileManager.php index 5a4076dcda65063e07e7dc432878d39a54104800..4dfe3ea6c7223c8f7ad690caf895e604e673849e 100644 --- a/library/Class/FileManager.php +++ b/library/Class/FileManager.php @@ -244,6 +244,7 @@ class Class_FileManager extends Class_Entity { public static function reset() { static::$_open_bar = false; + static::setFileSystem(null); } diff --git a/library/Class/Notice/Xsl.php b/library/Class/Notice/Xsl.php index 8a27c72ec41b23db082ee9a6b42abcdd91411494..ef7c8871e708ae089605c7fb30af844187a0ca7c 100644 --- a/library/Class/Notice/Xsl.php +++ b/library/Class/Notice/Xsl.php @@ -25,12 +25,21 @@ class Class_Notice_Xsl { const KEY = 'xslt'; + protected static $_xslt_processor; + protected $_record, $_profile, $_xsl_file; + public static function reset() { + static::$_xslt_processor = null; + static::setPhpCommand(null); + static::setYaz(null); + } + + public function __construct($record, $profile) { $this->_record = $record; $this->_profile = $profile; @@ -109,4 +118,35 @@ class Class_Notice_Xsl { Class_FileManager::beOpenBar(); return Class_FileManager::find($this->getXslFileUrl()); } + + + public function importStylesheet($path) { + $xsl = new DOMDocument(); + $xsl->load($path); + + $xslt = $this->getXSLTProcessor(); + $xslt->importStylesheet($xsl); + + return $this; + } + + + public function transformToXml($path) { + $xml = new DOMDocument(); + $xml->load($path); + + return $this->getXSLTProcessor()->transformToXml($xml); + } + + + public function getXSLTProcessor() { + return static::$_xslt_processor + ? static::$_xslt_processor + : new XSLTProcessor(); + } + + + public static function setXSLTProcessor($xslt_processor) { + static::$_xslt_processor = $xslt_processor; + } } \ 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 36c17f27458fe3db7a3e502aebf8a12482eea89a..9862b28309fd219d296f57d25417362f80438b66 100644 --- a/library/ZendAfi/View/Helper/Notice/Xsl.php +++ b/library/ZendAfi/View/Helper/Notice/Xsl.php @@ -35,16 +35,8 @@ class ZendAfi_View_Helper_Notice_Xsl extends ZendAfi_View_Helper_BaseHelper { $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()); - - $xml = new DOMDocument(); - $xml->load($marc_xml); - - $xslt = new XSLTProcessor(); - $xslt->importStylesheet($xsl_doc); - - $response = $xslt->transformToXml($xml); + $xslt = $xsl->importStylesheet($xsl_file->getRealpath()); + $response = $xsl->transformToXml($marc_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é.', diff --git a/tests/application/modules/AbstractControllerTestCase.php b/tests/application/modules/AbstractControllerTestCase.php index cdf885fb3e442079d5f2431c71161dee57d29042..f8e932cfea60e8a250595a780e35e86f9c17c6b3 100644 --- a/tests/application/modules/AbstractControllerTestCase.php +++ b/tests/application/modules/AbstractControllerTestCase.php @@ -194,6 +194,7 @@ abstract class AbstractControllerTestCase extends Zend_Test_PHPUnit_ControllerTe Class_Log::resetInstance(); Class_WebService_BibNumerique_Vignette::resetInstance(); Class_FileManager::reset(); + Class_Notice_Xsl::reset(); } diff --git a/tests/scenarios/Xsl/XslTest.php b/tests/scenarios/Xsl/XslTest.php index c7ecfac81bf63ea5811c94c33060483702631e2d..0f2bf35d8171f387a0a1b7720674c7f9d917b89f 100644 --- a/tests/scenarios/Xsl/XslTest.php +++ b/tests/scenarios/Xsl/XslTest.php @@ -143,6 +143,15 @@ class XslNoticeajaxDetailDispatchTest extends AbstractControllerTestCase { Class_Notice_Xsl::setPhpCommand($php_command); + $xslt_processor = $this->mock() + ->whenCalled('importStylesheet') + ->answers(true) + + ->whenCalled('transformToXml') + ->answers('<li><strong>Numéro de notice Koha : </strong>2774</li><br><li>'); + + Class_Notice_Xsl::setXSLTProcessor($xslt_processor); + $profile = Class_Profil::getCurrentProfil(); $profile->setCfgModulesPreferences(['xslt' => 'tests/scenarios/Xsl/record_description.xsl'], 'recherche',