From 1826dfb41b0e0a3b93bc5c3b7360e366242f4472 Mon Sep 17 00:00:00 2001 From: gloas <gloas@afi-sa.fr> Date: Mon, 16 Apr 2018 10:03:20 +0200 Subject: [PATCH] dev #73871 wrap DOMDocument for tests --- library/Class/Notice/Xsl.php | 23 +++++++++++++++++++---- tests/scenarios/Xsl/XslTest.php | 6 ++++++ 2 files changed, 25 insertions(+), 4 deletions(-) diff --git a/library/Class/Notice/Xsl.php b/library/Class/Notice/Xsl.php index ef7c8871e70..a4a23b3ed19 100644 --- a/library/Class/Notice/Xsl.php +++ b/library/Class/Notice/Xsl.php @@ -25,7 +25,9 @@ class Class_Notice_Xsl { const KEY = 'xslt'; - protected static $_xslt_processor; + protected static + $_xslt_processor, + $_dom_document; protected $_record, @@ -35,6 +37,7 @@ class Class_Notice_Xsl { public static function reset() { static::$_xslt_processor = null; + static::$_dom_document = null; static::setPhpCommand(null); static::setYaz(null); } @@ -121,7 +124,7 @@ class Class_Notice_Xsl { public function importStylesheet($path) { - $xsl = new DOMDocument(); + $xsl = $this->getDomDocument(); $xsl->load($path); $xslt = $this->getXSLTProcessor(); @@ -132,7 +135,7 @@ class Class_Notice_Xsl { public function transformToXml($path) { - $xml = new DOMDocument(); + $xml = $this->getDomDocument(); $xml->load($path); return $this->getXSLTProcessor()->transformToXml($xml); @@ -142,11 +145,23 @@ class Class_Notice_Xsl { public function getXSLTProcessor() { return static::$_xslt_processor ? static::$_xslt_processor - : new XSLTProcessor(); + : (static::$_xslt_processor = new XSLTProcessor()); } public static function setXSLTProcessor($xslt_processor) { static::$_xslt_processor = $xslt_processor; } + + + public function getDomDocument() { + return static::$_dom_document + ? static::$_dom_document + : new DOMDocument; + } + + + public static function setDomDocument($dom_document) { + static::$_dom_document = $dom_document; + } } \ No newline at end of file diff --git a/tests/scenarios/Xsl/XslTest.php b/tests/scenarios/Xsl/XslTest.php index 0f2bf35d817..e95f04f3709 100644 --- a/tests/scenarios/Xsl/XslTest.php +++ b/tests/scenarios/Xsl/XslTest.php @@ -143,6 +143,12 @@ class XslNoticeajaxDetailDispatchTest extends AbstractControllerTestCase { Class_Notice_Xsl::setPhpCommand($php_command); + $dom_document = $this->mock() + ->whenCalled('load') + ->answers(true); + + Class_Notice_Xsl::setDomDocument($dom_document); + $xslt_processor = $this->mock() ->whenCalled('importStylesheet') ->answers(true) -- GitLab