|
Lines 68-75
my $new_patron_2 = Koha::Patron->new(
Link Here
|
| 68 |
} |
68 |
} |
| 69 |
)->store; |
69 |
)->store; |
| 70 |
|
70 |
|
| 71 |
C4::Context->_new_userenv('xxx'); |
71 |
t::lib::Mocks::mock_userenv({ patron => $new_patron_1 }); |
| 72 |
set_logged_in_user( $new_patron_1 ); |
|
|
| 73 |
|
72 |
|
| 74 |
is( Koha::Patrons->search->count, $nb_of_patrons + 2, 'The 2 patrons should have been added' ); |
73 |
is( Koha::Patrons->search->count, $nb_of_patrons + 2, 'The 2 patrons should have been added' ); |
| 75 |
|
74 |
|
|
Lines 561-568
subtest 'checkouts + pending_checkouts + get_overdues + old_checkouts' => sub {
Link Here
|
| 561 |
# Not sure how this is useful, but AddIssue pass this variable to different other subroutines |
560 |
# Not sure how this is useful, but AddIssue pass this variable to different other subroutines |
| 562 |
$patron = Koha::Patrons->find( $patron->borrowernumber )->unblessed; |
561 |
$patron = Koha::Patrons->find( $patron->borrowernumber )->unblessed; |
| 563 |
|
562 |
|
| 564 |
my $module = new Test::MockModule('C4::Context'); |
563 |
t::lib::Mocks::mock_userenv({ branchcode => $library->{branchcode} }); |
| 565 |
$module->mock( 'userenv', sub { { branch => $library->{branchcode} } } ); |
|
|
| 566 |
|
564 |
|
| 567 |
AddIssue( $patron, $item_1->{barcode}, DateTime->now->subtract( days => 1 ) ); |
565 |
AddIssue( $patron, $item_1->{barcode}, DateTime->now->subtract( days => 1 ) ); |
| 568 |
AddIssue( $patron, $item_2->{barcode}, DateTime->now->subtract( days => 5 ) ); |
566 |
AddIssue( $patron, $item_2->{barcode}, DateTime->now->subtract( days => 5 ) ); |
|
Lines 595-601
subtest 'checkouts + pending_checkouts + get_overdues + old_checkouts' => sub {
Link Here
|
| 595 |
# Clean stuffs |
593 |
# Clean stuffs |
| 596 |
Koha::Checkouts->search( { borrowernumber => $patron->borrowernumber } )->delete; |
594 |
Koha::Checkouts->search( { borrowernumber => $patron->borrowernumber } )->delete; |
| 597 |
$patron->delete; |
595 |
$patron->delete; |
| 598 |
$module->unmock('userenv'); |
|
|
| 599 |
}; |
596 |
}; |
| 600 |
|
597 |
|
| 601 |
subtest 'get_routing_lists' => sub { |
598 |
subtest 'get_routing_lists' => sub { |
|
Lines 844-862
subtest 'search_patrons_to_anonymise & anonymise_issue_history' => sub {
Link Here
|
| 844 |
|
841 |
|
| 845 |
# TODO create a subroutine in t::lib::Mocks |
842 |
# TODO create a subroutine in t::lib::Mocks |
| 846 |
my $branch = $builder->build({ source => 'Branch' }); |
843 |
my $branch = $builder->build({ source => 'Branch' }); |
| 847 |
my $userenv_patron = $builder->build({ |
844 |
my $userenv_patron = $builder->build_object({ |
| 848 |
source => 'Borrower', |
845 |
class => 'Koha::Patrons', |
| 849 |
value => { branchcode => $branch->{branchcode} }, |
846 |
value => { branchcode => $branch->{branchcode}, flags => 0 }, |
| 850 |
}); |
847 |
}); |
| 851 |
C4::Context->_new_userenv('DUMMY SESSION'); |
848 |
t::lib::Mocks::mock_userenv({ patron => $userenv_patron }); |
| 852 |
C4::Context->set_userenv( |
849 |
|
| 853 |
$userenv_patron->{borrowernumber}, |
|
|
| 854 |
$userenv_patron->{userid}, |
| 855 |
'usercnum', 'First name', 'Surname', |
| 856 |
$branch->{branchcode}, |
| 857 |
$branch->{branchname}, |
| 858 |
0, |
| 859 |
); |
| 860 |
my $anonymous = $builder->build( { source => 'Borrower', }, ); |
850 |
my $anonymous = $builder->build( { source => 'Borrower', }, ); |
| 861 |
|
851 |
|
| 862 |
t::lib::Mocks::mock_preference( 'AnonymousPatron', $anonymous->{borrowernumber} ); |
852 |
t::lib::Mocks::mock_preference( 'AnonymousPatron', $anonymous->{borrowernumber} ); |
|
Lines 1052-1058
subtest 'search_patrons_to_anonymise & anonymise_issue_history' => sub {
Link Here
|
| 1052 |
}; |
1042 |
}; |
| 1053 |
|
1043 |
|
| 1054 |
Koha::Patrons->find( $anonymous->{borrowernumber})->delete; |
1044 |
Koha::Patrons->find( $anonymous->{borrowernumber})->delete; |
| 1055 |
Koha::Patrons->find( $userenv_patron->{borrowernumber})->delete; |
1045 |
$userenv_patron->delete; |
| 1056 |
|
1046 |
|
| 1057 |
# Reset IndependentBranches for further tests |
1047 |
# Reset IndependentBranches for further tests |
| 1058 |
t::lib::Mocks::mock_preference('IndependentBranches', 0); |
1048 |
t::lib::Mocks::mock_preference('IndependentBranches', 0); |
|
Lines 1108-1134
subtest 'libraries_where_can_see_patrons + can_see_patron_infos + search_limited
Link Here
|
| 1108 |
|
1098 |
|
| 1109 |
my @branchcodes; |
1099 |
my @branchcodes; |
| 1110 |
|
1100 |
|
| 1111 |
set_logged_in_user( $patron_11_1 ); |
1101 |
t::lib::Mocks::mock_userenv({ patron => $patron_11_1 }); |
| 1112 |
@branchcodes = $patron_11_1->libraries_where_can_see_patrons; |
1102 |
@branchcodes = $patron_11_1->libraries_where_can_see_patrons; |
| 1113 |
is_deeply( \@branchcodes, [], q|patron_11_1 has view_borrower_infos_from_any_libraries => No restriction| ); |
1103 |
is_deeply( \@branchcodes, [], q|patron_11_1 has view_borrower_infos_from_any_libraries => No restriction| ); |
| 1114 |
|
1104 |
|
| 1115 |
set_logged_in_user( $patron_11_2 ); |
1105 |
t::lib::Mocks::mock_userenv({ patron => $patron_11_2 }); |
| 1116 |
@branchcodes = $patron_11_2->libraries_where_can_see_patrons; |
1106 |
@branchcodes = $patron_11_2->libraries_where_can_see_patrons; |
| 1117 |
is_deeply( \@branchcodes, [ sort ( $library_11->branchcode, $library_12->branchcode ) ], q|patron_11_2 has not view_borrower_infos_from_any_libraries => Can only see patron's from its group| ); |
1107 |
is_deeply( \@branchcodes, [ sort ( $library_11->branchcode, $library_12->branchcode ) ], q|patron_11_2 has not view_borrower_infos_from_any_libraries => Can only see patron's from its group| ); |
| 1118 |
|
1108 |
|
| 1119 |
set_logged_in_user( $patron_21 ); |
1109 |
t::lib::Mocks::mock_userenv({ patron => $patron_21 }); |
| 1120 |
@branchcodes = $patron_21->libraries_where_can_see_patrons; |
1110 |
@branchcodes = $patron_21->libraries_where_can_see_patrons; |
| 1121 |
is_deeply( \@branchcodes, [$library_21->branchcode], q|patron_21 has not view_borrower_infos_from_any_libraries => Can only see patron's from its group| ); |
1111 |
is_deeply( \@branchcodes, [$library_21->branchcode], q|patron_21 has not view_borrower_infos_from_any_libraries => Can only see patron's from its group| ); |
| 1122 |
}; |
1112 |
}; |
| 1123 |
subtest 'can_see_patron_infos' => sub { |
1113 |
subtest 'can_see_patron_infos' => sub { |
| 1124 |
plan tests => 6; |
1114 |
plan tests => 6; |
| 1125 |
|
1115 |
|
| 1126 |
set_logged_in_user( $patron_11_1 ); |
1116 |
t::lib::Mocks::mock_userenv({ patron => $patron_11_1 }); |
| 1127 |
is( $patron_11_1->can_see_patron_infos( $patron_11_2 ), 1, q|patron_11_1 can see patron_11_2, from its library| ); |
1117 |
is( $patron_11_1->can_see_patron_infos( $patron_11_2 ), 1, q|patron_11_1 can see patron_11_2, from its library| ); |
| 1128 |
is( $patron_11_1->can_see_patron_infos( $patron_12 ), 1, q|patron_11_1 can see patron_12, from its group| ); |
1118 |
is( $patron_11_1->can_see_patron_infos( $patron_12 ), 1, q|patron_11_1 can see patron_12, from its group| ); |
| 1129 |
is( $patron_11_1->can_see_patron_infos( $patron_21 ), 1, q|patron_11_1 can see patron_11_2, from another group| ); |
1119 |
is( $patron_11_1->can_see_patron_infos( $patron_21 ), 1, q|patron_11_1 can see patron_11_2, from another group| ); |
| 1130 |
|
1120 |
|
| 1131 |
set_logged_in_user( $patron_11_2 ); |
1121 |
t::lib::Mocks::mock_userenv({ patron => $patron_11_2 }); |
| 1132 |
is( $patron_11_2->can_see_patron_infos( $patron_11_1 ), 1, q|patron_11_2 can see patron_11_1, from its library| ); |
1122 |
is( $patron_11_2->can_see_patron_infos( $patron_11_1 ), 1, q|patron_11_2 can see patron_11_1, from its library| ); |
| 1133 |
is( $patron_11_2->can_see_patron_infos( $patron_12 ), 1, q|patron_11_2 can see patron_12, from its group| ); |
1123 |
is( $patron_11_2->can_see_patron_infos( $patron_12 ), 1, q|patron_11_2 can see patron_12, from its group| ); |
| 1134 |
is( $patron_11_2->can_see_patron_infos( $patron_21 ), 0, q|patron_11_2 can NOT see patron_21, from another group| ); |
1124 |
is( $patron_11_2->can_see_patron_infos( $patron_21 ), 0, q|patron_11_2 can NOT see patron_21, from another group| ); |
|
Lines 1136-1151
subtest 'libraries_where_can_see_patrons + can_see_patron_infos + search_limited
Link Here
|
| 1136 |
subtest 'search_limited' => sub { |
1126 |
subtest 'search_limited' => sub { |
| 1137 |
plan tests => 6; |
1127 |
plan tests => 6; |
| 1138 |
|
1128 |
|
| 1139 |
set_logged_in_user( $patron_11_1 ); |
1129 |
t::lib::Mocks::mock_userenv({ patron => $patron_11_1 }); |
| 1140 |
my $total_number_of_patrons = $nb_of_patrons + 4; #we added four in these tests |
1130 |
my $total_number_of_patrons = $nb_of_patrons + 4; #we added four in these tests |
| 1141 |
is( Koha::Patrons->search->count, $total_number_of_patrons, 'Non-limited search should return all patrons' ); |
1131 |
is( Koha::Patrons->search->count, $total_number_of_patrons, 'Non-limited search should return all patrons' ); |
| 1142 |
is( Koha::Patrons->search_limited->count, $total_number_of_patrons, 'patron_11_1 is allowed to see all patrons' ); |
1132 |
is( Koha::Patrons->search_limited->count, $total_number_of_patrons, 'patron_11_1 is allowed to see all patrons' ); |
| 1143 |
|
1133 |
|
| 1144 |
set_logged_in_user( $patron_11_2 ); |
1134 |
t::lib::Mocks::mock_userenv({ patron => $patron_11_2 }); |
| 1145 |
is( Koha::Patrons->search->count, $total_number_of_patrons, 'Non-limited search should return all patrons'); |
1135 |
is( Koha::Patrons->search->count, $total_number_of_patrons, 'Non-limited search should return all patrons'); |
| 1146 |
is( Koha::Patrons->search_limited->count, 3, 'patron_12_1 is not allowed to see patrons from other groups, only patron_11_1, patron_11_2 and patron_12' ); |
1136 |
is( Koha::Patrons->search_limited->count, 3, 'patron_12_1 is not allowed to see patrons from other groups, only patron_11_1, patron_11_2 and patron_12' ); |
| 1147 |
|
1137 |
|
| 1148 |
set_logged_in_user( $patron_21 ); |
1138 |
t::lib::Mocks::mock_userenv({ patron => $patron_21 }); |
| 1149 |
is( Koha::Patrons->search->count, $total_number_of_patrons, 'Non-limited search should return all patrons'); |
1139 |
is( Koha::Patrons->search->count, $total_number_of_patrons, 'Non-limited search should return all patrons'); |
| 1150 |
is( Koha::Patrons->search_limited->count, 1, 'patron_21 is not allowed to see patrons from other groups, only himself' ); |
1140 |
is( Koha::Patrons->search_limited->count, 1, 'patron_21 is not allowed to see patrons from other groups, only himself' ); |
| 1151 |
}; |
1141 |
}; |
|
Lines 1285-1292
subtest 'get_overdues' => sub {
Link Here
|
| 1285 |
} |
1275 |
} |
| 1286 |
); |
1276 |
); |
| 1287 |
|
1277 |
|
| 1288 |
my $module = new Test::MockModule('C4::Context'); |
1278 |
t::lib::Mocks::mock_preference({ branchcode => $library->{branchcode} }); |
| 1289 |
$module->mock( 'userenv', sub { { branch => $library->{branchcode} } } ); |
|
|
| 1290 |
|
1279 |
|
| 1291 |
AddIssue( $patron, $item_1->{barcode}, DateTime->now->subtract( days => 1 ) ); |
1280 |
AddIssue( $patron, $item_1->{barcode}, DateTime->now->subtract( days => 1 ) ); |
| 1292 |
AddIssue( $patron, $item_2->{barcode}, DateTime->now->subtract( days => 5 ) ); |
1281 |
AddIssue( $patron, $item_2->{barcode}, DateTime->now->subtract( days => 5 ) ); |
|
Lines 1597-1613
subtest '->set_password' => sub {
Link Here
|
| 1597 |
|
1586 |
|
| 1598 |
$schema->storage->txn_rollback; |
1587 |
$schema->storage->txn_rollback; |
| 1599 |
}; |
1588 |
}; |
| 1600 |
|
|
|
| 1601 |
|
| 1602 |
|
| 1603 |
# TODO Move to t::lib::Mocks and reuse it! |
| 1604 |
sub set_logged_in_user { |
| 1605 |
my ($patron) = @_; |
| 1606 |
C4::Context->set_userenv( |
| 1607 |
$patron->borrowernumber, $patron->userid, |
| 1608 |
$patron->cardnumber, 'firstname', |
| 1609 |
'surname', $patron->library->branchcode, |
| 1610 |
'Midway Public Library', $patron->flags, |
| 1611 |
'', '' |
| 1612 |
); |
| 1613 |
} |