Bugzilla – Attachment 129508 Details for
Bug 29886
Add Koha::Suggestions->search_limited
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Help
|
New Account
|
Log In
[x]
|
Forgot Password
Login:
[x]
[patch]
Bug 29886: Unit tests
Bug-29886-Unit-tests.patch (text/plain), 3.40 KB, created by
Tomás Cohen Arazi (tcohen)
on 2022-01-14 17:52:26 UTC
(
hide
)
Description:
Bug 29886: Unit tests
Filename:
MIME Type:
Creator:
Tomás Cohen Arazi (tcohen)
Created:
2022-01-14 17:52:26 UTC
Size:
3.40 KB
patch
obsolete
>From 65034cb709b8d39e03a42a6dbd4c250cc73d8675 Mon Sep 17 00:00:00 2001 >From: Tomas Cohen Arazi <tomascohen@theke.io> >Date: Fri, 14 Jan 2022 14:49:29 -0300 >Subject: [PATCH] Bug 29886: Unit tests > >Signed-off-by: Tomas Cohen Arazi <tomascohen@theke.io> >--- > t/db_dependent/Koha/Suggestions.t | 74 ++++++++++++++++++++++++++++++- > 1 file changed, 73 insertions(+), 1 deletion(-) > >diff --git a/t/db_dependent/Koha/Suggestions.t b/t/db_dependent/Koha/Suggestions.t >index 9cd1bff8c0..8dbb93afd3 100755 >--- a/t/db_dependent/Koha/Suggestions.t >+++ b/t/db_dependent/Koha/Suggestions.t >@@ -19,7 +19,7 @@ > > use Modern::Perl; > >-use Test::More tests => 8; >+use Test::More tests => 9; > use Test::Exception; > > use Koha::Suggestion; >@@ -27,6 +27,7 @@ use Koha::Suggestions; > use Koha::Database; > use Koha::DateUtils qw( dt_from_string output_pref ); > >+use t::lib::Mocks; > use t::lib::TestBuilder; > > my $schema = Koha::Database->new->schema; >@@ -257,3 +258,74 @@ subtest 'fund' => sub { > > $schema->storage->txn_rollback; > }; >+ >+subtest 'search_limited() tests' => sub { >+ >+ plan tests => 4; >+ >+ $schema->storage->txn_begin; >+ >+ # Two libraries >+ my $library_1 = $builder->build_object({ class => 'Koha::Libraries' }); >+ my $library_2 = $builder->build_object({ class => 'Koha::Libraries' }); >+ >+ # A patron from $library_1, that is not superlibrarian at all >+ my $patron = $builder->build_object( >+ { >+ class => 'Koha::Patrons', >+ value => { branchcode => $library_1->id, flags => 0 } >+ } >+ ); >+ >+ # Add 3 suggestions, to be sorted by author >+ my $suggestion_1 = $builder->build_object( >+ { >+ class => 'Koha::Suggestions', >+ value => { branchcode => $library_1->id, author => 'A' } >+ } >+ ); >+ my $suggestion_2 = $builder->build_object( >+ { >+ class => 'Koha::Suggestions', >+ value => { branchcode => $library_2->id, author => 'B' } >+ } >+ ); >+ my $suggestion_3 = $builder->build_object( >+ { >+ class => 'Koha::Suggestions', >+ value => { branchcode => $library_2->id, author => 'C' } >+ } >+ ); >+ >+ my $resultset = Koha::Suggestions->search( >+ { branchcode => [ $library_1->id, $library_2->id ] }, >+ { order_by => { -desc => ['author'] } } ); >+ >+ is( $resultset->count, 3, 'Only this three suggestions are returned' ); >+ >+ # Now the tests >+ t::lib::Mocks::mock_userenv({ patron => $patron, branchcode => $library_1->id }); >+ >+ # Disable IndependentBranches >+ t::lib::Mocks::mock_preference( 'IndependentBranches', 0 ); >+ >+ my $filtered_rs = $resultset->search_limited; >+ is( $filtered_rs->count, 3, 'No IndependentBranches, all suggestions returned' ); >+ >+ # Enable IndependentBranches >+ t::lib::Mocks::mock_preference( 'IndependentBranches', 1 ); >+ >+ $filtered_rs = $resultset->search_limited; >+ >+ is( $filtered_rs->count, 1, 'IndependentBranches, only suggestions from own branch returned' ); >+ >+ # Make the patron superlibrarian to override IndependentBranches >+ $patron->flags(1)->store; >+ # So it reloads C4::Context->userenv->{flags} >+ t::lib::Mocks::mock_userenv({ patron => $patron, branchcode => $library_1->id }); >+ >+ $filtered_rs = $resultset->search_limited; >+ is( $filtered_rs->count, 3, 'IndependentBranches but patron is superlibrarian, all suggestions returned' ); >+ >+ $schema->storage->txn_rollback; >+}; >-- >2.32.0
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Diff
View Attachment As Raw
Actions:
View
|
Diff
|
Splinter Review
Attachments on
bug 29886
:
129508
|
129509
|
129709
|
129710
|
130294
|
130295
|
130296