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