Lines 19-25
Link Here
|
19 |
|
19 |
|
20 |
use Modern::Perl; |
20 |
use Modern::Perl; |
21 |
|
21 |
|
22 |
use Test::More tests => 6; |
22 |
use Test::More tests => 7; |
23 |
use Test::Exception; |
23 |
use Test::Exception; |
24 |
|
24 |
|
25 |
use Koha::Suggestion; |
25 |
use Koha::Suggestion; |
Lines 28-33
use Koha::Database;
Link Here
|
28 |
use Koha::DateUtils; |
28 |
use Koha::DateUtils; |
29 |
|
29 |
|
30 |
use t::lib::TestBuilder; |
30 |
use t::lib::TestBuilder; |
|
|
31 |
use t::lib::Mocks; |
31 |
|
32 |
|
32 |
my $schema = Koha::Database->new->schema; |
33 |
my $schema = Koha::Database->new->schema; |
33 |
$schema->storage->txn_begin; |
34 |
$schema->storage->txn_begin; |
Lines 171-173
subtest 'constraints' => sub {
Link Here
|
171 |
$schema->storage->dbh->{PrintError} = $print_error; |
172 |
$schema->storage->dbh->{PrintError} = $print_error; |
172 |
$schema->storage->txn_rollback; |
173 |
$schema->storage->txn_rollback; |
173 |
}; |
174 |
}; |
174 |
- |
175 |
|
|
|
176 |
subtest 'filter_by_user_branch' => sub { |
177 |
plan tests => 9; |
178 |
$schema->storage->txn_begin; |
179 |
|
180 |
my $pre_count = Koha::Suggestions->search()->count; |
181 |
|
182 |
my $branch = $builder->build_object( { class => "Koha::Libraries" } ); |
183 |
|
184 |
my $patron1 = $builder->build_object({class => "Koha::Patrons"}); |
185 |
my $patron2 = $builder->build_object({class => "Koha::Patrons"}); |
186 |
|
187 |
#Create a suggestion at each branch |
188 |
foreach( $branch->branchcode, $patron1->branchcode, $patron2->branchcode){ |
189 |
my $suggestion = $builder->build_object( |
190 |
{ |
191 |
class => "Koha::Suggestions", |
192 |
value => { |
193 |
suggestedby => $patron1->borrowernumber, |
194 |
branchcode => $_, |
195 |
managedby => undef, |
196 |
acceptedby => undef, |
197 |
rejectedby => undef, |
198 |
budgetid => undef, |
199 |
} |
200 |
} |
201 |
); |
202 |
} |
203 |
|
204 |
my $unfiltered_count = Koha::Suggestions->search()->count; |
205 |
is( $unfiltered_count, $pre_count + 3, "We added 3 new suggestions" ); |
206 |
|
207 |
t::lib::Mocks::mock_preference( 'IndependentBranches', 1 ); |
208 |
t::lib::Mocks::mock_userenv({ branchcode => $patron1->branchcode, flags => 1 }); |
209 |
my $implicitly_filtered = Koha::Suggestions->search()->filter_by_user_branch()->count; |
210 |
my $explicitly_filtered = Koha::Suggestions->search()->filter_by_user_branch(1)->count; |
211 |
is( $implicitly_filtered, $unfiltered_count, "If not explicitly filtering with IndependentBranches we get all suggestions for a superlibrarian"); |
212 |
is( $explicitly_filtered, 1, "If explicitly filtering with IndependentBranches we get only suggestions for a superlibrarian's branch"); |
213 |
|
214 |
t::lib::Mocks::mock_userenv({ branchcode => $patron2->branchcode, flags => 0 }); |
215 |
$implicitly_filtered = Koha::Suggestions->search()->filter_by_user_branch()->count; |
216 |
$explicitly_filtered = Koha::Suggestions->search()->filter_by_user_branch(1)->count; |
217 |
is( $implicitly_filtered, 1, "If not explicitly filtering with IndependentBranches we get only suggestions for a regular librarian's branch"); |
218 |
is( $explicitly_filtered, 1, "If explicitly filtering with IndependentBranchs we get only suggestions for a regular librarian's branch"); |
219 |
|
220 |
t::lib::Mocks::mock_preference( 'IndependentBranches', 0 ); |
221 |
t::lib::Mocks::mock_userenv({ branchcode => $patron1->branchcode, flags => 1 }); |
222 |
$implicitly_filtered = Koha::Suggestions->search()->filter_by_user_branch()->count; |
223 |
$explicitly_filtered = Koha::Suggestions->search()->filter_by_user_branch(1)->count; |
224 |
is( $implicitly_filtered, $unfiltered_count, "If not explicitly filtering we get all suggestions for a superlibrarian"); |
225 |
is( $explicitly_filtered, 1, "If explicitly filtering we get only suggestions for a superlibrarian's branch"); |
226 |
|
227 |
t::lib::Mocks::mock_userenv({ branchcode => $patron2->branchcode, flags => 0 }); |
228 |
$implicitly_filtered = Koha::Suggestions->search()->filter_by_user_branch()->count; |
229 |
$explicitly_filtered = Koha::Suggestions->search()->filter_by_user_branch(1)->count; |
230 |
is( $implicitly_filtered, $unfiltered_count, "If not explicitly filtering we get all suggestions for a regular librarian"); |
231 |
is( $explicitly_filtered, 1, "If explicitly filtering we get only suggestions for a regular librarian's branch"); |
232 |
|
233 |
}; |