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();
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({
type => 'export_basket',
csv_separator => ',',
content => 'biblio.author | title = biblio.title|quantity=aqorders.quantity',
+ description => 'csv profile 2',
})->store;
my $basketno;
', '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,,"",""
"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();