Bug 18839: Suggestion.pl spelling mistake
[koha.git] / t / Edifact.t
blobcc205393aebbffe48ca91c317bbe24b0e7982bab
1 #!/usr/bin/perl
2 use strict;
3 use warnings;
4 use FindBin qw( $Bin );
6 use Test::More tests => 34;
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" );
44 my $lin = $m->lineitems();
46 my $num_lines = @{$lin};
47 is( $num_lines, 18, 'Correct number of lines in message' );
49 my $test_line = $lin->[-1];
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' );
55 my $test_title = 'International business [electronic resource]';
56 my $marcrec = $test_line->marc_record;
57 isa_ok( $marcrec, 'MARC::Record' );
59 my $title = $test_line->title();
61 # also tests components are concatenated
62 is( $title, $test_title, "Title returned" );
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" );
71 # Test data encoded in GIR
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" );
82 #my $shelfmark = $test_line->girfield('shelfmark');
83 #my $classification = $test_line->girfield('classification');
85 ## text the free_text returned from the line
86 my $test_line_2 = $lin->[12];
88 my $ftx_string = 'E*610.72* - additional items';
90 is( $test_line_2->orderline_free_text, $ftx_string, "ftx note retrieved" );
92 my $filename2 = "$Bin/edi_testfiles/QUOTES_413514.CEQ";
94 my $q2 = Koha::Edifact->new( { filename => $filename2, } );
95 my $messages = $q2->message_array();
97 my $orderlines = $messages->[0]->lineitems();
99 my $ol = $orderlines->[0];
101 my $y = $ol->girfield( 'copy_value', 5 );
103 is( $y, undef, 'No extra item generated' );
105 $y = $ol->girfield( 'copy_value', 1 );
106 is( $y, '16.99', 'Copy Price returned' );
108 $y = $ol->girfield( 'classification', 4 );
109 is( $y, '914.1061', 'Copy classification returned' );
111 $y = $ol->girfield( 'fund_allocation', 4 );
112 is( $y, 'REF', 'Copy fund returned' );
114 $y = $ol->girfield( 'branch', 4 );
115 is( $y, 'SOU', 'Copy Branch returned' );
117 $y = $ol->girfield( 'collection_code', 4 );
118 is( $y, 'ANF', 'Collection code returned' );
120 $y = $ol->girfield( 'stock_category', 4 );
121 is( $y, 'RS', 'Copy stock category returned' );