From 53a301b8f20ba285c8e483aa6d5a3b2539380ccb Mon Sep 17 00:00:00 2001 From: Zach Sim Date: Mon, 17 Jan 2011 16:14:22 +1300 Subject: [PATCH] Bug 5327 - Adding UNIT Tests. Squashed commit of the following: commit 146d14665c52edaa85e38b70aabc9d52be5d64b6 Author: Zach Sim Date: Mon Jan 17 16:07:24 2011 +1300 Edited DisplayISBN to cleanup the ISBN using _isbn_cleanup if it is not 13 or 10 digits long. commit ba97b26d9a25470b0717cdd60a3d4f7a5c459ca9 Author: Zach Sim Date: Mon Jan 17 16:06:14 2011 +1300 Added extra unit tests to test C4::Koha::DisplayISBN. Signed-off-by: Chris Cormack --- C4/Koha.pm | 3 +++ t/Koha.t | 12 +++++++++++- 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/C4/Koha.pm b/C4/Koha.pm index d10c52e4f5..f2931a3e6e 100644 --- a/C4/Koha.pm +++ b/C4/Koha.pm @@ -115,6 +115,9 @@ sub slashifyDate { sub DisplayISBN { my ($isbn) = @_; + if (!length ($isbn)==13 && !length ($isbn)==10) { + $isbn=_isbn_cleanup($isbn); + } if (length ($isbn)<13){ my $seg1; if ( substr( $isbn, 0, 1 ) <= 7 ) { diff --git a/t/Koha.t b/t/Koha.t index be5a83800d..331bb4eef7 100755 --- a/t/Koha.t +++ b/t/Koha.t @@ -2,7 +2,7 @@ use strict; use warnings; -use Test::More tests => 8; +use Test::More tests => 12; use_ok('C4::Koha'); @@ -11,6 +11,10 @@ use_ok('C4::Koha'); # my $date = "01/01/2002"; my $newdate = &slashifyDate("2002-01-01"); +my $isbn13 = "9780330356473"; +my $isbn13D = "978-0-330-35647-3"; +my $isbn10 = "033035647X"; +my $isbn10D = "0-330-35647-X"; ok($date eq $newdate, 'slashifyDate'); @@ -23,3 +27,9 @@ is($str, q{'"&<>'}, '... and does not change input in place'); is(C4::Koha::_isbn_cleanup('0-590-35340-3'), '0590353403', '_isbn_cleanup removes hyphens'); is(C4::Koha::_isbn_cleanup('0590353403 (pbk.)'), '0590353403', '_isbn_cleanup removes parenthetical'); is(C4::Koha::_isbn_cleanup('978-0-321-49694-2'), '0321496949', '_isbn_cleanup converts ISBN-13 to ISBN-10'); + +is(C4::Koha::DisplayISBN($isbn13),$isbn13D,'DisplayISBN splits an ISBN-13 into 5 segments'); +is(C4::Koha::DisplayISBN($isbn10),$isbn10D,'DisplayISBN splits an ISBN-10 into 4 segments'); + +is(C4::Koha::DisplayISBN('9780330356473'),$isbn13D,'DisplayISBN splits an ISBN-13 into 5 segments after fixing the ISBN by using _isbn_cleanup'); +is(C4::Koha::DisplayISBN('033035647X'),$isbn10D,'DisplayISBN splits an ISBN-10 into 4 segments after fixing the ISBN by using _isbn_cleanup'); -- 2.39.5