From 10604e3ea59dfb91333baf51f50eb7665728d665 Mon Sep 17 00:00:00 2001 From: Ghislain Loas <ghislo@sandbox.pergame.net> Date: Tue, 3 Jun 2014 17:27:41 +0200 Subject: [PATCH] hotline 14019 fix export unimarc --- library/Class/NoticeUnimarc/Writer.php | 3 +- tests/library/Class/NoticeTest.php | 47 ++++++++++++++++++++++++-- 2 files changed, 45 insertions(+), 5 deletions(-) diff --git a/library/Class/NoticeUnimarc/Writer.php b/library/Class/NoticeUnimarc/Writer.php index 7fb188c52c2..f46be07ee08 100644 --- a/library/Class/NoticeUnimarc/Writer.php +++ b/library/Class/NoticeUnimarc/Writer.php @@ -542,7 +542,6 @@ class Class_NoticeUnimarc_Writer extends Class_NoticeUnimarc { $data .= $this->record_end; $inner_data_count = sizeof($inner_directory); - $inner_directory[0]['length']-=1; for($i = 1; $i < $inner_data_count; $i++) { $inner_directory[$i]['adress'] = $inner_directory[$i - 1]['length'] + $inner_directory[$i - 1]['adress']; } @@ -562,7 +561,7 @@ class Class_NoticeUnimarc_Writer extends Class_NoticeUnimarc { // mise à jour du guide // longueur de l'enregistrement iso2709 - $record_length = 24 + strlen($directory) + strlen($data); + $record_length = 24 + strlen($directory) + strlen($data) + 1; // statut de la notice $record_status = 'n'; // type de document diff --git a/tests/library/Class/NoticeTest.php b/tests/library/Class/NoticeTest.php index 243464844d9..f2cc30aa1b2 100644 --- a/tests/library/Class/NoticeTest.php +++ b/tests/library/Class/NoticeTest.php @@ -387,6 +387,24 @@ class NoticeStromaeTest extends Storm_Test_ModelTestCase { } + /** @test */ + public function baseAdresseLengthShouldBe673() { + $this->assertEquals(673, $this->getBaseAdresseLength()); + } + + + /** @test */ + public function fullLengthShouldBe2150() { + $this->assertEquals(2150, $this->getFullLength()); + } + + + /** @test */ + public function adressOfField5ShouldBe100() { + $this->assertEquals(99, $this->getFieldAdress(5)); + } + + /** @test */ public function tracksShouldContainsTaFete() { $this->assertEquals('Ta fête', $this->_tracks[1][1]['titre']); @@ -436,10 +454,33 @@ class NoticeStromaeTest extends Storm_Test_ModelTestCase { } } - protected function getDirectoryLength() { + protected function getFullLength() { + $datas = explode(' ',file_get_contents($this->_temp_file))[0]; + return (int) $datas; + } + + + protected function getDirectory() { $directory_with_first_data = substr_replace(explode(' ', file_get_contents($this->_temp_file))[4], "", -2); - $directory = explode('', file_get_contents($this->_temp_file))[0]; - return strlen($directory); + return explode('', $directory_with_first_data)[0]; + } + + + protected function getDirectoryLength() { + return strlen($this->getDirectory()); + } + + protected function getBaseAdresseLength() { + $datas = substr(substr(explode(' ',file_get_contents($this->_temp_file))[1], 2), 0, -1); + return (int) $datas; + } + + + protected function getFieldAdress($field_directory_position) { + $directory = $this->getDirectory(); + $directory_elements = str_split($directory, 12); + + return (int) substr($directory_elements[$field_directory_position], 7,12); } } -- GitLab