|
Line 0
Link Here
|
| 0 |
- |
1 |
#!/usr/bin/perl |
|
|
2 |
|
| 3 |
use Modern::Perl; |
| 4 |
|
| 5 |
use C4::Context; |
| 6 |
use C4::Circulation; |
| 7 |
use Koha::Database; |
| 8 |
|
| 9 |
use Test::More tests => 4; |
| 10 |
|
| 11 |
BEGIN { |
| 12 |
use_ok('C4::Circulation'); |
| 13 |
use_ok('Koha::Database'); |
| 14 |
} |
| 15 |
|
| 16 |
#Start transaction |
| 17 |
my $dbh = C4::Context->dbh; |
| 18 |
$dbh->{RaiseError} = 1; |
| 19 |
$dbh->{AutoCommit} = 0; |
| 20 |
|
| 21 |
$dbh->do(q|DELETE FROM issues|); |
| 22 |
$dbh->do(q|DELETE FROM items|); |
| 23 |
$dbh->do(q|DELETE FROM borrowers|); |
| 24 |
$dbh->do(q|DELETE FROM branches|); |
| 25 |
$dbh->do(q|DELETE FROM categories|); |
| 26 |
$dbh->do(q|DELETE FROM accountlines|); |
| 27 |
$dbh->do(q|DELETE FROM issuingrules|); |
| 28 |
|
| 29 |
my $schema = Koha::Database->new()->schema(); |
| 30 |
|
| 31 |
#Add branch and category |
| 32 |
my $samplebranch1 = $schema->resultset('Branch')->create( |
| 33 |
{ |
| 34 |
branchcode => 'CPL', |
| 35 |
branchname => 'Sample Branch', |
| 36 |
branchaddress1 => 'sample adr1', |
| 37 |
branchaddress2 => 'sample adr2', |
| 38 |
branchaddress3 => 'sample adr3', |
| 39 |
branchzip => 'sample zip', |
| 40 |
branchcity => 'sample city', |
| 41 |
branchstate => 'sample state', |
| 42 |
branchcountry => 'sample country', |
| 43 |
branchphone => 'sample phone', |
| 44 |
branchfax => 'sample fax', |
| 45 |
branchemail => 'sample email', |
| 46 |
branchurl => 'sample url', |
| 47 |
branchip => 'sample ip', |
| 48 |
branchprinter => undef, |
| 49 |
opac_info => 'sample opac', |
| 50 |
} |
| 51 |
); |
| 52 |
|
| 53 |
my $samplecat = $schema->resultset('Category')->create( |
| 54 |
{ |
| 55 |
categorycode => 'CAT1', |
| 56 |
description => 'Description1', |
| 57 |
enrolmentperiod => 'Null', |
| 58 |
enrolmentperioddate => 'Null', |
| 59 |
dateofbirthrequired => 'Null', |
| 60 |
finetype => 'Null', |
| 61 |
bulk => 'Null', |
| 62 |
enrolmentfee => 'Null', |
| 63 |
overduenoticerequired => 'Null', |
| 64 |
issuelimit => 'Null', |
| 65 |
reservefee => 'Null', |
| 66 |
hidelostitems => 0, |
| 67 |
category_type => 'Null' |
| 68 |
} |
| 69 |
); |
| 70 |
|
| 71 |
#Add biblio and item |
| 72 |
my $record = MARC::Record->new(); |
| 73 |
$record->append_fields( |
| 74 |
MARC::Field->new( '952', '0', '0', a => $samplebranch1->{branchcode} ) ); |
| 75 |
my ( $biblionumber, $biblioitemnumber ) = C4::Biblio::AddBiblio( $record, '' ); |
| 76 |
|
| 77 |
my $itemnumber; |
| 78 |
( $biblionumber, $biblioitemnumber, $itemnumber ) = C4::Items::AddItem( |
| 79 |
{ |
| 80 |
barcode => 'barcode_1', |
| 81 |
itemcallnumber => 'callnumber1', |
| 82 |
homebranch => $samplebranch1->branchcode(), |
| 83 |
holdingbranch => $samplebranch1->branchcode(), |
| 84 |
issue => 1, |
| 85 |
reserve => 1 |
| 86 |
}, |
| 87 |
$biblionumber |
| 88 |
); |
| 89 |
|
| 90 |
my $anonymous_patron = $schema->resultset('Borrower')->create( |
| 91 |
{ |
| 92 |
firstname => 'Anonymous', |
| 93 |
surname => 'Patron', |
| 94 |
categorycode => $samplecat->categorycode(), |
| 95 |
branchcode => $samplebranch1->branchcode(), |
| 96 |
} |
| 97 |
); |
| 98 |
C4::Context->set_preference( 'AnonymousPatron', $anonymous_patron->borrowernumber() ); |
| 99 |
|
| 100 |
my $borrower1 = $schema->resultset('Borrower')->create( |
| 101 |
{ |
| 102 |
firstname => 'firstname', |
| 103 |
surname => 'surname', |
| 104 |
categorycode => $samplecat->categorycode(), |
| 105 |
branchcode => $samplebranch1->branchcode(), |
| 106 |
privacy => 2, |
| 107 |
} |
| 108 |
); |
| 109 |
my $borrower_1 = C4::Members::GetMember( borrowernumber => $borrower1->borrowernumber() ); |
| 110 |
|
| 111 |
my $borrower2 = $schema->resultset('Borrower')->create( |
| 112 |
{ |
| 113 |
firstname => 'firstname', |
| 114 |
surname => 'surname', |
| 115 |
categorycode => $samplecat->categorycode(), |
| 116 |
branchcode => $samplebranch1->branchcode(), |
| 117 |
privacy => 1, |
| 118 |
} |
| 119 |
); |
| 120 |
my $borrower_2 = C4::Members::GetMember( borrowernumber => $borrower2->borrowernumber() ); |
| 121 |
|
| 122 |
# NEED TO BE FIXED !!! |
| 123 |
# The first parameter for set_userenv is the class ref |
| 124 |
#my @USERENV = ( $borrower_id1, 'test', 'MASTERTEST', 'firstname', 'username', 'CPL', 'CPL', 'email@example.org' ); |
| 125 |
my @USERENV = ( $borrower1->borrowernumber(), 'test', 'MASTERTEST', 'firstname', 'CPL', 'CPL', 'email@example.org' ); |
| 126 |
|
| 127 |
C4::Context->_new_userenv('DUMMY_SESSION_ID'); |
| 128 |
C4::Context->set_userenv(@USERENV); |
| 129 |
|
| 130 |
my $userenv = C4::Context->userenv |
| 131 |
or BAIL_OUT("No userenv"); |
| 132 |
|
| 133 |
#Begin Tests |
| 134 |
|
| 135 |
AddIssue( $borrower_1, 'barcode_1' ); |
| 136 |
AddReturn('barcode_1'); |
| 137 |
my $old_issue = |
| 138 |
$schema->resultset('OldIssue')->search( { itemnumber => $itemnumber }, |
| 139 |
{ order_by => { -desc => 'issue_id' } } )->next(); |
| 140 |
ok( $old_issue->borrower()->borrowernumber() == $anonymous_patron->borrowernumber(), "Patron with privacy of 2 anonymized" ); |
| 141 |
|
| 142 |
my $next_issue_id = $old_issue->issue_id() + 1; |
| 143 |
|
| 144 |
|
| 145 |
AddIssue( $borrower_2, 'barcode_1' ); |
| 146 |
AddReturn('barcode_1'); |
| 147 |
$old_issue = |
| 148 |
$schema->resultset('OldIssue')->find( $next_issue_id ); |
| 149 |
ok( $old_issue->borrower()->borrowernumber() == $borrower2->borrowernumber(), "Patron with privacy of 1 not anonymized" ); |
| 150 |
|
| 151 |
|
| 152 |
#End transaction |
| 153 |
$dbh->rollback; |