|
Lines 1547-1552
subtest 'search_patrons_to_anonymise' => sub {
Link Here
|
| 1547 |
t::lib::Mocks::mock_preference( 'IndependentBranches', 0 ); |
1547 |
t::lib::Mocks::mock_preference( 'IndependentBranches', 0 ); |
| 1548 |
}; |
1548 |
}; |
| 1549 |
|
1549 |
|
|
|
1550 |
subtest 'anonymize items_last_borrower' => sub { |
| 1551 |
plan tests => 2; |
| 1552 |
|
| 1553 |
my $anonymous = $builder->build_object( { class => 'Koha::Patrons', }, ); |
| 1554 |
|
| 1555 |
t::lib::Mocks::mock_preference( 'AnonymousPatron', $anonymous->borrowernumber ); |
| 1556 |
t::lib::Mocks::mock_preference( 'StoreLastBorrower', 1 ); |
| 1557 |
t::lib::Mocks::mock_preference( 'AnonymizeLastBorrower', 1 ); |
| 1558 |
|
| 1559 |
subtest 'anonymize items_last_borrower by days' => sub { |
| 1560 |
plan tests => 4; |
| 1561 |
|
| 1562 |
t::lib::Mocks::mock_preference( 'AnonymizeLastBorrowerDays', 5 ); |
| 1563 |
|
| 1564 |
my $patron = $builder->build_object( |
| 1565 |
{ |
| 1566 |
class => 'Koha::Patrons', |
| 1567 |
value => { privacy => 1, } |
| 1568 |
} |
| 1569 |
); |
| 1570 |
my $item_1 = $builder->build_sample_item; |
| 1571 |
my $issue_1 = $builder->build_object( |
| 1572 |
{ |
| 1573 |
class => 'Koha::Checkouts', |
| 1574 |
value => { |
| 1575 |
borrowernumber => $patron->borrowernumber, |
| 1576 |
itemnumber => $item_1->itemnumber, |
| 1577 |
}, |
| 1578 |
} |
| 1579 |
); |
| 1580 |
my $item_2 = $builder->build_sample_item; |
| 1581 |
my $issue_2 = $builder->build_object( |
| 1582 |
{ |
| 1583 |
class => 'Koha::Checkouts', |
| 1584 |
value => { |
| 1585 |
borrowernumber => $patron->borrowernumber, |
| 1586 |
itemnumber => $item_2->itemnumber, |
| 1587 |
}, |
| 1588 |
} |
| 1589 |
); |
| 1590 |
|
| 1591 |
my $dbh = C4::Context->dbh; |
| 1592 |
my ($returned_1) = C4::Circulation::AddReturn( $item_1->barcode, undef, undef, dt_from_string ); |
| 1593 |
my ($returned_2) = C4::Circulation::AddReturn( $item_2->barcode, undef, undef, dt_from_string ); |
| 1594 |
is( $returned_1 && $returned_2, 1, 'The items should have been returned' ); |
| 1595 |
my $stu = $dbh->prepare(q|UPDATE items_last_borrower set created_on = ? where itemnumber = ?|); |
| 1596 |
$stu->execute( DateTime->today( time_zone => C4::Context->tz() )->add( days => -6 ), $item_2->itemnumber ); |
| 1597 |
|
| 1598 |
my $nb_rows = Koha::Patrons->anonymize_last_borrowers(); |
| 1599 |
is( $nb_rows, 1, 'anonymize_last_borrowers should have returned the number of last borrowers anonymized' ); |
| 1600 |
|
| 1601 |
my $sth = $dbh->prepare(q|SELECT borrowernumber FROM items_last_borrower where itemnumber = ?|); |
| 1602 |
$sth->execute( $item_1->itemnumber ); |
| 1603 |
my ($borrowernumber_used_to_anonymize) = $sth->fetchrow_array; |
| 1604 |
is( |
| 1605 |
$borrowernumber_used_to_anonymize, $patron->borrowernumber, |
| 1606 |
'Last borrower less than 5 days old are not anonymized' |
| 1607 |
); |
| 1608 |
$sth->execute( $item_2->itemnumber ); |
| 1609 |
($borrowernumber_used_to_anonymize) = $sth->fetchrow_array; |
| 1610 |
is( |
| 1611 |
$borrowernumber_used_to_anonymize, $anonymous->borrowernumber, |
| 1612 |
'Last borrower older than 5 days are anonymized' |
| 1613 |
); |
| 1614 |
|
| 1615 |
}; |
| 1616 |
|
| 1617 |
subtest 'withrawn, lost and damaged items' => sub { |
| 1618 |
plan tests => 6; |
| 1619 |
|
| 1620 |
t::lib::Mocks::mock_preference( 'AnonymizeLastBorrowerDays', 0 ); |
| 1621 |
|
| 1622 |
my $patron = $builder->build_object( |
| 1623 |
{ |
| 1624 |
class => 'Koha::Patrons', |
| 1625 |
value => { privacy => 1, } |
| 1626 |
} |
| 1627 |
); |
| 1628 |
my $item_1 = $builder->build_sample_item; |
| 1629 |
my $issue_1 = $builder->build_object( |
| 1630 |
{ |
| 1631 |
class => 'Koha::Checkouts', |
| 1632 |
value => { |
| 1633 |
borrowernumber => $patron->borrowernumber, |
| 1634 |
itemnumber => $item_1->itemnumber, |
| 1635 |
}, |
| 1636 |
} |
| 1637 |
); |
| 1638 |
my $item_2 = $builder->build_sample_item; |
| 1639 |
my $issue_2 = $builder->build_object( |
| 1640 |
{ |
| 1641 |
class => 'Koha::Checkouts', |
| 1642 |
value => { |
| 1643 |
borrowernumber => $patron->borrowernumber, |
| 1644 |
itemnumber => $item_2->itemnumber, |
| 1645 |
}, |
| 1646 |
} |
| 1647 |
); |
| 1648 |
my $item_3 = $builder->build_sample_item; |
| 1649 |
my $issue_3 = $builder->build_object( |
| 1650 |
{ |
| 1651 |
class => 'Koha::Checkouts', |
| 1652 |
value => { |
| 1653 |
borrowernumber => $patron->borrowernumber, |
| 1654 |
itemnumber => $item_3->itemnumber, |
| 1655 |
}, |
| 1656 |
} |
| 1657 |
); |
| 1658 |
my $item_4 = $builder->build_sample_item; |
| 1659 |
my $issue_4 = $builder->build_object( |
| 1660 |
{ |
| 1661 |
class => 'Koha::Checkouts', |
| 1662 |
value => { |
| 1663 |
borrowernumber => $patron->borrowernumber, |
| 1664 |
itemnumber => $item_4->itemnumber, |
| 1665 |
}, |
| 1666 |
} |
| 1667 |
); |
| 1668 |
|
| 1669 |
my ($returned_1) = C4::Circulation::AddReturn( $item_1->barcode, undef, undef, dt_from_string('2010-10-11') ); |
| 1670 |
my ($returned_2) = C4::Circulation::AddReturn( $item_2->barcode, undef, undef, dt_from_string('2010-10-11') ); |
| 1671 |
my ($returned_3) = C4::Circulation::AddReturn( $item_3->barcode, undef, undef, dt_from_string('2010-10-11') ); |
| 1672 |
my ($returned_4) = C4::Circulation::AddReturn( $item_4->barcode, undef, undef, dt_from_string('2010-10-11') ); |
| 1673 |
is( $returned_1 && $returned_2 && $returned_3 && $returned_4, 1, 'The items should have been returned' ); |
| 1674 |
$item_1->withdrawn(1)->store; |
| 1675 |
$item_2->itemlost(1)->store; |
| 1676 |
$item_3->damaged(1)->store; |
| 1677 |
|
| 1678 |
my $dbh = C4::Context->dbh; |
| 1679 |
my $stu = $dbh->prepare(q|UPDATE items_last_borrower set created_on = ? where itemnumber in (?, ?, ?, ?)|); |
| 1680 |
$stu->execute( |
| 1681 |
DateTime->today( time_zone => C4::Context->tz() )->add( days => -1 ), $item_1->itemnumber, |
| 1682 |
$item_2->itemnumber, $item_3->itemnumber, $item_4->itemnumber |
| 1683 |
); |
| 1684 |
|
| 1685 |
my $nb_rows = Koha::Patrons->anonymize_last_borrowers(); |
| 1686 |
is( $nb_rows, 1, 'anonymise_last_borrowers should have returned the number of last borrowers anonymized' ); |
| 1687 |
|
| 1688 |
my $sth = $dbh->prepare(q|SELECT borrowernumber FROM items_last_borrower where itemnumber = ?|); |
| 1689 |
$sth->execute( $item_1->itemnumber ); |
| 1690 |
my ($borrowernumber_used_to_anonymize) = $sth->fetchrow_array; |
| 1691 |
is( $borrowernumber_used_to_anonymize, $patron->borrowernumber, 'withrawn items should not be anonymized' ); |
| 1692 |
$sth->execute( $item_2->itemnumber ); |
| 1693 |
($borrowernumber_used_to_anonymize) = $sth->fetchrow_array; |
| 1694 |
is( $borrowernumber_used_to_anonymize, $patron->borrowernumber, 'lost items should not be anonymized' ); |
| 1695 |
$sth->execute( $item_3->itemnumber ); |
| 1696 |
($borrowernumber_used_to_anonymize) = $sth->fetchrow_array; |
| 1697 |
is( $borrowernumber_used_to_anonymize, $patron->borrowernumber, 'damaged items should not be anonymized' ); |
| 1698 |
$sth->execute( $item_4->itemnumber ); |
| 1699 |
($borrowernumber_used_to_anonymize) = $sth->fetchrow_array; |
| 1700 |
is( |
| 1701 |
$borrowernumber_used_to_anonymize, $anonymous->borrowernumber, |
| 1702 |
'not withdrawn, lost or damaged items are anonymized' |
| 1703 |
); |
| 1704 |
|
| 1705 |
}; |
| 1706 |
|
| 1707 |
}; |
| 1708 |
|
| 1550 |
subtest |
1709 |
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' |
1710 |
'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 { |
1711 |
=> sub { |
| 1553 |
- |
|
|