Bug 16330: Add routes to add, update and delete patrons
[koha.git] / t / Edifact.t
1 #!/usr/bin/perl
2 use strict;
3 use warnings;
4 use FindBin qw( $Bin );
5
6 use Test::More tests => 34;
7
8 BEGIN { use_ok('Koha::Edifact') }
9
10 my $filename = "$Bin/edi_testfiles/prquotes_73050_20140430.CEQ";
11
12 my $quote = Koha::Edifact->new( { filename => $filename, } );
13
14 isa_ok( $quote, 'Koha::Edifact' );
15
16 my $x = $quote->interchange_header('sender');
17 is( $x, '5013546027856', "sender returned" );
18
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" );
26
27 $x = $quote->interchange_header('application_reference');
28 is( $x, 'QUOTES', "application_reference returned" );
29
30 $x = $quote->interchange_trailer('interchange_control_count');
31 is( $x, 1, "interchange_control_count returned" );
32
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];
37
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
44 my $lin = $m->lineitems();
45
46 my $num_lines = @{$lin};
47 is( $num_lines, 18, 'Correct number of lines in message' );
48
49 my $test_line = $lin->[-1];
50
51 is( $test_line->line_item_number, 18, 'correct line number returned' );
52 is( $test_line->item_number_id, '9780273761006', 'correct ean returned' );
53 is( $test_line->quantity, 1, 'quantity returned' );
54
55 my $test_title = 'International business [electronic resource]';
56 my $marcrec    = $test_line->marc_record;
57 isa_ok( $marcrec, 'MARC::Record' );
58
59 my $title = $test_line->title();
60
61 # also tests components are concatenated
62 is( $title, $test_title, "Title returned" );
63
64 # problems currently with the record (needs leader ??)
65 #is( $marcrec->title(), $test_title, "Title returned from marc");
66 my $test_author = q{Rugman, Alan M.};
67 is( $test_line->author,           $test_author,        "Author returned" );
68 is( $test_line->publisher,        'Pearson Education', "Publisher returned" );
69 is( $test_line->publication_date, q{2012.},            "Pub. date returned" );
70 #
71 # Test data encoded in GIR
72 #
73 my $stock_category = $test_line->girfield('stock_category');
74 is( $stock_category, 'EBOOK', "stock_category returned" );
75 my $branch = $test_line->girfield('branch');
76 is( $branch, 'ELIB', "branch returned" );
77 my $fund_allocation = $test_line->girfield('fund_allocation');
78 is( $fund_allocation, '660BOO_2013', "fund_allocation returned" );
79 my $collection_code = $test_line->girfield('collection_code');
80 is( $collection_code, 'EBOO', "collection_code returned" );
81
82 #my $shelfmark = $test_line->girfield('shelfmark');
83 #my $classification = $test_line->girfield('classification');
84
85 ## text the free_text returned from the line
86 my $test_line_2 = $lin->[12];
87
88 my $ftx_string = 'E*610.72* - additional items';
89
90 is( $test_line_2->orderline_free_text, $ftx_string, "ftx note retrieved" );
91
92 my $filename2 = "$Bin/edi_testfiles/QUOTES_413514.CEQ";
93
94 my $q2 = Koha::Edifact->new( { filename => $filename2, } );
95 my $messages = $q2->message_array();
96
97 my $orderlines = $messages->[0]->lineitems();
98
99 my $ol = $orderlines->[0];
100
101 my $y = $ol->girfield( 'copy_value', 5 );
102
103 is( $y, undef, 'No extra item generated' );
104
105 $y = $ol->girfield( 'copy_value', 1 );
106 is( $y, '16.99', 'Copy Price returned' );
107
108 $y = $ol->girfield( 'classification', 4 );
109 is( $y, '914.1061', 'Copy classification returned' );
110
111 $y = $ol->girfield( 'fund_allocation', 4 );
112 is( $y, 'REF', 'Copy fund returned' );
113
114 $y = $ol->girfield( 'branch', 4 );
115 is( $y, 'SOU', 'Copy Branch returned' );
116
117 $y = $ol->girfield( 'collection_code', 4 );
118 is( $y, 'ANF', 'Collection code returned' );
119
120 $y = $ol->girfield( 'stock_category', 4 );
121 is( $y, 'RS', 'Copy stock category returned' );