View | Details | Raw Unified | Return to bug 34415
Collapse All | Expand All

(-)a/t/EdiTransport.t (-57 lines)
Lines 1-57 Link Here
1
#!/usr/bin/perl
2
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/;
8
9
BEGIN {
10
    if ( check_install( module => 'Test::DBIx::Class' ) ) {
11
        plan tests => 5;
12
    }
13
    else {
14
        plan skip_all => 'Need Test::DBIx::Class';
15
    }
16
17
}
18
19
use Test::DBIx::Class;
20
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' ],
27
    ],
28
  ],
29
  'add_fixtures';
30
31
my $filename = 'QUOTES_413514.CEQ';
32
33
my $db = Test::MockModule->new('Koha::Database');
34
$db->mock( _new_schema => sub { return Schema(); } );
35
36
use_ok('Koha::Edifact::Transport');
37
38
my $trans = Koha::Edifact::Transport->new(1);
39
40
isa_ok( $trans, 'Koha::Edifact::Transport' );
41
42
$trans->working_directory("$Bin/edi_testfiles");
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 = ResultSet('EdifactMessage')->count();
50
51
is( $cnt, 2, 'unique message name ingested' );
52
53
$trans->ingest( $mhash, $filename );    # try a repeat ingest
54
55
my $cnt2 = ResultSet('EdifactMessage')->count();
56
57
is( $cnt2, 2, 'duplicate message name not ingested' );
(-)a/t/db_dependent/Koha/Edifact/Transport.t (-1 / +61 lines)
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;

Return to bug 34415