|
Lines 688-694
subtest 'search_patrons_to_anonymise & anonymise_issue_history' => sub {
Link Here
|
| 688 |
t::lib::Mocks::mock_preference( 'AnonymousPatron', $anonymous->{borrowernumber} ); |
688 |
t::lib::Mocks::mock_preference( 'AnonymousPatron', $anonymous->{borrowernumber} ); |
| 689 |
|
689 |
|
| 690 |
subtest 'patron privacy is 1 (default)' => sub { |
690 |
subtest 'patron privacy is 1 (default)' => sub { |
| 691 |
plan tests => 4; |
691 |
plan tests => 6; |
| 692 |
|
692 |
|
| 693 |
t::lib::Mocks::mock_preference('IndependentBranches', 0); |
693 |
t::lib::Mocks::mock_preference('IndependentBranches', 0); |
| 694 |
my $patron = $builder->build( |
694 |
my $patron = $builder->build( |
|
Lines 696-702
subtest 'search_patrons_to_anonymise & anonymise_issue_history' => sub {
Link Here
|
| 696 |
value => { privacy => 1, } |
696 |
value => { privacy => 1, } |
| 697 |
} |
697 |
} |
| 698 |
); |
698 |
); |
| 699 |
my $item = $builder->build( |
699 |
my $item_1 = $builder->build( |
| 700 |
{ source => 'Item', |
700 |
{ source => 'Item', |
| 701 |
value => { |
701 |
value => { |
| 702 |
itemlost => 0, |
702 |
itemlost => 0, |
|
Lines 704-732
subtest 'search_patrons_to_anonymise & anonymise_issue_history' => sub {
Link Here
|
| 704 |
}, |
704 |
}, |
| 705 |
} |
705 |
} |
| 706 |
); |
706 |
); |
| 707 |
my $issue = $builder->build( |
707 |
my $issue_1 = $builder->build( |
| 708 |
{ source => 'Issue', |
708 |
{ source => 'Issue', |
| 709 |
value => { |
709 |
value => { |
| 710 |
borrowernumber => $patron->{borrowernumber}, |
710 |
borrowernumber => $patron->{borrowernumber}, |
| 711 |
itemnumber => $item->{itemnumber}, |
711 |
itemnumber => $item_1->{itemnumber}, |
|
|
712 |
}, |
| 713 |
} |
| 714 |
); |
| 715 |
my $item_2 = $builder->build( |
| 716 |
{ source => 'Item', |
| 717 |
value => { |
| 718 |
itemlost => 0, |
| 719 |
withdrawn => 0, |
| 720 |
}, |
| 721 |
} |
| 722 |
); |
| 723 |
my $issue_2 = $builder->build( |
| 724 |
{ source => 'Issue', |
| 725 |
value => { |
| 726 |
borrowernumber => $patron->{borrowernumber}, |
| 727 |
itemnumber => $item_2->{itemnumber}, |
| 712 |
}, |
728 |
}, |
| 713 |
} |
729 |
} |
| 714 |
); |
730 |
); |
| 715 |
|
731 |
|
| 716 |
my ( $returned, undef, undef ) = C4::Circulation::AddReturn( $item->{barcode}, undef, undef, undef, '2010-10-10' ); |
732 |
my ( $returned_1, undef, undef ) = C4::Circulation::AddReturn( $item_1->{barcode}, undef, undef, undef, '2010-10-10' ); |
| 717 |
is( $returned, 1, 'The item should have been returned' ); |
733 |
my ( $returned_2, undef, undef ) = C4::Circulation::AddReturn( $item_2->{barcode}, undef, undef, undef, '2011-11-11' ); |
|
|
734 |
is( $returned_1 && $returned_2, 1, 'The items should have been returned' ); |
| 718 |
|
735 |
|
| 719 |
my $patrons_to_anonymise = Koha::Patrons->search_patrons_to_anonymise( { before => '2010-10-11' } )->search( { 'me.borrowernumber' => $patron->{borrowernumber} } ); |
736 |
my $patrons_to_anonymise = Koha::Patrons->search_patrons_to_anonymise( { before => '2010-10-11' } )->search( { 'me.borrowernumber' => $patron->{borrowernumber} } ); |
| 720 |
is( ref($patrons_to_anonymise), 'Koha::Patrons', 'search_patrons_to_anonymise should return Koha::Patrons' ); |
737 |
is( ref($patrons_to_anonymise), 'Koha::Patrons', 'search_patrons_to_anonymise should return Koha::Patrons' ); |
| 721 |
|
738 |
|
| 722 |
my $rows_affected = Koha::Patrons->search_patrons_to_anonymise( { before => '2010-10-11' } )->anonymise_issue_history( { before => '2010-10-11' } ); |
739 |
my $rows_affected = Koha::Patrons->search_patrons_to_anonymise( { before => '2011-11-12' } )->anonymise_issue_history( { before => '2010-10-11' } ); |
| 723 |
ok( $rows_affected > 0, 'AnonymiseIssueHistory should affect at least 1 row' ); |
740 |
ok( $rows_affected > 0, 'AnonymiseIssueHistory should affect at least 1 row' ); |
| 724 |
|
741 |
|
| 725 |
my $dbh = C4::Context->dbh; |
742 |
my $dbh = C4::Context->dbh; |
| 726 |
my ($borrowernumber_used_to_anonymised) = $dbh->selectrow_array(q| |
743 |
my $sth = $dbh->prepare(q|SELECT borrowernumber FROM old_issues where itemnumber = ?|); |
| 727 |
SELECT borrowernumber FROM old_issues where itemnumber = ? |
744 |
$sth->execute($item_1->{itemnumber}); |
| 728 |
|, undef, $item->{itemnumber}); |
745 |
my ($borrowernumber_used_to_anonymised) = $sth->fetchrow_array; |
| 729 |
is( $borrowernumber_used_to_anonymised, $anonymous->{borrowernumber}, 'With privacy=1, the issue should have been anonymised' ); |
746 |
is( $borrowernumber_used_to_anonymised, $anonymous->{borrowernumber}, 'With privacy=1, the issue should have been anonymised' ); |
|
|
747 |
$sth->execute($item_2->{itemnumber}); |
| 748 |
($borrowernumber_used_to_anonymised) = $sth->fetchrow_array; |
| 749 |
is( $borrowernumber_used_to_anonymised, $patron->{borrowernumber}, 'The issue should not have been anonymised, the returned date is later' ); |
| 750 |
|
| 751 |
$rows_affected = Koha::Patrons->search_patrons_to_anonymise( { before => '2011-11-12' } )->anonymise_issue_history; |
| 752 |
$sth->execute($item_2->{itemnumber}); |
| 753 |
($borrowernumber_used_to_anonymised) = $sth->fetchrow_array; |
| 754 |
is( $borrowernumber_used_to_anonymised, $anonymous->{borrowernumber}, 'The issue should have been anonymised, the returned date is before' ); |
| 755 |
|
| 730 |
Koha::Patrons->find( $patron->{borrowernumber})->delete; |
756 |
Koha::Patrons->find( $patron->{borrowernumber})->delete; |
| 731 |
}; |
757 |
}; |
| 732 |
|
758 |
|
| 733 |
- |
|
|