Bug 26922: Regression tests
[koha.git] / t / EdiTransport.t
blobfb2442ea7e739831848c91968388a8dfca3f7d5f
1 #!/usr/bin/perl
3 use Modern::Perl;
4 use FindBin qw( $Bin );
5 use Test::More;
6 use Test::MockModule;
7 use Module::Load::Conditional qw/check_install/;
9 BEGIN {
10 if ( check_install( module => 'Test::DBIx::Class' ) ) {
11 plan tests => 5;
13 else {
14 plan skip_all => 'Need Test::DBIx::Class';
19 use Test::DBIx::Class;
21 fixtures_ok [
22 VendorEdiAccount =>
23 [ [ 'id', 'description', 'transport' ], [ 1, 'test vendor', 'FILE' ], ],
24 EdifactMessage => [
25 [ 'message_type', 'filename', 'raw_msg' ],
26 [ 'TEST', 'duplicate', 'message_contents' ],
29 'add_fixtures';
31 my $filename = 'QUOTES_413514.CEQ';
33 my $db = Test::MockModule->new('Koha::Database');
34 $db->mock( _new_schema => sub { return Schema(); } );
36 use_ok('Koha::Edifact::Transport');
38 my $trans = Koha::Edifact::Transport->new(1);
40 isa_ok( $trans, 'Koha::Edifact::Transport' );
42 $trans->working_directory("$Bin/edi_testfiles");
44 my $mhash = $trans->message_hash();
45 $mhash->{message_type} = 'TEST'; # set a bogus message type
47 $trans->ingest( $mhash, $filename );
49 my $cnt = ResultSet('EdifactMessage')->count();
51 is( $cnt, 2, 'unique message name ingested' );
53 $trans->ingest( $mhash, $filename ); # try a repeat ingest
55 my $cnt2 = ResultSet('EdifactMessage')->count();
57 is( $cnt2, 2, 'duplicate message name not ingested' );