Bugzilla – Attachment 104790 Details for
Bug 24368
Koha::Libraries->pickup_locations needs refactoring/ratifying
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Help
|
New Account
|
Log In
[x]
|
Forgot Password
Login:
[x]
[patch]
Bug 24368: Comprehensive tests for Koha::Template::Plugin::Branches::pickup_locations
Bug-24368-Comprehensive-tests-for-KohaTemplatePlug.patch (text/plain), 5.57 KB, created by
Jonathan Druart
on 2020-05-12 14:33:10 UTC
(
hide
)
Description:
Bug 24368: Comprehensive tests for Koha::Template::Plugin::Branches::pickup_locations
Filename:
MIME Type:
Creator:
Jonathan Druart
Created:
2020-05-12 14:33:10 UTC
Size:
5.57 KB
patch
obsolete
>From 2a7b09bb85ecd8c26337fd594230dea2c71bb229 Mon Sep 17 00:00:00 2001 >From: Tomas Cohen Arazi <tomascohen@theke.io> >Date: Fri, 8 May 2020 16:04:17 -0300 >Subject: [PATCH] Bug 24368: Comprehensive tests for > Koha::Template::Plugin::Branches::pickup_locations > >Signed-off-by: Tomas Cohen Arazi <tomascohen@theke.io> > >Signed-off-by: Jonathan Druart <jonathan.druart@bugs.koha-community.org> >--- > t/db_dependent/Template/Plugin/Branches.t | 94 ++++++++++++++++------- > 1 file changed, 68 insertions(+), 26 deletions(-) > >diff --git a/t/db_dependent/Template/Plugin/Branches.t b/t/db_dependent/Template/Plugin/Branches.t >index 103476b236..b75b37632b 100644 >--- a/t/db_dependent/Template/Plugin/Branches.t >+++ b/t/db_dependent/Template/Plugin/Branches.t >@@ -113,38 +113,80 @@ subtest 'pickup_locations() tests' => sub { > > plan tests => 8; > >- my $library_1 = { branchcode => 'A' }; >- my $library_2 = { branchcode => 'B' }; >- my $library_3 = { branchcode => 'C' }; >- my @library_array = ( $library_1, $library_2, $library_3 ); >+ $schema->storage->txn_begin; >+ >+ Koha::Libraries->search->update({ pickup_location => 0 }); >+ >+ my $library_1 = $builder->build_object({ class => 'Koha::Libraries', value => { pickup_location => 1 } }); >+ my $library_2 = $builder->build_object({ class => 'Koha::Libraries', value => { pickup_location => 1 } }); >+ my $library_3 = $builder->build_object({ class => 'Koha::Libraries', value => { pickup_location => 1 } }); >+ >+ my $plugin = Koha::Template::Plugin::Branches->new(); >+ my $pickup_locations = $plugin->pickup_locations(); >+ >+ is( scalar @{$pickup_locations}, 3, 'Libraries count is correct' ); > >- my $libraries = Test::MockModule->new('Koha::Libraries'); >- $libraries->mock( >+ $pickup_locations = $plugin->pickup_locations({ search_params => { item => undef }}); >+ is( scalar @{$pickup_locations}, 3, 'item parameter not a ref, fallback to general search' ); >+ >+ $pickup_locations = $plugin->pickup_locations({ search_params => { biblio => undef }}); >+ is( scalar @{$pickup_locations}, 3, 'biblio parameter not a ref, fallback to general search' ); >+ >+ my $item_class = Test::MockModule->new('Koha::Item'); >+ $item_class->mock( > 'pickup_locations', > sub { >- my $result = clone(\@library_array); >- return @$result; >+ return [$library_1]; > } > ); > >- my $plugin = Koha::Template::Plugin::Branches->new(); >- my $pickup_locations = $plugin->pickup_locations(); >+ my $item = $builder->build_sample_item(); >+ my $patron = $builder->build_object({ class => 'Koha::Patrons' }); > >- is( scalar @{$pickup_locations}, 3, 'Libraries count is correct' ); >- for my $library ( @{$pickup_locations} ) { >- ok( ( any { $_->{branchcode} eq $library->{branchcode} } @library_array ), >- 'Library ' . $library->{branchcode} . ' in results' ); >- } >- >- $pickup_locations = $plugin->pickup_locations({ selected => $library_2->{branchcode} }); >- my @selected = grep { exists $_->{selected} } @{ $pickup_locations }; >- is( scalar @selected, 1, '(param) Only one is selected' ); >- is( $selected[0]->{branchcode}, $library_2->{branchcode}, '(param) The selected one is the right one' ); >- >- t::lib::Mocks::mock_userenv({ branchcode => $library_3->{branchcode} }); >- $pickup_locations = $plugin->pickup_locations(); >- @selected = grep { exists $_->{selected} } @{ $pickup_locations }; >- is( scalar @selected, 1, '(userenv) Only one is selected' ); >- is( $selected[0]->{branchcode}, $library_3->{branchcode}, '(userenv) The selected one is the right one' ); >+ $pickup_locations = $plugin->pickup_locations( >+ { search_params => { item => $item, patron => Koha::Patron->new } } ); >+ >+ is( scalar @{$pickup_locations}, 1, 'Only the library returned by $item->pickup_locations is returned' ); >+ is( $pickup_locations->[0]->{branchcode}, $library_1->branchcode, 'Not cheating' ); >+ >+ my $biblio_class = Test::MockModule->new('Koha::Biblio'); >+ $biblio_class->mock( >+ 'pickup_locations', >+ sub { >+ return [$library_2]; >+ } >+ ); >+ >+ my $biblio = $builder->build_sample_biblio(); >+ >+ $pickup_locations = $plugin->pickup_locations( >+ { search_params => { biblio => $biblio, patron => Koha::Patron->new } } ); >+ >+ is( scalar @{$pickup_locations}, 1, 'Only the library returned by $biblio->pickup_locations is returned' ); >+ is( $pickup_locations->[0]->{branchcode}, $library_2->branchcode, 'Not cheating' ); >+ >+ subtest 'selected tests' => sub { >+ >+ plan tests => 4; > >+ t::lib::Mocks::mock_userenv({ branchcode => $library_2->branchcode }); >+ >+ $pickup_locations = $plugin->pickup_locations(); >+ >+ is( scalar @{$pickup_locations}, 3, 'Libraries count is correct' ); >+ foreach my $pickup_location (@{ $pickup_locations }) { >+ next unless exists $pickup_location->{selected} and $pickup_location->{selected} == 1; >+ is( $pickup_location->{branchcode}, $library_2->branchcode, 'The right library is marked as selected' ); >+ } >+ >+ $pickup_locations = $plugin->pickup_locations({ selected => $library_3->branchcode }); >+ >+ is( scalar @{$pickup_locations}, 3, 'Libraries count is correct' ); >+ foreach my $pickup_location (@{ $pickup_locations }) { >+ next unless exists $pickup_location->{selected} and $pickup_location->{selected} == 1; >+ is( $pickup_location->{branchcode}, $library_3->branchcode, 'The right library is marked as selected' ); >+ } >+ }; >+ >+ $schema->storage->txn_rollback; > }; >-- >2.20.1
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 24368
:
104615
|
104616
|
104789
|
104790
|
104830
|
104831