7 use Test::More tests => 3;
14 use Koha::Acquisition::Orders;
17 my $schema = Koha::Database->new()->schema();
18 $schema->storage->txn_begin();
20 my $query = CGI->new();
22 my $vendor = Koha::Acquisition::Bookseller->new({
24 address1 => 'vendor address',
29 my $budget_id = C4::Budgets::AddBudget({
30 budget_code => 'my_budget_code',
31 budget_name => 'My budget name',
33 my $budget = C4::Budgets::GetBudget( $budget_id );
35 my $csv_profile = Koha::CsvProfile->new({
36 profile => 'my user profile',
37 type => 'export_basket',
39 content => 'autor=biblio.author|title=biblio.title|quantity=aqorders.quantity',
40 description => 'csv profile',
43 my $csv_profile2 = Koha::CsvProfile->new({
44 profile => 'my user profile',
45 type => 'export_basket',
47 content => 'biblio.author | title = biblio.title|quantity=aqorders.quantity',
48 description => 'csv profile 2',
52 $basketno = NewBasket($vendor->id, 1);
54 my $biblio = MARC::Record->new();
55 $biblio->append_fields(
56 MARC::Field->new( '100', ' ', ' ', a => 'King, Stephen' ),
57 MARC::Field->new( '245', ' ', ' ', a => 'Test Record' ),
59 my ($biblionumber, $biblioitemnumber) = AddBiblio($biblio, '');
61 my $order = Koha::Acquisition::Order->new({
62 basketno => $basketno,
64 biblionumber => $biblionumber,
65 budget_id => $budget_id,
66 entrydate => '2016-01-02',
69 # Use user CSV profile
70 my $basket_csv1 = C4::Acquisition::GetBasketAsCSV($basketno, $query, $csv_profile->export_format_id);
71 is($basket_csv1, 'autor,title,quantity
72 "King, Stephen","Test Record",3
73 ', 'CSV should be generated with user profile');
75 # Use default template
76 t::lib::Mocks::mock_preference('delimiter', ',');
77 my $basket_csv2 = C4::Acquisition::GetBasketAsCSV($basketno, $query);
78 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
79 "",' . $order->ordernumber . ',2016-01-02,,"King, Stephen","Test Record",,"","","",3,,"",""
80 ', 'CSV should be generated with default template');
82 my $basket_csv3 = C4::Acquisition::GetBasketAsCSV($basketno, $query, $csv_profile2->export_format_id);
83 is($basket_csv3, 'biblio.author,title,quantity
84 "King, Stephen","Test Record",3
85 ', 'CSV should be generated with user profile which does not have all headers defined');
87 $schema->storage->txn_rollback();