Line 0
Link Here
|
0 |
- |
1 |
use Modern::Perl; |
|
|
2 |
use Test::More tests => 3; |
3 |
|
4 |
use C4::Context; |
5 |
use C4::Circulation; |
6 |
use t::lib::Mocks; |
7 |
use t::lib::TestBuilder; |
8 |
|
9 |
my $builder = t::lib::TestBuilder->new; |
10 |
|
11 |
# TODO create a subroutine in t::lib::Mocks |
12 |
my $userenv_patron = $builder->build( { source => 'Borrower', }, ); |
13 |
C4::Context->_new_userenv('DUMMY SESSION'); |
14 |
C4::Context->set_userenv( |
15 |
$userenv_patron->{borrowernumber}, |
16 |
$userenv_patron->{userid}, |
17 |
'usercnum', 'First name', 'Surname', |
18 |
$userenv_patron->{_fk}{branchcode}{branchcode}, |
19 |
$userenv_patron->{_fk}{branchcode}{branchname}, 0 |
20 |
); |
21 |
|
22 |
my $anonymous = $builder->build( { source => 'Borrower', }, ); |
23 |
|
24 |
t::lib::Mocks::mock_preference( 'AnonymousPatron', $anonymous->{borrowernumber} ); |
25 |
|
26 |
subtest 'patron privacy is 1 (default)' => sub { |
27 |
plan tests => 4; |
28 |
my $patron = $builder->build( |
29 |
{ source => 'Borrower', |
30 |
value => { privacy => 1, } |
31 |
} |
32 |
); |
33 |
my $item = $builder->build( |
34 |
{ source => 'Item', |
35 |
value => { |
36 |
itemlost => 0, |
37 |
withdrawn => 0, |
38 |
}, |
39 |
} |
40 |
); |
41 |
my $issue = $builder->build( |
42 |
{ source => 'Issue', |
43 |
value => { |
44 |
borrowernumber => $patron->{borrowernumber}, |
45 |
itemnumber => $item->{itemnumber}, |
46 |
}, |
47 |
} |
48 |
); |
49 |
|
50 |
my ( $returned, undef, undef ) = C4::Circulation::AddReturn( $item->{barcode}, undef, undef, undef, '2010-10-10' ); |
51 |
is( $returned, 1, 'The item should have been returned' ); |
52 |
my ( $rows_affected, $err ) = C4::Circulation::AnonymiseIssueHistory('2010-10-11'); |
53 |
ok( $rows_affected > 0, 'AnonymiseIssueHistory should affect at least 1 row' ); |
54 |
is( $err, undef, 'AnonymiseIssueHistory should not return any error if success' ); |
55 |
|
56 |
my $dbh = C4::Context->dbh; |
57 |
my ($borrowernumber_used_to_anonymised) = $dbh->selectrow_array(q| |
58 |
SELECT borrowernumber FROM old_issues where itemnumber = ? |
59 |
|, undef, $item->{itemnumber}); |
60 |
is( $borrowernumber_used_to_anonymised, $anonymous->{borrowernumber}, 'With privacy=1, the issue should have been anonymised' ); |
61 |
|
62 |
}; |
63 |
|
64 |
subtest 'patron privacy is 0 (forever)' => sub { |
65 |
plan tests => 3; |
66 |
|
67 |
my $patron = $builder->build( |
68 |
{ source => 'Borrower', |
69 |
value => { privacy => 0, } |
70 |
} |
71 |
); |
72 |
my $item = $builder->build( |
73 |
{ source => 'Item', |
74 |
value => { |
75 |
itemlost => 0, |
76 |
withdrawn => 0, |
77 |
}, |
78 |
} |
79 |
); |
80 |
my $issue = $builder->build( |
81 |
{ source => 'Issue', |
82 |
value => { |
83 |
borrowernumber => $patron->{borrowernumber}, |
84 |
itemnumber => $item->{itemnumber}, |
85 |
}, |
86 |
} |
87 |
); |
88 |
|
89 |
my ( $returned, undef, undef ) = C4::Circulation::AddReturn( $item->{barcode}, undef, undef, undef, '2010-10-10' ); |
90 |
is( $returned, 1, 'The item should have been returned' ); |
91 |
my ( $rows_affected, $err ) = C4::Circulation::AnonymiseIssueHistory('2010-10-11'); |
92 |
is( $err, undef, 'AnonymiseIssueHistory should not return any error if success' ); |
93 |
|
94 |
my $dbh = C4::Context->dbh; |
95 |
my ($borrowernumber_used_to_anonymised) = $dbh->selectrow_array(q| |
96 |
SELECT borrowernumber FROM old_issues where itemnumber = ? |
97 |
|, undef, $item->{itemnumber}); |
98 |
is( $borrowernumber_used_to_anonymised, $patron->{borrowernumber}, 'With privacy=0, the issue should not be anonymised' ); |
99 |
}; |
100 |
|
101 |
t::lib::Mocks::mock_preference( 'AnonymousPatron', '' ); |
102 |
|
103 |
subtest 'AnonymousPatron is not defined' => sub { |
104 |
plan tests => 4; |
105 |
my $patron = $builder->build( |
106 |
{ source => 'Borrower', |
107 |
value => { privacy => 1, } |
108 |
} |
109 |
); |
110 |
my $item = $builder->build( |
111 |
{ source => 'Item', |
112 |
value => { |
113 |
itemlost => 0, |
114 |
withdrawn => 0, |
115 |
}, |
116 |
} |
117 |
); |
118 |
my $issue = $builder->build( |
119 |
{ source => 'Issue', |
120 |
value => { |
121 |
borrowernumber => $patron->{borrowernumber}, |
122 |
itemnumber => $item->{itemnumber}, |
123 |
}, |
124 |
} |
125 |
); |
126 |
|
127 |
my ( $returned, undef, undef ) = C4::Circulation::AddReturn( $item->{barcode}, undef, undef, undef, '2010-10-10' ); |
128 |
is( $returned, 1, 'The item should have been returned' ); |
129 |
my ( $rows_affected, $err ) = C4::Circulation::AnonymiseIssueHistory('2010-10-11'); |
130 |
ok( $rows_affected > 0, 'AnonymiseIssueHistory should affect at least 1 row' ); |
131 |
is( $err, undef, 'AnonymiseIssueHistory should not return any error if success' ); |
132 |
|
133 |
my $dbh = C4::Context->dbh; |
134 |
my ($borrowernumber_used_to_anonymised) = $dbh->selectrow_array(q| |
135 |
SELECT borrowernumber FROM old_issues where itemnumber = ? |
136 |
|, undef, $item->{itemnumber}); |
137 |
is( $borrowernumber_used_to_anonymised, undef, 'With AnonymousPatron is not defined, the issue should have been anonymised anyway' ); |
138 |
}; |