diff --git a/library/Class/Notice/Xsl.php b/library/Class/Notice/Xsl.php index ac16ff255d1162adc18c67ddee6748c29aaf06aa..28dcd25024f5bc70ed795a9c7ab1dc3fcbfbb94c 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 d184b1fa0d99d1946c05c1885a285e578bfb1557..a33d7e2cee3e8ac5d33e6a80a8de913eda5344f3 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();