Line 0
Link Here
|
0 |
- |
1 |
#!/usr/bin/perl |
|
|
2 |
|
3 |
use Modern::Perl; |
4 |
use FindBin qw( $Bin ); |
5 |
use Test::More tests => 6; |
6 |
use Test::Warn; |
7 |
|
8 |
use t::lib::TestBuilder; |
9 |
|
10 |
use Koha::Database; |
11 |
|
12 |
use_ok('Koha::Edifact::Transport'); |
13 |
|
14 |
my $schema = Koha::Database->new->schema; |
15 |
my $builder = t::lib::TestBuilder->new; |
16 |
|
17 |
$schema->storage->txn_begin; |
18 |
|
19 |
my $account = $builder->build( |
20 |
{ |
21 |
source => 'VendorEdiAccount', |
22 |
value => { |
23 |
description => 'test vendor', transport => 'FILE', |
24 |
} |
25 |
} |
26 |
); |
27 |
$builder->build( |
28 |
{ |
29 |
source => 'EdifactMessage', |
30 |
value => { message_type => 'TEST', filename => 'duplicate', raw_msg => 'message_contents' } |
31 |
} |
32 |
); |
33 |
|
34 |
my $dirname = ( $Bin =~ /^(.*\/t\/)/ ? $1 . 'edi_testfiles/' : q{} ); |
35 |
my $filename = 'QUOTES_413514.CEQ'; |
36 |
ok( -e $dirname . $filename, 'File QUOTES_413514.CEQ found' ); |
37 |
|
38 |
my $trans = Koha::Edifact::Transport->new( $account->{id} ); |
39 |
|
40 |
isa_ok( $trans, 'Koha::Edifact::Transport' ); |
41 |
|
42 |
$trans->working_directory($dirname); |
43 |
|
44 |
my $mhash = $trans->message_hash(); |
45 |
$mhash->{message_type} = 'TEST'; # set a bogus message type |
46 |
|
47 |
$trans->ingest( $mhash, $filename ); |
48 |
|
49 |
my $cnt = $schema->resultset('EdifactMessage')->count(); |
50 |
|
51 |
is( $cnt, 2, 'unique message name ingested' ); |
52 |
|
53 |
# try a repeat ingest |
54 |
warning_like { $trans->ingest( $mhash, $filename ) } qr/skipping ingest of QUOTES_413514.CEQ/, |
55 |
'Warning on repeated ingest'; |
56 |
|
57 |
my $cnt2 = $schema->resultset('EdifactMessage')->count(); |
58 |
|
59 |
is( $cnt2, 2, 'duplicate message name not ingested' ); |
60 |
|
61 |
$schema->storage->txn_rollback; |