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

(-)a/t/Acquisition/Invoice.t (-7 / +4 lines)
Lines 1-17 Link Here
1
#!/usr/bin/perl
1
#!/usr/bin/perl
2
2
3
use Modern::Perl;
3
use Modern::Perl;
4
use C4::Context;
5
4
6
use Test::More tests => 50;
5
use Test::More tests => 50;
7
use Test::MockModule;
6
use Test::MockModule;
7
use t::lib::Mocks;
8
use C4::Context;
8
9
9
my $module = new Test::MockModule('C4::Context');
10
# Mock the DB connexion and C4::Context
10
$module->mock('_new_dbh', sub {
11
my $context = t::lib::Mocks::mock_dbh;
11
    my $dbh = DBI->connect( 'DBI:Mock:', '', '' )
12
        || die "Cannot create handle: $DBI::errstr\n";
13
    return $dbh;
14
});
15
12
16
my $dbh = C4::Context->dbh;
13
my $dbh = C4::Context->dbh;
17
14
(-)a/t/Barcodes_ValueBuilder.t (-6 / +5 lines)
Lines 1-20 Link Here
1
#!/usr/bin/perl
1
#!/usr/bin/perl
2
2
use strict;
3
use strict;
3
use warnings;
4
use warnings;
4
use DBI;
5
5
use Test::More tests => 10;
6
use Test::More tests => 10;
6
use Test::MockModule;
7
use Test::MockModule;
8
use t::lib::Mocks;
7
9
8
BEGIN {
10
BEGIN {
9
    use_ok('C4::Barcodes::ValueBuilder');
11
    use_ok('C4::Barcodes::ValueBuilder');
10
}
12
}
11
13
12
14
13
my $module = new Test::MockModule('C4::Context');
15
# Mock the DB connexion and C4::Context
14
$module->mock('_new_dbh', sub {
16
my $context = t::lib::Mocks::mock_dbh;
15
                             my $dbh = DBI->connect( 'DBI:Mock:', '', '' )
16
                             || die "Cannot create handle: $DBI::errstr\n";
17
                             return $dbh });
18
17
19
# Mock data
18
# Mock data
20
my $incrementaldata = [
19
my $incrementaldata = [
(-)a/t/Biblio.t (-10 / +3 lines)
Lines 20-40 use Modern::Perl; Link Here
20
use Test::More tests => 46;
20
use Test::More tests => 46;
21
use Test::MockModule;
21
use Test::MockModule;
22
use Test::Warn;
22
use Test::Warn;
23
use DBD::Mock;
23
use t::lib::Mocks;
24
24
25
BEGIN {
25
BEGIN {
26
        use_ok('C4::Biblio');
26
        use_ok('C4::Biblio');
27
}
27
}
28
28
29
my $context = new Test::MockModule('C4::Context');
29
# Mock the DB connexion and C4::Context
30
$context->mock(
30
my $context = t::lib::Mocks::mock_dbh;
31
    '_new_dbh',
32
    sub {
33
        my $dbh = DBI->connect( 'DBI:Mock:', '', '' )
34
          || die "Cannot create handle: $DBI::errstr\n";
35
        return $dbh;
36
    }
37
);
38
31
39
my @arr;
32
my @arr;
40
my $ret;
33
my $ret;
(-)a/t/Calendar.t (-11 / +5 lines)
Lines 2-12 Link Here
2
2
3
use strict;
3
use strict;
4
use warnings;
4
use warnings;
5
5
use DateTime;
6
use DateTime;
6
use DateTime::Duration;
7
use DateTime::Duration;
7
use Test::More tests => 35;
8
use Test::More tests => 35;
8
use Test::MockModule;
9
use Test::MockModule;
9
use DBD::Mock;
10
use t::lib::Mocks;
10
use Koha::DateUtils;
11
use Koha::DateUtils;
11
12
12
BEGIN {
13
BEGIN {
Lines 17-32 BEGIN { Link Here
17
    use_ok('C4::Calendar');
18
    use_ok('C4::Calendar');
18
}
19
}
19
20
20
my $module_context = new Test::MockModule('C4::Context');
21
# Mock the DB connexion and C4::Context
21
$module_context->mock(
22
my $module_context = t::lib::Mocks::mock_dbh;
22
    '_new_dbh',
23
    
23
    sub {
24
        my $dbh = DBI->connect( 'DBI:Mock:', '', '' )
25
          || die "Cannot create handle: $DBI::errstr\n";
26
        return $dbh;
27
    }
28
);
29
30
# We need to mock the C4::Context->preference method for
24
# We need to mock the C4::Context->preference method for
31
# simplicity and re-usability of the session definition. Any
25
# simplicity and re-usability of the session definition. Any
32
# syspref fits for syspref-agnostic tests.
26
# syspref fits for syspref-agnostic tests.
(-)a/t/Images.t (-9 / +5 lines)
Lines 4-25 Link Here
4
4
5
use strict;
5
use strict;
6
use warnings;
6
use warnings;
7
7
use Test::More tests => 7;
8
use Test::More tests => 7;
8
use Test::MockModule;
9
use Test::MockModule;
10
use t::lib::Mocks;
9
11
10
BEGIN {
12
BEGIN {
11
    use_ok('C4::Images');
13
    use_ok('C4::Images');
12
}
14
}
13
15
14
my $module = new Test::MockModule('C4::Context');
16
# Mock the DB connexion and C4::Context
15
$module->mock(
17
my $context = t::lib::Mocks::mock_dbh;
16
    '_new_dbh',
18
17
    sub {
18
        my $dbh = DBI->connect( 'DBI:Mock:', '', '' )
19
          || die "Cannot create handle: $DBI::errstr\n";
20
        return $dbh;
21
    }
22
);
23
my $images = [
19
my $images = [
24
    [ 'imagenumber', 'biblionumber', 'mimetype', 'imagefile', 'thumbnail' ],
20
    [ 'imagenumber', 'biblionumber', 'mimetype', 'imagefile', 'thumbnail' ],
25
    [ 1, 2, 'gif',  'red',  001, 000 ],
21
    [ 1, 2, 'gif',  'red',  001, 000 ],
(-)a/t/ItemType.t (-10 / +4 lines)
Lines 1-23 Link Here
1
#!/usr/bin/perl
1
#!/usr/bin/perl
2
2
3
use Modern::Perl;
3
use Modern::Perl;
4
use DBI;
4
5
use Test::More tests => 27;
5
use Test::More tests => 27;
6
use Test::MockModule;
6
use Test::MockModule;
7
use t::lib::Mocks;
7
8
8
BEGIN {
9
BEGIN {
9
    use_ok('C4::ItemType');
10
    use_ok('C4::ItemType');
10
}
11
}
11
12
12
my $module = new Test::MockModule('C4::Context');
13
# Mock the DB connexion and C4::Context
13
$module->mock(
14
my $context = t::lib::Mocks::mock_dbh;
14
    '_new_dbh',
15
    sub {
16
        my $dbh = DBI->connect( 'DBI:Mock:', '', '' )
17
          || die "Cannot create handle: $DBI::errstr\n";
18
        return $dbh;
19
    }
20
);
21
15
22
# Mock data
16
# Mock data
23
my $itemtypes = [
17
my $itemtypes = [
(-)a/t/Koha.t (-9 / +4 lines)
Lines 20-38 use Modern::Perl; Link Here
20
use C4::Context;
20
use C4::Context;
21
use Test::More tests => 29;
21
use Test::More tests => 29;
22
use Test::MockModule;
22
use Test::MockModule;
23
use t::lib::Mocks;
23
use DBD::Mock;
24
use DBD::Mock;
24
25
25
use_ok('C4::Koha');
26
use_ok('C4::Koha');
26
27
27
my $module_context = new Test::MockModule('C4::Context');
28
# Mock the DB connexion and C4::Context
28
$module_context->mock(
29
my $context = t::lib::Mocks::mock_dbh;
29
    '_new_dbh',
30
30
    sub {
31
        my $dbh = DBI->connect( 'DBI:Mock:', '', '' )
32
          || die "Cannot create handle: $DBI::errstr\n";
33
        return $dbh;
34
    }
35
);
36
31
37
SKIP: {
32
SKIP: {
38
33
(-)a/t/Letters.t (-10 / +4 lines)
Lines 17-35 Link Here
17
17
18
use Modern::Perl;
18
use Modern::Perl;
19
19
20
use DBI;
21
use Test::MockModule;
20
use Test::MockModule;
22
use Test::More tests => 5;
21
use Test::More tests => 5;
23
use t::lib::Mocks;
22
use t::lib::Mocks;
24
my $module = new Test::MockModule('C4::Context');
23
25
$module->mock(
24
# Mock the DB connexion and C4::Context
26
    '_new_dbh',
25
my $context = t::lib::Mocks::mock_dbh;
27
    sub {
26
28
        my $dbh = DBI->connect( 'DBI:Mock:', '', '' )
29
          || die "Cannot create handle: $DBI::errstr\n";
30
        return $dbh;
31
    }
32
);
33
my $mock_letters = [
27
my $mock_letters = [
34
    [ 'module', 'code', 'branchcode', 'name', 'is_html', 'title', 'content' ],
28
    [ 'module', 'code', 'branchcode', 'name', 'is_html', 'title', 'content' ],
35
    [ 'blah',   'ISBN', 'NBSI',       'book', 1,         'green', 'blahblah' ],
29
    [ 'blah',   'ISBN', 'NBSI',       'book', 1,         'green', 'blahblah' ],
(-)a/t/Matcher.t (-9 / +5 lines)
Lines 4-25 Link Here
4
4
5
use strict;
5
use strict;
6
use warnings;
6
use warnings;
7
7
use Test::More tests => 10;
8
use Test::More tests => 10;
8
use Test::MockModule;
9
use Test::MockModule;
10
use t::lib::Mocks;
9
11
10
BEGIN {
12
BEGIN {
11
    use_ok('C4::Matcher');
13
    use_ok('C4::Matcher');
12
}
14
}
13
15
14
my $module = new Test::MockModule('C4::Context');
16
# Mock the DB connexion and C4::Context
15
$module->mock(
17
my $context = t::lib::Mocks::mock_dbh;
16
    '_new_dbh',
18
17
    sub {
18
        my $dbh = DBI->connect( 'DBI:Mock:', '', '' )
19
          || die "Cannot create handle: $DBI::errstr\n";
20
        return $dbh;
21
    }
22
);
23
my $matcher = [
19
my $matcher = [
24
    [ 'matcher_id', 'code', 'description', 'record_type', 'threshold' ],
20
    [ 'matcher_id', 'code', 'description', 'record_type', 'threshold' ],
25
    [ 1,            'ISBN', 'ISBN',        'red',         1 ],
21
    [ 1,            'ISBN', 'ISBN',        'red',         1 ],
(-)a/t/Members/cardnumber.t (-11 / +3 lines)
Lines 1-23 Link Here
1
#!/usr/bin/env perl
1
#!/usr/bin/env perl
2
2
3
use Modern::Perl;
3
use Modern::Perl;
4
use Test::More tests => 23;
5
4
5
use Test::More tests => 23;
6
use Test::MockModule;
6
use Test::MockModule;
7
use DBD::Mock;
8
use t::lib::Mocks;
7
use t::lib::Mocks;
9
8
10
use_ok('C4::Members');
9
use_ok('C4::Members');
11
10
12
my $module_context = new Test::MockModule('C4::Context');
11
# Mock the DB connexion and C4::Context
13
$module_context->mock(
12
my $context = t::lib::Mocks::mock_dbh;
14
    '_new_dbh',
15
    sub {
16
        my $dbh = DBI->connect( 'DBI:Mock:', '', '' )
17
          || die "Cannot create handle: $DBI::errstr\n";
18
        return $dbh;
19
    }
20
);
21
13
22
my $dbh = C4::Context->dbh;
14
my $dbh = C4::Context->dbh;
23
my $rs = [];
15
my $rs = [];
(-)a/t/Members_AttributeTypes.t (-9 / +5 lines)
Lines 4-25 Link Here
4
4
5
use strict;
5
use strict;
6
use warnings;
6
use warnings;
7
7
use Test::MockModule;
8
use Test::MockModule;
8
use Test::More tests => 9;
9
use Test::More tests => 9;
10
use t::lib::Mocks;
9
11
10
BEGIN {
12
BEGIN {
11
    use_ok('C4::Members::AttributeTypes');
13
    use_ok('C4::Members::AttributeTypes');
12
}
14
}
13
15
14
my $module = new Test::MockModule('C4::Context');
16
# Mock the DB connexion and C4::Context
15
$module->mock(
17
my $context = t::lib::Mocks::mock_dbh;
16
    '_new_dbh',
18
17
    sub {
18
        my $dbh = DBI->connect( 'DBI:Mock:', '', '' )
19
          || die "Cannot create handle: $DBI::errstr\n";
20
        return $dbh;
21
    }
22
);
23
my $members_attributetypes = [
19
my $members_attributetypes = [
24
    [
20
    [
25
        'code',             'description',
21
        'code',             'description',
(-)a/t/SocialData.t (-9 / +5 lines)
Lines 4-25 Link Here
4
4
5
use strict;
5
use strict;
6
use warnings;
6
use warnings;
7
7
use Test::More tests => 5;
8
use Test::More tests => 5;
8
use Test::MockModule;
9
use Test::MockModule;
10
use t::lib::Mocks;
9
11
10
BEGIN {
12
BEGIN {
11
    use_ok('C4::SocialData');
13
    use_ok('C4::SocialData');
12
}
14
}
13
15
14
my $module = new Test::MockModule('C4::Context');
16
# Mock the DB connexion and C4::Context
15
$module->mock(
17
my $context = t::lib::Mocks::mock_dbh;
16
    '_new_dbh',
18
17
    sub {
18
        my $dbh = DBI->connect( 'DBI:Mock:', '', '' )
19
          || die "Cannot create handle: $DBI::errstr\n";
20
        return $dbh;
21
    }
22
);
23
my $socialdata = [
19
my $socialdata = [
24
    [
20
    [
25
        'isbn',            'num_critics',
21
        'isbn',            'num_critics',
(-)a/t/db_dependent/Circulation_issuingrules.t (-7 / +3 lines)
Lines 4-18 use Modern::Perl; Link Here
4
4
5
use Test::More tests => 7;
5
use Test::More tests => 7;
6
use Test::MockModule;
6
use Test::MockModule;
7
use DBI;
7
use t::lib::Mocks;
8
use DateTime;
8
use DateTime;
9
9
10
my $contextmodule = new Test::MockModule('C4::Context');
10
# Mock the DB connexion and C4::Context
11
$contextmodule->mock('_new_dbh', sub {
11
my $contextmodule = t::lib::Mocks::mock_dbh;
12
    my $dbh = DBI->connect( 'DBI:Mock:', '', '' )
13
    || die "Cannot create handle: $DBI::errstr\n";
14
    return $dbh
15
});
16
12
17
use_ok('C4::Circulation');
13
use_ok('C4::Circulation');
18
14
(-)a/t/db_dependent/Context.t (-9 / +4 lines)
Lines 5-10 use warnings; Link Here
5
5
6
use Test::More;
6
use Test::More;
7
use Test::MockModule;
7
use Test::MockModule;
8
use t::lib::Mocks;
8
use vars qw($debug $koha $dbh $config $ret);
9
use vars qw($debug $koha $dbh $config $ret);
9
10
10
use Koha::Database;
11
use Koha::Database;
Lines 63-77 foreach (sort @keys) { Link Here
63
ok($config = $koha->{config}, 'Getting $koha->{config} ');
64
ok($config = $koha->{config}, 'Getting $koha->{config} ');
64
65
65
# Testing syspref caching
66
# Testing syspref caching
66
my $module = new Test::MockModule('C4::Context');
67
67
$module->mock(
68
# Mock the DB connexion
68
    '_new_dbh',
69
t::lib::Mocks::mock_dbh;
69
    sub {
70
        my $dbh = DBI->connect( 'DBI:Mock:', '', '' )
71
          || die "Cannot create handle: $DBI::errstr\n";
72
        return $dbh;
73
    }
74
);
75
70
76
my $history;
71
my $history;
77
72
(-)a/t/db_dependent/ReportsGuided.t (-10 / +3 lines)
Lines 4-25 use Modern::Perl; Link Here
4
4
5
use Test::More tests => 13;
5
use Test::More tests => 13;
6
use Test::MockModule;
6
use Test::MockModule;
7
use DBD::Mock;
7
use t::lib::Mocks;
8
8
9
use_ok('C4::Reports::Guided');
9
use_ok('C4::Reports::Guided');
10
10
11
my $context = new Test::MockModule('C4::Context');
11
my $context = new Test::MockModule('C4::Context');
12
my $koha = new Test::MockModule('C4::Koha');
12
my $koha = new Test::MockModule('C4::Koha');
13
13
14
$context->mock(
14
# Mock the DB connexion and C4::Context
15
    '_new_dbh',
15
my $context = t::lib::Mocks::mock_dbh;
16
    sub {
17
        my $dbh = DBI->connect( 'DBI:Mock:', '', '' )
18
          || die "Cannot create handle: $DBI::errstr\n";
19
        return $dbh;
20
    }
21
);
22
23
16
24
sub MockedIsAuthorisedValueCategory {
17
sub MockedIsAuthorisedValueCategory {
25
    my $authorised_value = shift;
18
    my $authorised_value = shift;
(-)a/t/db_dependent/Search.t (-6 / +5 lines)
Lines 29-34 use open ':std', ':encoding(utf8)'; Link Here
29
29
30
use Test::More tests => 4;
30
use Test::More tests => 4;
31
use Test::MockModule;
31
use Test::MockModule;
32
use t::lib::Mocks;
32
use MARC::Record;
33
use MARC::Record;
33
use File::Spec;
34
use File::Spec;
34
use File::Basename;
35
use File::Basename;
Lines 36-42 use File::Find; Link Here
36
use Test::Warn;
37
use Test::Warn;
37
use File::Temp qw/ tempdir /;
38
use File::Temp qw/ tempdir /;
38
use File::Path;
39
use File::Path;
39
use DBI;
40
40
41
our $child;
41
our $child;
42
our $datadir;
42
our $datadir;
Lines 96-106 our $QueryFuzzy = 0; Link Here
96
our $QueryRemoveStopwords = 0;
96
our $QueryRemoveStopwords = 0;
97
our $UseQueryParser = 0;
97
our $UseQueryParser = 0;
98
our $marcflavour = 'MARC21';
98
our $marcflavour = 'MARC21';
99
our $contextmodule = new Test::MockModule('C4::Context');
99
100
$contextmodule->mock('_new_dbh', sub {
100
# Mock the DB connexion and C4::Context
101
    my $dbh = DBI->connect( 'DBI:Mock:', '', '' )
101
my $contextmodule = t::lib::Mocks::mock_dbh;
102
    || die "Cannot create handle: $DBI::errstr\n";
102
103
    return $dbh });
104
$contextmodule->mock('preference', sub {
103
$contextmodule->mock('preference', sub {
105
    my ($self, $pref) = @_;
104
    my ($self, $pref) = @_;
106
    if ($pref eq 'marcflavour') {
105
    if ($pref eq 'marcflavour') {
(-)a/t/lib/Mocks.pm (-6 / +9 lines)
Lines 38-50 sub mock_preference { Link Here
38
    });
38
    });
39
}
39
}
40
40
41
# Set mock on database handler
41
sub mock_dbh {
42
sub mock_dbh {
43
    my $mock_dbh = DBI->connect( 'DBI:Mock:', '', '' )
44
      || die "Cannot create handle: $DBI::errstr\n";
42
    my $context = new Test::MockModule('C4::Context');
45
    my $context = new Test::MockModule('C4::Context');
43
    $context->mock( '_new_dbh', sub {
46
    $context->mock(
44
        my $dbh = DBI->connect( 'DBI:Mock:', '', '' )
47
        'dbh',
45
          || die "Cannot create handle: $DBI::errstr\n";
48
        sub {
46
        return $dbh;
49
            return $mock_dbh;
47
    } );
50
        }
51
    );
48
    return $context;
52
    return $context;
49
}
53
}
50
54
51
- 

Return to bug 14375