7 use Test
::More tests
=> 3;
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({
23 address1
=> 'vendor address',
28 my $budget_id = C4
::Budgets
::AddBudget
({
29 budget_code
=> 'my_budget_code',
30 budget_name
=> 'My budget name',
32 my $budget = C4
::Budgets
::GetBudget
( $budget_id );
34 my $csv_profile = Koha
::CsvProfile
->new({
35 profile
=> 'my user profile',
36 type
=> 'export_basket',
38 content
=> 'autor=biblio.author|title=biblio.title|quantity=aqorders.quantity',
41 my $csv_profile2 = Koha
::CsvProfile
->new({
42 profile
=> 'my user profile',
43 type
=> 'export_basket',
45 content
=> 'biblio.author | title = biblio.title|quantity=aqorders.quantity',
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,
61 biblionumber
=> $biblionumber,
62 budget_id
=> $budget_id,
63 entrydate
=> '2016-01-02',
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();