Bug 18720: Use exception instead of die in GetBasketAsCsv
authorJosef Moravec <josef.moravec@gmail.com>
Mon, 5 Jun 2017 09:55:12 +0000 (11:55 +0200)
committerFridolin Somers <fridolin.somers@biblibre.com>
Wed, 28 Nov 2018 13:34:18 +0000 (14:34 +0100)
Test plan:
prove t/db_dependent/Acquisition/GetBasketAsCSV.t

Signed-off-by: Andrew Isherwood <andrew.isherwood@ptfs-europe.com>

Signed-off-by: Katrin Fischer <katrin.fischer.83@web.de>

Signed-off-by: Nick Clemens <nick@bywatersolutions.com>
(cherry picked from commit 77ea4686395f88c9678c611a78e6db4fd4c04101)
Signed-off-by: Martin Renvoize <martin.renvoize@ptfs-europe.com>
(cherry picked from commit 1ee7a438b2dc18e2a202795bb4203b58a0c36674)
Signed-off-by: Fridolin Somers <fridolin.somers@biblibre.com>

C4/Acquisition.pm
t/db_dependent/Acquisition/GetBasketAsCSV.t

index 15a51dd..5c4219e 100644 (file)
@@ -31,6 +31,7 @@ use Koha::DateUtils qw( dt_from_string output_pref );
 use Koha::Acquisition::Booksellers;
 use Koha::Acquisition::Orders;
 use Koha::Biblios;
+use Koha::Exceptions;
 use Koha::Items;
 use Koha::Number::Price;
 use Koha::Libraries;
@@ -293,7 +294,7 @@ sub GetBasketAsCSV {
     my @rows;
     if ($csv_profile_id) {
         my $csv_profile = Koha::CsvProfiles->find( $csv_profile_id );
-        die "There is no valid csv profile given" unless $csv_profile;
+        Koha::Exceptions::ObjectNotFound->throw( 'There is no valid csv profile given') unless $csv_profile;
 
         my $csv = Text::CSV_XS->new({'quote_char'=>'"','escape_char'=>'"','sep_char'=>$csv_profile->csv_separator,'binary'=>1});
         my $csv_profile_content = $csv_profile->content;
index 6de23d1..c9d966f 100644 (file)
@@ -4,15 +4,16 @@ use Modern::Perl;
 
 use CGI;
 
-use Test::More tests => 3;
+use Test::More tests => 4;
 
 use C4::Acquisition;
 use C4::Biblio;
 use Koha::Database;
-use Koha::CsvProfile;
-
+use Koha::CsvProfiles;
 use Koha::Acquisition::Orders;
+
 use t::lib::Mocks;
+use Try::Tiny;
 
 my $schema = Koha::Database->new()->schema();
 $schema->storage->txn_begin();
@@ -82,4 +83,11 @@ is($basket_csv3, 'biblio.author,title,quantity
 "King, Stephen","Test Record",3
 ', 'CSV should be generated with user profile which does not have all headers defined');
 
+try {
+    my $basket_csv4 = C4::Acquisition::GetBasketAsCSV($basketno, $query, 'non_existant_profile_id');
+    fail("It is not possible to export basket using non-existant profile");
+} catch {
+    ok($_->isa("Koha::Exceptions::ObjectNotFound"), "Using non-existant profile should throw ObjectNotFound exception");
+};
+
 $schema->storage->txn_rollback();