Bug 14285: Bengali locale needs to be re-defined
[koha.git] / t / db_dependent / Circulation_issuingrules.t
blobf5abbda6b82ef259effc2f8b71613bbb496d4f45
1 #!/usr/bin/perl
3 use Modern::Perl;
5 use Test::More tests => 7;
6 use Test::MockModule;
7 use DBI;
8 use DateTime;
10 my $contextmodule = new Test::MockModule('C4::Context');
11 $contextmodule->mock('_new_dbh', sub {
12 my $dbh = DBI->connect( 'DBI:Mock:', '', '' )
13 || die "Cannot create handle: $DBI::errstr\n";
14 return $dbh
15 });
17 use_ok('C4::Circulation');
19 my $dbh = C4::Context->dbh();
21 my $issuelength = 10;
22 my $renewalperiod = 5;
23 my $lengthunit = 'days';
25 my $expected = {
26 issuelength => $issuelength,
27 renewalperiod => $renewalperiod,
28 lengthunit => $lengthunit
31 my $default = {
32 issuelength => 21,
33 renewalperiod => 21,
34 lengthunit => 'days'
37 my $loanlength;
38 my $mock_undef = [
42 my $mock_loan_length = [
43 ['issuelength', 'renewalperiod', 'lengthunit'],
44 [$issuelength, $renewalperiod, $lengthunit]
47 my $categorycode = 'B';
48 my $itemtype = 'MX';
49 my $branchcode = 'FPL';
51 #=== GetLoanLength
52 $dbh->{mock_add_resultset} = $mock_loan_length;
53 $loanlength = C4::Circulation::GetLoanLength($categorycode, $itemtype, $branchcode);
54 is_deeply($loanlength, $expected, 'first matches');
56 $dbh->{mock_add_resultset} = $mock_undef;
57 $loanlength = C4::Circulation::GetLoanLength($categorycode, $itemtype, $branchcode);
58 is_deeply($loanlength, $default, 'none matches');
60 #=== CalcDateDue
62 #Set syspref ReturnBeforeExpiry = 1 and useDaysMode = 'Days'
63 $contextmodule->mock('preference', sub {
64 my ($self, $syspref) = @_;
65 if ( $syspref eq "ReturnBeforeExpiry" ) {
66 return 1;
67 } elsif ( $syspref eq "useDaysMode" ) {
68 return 'Days';
69 } else {
70 return;
72 });
74 my $dateexpiry = '2013-01-01';
76 my $borrower = {categorycode => 'B', dateexpiry => $dateexpiry};
77 my $start_date = DateTime->new({year => 2013, month => 2, day => 9});
78 $dbh->{mock_add_resultset} = $mock_loan_length;
79 my $date = C4::Circulation::CalcDateDue( $start_date, $itemtype, $branchcode, $borrower );
80 is($date, $dateexpiry . 'T23:59:00', 'date expiry');
81 $dbh->{mock_add_resultset} = $mock_loan_length;
82 $date = C4::Circulation::CalcDateDue( $start_date, $itemtype, $branchcode, $borrower, 1 );
85 #Set syspref ReturnBeforeExpiry = 1 and useDaysMode != 'Days'
86 $contextmodule->mock('preference', sub {
87 my ($self, $syspref) = @_;
88 if ( $syspref eq "ReturnBeforeExpiry" ) {
89 return 1;
90 } elsif ( $syspref eq "useDaysMode" ) {
91 return 'noDays';
92 } else {
93 return;
95 });
97 $borrower = {categorycode => 'B', dateexpiry => $dateexpiry};
98 $start_date = DateTime->new({year => 2013, month => 2, day => 9});
99 $dbh->{mock_add_resultset} = $mock_loan_length;
100 $date = C4::Circulation::CalcDateDue( $start_date, $itemtype, $branchcode, $borrower );
101 is($date, $dateexpiry . 'T23:59:00', 'date expiry');
103 $dbh->{mock_add_resultset} = $mock_loan_length;
104 $date = C4::Circulation::CalcDateDue( $start_date, $itemtype, $branchcode, $borrower, 1 );
107 #Set syspref ReturnBeforeExpiry = 0 and useDaysMode = 'Days'
108 $contextmodule->mock('preference', sub {
109 my ($self, $syspref) = @_;
110 if ( $syspref eq "ReturnBeforeExpiry" ) {
111 return 0;
112 } elsif ( $syspref eq "useDaysMode" ) {
113 return 'Days';
114 } else {
115 return;
119 $borrower = {categorycode => 'B', dateexpiry => $dateexpiry};
120 $start_date = DateTime->new({year => 2013, month => 2, day => 9});
121 $dbh->{mock_add_resultset} = $mock_loan_length;
122 $date = C4::Circulation::CalcDateDue( $start_date, $itemtype, $branchcode, $borrower );
123 is($date, '2013-02-' . (9 + $issuelength) . 'T23:59:00', "date expiry ( 9 + $issuelength )");
125 $dbh->{mock_add_resultset} = $mock_loan_length;
126 $date = C4::Circulation::CalcDateDue( $start_date, $itemtype, $branchcode, $borrower, 1 );
127 is($date, '2013-02-' . (9 + $renewalperiod) . 'T23:59:00', "date expiry ( 9 + $renewalperiod )");