From 73ed3bd8f192236eecdf16fd5595bdeec414f8ce Mon Sep 17 00:00:00 2001 From: Laurent Laffont <llaffont@afi-sa.fr> Date: Mon, 16 Sep 2019 17:05:13 +0200 Subject: [PATCH] hotline #95686 try to fix failing test on CI --- library/Class/Notice/Xsl.php | 8 +++++- tests/scenarios/Xsl/XslTest.php | 50 ++++++++++++--------------------- 2 files changed, 25 insertions(+), 33 deletions(-) diff --git a/library/Class/Notice/Xsl.php b/library/Class/Notice/Xsl.php index ac16ff255d1..28dcd25024f 100644 --- a/library/Class/Notice/Xsl.php +++ b/library/Class/Notice/Xsl.php @@ -87,8 +87,14 @@ class Class_Notice_Xsl { if(!$marc = $this->_record->getUnimarc()) return ''; + + return $this->filePutMarcToXML($marc); + } + + + public function filePutMarcToXML($marc) { return ($marc_xml_array = static::getYaz()->marcToMarcXml($marc)) - ? static::getYaz()->writeMarcXmlInFile(implode("\n",$marc_xml_array)) + ? static::getYaz()->writeMarcXmlInFile(implode("\n", $marc_xml_array)) : ''; } diff --git a/tests/scenarios/Xsl/XslTest.php b/tests/scenarios/Xsl/XslTest.php index d184b1fa0d9..a33d7e2cee3 100644 --- a/tests/scenarios/Xsl/XslTest.php +++ b/tests/scenarios/Xsl/XslTest.php @@ -75,17 +75,12 @@ class XslRechercheControllerViewnoticeWithInspectorGadgetAndMarcXMLEnabledTest e -class XslRechercheControllerViewnoticeAndMarcXMLWithLineBreaksTest extends AbstractControllerTestCase { - protected $_storm_default_to_volatile = true; +class XslRechercheControllerViewnoticeAndMarcXMLWithLineBreaksTest extends ModelTestCase { + protected + $_written_content; /** @test */ public function writtenXmlShouldKeepNewLines() { - $profile = Class_Profil::getCurrentProfil(); - $profile->setCfgModulesPreferences(['xslt' => '/tests/scenarios/Xsl/break_line.xsl'], - 'recherche', - 'viewnotice', - Class_TypeDoc::PERIODIQUE); - $profile->save(); $marcxml_output = [ " <subfield code=\"a\">Détail du contenu :", " 1 pochette contenant des instruments pour enfant", @@ -93,33 +88,23 @@ class XslRechercheControllerViewnoticeAndMarcXMLWithLineBreaksTest extends Abstr " 1 flûte à bec", " </subfield>" ]; - $cmd = $this->mock() - ->whenCalled('exec') - ->answers(true) - ->whenCalled('getOutput') - ->answers($marcxml_output); - $filesystem = $this->mock() - ->whenCalled('unlink') - ->answers(true) + $yaz = $this->mock() + ->whenCalled('marcToMarcXml') + ->with('marc content') + ->answers($marcxml_output) - ->whenCalled('file_put_contents') - ->willDo(function($filename,$content) use ($marcxml_output) - { - if (FALSE === strpos($filename,'.xml')) - return; - $this->assertEquals($marcxml_output, explode("\n",$content),$content); - }); - Class_Testing_Yaz::setCommand($cmd); - Class_Testing_Yaz::setFileSystem($filesystem); + ->whenCalled('writeMarcXmlInFile') + ->willDo(function($marcxml) + { + $this->_written_content = $marcxml; + }); - $this->fixture('Class_Notice', - ['id' => 2, - 'type_doc' => Class_TypeDoc::PERIODIQUE, - 'unimarc' => file_get_contents('tests/scenarios/Xsl/notice_onde.txt')]); - $this->dispatch('/opac/noticeajax/detail/id_notice/2', true); + $xsl = new Class_Notice_Xsl(new Class_Notice(), new Class_Profil()); + $xsl->setYaz($yaz); + $xsl->filePutMarcToXML('marc content'); - $this->assertTrue($filesystem->methodHasBeenCalled('file_put_contents')); + $this->assertEquals($marcxml_output, explode("\n", $this->_written_content)); } } @@ -162,10 +147,11 @@ class XslDocTypeConfigurationPostDispatchTest extends Admin_AbstractControllerTe } + + abstract class XslNoticeajaxDetailTestCase extends AbstractControllerTestCase { protected $_storm_default_to_volatile = true; - public function setUp() { parent::setUp(); Storm_Cache::beVolatile(); -- GitLab