|
Lines 20-26
Link Here
|
| 20 |
use Modern::Perl; |
20 |
use Modern::Perl; |
| 21 |
|
21 |
|
| 22 |
use Test::NoWarnings; |
22 |
use Test::NoWarnings; |
| 23 |
use Test::More tests => 48; |
23 |
use Test::More tests => 49; |
| 24 |
use Test::Warn; |
24 |
use Test::Warn; |
| 25 |
use Test::Exception; |
25 |
use Test::Exception; |
| 26 |
use Test::MockModule; |
26 |
use Test::MockModule; |
|
Lines 502-508
subtest 'renew_account' => sub {
Link Here
|
| 502 |
); |
502 |
); |
| 503 |
my $number_of_logs = |
503 |
my $number_of_logs = |
| 504 |
$schema->resultset('ActionLog') |
504 |
$schema->resultset('ActionLog') |
| 505 |
->search( { module => 'MEMBERS', action => 'RENEW', object => $retrieved_patron->borrowernumber } )->count; |
505 |
->search( { module => 'MEMBERS', action => 'RENEW', object => $retrieved_patron->borrowernumber } ) |
|
|
506 |
->count; |
| 506 |
is( $number_of_logs, 1, 'With BorrowersLog, Koha::Patron->renew_account should have logged' ); |
507 |
is( $number_of_logs, 1, 'With BorrowersLog, Koha::Patron->renew_account should have logged' ); |
| 507 |
|
508 |
|
| 508 |
t::lib::Mocks::mock_preference( 'BorrowerRenewalPeriodBase', 'now' ); |
509 |
t::lib::Mocks::mock_preference( 'BorrowerRenewalPeriodBase', 'now' ); |
|
Lines 518-524
subtest 'renew_account' => sub {
Link Here
|
| 518 |
is( dt_from_string($retrieved_expiry_date), $a_year_later, "today + 12 months must be $a_year_later" ); |
519 |
is( dt_from_string($retrieved_expiry_date), $a_year_later, "today + 12 months must be $a_year_later" ); |
| 519 |
$number_of_logs = |
520 |
$number_of_logs = |
| 520 |
$schema->resultset('ActionLog') |
521 |
$schema->resultset('ActionLog') |
| 521 |
->search( { module => 'MEMBERS', action => 'RENEW', object => $retrieved_patron->borrowernumber } )->count; |
522 |
->search( { module => 'MEMBERS', action => 'RENEW', object => $retrieved_patron->borrowernumber } ) |
|
|
523 |
->count; |
| 522 |
is( $number_of_logs, 1, 'Without BorrowersLog, Koha::Patron->renew_account should not have logged' ); |
524 |
is( $number_of_logs, 1, 'Without BorrowersLog, Koha::Patron->renew_account should not have logged' ); |
| 523 |
|
525 |
|
| 524 |
t::lib::Mocks::mock_preference( 'BorrowerRenewalPeriodBase', 'combination' ); |
526 |
t::lib::Mocks::mock_preference( 'BorrowerRenewalPeriodBase', 'combination' ); |
|
Lines 654-660
subtest "delete" => sub {
Link Here
|
| 654 |
|
656 |
|
| 655 |
my $number_of_logs = |
657 |
my $number_of_logs = |
| 656 |
$schema->resultset('ActionLog') |
658 |
$schema->resultset('ActionLog') |
| 657 |
->search( { module => 'MEMBERS', action => 'DELETE', object => $patron->borrowernumber } )->count; |
659 |
->search( { module => 'MEMBERS', action => 'DELETE', object => $patron->borrowernumber } ) |
|
|
660 |
->count; |
| 658 |
is( $number_of_logs, 1, 'With BorrowersLog, Koha::Patron->delete should have logged' ); |
661 |
is( $number_of_logs, 1, 'With BorrowersLog, Koha::Patron->delete should have logged' ); |
| 659 |
|
662 |
|
| 660 |
# Test deletion with designated fallback owner |
663 |
# Test deletion with designated fallback owner |
|
Lines 727-733
subtest 'add_enrolment_fee_if_needed' => sub {
Link Here
|
| 727 |
foreach ( keys %{$enrolmentfees} ) { |
730 |
foreach ( keys %{$enrolmentfees} ) { |
| 728 |
( Koha::Patron::Categories->find($_) |
731 |
( Koha::Patron::Categories->find($_) |
| 729 |
// $builder->build_object( { class => 'Koha::Patron::Categories', value => { categorycode => $_ } } ) ) |
732 |
// $builder->build_object( { class => 'Koha::Patron::Categories', value => { categorycode => $_ } } ) ) |
| 730 |
->enrolmentfee( $enrolmentfees->{$_} )->store; |
733 |
->enrolmentfee( $enrolmentfees->{$_} ) |
|
|
734 |
->store; |
| 731 |
} |
735 |
} |
| 732 |
my $enrolmentfee_K = $enrolmentfees->{K}; |
736 |
my $enrolmentfee_K = $enrolmentfees->{K}; |
| 733 |
my $enrolmentfee_J = $enrolmentfees->{J}; |
737 |
my $enrolmentfee_J = $enrolmentfees->{J}; |
|
Lines 1547-1552
subtest 'search_patrons_to_anonymise' => sub {
Link Here
|
| 1547 |
t::lib::Mocks::mock_preference( 'IndependentBranches', 0 ); |
1551 |
t::lib::Mocks::mock_preference( 'IndependentBranches', 0 ); |
| 1548 |
}; |
1552 |
}; |
| 1549 |
|
1553 |
|
|
|
1554 |
subtest 'anonymize items_last_borrower' => sub { |
| 1555 |
plan tests => 2; |
| 1556 |
|
| 1557 |
my $anonymous = $builder->build_object( { class => 'Koha::Patrons', }, ); |
| 1558 |
|
| 1559 |
t::lib::Mocks::mock_preference( 'AnonymousPatron', $anonymous->borrowernumber ); |
| 1560 |
t::lib::Mocks::mock_preference( 'StoreLastBorrower', 1 ); |
| 1561 |
t::lib::Mocks::mock_preference( 'AnonymizeLastBorrower', 1 ); |
| 1562 |
|
| 1563 |
subtest 'anonymize items_last_borrower by days' => sub { |
| 1564 |
plan tests => 4; |
| 1565 |
|
| 1566 |
t::lib::Mocks::mock_preference( 'AnonymizeLastBorrowerDays', 5 ); |
| 1567 |
|
| 1568 |
my $patron = $builder->build_object( |
| 1569 |
{ |
| 1570 |
class => 'Koha::Patrons', |
| 1571 |
value => { privacy => 1, } |
| 1572 |
} |
| 1573 |
); |
| 1574 |
my $item_1 = $builder->build_sample_item; |
| 1575 |
my $issue_1 = $builder->build_object( |
| 1576 |
{ |
| 1577 |
class => 'Koha::Checkouts', |
| 1578 |
value => { |
| 1579 |
borrowernumber => $patron->borrowernumber, |
| 1580 |
itemnumber => $item_1->itemnumber, |
| 1581 |
}, |
| 1582 |
} |
| 1583 |
); |
| 1584 |
my $item_2 = $builder->build_sample_item; |
| 1585 |
my $issue_2 = $builder->build_object( |
| 1586 |
{ |
| 1587 |
class => 'Koha::Checkouts', |
| 1588 |
value => { |
| 1589 |
borrowernumber => $patron->borrowernumber, |
| 1590 |
itemnumber => $item_2->itemnumber, |
| 1591 |
}, |
| 1592 |
} |
| 1593 |
); |
| 1594 |
|
| 1595 |
my $dbh = C4::Context->dbh; |
| 1596 |
my ($returned_1) = C4::Circulation::AddReturn( $item_1->barcode, undef, undef, dt_from_string ); |
| 1597 |
my ($returned_2) = C4::Circulation::AddReturn( $item_2->barcode, undef, undef, dt_from_string ); |
| 1598 |
is( $returned_1 && $returned_2, 1, 'The items should have been returned' ); |
| 1599 |
my $stu = $dbh->prepare(q|UPDATE items_last_borrower set created_on = ? where itemnumber = ?|); |
| 1600 |
$stu->execute( DateTime->today( time_zone => C4::Context->tz() )->add( days => -6 ), $item_2->itemnumber ); |
| 1601 |
|
| 1602 |
my $nb_rows = Koha::Patrons->anonymize_last_borrowers(); |
| 1603 |
is( $nb_rows, 1, 'anonymize_last_borrowers should have returned the number of last borrowers anonymized' ); |
| 1604 |
|
| 1605 |
my $sth = $dbh->prepare(q|SELECT borrowernumber FROM items_last_borrower where itemnumber = ?|); |
| 1606 |
$sth->execute( $item_1->itemnumber ); |
| 1607 |
my ($borrowernumber_used_to_anonymize) = $sth->fetchrow_array; |
| 1608 |
is( |
| 1609 |
$borrowernumber_used_to_anonymize, $patron->borrowernumber, |
| 1610 |
'Last borrower less than 5 days old are not anonymized' |
| 1611 |
); |
| 1612 |
$sth->execute( $item_2->itemnumber ); |
| 1613 |
($borrowernumber_used_to_anonymize) = $sth->fetchrow_array; |
| 1614 |
is( |
| 1615 |
$borrowernumber_used_to_anonymize, $anonymous->borrowernumber, |
| 1616 |
'Last borrower older than 5 days are anonymized' |
| 1617 |
); |
| 1618 |
|
| 1619 |
}; |
| 1620 |
|
| 1621 |
subtest 'withrawn, lost and damaged items' => sub { |
| 1622 |
plan tests => 6; |
| 1623 |
|
| 1624 |
t::lib::Mocks::mock_preference( 'AnonymizeLastBorrowerDays', 0 ); |
| 1625 |
|
| 1626 |
my $patron = $builder->build_object( |
| 1627 |
{ |
| 1628 |
class => 'Koha::Patrons', |
| 1629 |
value => { privacy => 1, } |
| 1630 |
} |
| 1631 |
); |
| 1632 |
my $item_1 = $builder->build_sample_item; |
| 1633 |
my $issue_1 = $builder->build_object( |
| 1634 |
{ |
| 1635 |
class => 'Koha::Checkouts', |
| 1636 |
value => { |
| 1637 |
borrowernumber => $patron->borrowernumber, |
| 1638 |
itemnumber => $item_1->itemnumber, |
| 1639 |
}, |
| 1640 |
} |
| 1641 |
); |
| 1642 |
my $item_2 = $builder->build_sample_item; |
| 1643 |
my $issue_2 = $builder->build_object( |
| 1644 |
{ |
| 1645 |
class => 'Koha::Checkouts', |
| 1646 |
value => { |
| 1647 |
borrowernumber => $patron->borrowernumber, |
| 1648 |
itemnumber => $item_2->itemnumber, |
| 1649 |
}, |
| 1650 |
} |
| 1651 |
); |
| 1652 |
my $item_3 = $builder->build_sample_item; |
| 1653 |
my $issue_3 = $builder->build_object( |
| 1654 |
{ |
| 1655 |
class => 'Koha::Checkouts', |
| 1656 |
value => { |
| 1657 |
borrowernumber => $patron->borrowernumber, |
| 1658 |
itemnumber => $item_3->itemnumber, |
| 1659 |
}, |
| 1660 |
} |
| 1661 |
); |
| 1662 |
my $item_4 = $builder->build_sample_item; |
| 1663 |
my $issue_4 = $builder->build_object( |
| 1664 |
{ |
| 1665 |
class => 'Koha::Checkouts', |
| 1666 |
value => { |
| 1667 |
borrowernumber => $patron->borrowernumber, |
| 1668 |
itemnumber => $item_4->itemnumber, |
| 1669 |
}, |
| 1670 |
} |
| 1671 |
); |
| 1672 |
|
| 1673 |
my ($returned_1) = C4::Circulation::AddReturn( $item_1->barcode, undef, undef, dt_from_string('2010-10-11') ); |
| 1674 |
my ($returned_2) = C4::Circulation::AddReturn( $item_2->barcode, undef, undef, dt_from_string('2010-10-11') ); |
| 1675 |
my ($returned_3) = C4::Circulation::AddReturn( $item_3->barcode, undef, undef, dt_from_string('2010-10-11') ); |
| 1676 |
my ($returned_4) = C4::Circulation::AddReturn( $item_4->barcode, undef, undef, dt_from_string('2010-10-11') ); |
| 1677 |
is( $returned_1 && $returned_2 && $returned_3 && $returned_4, 1, 'The items should have been returned' ); |
| 1678 |
$item_1->withdrawn(1)->store; |
| 1679 |
$item_2->itemlost(1)->store; |
| 1680 |
$item_3->damaged(1)->store; |
| 1681 |
|
| 1682 |
my $dbh = C4::Context->dbh; |
| 1683 |
my $stu = $dbh->prepare(q|UPDATE items_last_borrower set created_on = ? where itemnumber in (?, ?, ?, ?)|); |
| 1684 |
$stu->execute( |
| 1685 |
DateTime->today( time_zone => C4::Context->tz() )->add( days => -1 ), $item_1->itemnumber, |
| 1686 |
$item_2->itemnumber, $item_3->itemnumber, $item_4->itemnumber |
| 1687 |
); |
| 1688 |
|
| 1689 |
my $nb_rows = Koha::Patrons->anonymize_last_borrowers(); |
| 1690 |
is( $nb_rows, 1, 'anonymise_last_borrowers should have returned the number of last borrowers anonymized' ); |
| 1691 |
|
| 1692 |
my $sth = $dbh->prepare(q|SELECT borrowernumber FROM items_last_borrower where itemnumber = ?|); |
| 1693 |
$sth->execute( $item_1->itemnumber ); |
| 1694 |
my ($borrowernumber_used_to_anonymize) = $sth->fetchrow_array; |
| 1695 |
is( $borrowernumber_used_to_anonymize, $patron->borrowernumber, 'withrawn items should not be anonymized' ); |
| 1696 |
$sth->execute( $item_2->itemnumber ); |
| 1697 |
($borrowernumber_used_to_anonymize) = $sth->fetchrow_array; |
| 1698 |
is( $borrowernumber_used_to_anonymize, $patron->borrowernumber, 'lost items should not be anonymized' ); |
| 1699 |
$sth->execute( $item_3->itemnumber ); |
| 1700 |
($borrowernumber_used_to_anonymize) = $sth->fetchrow_array; |
| 1701 |
is( $borrowernumber_used_to_anonymize, $patron->borrowernumber, 'damaged items should not be anonymized' ); |
| 1702 |
$sth->execute( $item_4->itemnumber ); |
| 1703 |
($borrowernumber_used_to_anonymize) = $sth->fetchrow_array; |
| 1704 |
is( |
| 1705 |
$borrowernumber_used_to_anonymize, $anonymous->borrowernumber, |
| 1706 |
'not withdrawn, lost or damaged items are anonymized' |
| 1707 |
); |
| 1708 |
|
| 1709 |
}; |
| 1710 |
|
| 1711 |
}; |
| 1712 |
|
| 1550 |
subtest |
1713 |
subtest |
| 1551 |
'libraries_where_can_see_patrons + libraries_where_can_see_things + can_see_patron_infos + search_limited+ can_see_patrons_from + can_edit_items_from' |
1714 |
'libraries_where_can_see_patrons + libraries_where_can_see_things + can_see_patron_infos + search_limited+ can_see_patrons_from + can_edit_items_from' |
| 1552 |
=> sub { |
1715 |
=> sub { |
|
Lines 2475-2481
subtest '->set_password' => sub {
Link Here
|
| 2475 |
|
2638 |
|
| 2476 |
my $number_of_logs = |
2639 |
my $number_of_logs = |
| 2477 |
$schema->resultset('ActionLog') |
2640 |
$schema->resultset('ActionLog') |
| 2478 |
->search( { module => 'MEMBERS', action => 'CHANGE PASS', object => $patron->borrowernumber } )->count; |
2641 |
->search( { module => 'MEMBERS', action => 'CHANGE PASS', object => $patron->borrowernumber } ) |
|
|
2642 |
->count; |
| 2479 |
is( $number_of_logs, 0, 'Without BorrowersLog, Koha::Patron->set_password doesn\'t log password changes' ); |
2643 |
is( $number_of_logs, 0, 'Without BorrowersLog, Koha::Patron->set_password doesn\'t log password changes' ); |
| 2480 |
|
2644 |
|
| 2481 |
# Enable logging password changes |
2645 |
# Enable logging password changes |
|
Lines 3005-3012
subtest "search_patrons_to_update_category tests" => sub {
Link Here
|
| 3005 |
class => 'Koha::Patrons', |
3169 |
class => 'Koha::Patrons', |
| 3006 |
value => { |
3170 |
value => { |
| 3007 |
categorycode => $category_code, |
3171 |
categorycode => $category_code, |
| 3008 |
dateofbirth => |
3172 |
dateofbirth => $current_dt->clone->subtract( years => $category->upperagelimit + 1 ) |
| 3009 |
$current_dt->clone->subtract( years => $category->upperagelimit + 1 )->subtract( days => 1 ) |
3173 |
->subtract( days => 1 ) |
| 3010 |
->ymd, |
3174 |
->ymd, |
| 3011 |
} |
3175 |
} |
| 3012 |
} |
3176 |
} |
|
Lines 3456-3462
subtest 'filter_by_have_permission' => sub {
Link Here
|
| 3456 |
is_deeply( |
3620 |
is_deeply( |
| 3457 |
[ |
3621 |
[ |
| 3458 |
Koha::Patrons->search( { branchcode => $library->branchcode } ) |
3622 |
Koha::Patrons->search( { branchcode => $library->branchcode } ) |
| 3459 |
->filter_by_have_permission('suggestions.suggestions_manage')->get_column('borrowernumber') |
3623 |
->filter_by_have_permission('suggestions.suggestions_manage') |
|
|
3624 |
->get_column('borrowernumber') |
| 3460 |
], |
3625 |
], |
| 3461 |
[ $patron_1->borrowernumber, $patron_2->borrowernumber ], |
3626 |
[ $patron_1->borrowernumber, $patron_2->borrowernumber ], |
| 3462 |
'Superlibrarian and patron with suggestions.suggestions_manage' |
3627 |
'Superlibrarian and patron with suggestions.suggestions_manage' |
|
Lines 3465-3471
subtest 'filter_by_have_permission' => sub {
Link Here
|
| 3465 |
is_deeply( |
3630 |
is_deeply( |
| 3466 |
[ |
3631 |
[ |
| 3467 |
Koha::Patrons->search( { branchcode => $library->branchcode } ) |
3632 |
Koha::Patrons->search( { branchcode => $library->branchcode } ) |
| 3468 |
->filter_by_have_permission('acquisition.order_manage')->get_column('borrowernumber') |
3633 |
->filter_by_have_permission('acquisition.order_manage') |
|
|
3634 |
->get_column('borrowernumber') |
| 3469 |
], |
3635 |
], |
| 3470 |
[ $patron_1->borrowernumber, $patron_3->borrowernumber ], |
3636 |
[ $patron_1->borrowernumber, $patron_3->borrowernumber ], |
| 3471 |
'Superlibrarian and patron with acquisition.order_manage' |
3637 |
'Superlibrarian and patron with acquisition.order_manage' |
|
Lines 3474-3480
subtest 'filter_by_have_permission' => sub {
Link Here
|
| 3474 |
is_deeply( |
3640 |
is_deeply( |
| 3475 |
[ |
3641 |
[ |
| 3476 |
Koha::Patrons->search( { branchcode => $library->branchcode } ) |
3642 |
Koha::Patrons->search( { branchcode => $library->branchcode } ) |
| 3477 |
->filter_by_have_permission('parameters.manage_cities')->get_column('borrowernumber') |
3643 |
->filter_by_have_permission('parameters.manage_cities') |
|
|
3644 |
->get_column('borrowernumber') |
| 3478 |
], |
3645 |
], |
| 3479 |
[ $patron_1->borrowernumber ], |
3646 |
[ $patron_1->borrowernumber ], |
| 3480 |
'Only Superlibrarian is returned' |
3647 |
'Only Superlibrarian is returned' |
|
Lines 3482-3488
subtest 'filter_by_have_permission' => sub {
Link Here
|
| 3482 |
|
3649 |
|
| 3483 |
is_deeply( |
3650 |
is_deeply( |
| 3484 |
[ |
3651 |
[ |
| 3485 |
Koha::Patrons->search( { branchcode => $library->branchcode } )->filter_by_have_permission('suggestions') |
3652 |
Koha::Patrons->search( { branchcode => $library->branchcode } ) |
|
|
3653 |
->filter_by_have_permission('suggestions') |
| 3486 |
->get_column('borrowernumber') |
3654 |
->get_column('borrowernumber') |
| 3487 |
], |
3655 |
], |
| 3488 |
[ $patron_1->borrowernumber, $patron_2->borrowernumber ], |
3656 |
[ $patron_1->borrowernumber, $patron_2->borrowernumber ], |
| 3489 |
- |
|
|