Bugzilla – Attachment 111769 Details for
Bug 24786
Allow setting a cash register for a login session and configuring library-default cash registers
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Help
|
New Account
|
Log In
[x]
|
Forgot Password
Login:
[x]
[patch]
Bug 24786: (QA follow-up) Unit tests for Registers plugin
Bug-24786-QA-follow-up-Unit-tests-for-Registers-pl.patch (text/plain), 7.95 KB, created by
Martin Renvoize (ashimema)
on 2020-10-15 16:05:51 UTC
(
hide
)
Description:
Bug 24786: (QA follow-up) Unit tests for Registers plugin
Filename:
MIME Type:
Creator:
Martin Renvoize (ashimema)
Created:
2020-10-15 16:05:51 UTC
Size:
7.95 KB
patch
obsolete
>From 403cb126c121204890eef49576df74e0befab302 Mon Sep 17 00:00:00 2001 >From: Martin Renvoize <martin.renvoize@ptfs-europe.com> >Date: Thu, 15 Oct 2020 17:03:04 +0100 >Subject: [PATCH] Bug 24786: (QA follow-up) Unit tests for Registers plugin > >--- > Koha/Template/Plugin/Registers.pm | 5 +- > .../Koha/Template/Plugin/Registers.t | 173 ++++++++++++++++++ > t/lib/Mocks.pm | 11 +- > 3 files changed, 185 insertions(+), 4 deletions(-) > create mode 100644 t/db_dependent/Koha/Template/Plugin/Registers.t > >diff --git a/Koha/Template/Plugin/Registers.pm b/Koha/Template/Plugin/Registers.pm >index 05e0579544..7baf5d6bf8 100644 >--- a/Koha/Template/Plugin/Registers.pm >+++ b/Koha/Template/Plugin/Registers.pm >@@ -86,9 +86,8 @@ sub all { > > my $filters = $params->{filters} // {}; > my $where; >- $where->{branch} = >- C4::Context->userenv ? C4::Context->userenv->{'branch'} : undef >- if $filters->{current_branch}; >+ $where->{branch} = C4::Context->userenv->{'branch'} >+ if ( $filters->{current_branch} && C4::Context->userenv ); > my $registers = Koha::Cash::Registers->search($where)->unblessed(); > for my $register ( @{$registers} ) { > $register->{selected} = ( defined( $self->session_register_id ) >diff --git a/t/db_dependent/Koha/Template/Plugin/Registers.t b/t/db_dependent/Koha/Template/Plugin/Registers.t >new file mode 100644 >index 0000000000..7bc36e47d9 >--- /dev/null >+++ b/t/db_dependent/Koha/Template/Plugin/Registers.t >@@ -0,0 +1,173 @@ >+#!/usr/bin/perl >+ >+# Copyright PTFS Europe 2020 >+ >+# This file is part of Koha. >+# >+# Koha is free software; you can redistribute it and/or modify it under the >+# terms of the GNU General Public License as published by the Free Software >+# Foundation; either version 3 of the License, or (at your option) any later >+# version. >+# >+# Koha is distributed in the hope that it will be useful, but WITHOUT ANY >+# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR >+# A PARTICULAR PURPOSE. See the GNU General Public License for more details. >+# >+# You should have received a copy of the GNU General Public License along >+# with Koha; if not, see <http://www.gnu.org/licenses>. >+ >+use Modern::Perl; >+use Test::More tests => 4; >+ >+use t::lib::TestBuilder; >+use t::lib::Mocks; >+ >+use C4::Context; >+use Koha::Database; >+ >+BEGIN { >+ use_ok('Koha::Template::Plugin::Registers'); >+} >+ >+my $schema = Koha::Database->schema; >+my $builder = t::lib::TestBuilder->new; >+ >+subtest 'session_register_id' => sub { >+ >+ plan tests => 3; >+ >+ my $plugin = Koha::Template::Plugin::Registers->new(); >+ ok( $plugin, "Plugin initialized" ); >+ is( $plugin->session_register_id, >+ '', "Returns empty string if no userenv is set" ); >+ t::lib::Mocks::mock_userenv( { register_id => '1' } ); >+ is( $plugin->session_register_id, >+ '1', "Returns the register id when set in the userenv" ); >+ >+ # Unset the userenv >+ C4::Context->_new_userenv(undef); >+}; >+ >+subtest 'session_register_name' => sub { >+ >+ plan tests => 3; >+ >+ my $plugin = Koha::Template::Plugin::Registers->new(); >+ ok( $plugin, "Plugin initialized" ); >+ is( $plugin->session_register_name, >+ '', "Returns empty string if no userenv is set" ); >+ t::lib::Mocks::mock_userenv( { register_name => 'Register One' } ); >+ is( $plugin->session_register_name, >+ 'Register One', "Returns the register name when set in the userenv" ); >+ >+ # Unset the userenv >+ C4::Context->_new_userenv(undef); >+}; >+ >+subtest 'all() tests' => sub { >+ >+ plan tests => 20; >+ >+ $schema->storage->txn_begin; >+ >+ my $library1 = $builder->build_object( >+ { >+ class => 'Koha::Libraries' >+ } >+ ); >+ my $register1 = $builder->build_object( >+ { >+ class => 'Koha::Cash::Registers', >+ value => { >+ branch => $library1->branchcode, >+ branch_default => 0 >+ } >+ } >+ ); >+ my $register2 = $builder->build_object( >+ { >+ class => 'Koha::Cash::Registers', >+ value => { >+ branch => $library1->branchcode, >+ branch_default => 1 >+ } >+ } >+ ); >+ >+ my $library2 = $builder->build_object( >+ { >+ class => 'Koha::Libraries' >+ } >+ ); >+ my $register3 = $builder->build_object( >+ { >+ class => 'Koha::Cash::Registers', >+ value => { >+ branch => $library2->branchcode >+ } >+ } >+ ); >+ >+ my $plugin = Koha::Template::Plugin::Registers->new(); >+ ok( $plugin, "Plugin initialized" ); >+ >+ my $result = $plugin->all; >+ is( ref($result), 'ARRAY', "Return arrayref (no userenv, no filters)" ); >+ is( scalar( @{$result} ), >+ 3, "Array contains all 3 registers (no userenv, no filters)" ); >+ for my $register ( @{$result} ) { >+ is( $register->{selected}, 0, "Register is not selected (no userenv)" ); >+ } >+ >+ $result = $plugin->all( { filters => { current_branch => 1 } } ); >+ is( ref($result), 'ARRAY', >+ "Return arrayref (no userenv, filters: current_branch)" ); >+ >+ t::lib::Mocks::mock_userenv( { branchcode => $library1->branchcode } ); >+ $result = $plugin->all; >+ is( ref($result), 'ARRAY', >+ "Return arrayref (userenv: branchcode, no filters)" ); >+ is( scalar( @{$result} ), >+ 3, "Array contains all 3 registers (userenv: branchcode, no filters)" ); >+ for my $register ( @{$result} ) { >+ is( $register->{selected}, 0, >+ "Register is not selected (userenv: branchcode, no filters)" ); >+ } >+ >+ $result = $plugin->all( { filters => { current_branch => 1 } } ); >+ is( ref($result), 'ARRAY', >+ "Return arrayref (userenv: branchcode, filters: current_branch)" ); >+ is( >+ scalar( @{$result} ), >+ 2, >+"Array contains 2 branch registers (userenv: branchcode, filters: current_branch)" >+ ); >+ for my $register ( @{$result} ) { >+ is( $register->{selected}, 0, >+"Register is not selected (userenv: branchcode, filters: current_branch)" >+ ); >+ } >+ >+ t::lib::Mocks::mock_userenv( >+ { branchcode => $library1->branchcode, register_id => $register2->id } >+ ); >+ $result = $plugin->all( { filters => { current_branch => 1 } } ); >+ is( ref($result), 'ARRAY', >+"Return arrayref (userenv: branchcode + register_id, filters: current_branch)" >+ ); >+ is( >+ scalar( @{$result} ), >+ 2, >+"Array contains 2 branch registers (userenv: branchcode + register_id, filters: current_branch)" >+ ); >+ for my $register ( @{$result} ) { >+ my $selected = ( $register->{id} == $register2->id ) ? 1 : 0; >+ is( $register->{selected}, $selected, >+"Register is selected $selected (userenv: brancode, filters: current_branch)" >+ ); >+ } >+ >+ $schema->storage->txn_rollback; >+}; >+ >+1; >diff --git a/t/lib/Mocks.pm b/t/lib/Mocks.pm >index 35aa8f900f..17d54f1a53 100644 >--- a/t/lib/Mocks.pm >+++ b/t/lib/Mocks.pm >@@ -60,9 +60,18 @@ sub mock_userenv { > my $branchname = $params->{branchname} || $userenv->{branchname}; > my $flags = $params->{flags} || $userenv->{flags} || 0; > my $emailaddress = $params->{emailaddress} || $userenv->{emailaddress}; >+ my $desk_id = $params->{desk_id} || $userenv->{desk_id}; >+ my $desk_name = $params->{desk_name} || $userenv->{desk_name}; >+ my $register_id = $params->{register_id} || $userenv->{register_id}; >+ my $register_name = $params->{register_name} || $userenv->{register_name}; > my ( $shibboleth ); > >- C4::Context->set_userenv($usernum, $userid, $cardnumber, $firstname, $surname, $branchcode, $branchname, $flags, $emailaddress, $shibboleth ); >+ C4::Context->set_userenv( >+ $usernum, $userid, $cardnumber, $firstname, >+ $surname, $branchcode, $branchname, $flags, >+ $emailaddress, $shibboleth, $desk_id, $desk_name, >+ $register_id, $register_name >+ ); > } > > 1; >-- >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 24786
:
107145
|
107146
|
107147
|
107148
|
107149
|
107739
|
107740
|
107741
|
107742
|
107743
|
107754
|
107755
|
107756
|
107757
|
107758
|
107759
|
107957
|
107958
|
107959
|
107960
|
107961
|
107962
|
108060
|
108061
|
108062
|
108063
|
108064
|
108065
|
108066
|
108510
|
108511
|
108512
|
108513
|
108514
|
108515
|
108516
|
110162
|
110163
|
110164
|
110165
|
110166
|
110167
|
110168
|
110187
|
110188
|
110189
|
110190
|
110191
|
110192
|
110193
|
111066
|
111067
|
111068
|
111069
|
111070
|
111071
|
111072
|
111074
|
111126
|
111127
|
111128
|
111129
|
111130
|
111131
|
111132
|
111133
|
111220
|
111221
|
111222
|
111223
|
111224
|
111225
|
111226
|
111227
|
111228
|
111229
|
111230
|
111231
|
111232
|
111233
|
111234
|
111235
|
111611
|
111612
|
111613
|
111614
|
111615
|
111616
|
111617
|
111618
|
111619
|
111620
|
111623
|
111725
|
111757
|
111758
|
111759
|
111760
|
111761
|
111762
|
111763
|
111764
|
111765
|
111766
|
111767
|
111768
|
111769
|
111770
|
111776
|
111777
|
111778
|
111779
|
111780
|
111781
|
111782
|
111783
|
111784
|
111785
|
111786
|
111787
|
111788
|
112985
|
112988
|
112989
|
113226
|
113227
|
113241
|
113251
|
113253
|
113256
|
113257
|
113260