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

(-)a/t/db_dependent/Circulation/CalcDateDue.t (-23 / +17 lines)
Lines 7-37 use Test::MockModule; Link Here
7
use DBI;
7
use DBI;
8
use DateTime;
8
use DateTime;
9
use t::lib::Mocks;
9
use t::lib::Mocks;
10
10
use t::lib::TestBuilder;
11
BEGIN {
12
    t::lib::Mocks::mock_dbh;
13
}
14
11
15
use_ok('C4::Circulation');
12
use_ok('C4::Circulation');
16
13
17
my $dbh = C4::Context->dbh();
14
my $schema = Koha::Database->new->schema;
15
$schema->storage->txn_begin;
16
my $builder = t::lib::TestBuilder->new;
18
17
18
my $categorycode = 'B';
19
my $itemtype = 'MX';
20
my $branchcode = 'FPL';
19
my $issuelength = 10;
21
my $issuelength = 10;
20
my $renewalperiod = 5;
22
my $renewalperiod = 5;
21
my $lengthunit = 'days';
23
my $lengthunit = 'days';
22
24
23
my $mock_undef = [
25
Koha::Database->schema->resultset('Issuingrule')->create({
24
    []
26
  categorycode => $categorycode,
25
];
27
  itemtype => $itemtype,
26
28
  branchcode => $branchcode,
27
my $mock_loan_length = [
29
  issuelength => $issuelength,
28
    ['issuelength', 'renewalperiod', 'lengthunit'],
30
  renewalperiod => $renewalperiod,
29
    [$issuelength, $renewalperiod, $lengthunit]
31
  lengthunit => $lengthunit,
30
];
32
});
31
32
my $categorycode = 'B';
33
my $itemtype = 'MX';
34
my $branchcode = 'FPL';
35
33
36
#Set syspref ReturnBeforeExpiry = 1 and useDaysMode = 'Days'
34
#Set syspref ReturnBeforeExpiry = 1 and useDaysMode = 'Days'
37
t::lib::Mocks::mock_preference('ReturnBeforeExpiry', 1);
35
t::lib::Mocks::mock_preference('ReturnBeforeExpiry', 1);
Lines 41-50 my $dateexpiry = '2013-01-01'; Link Here
41
39
42
my $borrower = {categorycode => 'B', dateexpiry => $dateexpiry};
40
my $borrower = {categorycode => 'B', dateexpiry => $dateexpiry};
43
my $start_date = DateTime->new({year => 2013, month => 2, day => 9});
41
my $start_date = DateTime->new({year => 2013, month => 2, day => 9});
44
$dbh->{mock_add_resultset} = $mock_loan_length;
45
my $date = C4::Circulation::CalcDateDue( $start_date, $itemtype, $branchcode, $borrower );
42
my $date = C4::Circulation::CalcDateDue( $start_date, $itemtype, $branchcode, $borrower );
46
is($date, $dateexpiry . 'T23:59:00', 'date expiry');
43
is($date, $dateexpiry . 'T23:59:00', 'date expiry');
47
$dbh->{mock_add_resultset} = $mock_loan_length;
48
$date = C4::Circulation::CalcDateDue( $start_date, $itemtype, $branchcode, $borrower, 1 );
44
$date = C4::Circulation::CalcDateDue( $start_date, $itemtype, $branchcode, $borrower, 1 );
49
45
50
46
Lines 54-64 t::lib::Mocks::mock_preference('useDaysMode', 'noDays'); Link Here
54
50
55
$borrower = {categorycode => 'B', dateexpiry => $dateexpiry};
51
$borrower = {categorycode => 'B', dateexpiry => $dateexpiry};
56
$start_date = DateTime->new({year => 2013, month => 2, day => 9});
52
$start_date = DateTime->new({year => 2013, month => 2, day => 9});
57
$dbh->{mock_add_resultset} = $mock_loan_length;
58
$date = C4::Circulation::CalcDateDue( $start_date, $itemtype, $branchcode, $borrower );
53
$date = C4::Circulation::CalcDateDue( $start_date, $itemtype, $branchcode, $borrower );
59
is($date, $dateexpiry . 'T23:59:00', 'date expiry');
54
is($date, $dateexpiry . 'T23:59:00', 'date expiry');
60
55
61
$dbh->{mock_add_resultset} = $mock_loan_length;
62
$date = C4::Circulation::CalcDateDue( $start_date, $itemtype, $branchcode, $borrower, 1 );
56
$date = C4::Circulation::CalcDateDue( $start_date, $itemtype, $branchcode, $borrower, 1 );
63
57
64
58
Lines 68-77 t::lib::Mocks::mock_preference('useDaysMode', 'Days'); Link Here
68
62
69
$borrower = {categorycode => 'B', dateexpiry => $dateexpiry};
63
$borrower = {categorycode => 'B', dateexpiry => $dateexpiry};
70
$start_date = DateTime->new({year => 2013, month => 2, day => 9});
64
$start_date = DateTime->new({year => 2013, month => 2, day => 9});
71
$dbh->{mock_add_resultset} = $mock_loan_length;
72
$date = C4::Circulation::CalcDateDue( $start_date, $itemtype, $branchcode, $borrower );
65
$date = C4::Circulation::CalcDateDue( $start_date, $itemtype, $branchcode, $borrower );
73
is($date, '2013-02-' . (9 + $issuelength) . 'T23:59:00', "date expiry ( 9 + $issuelength )");
66
is($date, '2013-02-' . (9 + $issuelength) . 'T23:59:00', "date expiry ( 9 + $issuelength )");
74
67
75
$dbh->{mock_add_resultset} = $mock_loan_length;
76
$date = C4::Circulation::CalcDateDue( $start_date, $itemtype, $branchcode, $borrower, 1 );
68
$date = C4::Circulation::CalcDateDue( $start_date, $itemtype, $branchcode, $borrower, 1 );
77
is($date, '2013-02-' . (9 + $renewalperiod) . 'T23:59:00', "date expiry ( 9 + $renewalperiod )");
69
is($date, '2013-02-' . (9 + $renewalperiod) . 'T23:59:00', "date expiry ( 9 + $renewalperiod )");
70
71
$schema->storage->txn_rollback;
(-)a/t/lib/Mocks.pm (-10 lines)
Lines 41-53 sub mock_preference { Link Here
41
    });
41
    });
42
}
42
}
43
43
44
sub mock_dbh {
45
    our $context = new Test::MockModule('Koha::Database');
46
    $context->mock( '_new_schema', sub {
47
        my $dbh = Koha::Schema->connect( 'DBI:Mock:', '', '' );
48
        return $dbh;
49
    } );
50
    return $context;
51
}
52
53
1;
44
1;
54
- 

Return to bug 18226