Bug 17600: Standardize our EXPORT_OK
[srvgit] / t / db_dependent / Acquisition / GetBasketAsCSV.t
old mode 100644 (file)
new mode 100755 (executable)
index 130de06..ae79a8d
@@ -4,15 +4,17 @@ use Modern::Perl;
 
 use CGI;
 
-use Test::More tests => 3;
+use Test::More tests => 4;
 
-use C4::Acquisition;
-use C4::Biblio;
+use C4::Acquisition qw( NewBasket GetBasket GetBasketAsCSV );
+use C4::Biblio qw( AddBiblio );
 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();
 
@@ -36,6 +38,7 @@ my $csv_profile = Koha::CsvProfile->new({
     type => 'export_basket',
     csv_separator => ',',
     content => 'autor=biblio.author|title=biblio.title|quantity=aqorders.quantity',
+    description => 'csv profile',
 })->store;
 
 my $csv_profile2 = Koha::CsvProfile->new({
@@ -43,6 +46,7 @@ my $csv_profile2 = Koha::CsvProfile->new({
     type => 'export_basket',
     csv_separator => ',',
     content => 'biblio.author | title = biblio.title|quantity=aqorders.quantity',
+    description => 'csv profile 2',
 })->store;
 
 my $basketno;
@@ -70,6 +74,7 @@ is($basket_csv1, 'autor,title,quantity
 ', 'CSV should be generated with user profile');
 
 # Use default template
+t::lib::Mocks::mock_preference('CSVDelimiter', ',');
 my $basket_csv2 = C4::Acquisition::GetBasketAsCSV($basketno, $query);
 is($basket_csv2, 'Contract name,Order number,Entry date,ISBN,Author,Title,Publication year,Publisher,Collection title,Note for vendor,Quantity,RRP,Delivery place,Billing place
 "",' . $order->ordernumber  . ',2016-01-02,,"King, Stephen","Test Record",,"","","",3,,"",""
@@ -80,4 +85,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();