Skip to content
Snippets Groups Projects
Commit 2bd2a7cb authored by Patrick Barroca's avatar Patrick Barroca :grin:
Browse files

hotline #90675 : xslt empty transform message enlightment

parent ae1e4ae8
Branches
Tags
3 merge requests!3297WIP: Master,!3125Hotline,!3118hotline #90675 : xslt empty transform message enlightment
Pipeline #6952 passed with stage
in 36 minutes and 19 seconds
- ticket #90675 : Résultat de recherche : Amélioration du messages d'erreur lorsque la transformation XSLT produit un résultat vide
\ No newline at end of file
......@@ -38,30 +38,33 @@ class ZendAfi_View_Helper_Notice_Xsl extends ZendAfi_View_Helper_BaseHelper {
$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é.',
$this->view->tagAnchor(Class_Url::absolute($marc_xml),
$this->_('marc-xml'),
['target' => 'blank']),
$this->view->tagAnchor(Class_Url::absolute($xsl_file->getPath()),
$this->_('xsl'),
['target' => 'blank'])),
['class' => 'error'])
if(($errors = $xsl->getErrors()))
return $this->_errorMessage($this->_('n\'a pas fonctionné.'), $marc_xml, $xsl_file)
. $this->_renderXsltErrors($errors);
if (!$response)
return $this->_errorMessage($this->_('a produit un résultat vide.'), $marc_xml, $xsl_file);
$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;
protected function _errorMessage($message, $marc_xml, $xsl_file) {
return $this->_tag('p', $this->_('La transformation du %s en HTML par le fichier %s %s',
$this->view->tagAnchor(Class_Url::absolute($marc_xml),
$this->_('marc-xml'),
['target' => 'blank']),
$this->view->tagAnchor(Class_Url::absolute($xsl_file->getPath()),
$this->_('xsl'),
['target' => 'blank']),
$message),
['class' => 'error']);
}
protected function _renderXsltErrors($errors) {
$html = [];
foreach ($errors as $error)
$html [] = $this->_tag('li', $this->_('Erreur levée par Libxml: %s', $error->message));
......
......@@ -498,3 +498,85 @@ class XslSearchResultDispatchTest extends AbstractControllerTestCase {
$this->assertContains('<strong>Numéro de notice Koha : </strong>2774</li><br><li>', $this->_response->getBody());
}
}
class XslSearchResultDispatchWithEmptyTransformTest extends AbstractControllerTestCase {
protected $_storm_default_to_volatile = true;
public function setUp() {
parent::setUp();
Storm_Cache::beVolatile();
(new Storm_Cache)->clean();
Class_MoteurRecherche::resetInstance();
Zend_Registry::set('sql', $this->mock()
->whenCalled('fetchAll')
->answers([[5], ['T1']]));
$disk = $this->mock()
->whenCalled('directoryAt')
->answers(null)
->whenCalled('fileAt')
->answers((new Class_FileManager)
->setRealpath('tests/scenarios/Xsl/search_result.xsl'));
Class_FileManager::setFileSystem($disk);
$php_command = $this->mock()
->whenCalled('extension_loaded')
->answers(true)
->whenCalled('unlink')
->answers(true)
->whenCalled('libxml_use_internal_errors')
->answers(true)
->whenCalled('libxml_get_errors')
->answers([]);
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)
->whenCalled('transformToXml')
->answers('');
Class_Notice_Xsl::setXSLTProcessor($xslt_processor);
$profile = $this->fixture('Class_Profil',
['id' => 89]);
$profile->setCfgModulesPreferences(['xslt' => '/tests/scenarios/Xsl/search_result.xsl'],
'recherche',
'resultat',
'simple');
$profile->save();
$this->fixture('Class_Notice',
['id' => 5,
'type_doc' => 1,
'unimarc' => "01185nam0 2200217 450 0010005000000100031000050350016000360900009000520990038000611000041000991010008001402000036001482100013001842150011001973300660002083330010008686760006008787000028008848010026009129020029009382774 a2-84563-280-0d19,90 Euros aALOES355754 a2774 c2017-12-11d2018-03-16tLIVREx12 a20171211 frey50  afre aSeras-tu là ?fGuillaume Musso cXOd2012 a301 p. aUn seul geste aurait suffi pour tout changer. Qui n'a jamais rêvé de revenir à cet instant décisif où le bonheur était possible ? San Francisco. Elliott, médecin passionné, ne s'est jamais consolé de la disparition d'Ilena, la femme qu'il aimait, morte il y a trente ans. Un jour, par une circonstance extraordinaire, il est ramené en arrière et rencontre le jeune homme qu'il était, trente ans plus tôt. Il est revenu à l'instant décisif où un geste de lui peut sauver Ilena. Et modifier l'implacable destin qui a figé son sort à jamais. Un stupéfiant face-à-face, Une histoire d'amour bouleversante, Un suspense à couper le souffle. aAG 14 aR aMussobGuillaume960415 aFRbCALUIREc20060516 981440aroman francophone"]);
$this->dispatch('/opac/recherche/simple/liste_format/3/id_profil/89', true);
}
/** @test */
public function pageShouldContainEmptyTransformMessage() {
$this->assertXPathContentContains('//p[@class="error"]', 'a produit un résultat vide');
}
}
\ No newline at end of file
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment