Lines 1022-1028
subtest 'notice_email_address' => sub {
Link Here
|
1022 |
$patron->delete; |
1022 |
$patron->delete; |
1023 |
}; |
1023 |
}; |
1024 |
|
1024 |
|
1025 |
subtest 'search_patrons_to_anonymise & anonymise_issue_history' => sub { |
1025 |
subtest 'search_patrons_to_anonymise' => sub { |
|
|
1026 |
|
1026 |
plan tests => 5; |
1027 |
plan tests => 5; |
1027 |
|
1028 |
|
1028 |
# TODO create a subroutine in t::lib::Mocks |
1029 |
# TODO create a subroutine in t::lib::Mocks |
Lines 1083-1089
subtest 'search_patrons_to_anonymise & anonymise_issue_history' => sub {
Link Here
|
1083 |
my $patrons_to_anonymise = Koha::Patrons->search_patrons_to_anonymise( { before => '2010-10-11' } )->search( { 'me.borrowernumber' => $patron->{borrowernumber} } ); |
1084 |
my $patrons_to_anonymise = Koha::Patrons->search_patrons_to_anonymise( { before => '2010-10-11' } )->search( { 'me.borrowernumber' => $patron->{borrowernumber} } ); |
1084 |
is( ref($patrons_to_anonymise), 'Koha::Patrons', 'search_patrons_to_anonymise should return Koha::Patrons' ); |
1085 |
is( ref($patrons_to_anonymise), 'Koha::Patrons', 'search_patrons_to_anonymise should return Koha::Patrons' ); |
1085 |
|
1086 |
|
1086 |
my $rows_affected = Koha::Patrons->search_patrons_to_anonymise( { before => '2011-11-12' } )->anonymise_issue_history( { before => '2010-10-11' } ); |
1087 |
my $rows_affected = Koha::Old::Checkouts->search( |
|
|
1088 |
{ |
1089 |
borrowernumber => [ |
1090 |
Koha::Patrons->search_patrons_to_anonymise( |
1091 |
{ before => '2011-11-12' } |
1092 |
)->get_column('borrowernumber') |
1093 |
], |
1094 |
returndate => { '<' => '2011-10-11', } |
1095 |
} |
1096 |
)->anonymize; |
1087 |
ok( $rows_affected > 0, 'AnonymiseIssueHistory should affect at least 1 row' ); |
1097 |
ok( $rows_affected > 0, 'AnonymiseIssueHistory should affect at least 1 row' ); |
1088 |
|
1098 |
|
1089 |
$patrons_to_anonymise = Koha::Patrons->search_patrons_to_anonymise( { before => '2010-10-11' } ); |
1099 |
$patrons_to_anonymise = Koha::Patrons->search_patrons_to_anonymise( { before => '2010-10-11' } ); |
Lines 1098-1104
subtest 'search_patrons_to_anonymise & anonymise_issue_history' => sub {
Link Here
|
1098 |
($borrowernumber_used_to_anonymised) = $sth->fetchrow_array; |
1108 |
($borrowernumber_used_to_anonymised) = $sth->fetchrow_array; |
1099 |
is( $borrowernumber_used_to_anonymised, $patron->{borrowernumber}, 'The issue should not have been anonymised, the returned date is later' ); |
1109 |
is( $borrowernumber_used_to_anonymised, $patron->{borrowernumber}, 'The issue should not have been anonymised, the returned date is later' ); |
1100 |
|
1110 |
|
1101 |
$rows_affected = Koha::Patrons->search_patrons_to_anonymise( { before => '2011-11-12' } )->anonymise_issue_history; |
1111 |
$rows_affected = Koha::Old::Checkouts->search( |
|
|
1112 |
{ |
1113 |
borrowernumber => [ |
1114 |
Koha::Patrons->search_patrons_to_anonymise( |
1115 |
{ before => '2011-11-12' } |
1116 |
)->get_column('borrowernumber') |
1117 |
], |
1118 |
returndate => { '<' => '2011-11-12', } |
1119 |
} |
1120 |
)->anonymize; |
1102 |
$sth->execute($item_2->itemnumber); |
1121 |
$sth->execute($item_2->itemnumber); |
1103 |
($borrowernumber_used_to_anonymised) = $sth->fetchrow_array; |
1122 |
($borrowernumber_used_to_anonymised) = $sth->fetchrow_array; |
1104 |
is( $borrowernumber_used_to_anonymised, $anonymous->{borrowernumber}, 'The issue should have been anonymised, the returned date is before' ); |
1123 |
is( $borrowernumber_used_to_anonymised, $anonymous->{borrowernumber}, 'The issue should have been anonymised, the returned date is before' ); |
Lines 1106-1112
subtest 'search_patrons_to_anonymise & anonymise_issue_history' => sub {
Link Here
|
1106 |
my $sth_reset = $dbh->prepare(q|UPDATE old_issues SET borrowernumber = ? WHERE itemnumber = ?|); |
1125 |
my $sth_reset = $dbh->prepare(q|UPDATE old_issues SET borrowernumber = ? WHERE itemnumber = ?|); |
1107 |
$sth_reset->execute( $patron->{borrowernumber}, $item_1->itemnumber ); |
1126 |
$sth_reset->execute( $patron->{borrowernumber}, $item_1->itemnumber ); |
1108 |
$sth_reset->execute( $patron->{borrowernumber}, $item_2->itemnumber ); |
1127 |
$sth_reset->execute( $patron->{borrowernumber}, $item_2->itemnumber ); |
1109 |
$rows_affected = Koha::Patrons->search_patrons_to_anonymise->anonymise_issue_history; |
1128 |
$rows_affected = Koha::Old::Checkouts->search( |
|
|
1129 |
{ |
1130 |
borrowernumber => [ |
1131 |
Koha::Patrons->search_patrons_to_anonymise->get_column( |
1132 |
'borrowernumber') |
1133 |
] |
1134 |
} |
1135 |
)->anonymize; |
1110 |
$sth->execute($item_1->itemnumber); |
1136 |
$sth->execute($item_1->itemnumber); |
1111 |
($borrowernumber_used_to_anonymised) = $sth->fetchrow_array; |
1137 |
($borrowernumber_used_to_anonymised) = $sth->fetchrow_array; |
1112 |
is( $borrowernumber_used_to_anonymised, $anonymous->{borrowernumber}, 'The issue 1 should have been anonymised, before parameter was not passed' ); |
1138 |
is( $borrowernumber_used_to_anonymised, $anonymous->{borrowernumber}, 'The issue 1 should have been anonymised, before parameter was not passed' ); |
Lines 1170-1176
subtest 'search_patrons_to_anonymise & anonymise_issue_history' => sub {
Link Here
|
1170 |
|
1196 |
|
1171 |
my ( $returned, undef, undef ) = C4::Circulation::AddReturn( $item->barcode, undef, undef, dt_from_string('2010-10-10') ); |
1197 |
my ( $returned, undef, undef ) = C4::Circulation::AddReturn( $item->barcode, undef, undef, dt_from_string('2010-10-10') ); |
1172 |
is( $returned, 1, 'The item should have been returned' ); |
1198 |
is( $returned, 1, 'The item should have been returned' ); |
1173 |
my $rows_affected = Koha::Patrons->search_patrons_to_anonymise( { before => '2010-10-11' } )->anonymise_issue_history( { before => '2010-10-11' } ); |
1199 |
my $rows_affected = Koha::Old::Checkouts->search( |
|
|
1200 |
{ |
1201 |
borrowernumber => [ |
1202 |
Koha::Patrons->search_patrons_to_anonymise( |
1203 |
{ before => '2010-10-11' } |
1204 |
)->get_column('borrowernumber') |
1205 |
] |
1206 |
} |
1207 |
)->anonymize; |
1174 |
ok( $rows_affected > 0, 'AnonymiseIssueHistory should affect at least 1 row' ); |
1208 |
ok( $rows_affected > 0, 'AnonymiseIssueHistory should affect at least 1 row' ); |
1175 |
|
1209 |
|
1176 |
my $dbh = C4::Context->dbh; |
1210 |
my $dbh = C4::Context->dbh; |
1177 |
- |
|
|