Lines 19-25
Link Here
|
19 |
|
19 |
|
20 |
use Modern::Perl; |
20 |
use Modern::Perl; |
21 |
|
21 |
|
22 |
use Test::More tests => 41; |
22 |
use Test::More tests => 42; |
23 |
use Test::Warn; |
23 |
use Test::Warn; |
24 |
use Test::Exception; |
24 |
use Test::Exception; |
25 |
use Test::MockModule; |
25 |
use Test::MockModule; |
Lines 2121-2123
subtest 'extended_attributes' => sub {
Link Here
|
2121 |
|
2121 |
|
2122 |
$schema->storage->txn_rollback; |
2122 |
$schema->storage->txn_rollback; |
2123 |
}; |
2123 |
}; |
2124 |
- |
2124 |
|
|
|
2125 |
subtest 'filter_by_debts' => sub { |
2126 |
|
2127 |
plan tests => 7; |
2128 |
my $schema = Koha::Database->new->schema; |
2129 |
$schema->storage->txn_begin; |
2130 |
|
2131 |
my $library = $builder->build({source => 'Branch' }); |
2132 |
my $max_owing = 10; |
2133 |
|
2134 |
my $patrons = Koha::Patrons->filter_by_owings({ branchcode => $library->{branchcode}, amountoutstanding => { '>=' => $max_owing } }); |
2135 |
is(ref($patrons), 'Koha::Patrons', 'filter_by_owings returns set of Koha::Patrons'); |
2136 |
is($patrons->count, 0, 'Empty set of Koha::Patrons returned'); |
2137 |
|
2138 |
my $patron1 = $builder->build_object({ class => 'Koha::Patrons', value => { branchcode => $library->{branchcode} }}); |
2139 |
my $account1 = $patron1->account; |
2140 |
$account1->add_debit({ amount => 10, interface => 'commandline', type => 'OVERDUE', library_id => $library->{branchcode} }); |
2141 |
|
2142 |
my $patron2 = $builder->build_object({ class => 'Koha::Patrons', value => { branchcode => $library->{branchcode} }}); |
2143 |
my $account2 = $patron2->account; |
2144 |
$account2->add_debit({ amount => 10, interface => 'commandline', type => 'OVERDUE', library_id => $library->{branchcode} }); |
2145 |
|
2146 |
t::lib::Mocks::mock_userenv({ patron => $patron1 }); |
2147 |
|
2148 |
$patrons = Koha::Patrons->filter_by_owings({ branchcode => $library->{branchcode}, amountoutstanding => { '>=' => $max_owing } }); |
2149 |
is($patrons->count, 2, 'filter_by_debts() should return set of 2 patrons when filtered with amountoutstanding'); |
2150 |
|
2151 |
my $found_patron1 = $patrons->find($patron1->borrowernumber); |
2152 |
my $found_patron2 = $patrons->find($patron2->borrowernumber); |
2153 |
|
2154 |
is($found_patron1->borrowernumber, $patron1->borrowernumber, 'patron 1 returned'); |
2155 |
is($found_patron2->borrowernumber, $patron2->borrowernumber, 'patron 2 returned'); |
2156 |
|
2157 |
$account1->pay({ amount => 10, interface => 'commandline', library_id => $library->{branchcode}, manager_id => $patron1->borrowernumber }); |
2158 |
$patrons = Koha::Patrons->filter_by_owings({ branchcode => $library->{branchcode}, amountoutstanding => { '>=' => $max_owing } }); |
2159 |
|
2160 |
is( $patrons->count, 1, 'filter_by_debts() should return 1 patron when filtered with amountoutstanding'); |
2161 |
my $found_patron = $patrons->next; |
2162 |
is( $found_patron->borrowernumber, $patron2->borrowernumber, 'Only patron 2 returned'); |
2163 |
|
2164 |
$schema->storage->txn_rollback; |
2165 |
}; |