Bug 20144: [sql_modes] Add default value for export_basket.description in tests
[koha.git] / t / db_dependent / Acquisition / GetBasketAsCSV.t
1 #!/usr/bin/perl
2
3 use Modern::Perl;
4
5 use CGI;
6
7 use Test::More tests => 3;
8
9 use C4::Acquisition;
10 use C4::Biblio;
11 use Koha::Database;
12 use Koha::CsvProfile;
13
14 use Koha::Acquisition::Orders;
15 use t::lib::Mocks;
16
17 my $schema = Koha::Database->new()->schema();
18 $schema->storage->txn_begin();
19
20 my $query = CGI->new();
21
22 my $vendor = Koha::Acquisition::Bookseller->new({
23     name => 'my vendor',
24     address1 => 'vendor address',
25     active => 1,
26     deliverytime => 5,
27 })->store;
28
29 my $budget_id = C4::Budgets::AddBudget({
30     budget_code => 'my_budget_code',
31     budget_name => 'My budget name',
32 });
33 my $budget = C4::Budgets::GetBudget( $budget_id );
34
35 my $csv_profile = Koha::CsvProfile->new({
36     profile => 'my user profile',
37     type => 'export_basket',
38     csv_separator => ',',
39     content => 'autor=biblio.author|title=biblio.title|quantity=aqorders.quantity',
40     description => 'csv profile',
41 })->store;
42
43 my $csv_profile2 = Koha::CsvProfile->new({
44     profile => 'my user profile',
45     type => 'export_basket',
46     csv_separator => ',',
47     content => 'biblio.author | title = biblio.title|quantity=aqorders.quantity',
48     description => 'csv profile 2',
49 })->store;
50
51 my $basketno;
52 $basketno = NewBasket($vendor->id, 1);
53
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' ),
58 );
59 my ($biblionumber, $biblioitemnumber) = AddBiblio($biblio, '');
60
61 my $order = Koha::Acquisition::Order->new({
62     basketno => $basketno,
63     quantity => 3,
64     biblionumber => $biblionumber,
65     budget_id => $budget_id,
66     entrydate => '2016-01-02',
67 })->store;
68
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');
74
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');
81
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');
86
87 $schema->storage->txn_rollback();