Bug 18917: Use font-awesome buttons for CSV profiles
[koha.git] / t / db_dependent / Acquisition / GetBasketAsCSV.t
blob33e6f163ef46a706b8f4be6b3e14e5e6e7b3f8a8
1 #!/usr/bin/perl
3 use Modern::Perl;
5 use CGI;
7 use Test::More tests => 3;
9 use C4::Acquisition;
10 use C4::Biblio;
11 use Koha::Database;
12 use Koha::CsvProfile;
14 use Koha::Acquisition::Order;
16 my $schema = Koha::Database->new()->schema();
17 $schema->storage->txn_begin();
19 my $query = CGI->new();
21 my $vendor = Koha::Acquisition::Bookseller->new({
22 name => 'my vendor',
23 address1 => 'vendor address',
24 active => 1,
25 deliverytime => 5,
26 })->store;
28 my $budget_id = C4::Budgets::AddBudget({
29 budget_code => 'my_budget_code',
30 budget_name => 'My budget name',
31 });
32 my $budget = C4::Budgets::GetBudget( $budget_id );
34 my $csv_profile = Koha::CsvProfile->new({
35 profile => 'my user profile',
36 type => 'export_basket',
37 csv_separator => ',',
38 content => 'autor=biblio.author|title=biblio.title|quantity=aqorders.quantity',
39 })->store;
41 my $csv_profile2 = Koha::CsvProfile->new({
42 profile => 'my user profile',
43 type => 'export_basket',
44 csv_separator => ',',
45 content => 'biblio.author | title = biblio.title|quantity=aqorders.quantity',
46 })->store;
48 my $basketno;
49 $basketno = NewBasket($vendor->id, 1);
51 my $biblio = MARC::Record->new();
52 $biblio->append_fields(
53 MARC::Field->new( '100', ' ', ' ', a => 'King, Stephen' ),
54 MARC::Field->new( '245', ' ', ' ', a => 'Test Record' ),
56 my ($biblionumber, $biblioitemnumber) = AddBiblio($biblio, '');
58 my $order = Koha::Acquisition::Order->new({
59 basketno => $basketno,
60 quantity => 3,
61 biblionumber => $biblionumber,
62 budget_id => $budget_id,
63 entrydate => '2016-01-02',
64 })->insert;
66 # Use user CSV profile
67 my $basket_csv1 = C4::Acquisition::GetBasketAsCSV($basketno, $query, $csv_profile->export_format_id);
68 is($basket_csv1, 'autor,title,quantity
69 "King, Stephen","Test Record",3
70 ', 'CSV should be generated with user profile');
72 # Use default template
73 my $basket_csv2 = C4::Acquisition::GetBasketAsCSV($basketno, $query);
74 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
75 "",' . $order->{ordernumber} . ',2016-01-02,,"King, Stephen","Test Record",,"","","",3,,"",""
76 ', 'CSV should be generated with default template');
78 my $basket_csv3 = C4::Acquisition::GetBasketAsCSV($basketno, $query, $csv_profile2->export_format_id);
79 is($basket_csv3, 'biblio.author,title,quantity
80 "King, Stephen","Test Record",3
81 ', 'CSV should be generated with user profile which does not have all headers defined');
83 $schema->storage->txn_rollback();