Bug 26232: Test for empty smart rule fine grace period
[koha.git] / t / Edifact.t
blob6dedeac3a22f14691d405553aac00e325ea204cd
1 #!/usr/bin/perl
2 use strict;
3 use warnings;
4 use FindBin qw( $Bin );
6 use Test::More tests => 35;
8 BEGIN { use_ok('Koha::Edifact') }
10 my $filename = "$Bin/edi_testfiles/prquotes_73050_20140430.CEQ";
12 my $quote = Koha::Edifact->new( { filename => $filename, } );
14 isa_ok( $quote, 'Koha::Edifact' );
16 my $x = $quote->interchange_header('sender');
17 is( $x, '5013546027856', "sender returned" );
19 $x = $quote->interchange_header('recipient');
20 is( $x, '5030670137480', "recipient returned" );
21 $x = $quote->interchange_header('datetime');
22 is( $x->[0], '140430', "datetime returned" );
23 my $control_reference = 'EDIQ2857763';
24 $x = $quote->interchange_header('interchange_control_reference');
25 is( $x, $control_reference, "interchange_control_reference returned" );
27 $x = $quote->interchange_header('application_reference');
28 is( $x, 'QUOTES', "application_reference returned" );
30 $x = $quote->interchange_trailer('interchange_control_count');
31 is( $x, 1, "interchange_control_count returned" );
33 my $msgs = $quote->message_array();
34 my $msg_count = @{$msgs};
35 is( $msg_count, 1, "correct message count returned" );
36 my $m = $msgs->[0];
38 is( $m->message_type, 'QUOTES', "Message shows correct type" );
39 is( $m->message_reference_number,
40 'MQ09791', "Message reference number returned" );
41 is( $m->docmsg_number, 'Q741588', "Message docmsg number returned" );
42 is( $m->message_date, '20140430', "Message date returned" );
43 is( $m->buyer_ean, '5030670137480', 'buyer ean returned');
45 my $lin = $m->lineitems();
47 my $num_lines = @{$lin};
48 is( $num_lines, 18, 'Correct number of lines in message' );
50 my $test_line = $lin->[-1];
52 is( $test_line->line_item_number, 18, 'correct line number returned' );
53 is( $test_line->item_number_id, '9780273761006', 'correct ean returned' );
54 is( $test_line->quantity, 1, 'quantity returned' );
56 my $test_title = 'International business [electronic resource]';
57 my $marcrec = $test_line->marc_record;
58 isa_ok( $marcrec, 'MARC::Record' );
60 my $title = $test_line->title();
62 # also tests components are concatenated
63 is( $title, $test_title, "Title returned" );
65 # problems currently with the record (needs leader ??)
66 #is( $marcrec->title(), $test_title, "Title returned from marc");
67 my $test_author = q{Rugman, Alan M.};
68 is( $test_line->author, $test_author, "Author returned" );
69 is( $test_line->publisher, 'Pearson Education', "Publisher returned" );
70 is( $test_line->publication_date, q{2012.}, "Pub. date returned" );
72 # Test data encoded in GIR
74 my $stock_category = $test_line->girfield('stock_category');
75 is( $stock_category, 'EBOOK', "stock_category returned" );
76 my $branch = $test_line->girfield('branch');
77 is( $branch, 'ELIB', "branch returned" );
78 my $fund_allocation = $test_line->girfield('fund_allocation');
79 is( $fund_allocation, '660BOO_2013', "fund_allocation returned" );
80 my $collection_code = $test_line->girfield('collection_code');
81 is( $collection_code, 'EBOO', "collection_code returned" );
83 #my $shelfmark = $test_line->girfield('shelfmark');
84 #my $classification = $test_line->girfield('classification');
86 ## text the free_text returned from the line
87 my $test_line_2 = $lin->[12];
89 my $ftx_string = 'E*610.72* - additional items';
91 is( $test_line_2->orderline_free_text, $ftx_string, "ftx note retrieved" );
93 my $filename2 = "$Bin/edi_testfiles/QUOTES_413514.CEQ";
95 my $q2 = Koha::Edifact->new( { filename => $filename2, } );
96 my $messages = $q2->message_array();
98 my $orderlines = $messages->[0]->lineitems();
100 my $ol = $orderlines->[0];
102 my $y = $ol->girfield( 'copy_value', 5 );
104 is( $y, undef, 'No extra item generated' );
106 $y = $ol->girfield( 'copy_value', 1 );
107 is( $y, '16.99', 'Copy Price returned' );
109 $y = $ol->girfield( 'classification', 4 );
110 is( $y, '914.1061', 'Copy classification returned' );
112 $y = $ol->girfield( 'fund_allocation', 4 );
113 is( $y, 'REF', 'Copy fund returned' );
115 $y = $ol->girfield( 'branch', 4 );
116 is( $y, 'SOU', 'Copy Branch returned' );
118 $y = $ol->girfield( 'collection_code', 4 );
119 is( $y, 'ANF', 'Collection code returned' );
121 $y = $ol->girfield( 'stock_category', 4 );
122 is( $y, 'RS', 'Copy stock category returned' );