From 8016d93c276fd77be58d96bc253059436c6fde60 Mon Sep 17 00:00:00 2001 From: gloas <gloas@afi-sa.fr> Date: Thu, 29 Sep 2022 17:05:19 +0200 Subject: [PATCH] fix 8.0.170 : record title with subtitle concat with two dots --- library/Class/Notice/Titles.php | 6 +- tests/library/Class/NoticeTest.php | 140 ++++++++++++++--------------- 2 files changed, 68 insertions(+), 78 deletions(-) diff --git a/library/Class/Notice/Titles.php b/library/Class/Notice/Titles.php index a6cdd5ac4ab..536b427392e 100644 --- a/library/Class/Notice/Titles.php +++ b/library/Class/Notice/Titles.php @@ -109,7 +109,7 @@ class Class_Notice_Titles { public function getAllTitlesAndSubtitlesAsArray() : array { $titles = $this->getAllTitlesAsArray(); - if ( $subtitles = $this->_getSubtitlesAsArray()) + if ( $subtitles = $this->getSubtitlesAsArray()) $subtitles = array_map(fn($subtitle) => ': ' . $subtitle, $subtitles); @@ -117,7 +117,7 @@ class Class_Notice_Titles { } - protected function _getSubtitlesAsArray() : array { + public function getSubtitlesAsArray() : array { $subtitles = []; foreach(Class_Profil::getCurrentProfil()->getZonesTitre() as $zone) if ($subtitle = $this->_getFirstSubfield($zone)) @@ -128,7 +128,7 @@ class Class_Notice_Titles { public function getSubtitle() : string { - return implode($this->_getSubtitlesAsArray()); + return implode(' : ', $this->getSubtitlesAsArray()); } diff --git a/tests/library/Class/NoticeTest.php b/tests/library/Class/NoticeTest.php index 5995965504d..31c1e30c0ca 100644 --- a/tests/library/Class/NoticeTest.php +++ b/tests/library/Class/NoticeTest.php @@ -1068,89 +1068,56 @@ class NoticeGetMatieresTest extends ModelTestCase { class NoticeTitleWithSeveral461Test extends ModelTestCase { public function titlesForUnimarc() { - return [ - [ - 'Le gros titre', - [ - [200, ['a' => 'Le gros titre']], - ] - ], - - - [ - 'le monde n° 2', - [ - [200, ['a' => 'le monde']], - [461, ['t' => 'le monde', 'v' => 2]], - ] - ], - - - [ - 'Harry Potter n° 5', - [ - [200, ['a' => 'Harry Potter']], - [461, ['v' => 5]], - ] - ], - - - [ - 'Cinéma n° 2 : Documentaire : le gros titre', - [ - [200, ['a' => 'le gros titre']], - [461, ['t' => 'Cinéma', 'v' => 2]], - [461, ['t' => 'Documentaire']] - ] - ], - - [ - 'le monde n° 2', - [ - [200, ['a' => 'le monde']], - [461, ['t' => '[le >monde<]', 'v' => 2]], - ] - ], - - - [ - 'le monde n° 2', - [ - [461, ['t' => 'le monde', 'v' => 2]], - ] - ], - - - [ - 'Cinéma n° 2 : Documentaire n° 3 : le gros titre', - [ - [200, ['a' => 'le gros titre']], + return [['Le gros titre', + [[200, ['a' => 'Le gros titre']]]], + + ['le monde n° 2', + [[200, ['a' => 'le monde']], + [461, ['t' => 'le monde', 'v' => 2]]]], + + ['Harry Potter n° 5', + [[200, ['a' => 'Harry Potter']], + [461, ['v' => 5]]]], + + ['Cinéma n° 2 : Documentaire : le gros titre', + [[200, ['a' => 'le gros titre']], [461, ['t' => 'Cinéma', 'v' => 2]], - [461, ['t' => 'Documentaire', 'v' => 3]] - ] - ], + [461, ['t' => 'Documentaire']]]], + ['le monde n° 2', + [[200, ['a' => 'le monde']], + [461, ['t' => '[le >monde<]', 'v' => 2]]]], + + ['le monde n° 2', + [[461, ['t' => 'le monde', 'v' => 2]]]], + + ['Cinéma n° 2 : Documentaire n° 3 : le gros titre', + [[200, ['a' => 'le gros titre']], + [461, ['t' => 'Cinéma', 'v' => 2]], + [461, ['t' => 'Documentaire', 'v' => 3]]]], - [ - 'Cinéma : Documentaire n° 9 novembre', - [ - [200, ['a' => 'Documentaire']], + ['Cinéma : Documentaire n° 9 novembre', + [[200, ['a' => 'Documentaire']], [461, ['t' => 'Cinéma']], - [461, ['t' => 'Documentaire', 'v' => '9 novembre']] - ] - ], - - [ - 'Le gros titre', - [ - [200, ['a' => 'Le gros titre']], - [461, ['t' => 'Le gros titre']], - ] - ], + [461, ['t' => 'Documentaire', 'v' => '9 novembre']]]], + + ['Le gros titre', + [[200, ['a' => 'Le gros titre']], + [461, ['t' => 'Le gros titre']]]] ]; } + public function titlesAndSubtitlesForUnimar() : array { + return array_merge($this->titlesForUnimarc(), + [['titre 461$t n° titre 461$v : titre 200$a : titre 461$o', + [[200, ['a' => 'titre 200$a']], + [461, ['t' => 'titre 461$t', + 'v' => 'titre 461$v', + 'o' => 'titre 461$o']]]]]); + } + + /** * @dataProvider titlesForUnimarc * @test @@ -1164,6 +1131,29 @@ class NoticeTitleWithSeveral461Test extends ModelTestCase { $this->assertEquals($expected_title, $record->getTitrePrincipal(' : ')); } + + + + /** + * @dataProvider titlesAndSubtitlesForUnimar + * @test + */ + public function shouldGenerateMainTitleAndSubtitle($expected_title, $zones) { + $this + ->fixture(Class_Profil::class, + ['id' => 1]) + ->setCfgModules(['recherche' => ['resultatsimple' => ['zones_titre' => '461$o']]]) + ->beCurrentProfil() + ->save(); + + $unimarc = (new Class_NoticeUnimarc_Fluent)->zoneWithContent('001', '1234'); + foreach($zones as $zone) + $unimarc->zoneWithChildren($zone[0], $zone[1]); + + $record = Class_Notice::newInstance(['unimarc' => $unimarc->render()]); + $this->assertEquals($expected_title, + $record->getTitreEtSousTitre(' : ')); + } } -- GitLab