Bugzilla – Attachment 61223 Details for
Bug 8010
Search history can be added to the wrong patron
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Help
|
New Account
|
Log In
[x]
|
Forgot Password
Login:
[x]
[patch]
BUG 8010: Correct a few syntax errors, and moved tests
BUG-8010-Correct-a-few-syntax-errors-and-moved-tes.patch (text/plain), 7.56 KB, created by
Baptiste Wojtkowski (bwoj)
on 2017-03-17 16:15:59 UTC
(
hide
)
Description:
BUG 8010: Correct a few syntax errors, and moved tests
Filename:
MIME Type:
Creator:
Baptiste Wojtkowski (bwoj)
Created:
2017-03-17 16:15:59 UTC
Size:
7.56 KB
patch
obsolete
>From 5c420c6dfc8f507551ffe1ad0abfcb8e76fd5753 Mon Sep 17 00:00:00 2001 >From: Baptiste Wojtkowski <baptiste.wojtkowski@biblibre.com> >Date: Fri, 17 Mar 2017 16:12:59 +0000 >Subject: [PATCH] BUG 8010: Correct a few syntax errors, and moved tests > >- Tests are now in t/db_dependent/Search/History.t >- There were 2 differents sysprefs in sysprefs.sql and in atomicupdate => fixed >--- > C4/Auth.pm | 2 +- > ...adSearchHistoryToTheFirstLoggedUser_syspref.sql | 2 +- > installer/data/mysql/sysprefs.sql | 2 +- > t/db_dependent/Search/History.t | 129 ++++++++++++++++++++- > 4 files changed, 131 insertions(+), 4 deletions(-) > >diff --git a/C4/Auth.pm b/C4/Auth.pm >index 5b418a6..9cf6af8 100644 >--- a/C4/Auth.pm >+++ b/C4/Auth.pm >@@ -330,7 +330,7 @@ sub get_template_and_user { > # We show the link in opac > $template->param( EnableOpacSearchHistory => 1 ); > } >- if (C4::Context->preference('addSearchHistoryToTheFirstLoggedUser')) >+ if (C4::Context->preference('LoadSearchHistoryToTheFirstLoggedUser')) > { > # And if there are searches performed when the user was not logged in, > # we add them to the logged-in search history >diff --git a/installer/data/mysql/atomicupdate/bug_8010-add_LoadSearchHistoryToTheFirstLoggedUser_syspref.sql b/installer/data/mysql/atomicupdate/bug_8010-add_LoadSearchHistoryToTheFirstLoggedUser_syspref.sql >index 78c7256..157e3ee 100644 >--- a/installer/data/mysql/atomicupdate/bug_8010-add_LoadSearchHistoryToTheFirstLoggedUser_syspref.sql >+++ b/installer/data/mysql/atomicupdate/bug_8010-add_LoadSearchHistoryToTheFirstLoggedUser_syspref.sql >@@ -1,2 +1,2 @@ > INSERT INTO systempreferences ( `variable`, `value`, `options`, `explanation`, `type` ) VALUES >-('addSearchHistoryToTheFirstLoggedUser', '1', NULL, 'If ON, the next user will automatically get the last seaches in his history', 'YesNo'); >+('LoadSearchHistoryToTheFirstLoggedUser', '1', NULL, 'If ON, the next user will automatically get the last searches in his history', 'YesNo'); >diff --git a/installer/data/mysql/sysprefs.sql b/installer/data/mysql/sysprefs.sql >index 9993523..c930530 100644 >--- a/installer/data/mysql/sysprefs.sql >+++ b/installer/data/mysql/sysprefs.sql >@@ -234,7 +234,7 @@ INSERT INTO systempreferences ( `variable`, `value`, `options`, `explanation`, ` > ('LinkerModule','Default','Default|FirstMatch|LastMatch','Chooses which linker module to use (see documentation).','Choice'), > ('LinkerOptions','','','A pipe-separated list of options for the linker.','free'), > ('LinkerRelink','1',NULL,'If ON the authority linker will relink headings that have previously been linked every time it runs.','YesNo'), >-('LoadSearchHistoryToTheFirstLoggedUser', '1', NULL, 'If ON, the next user will automatically get the last seaches in his history', 'YesNo'), >+('LoadSearchHistoryToTheFirstLoggedUser', '1', NULL, 'If ON, the next user will automatically get the last searches in his history', 'YesNo'), > ('LocalCoverImages','0','1','Display local cover images on intranet details pages.','YesNo'), > ('LocalHoldsPriority', '0', NULL, 'Enables the LocalHoldsPriority feature', 'YesNo'), > ('LocalHoldsPriorityItemControl', 'holdingbranch', 'holdingbranch|homebranch', 'decides if the feature operates using the item''s home or holding library.', 'Choice'), >diff --git a/t/db_dependent/Search/History.t b/t/db_dependent/Search/History.t >index 27a7a73..7044921 100644 >--- a/t/db_dependent/Search/History.t >+++ b/t/db_dependent/Search/History.t >@@ -2,7 +2,17 @@ > > use Modern::Perl; > >-use Test::More tests => 26; >+use CGI qw ( -utf8 ); >+use Test::MockModule; >+use List::MoreUtils qw/all any none/; >+use t::lib::Mocks; >+use t::lib::TestBuilder; >+ >+use C4::Auth; >+use Koha::AuthUtils qw/hash_password/; >+use Koha::Database; >+ >+use Test::More tests => 27; > use Test::Warn; > use URI::Escape; > use List::Util qw( shuffle ); >@@ -345,6 +355,123 @@ sub delete_all { > }); > } > >+subtest 'LoadSearchHistoryToTheFirstLoggedUser working' => sub { >+plan tests =>2; >+ >+my $query = new CGI; >+ >+my $schema = Koha::Database->schema; >+my $builder = t::lib::TestBuilder->new; >+ >+# Borrower Creation >+my $hash = hash_password('password'); >+our $patron = $builder->build( { source => 'Borrower' } ); >+Koha::Patrons->find( $patron->{borrowernumber} )->update_password( $patron->{userid}, $hash ); >+ >+my $session = C4::Auth::get_session(""); >+$session->flush; >+ >+sub myMockedget_from_session { >+ my $expected_recent_searches = [ >+ { >+ 'time' => 1374978877, >+ 'query_cgi' => 'cgi_test', >+ 'total' => 2, >+ 'query_desc' => 'kw,wrdl: history, ' >+ } >+ ]; >+ return @{$expected_recent_searches}; >+ >+} >+ >+my $getfrom = new Test::MockModule( 'C4::Search::History' ); >+$getfrom->mock( 'get_from_session', \&myMockedget_from_session ); >+ >+my $cgi = new Test::MockModule( 'CGI'); >+$cgi->mock('cookie', sub { >+ my ($self, $key) = @_; >+ if (!ref($key) && $key eq 'CGISESSID'){ >+ return 'ID'; >+ } >+}); >+ >+sub MockedCheckauth { >+ my ($query,$authnotrequired,$flagsrequired,$type) = @_; >+ my $userid = $patron->{userid}; >+ my $sessionID = 234; >+ my $flags = { >+ superlibrarian => 1, acquisition => 0, >+ borrowers => 0, >+ catalogue => 1, circulate => 0, >+ coursereserves => 0, editauthorities => 0, >+ editcatalogue => 0, management => 0, >+ parameters => 0, permissions => 0, >+ plugins => 0, reports => 0, >+ reserveforothers => 0, serials => 0, >+ staffaccess => 0, tools => 0, >+ updatecharges => 0 >+ }; >+ >+ my $session_cookie = $query->cookie( >+ -name => 'CGISESSID', >+ -value => '9884013ae2c441d12e0bc9376242d2a8', >+ -HttpOnly => 1 >+ ); >+ return ( $userid, $session_cookie, $sessionID, $flags ); >+} >+ >+# Mock checkauth >+my $auth = new Test::MockModule( 'C4::Auth' ); >+$auth->mock( 'checkauth', \&MockedCheckauth ); >+ >+$query->param('koha_login_context', 'opac'); >+$query->param('userid', $patron->{userid}); >+$query->param('password', 'password'); >+ >+# Test when the syspref is disabled >+t::lib::Mocks::mock_preference('LoadSearchHistoryToTheFirstLoggedUser', 0); >+my $result = $schema->resultset('SearchHistory')->search()->count; >+ >+my ( $template, $loggedinuser, $cookies ) = get_template_and_user( >+ { >+ template_name => "opac-user.tt", >+ query => $query, >+ type => "opac", >+ authnotrequired => 0, >+ debug => 1 >+ } >+); >+ >+my $result2 = $schema->resultset('SearchHistory')->search()->count; >+is($result2, $result, 'no new search added to borrower'); >+ >+# Test when the syspref is enabled >+t::lib::Mocks::mock_preference('LoadSearchHistoryToTheFirstLoggedUser', 1); >+$query->param('koha_login_context', 'opac'); >+$query->param('userid', $patron->{userid}); >+$query->param('password', 'password'); >+$query->cookie( >+ -name => 'CGISESSID', >+ -value => $session->id, >+ -HttpOnly => 1 >+); >+ >+$result = $schema->resultset('SearchHistory')->search()->count; >+ >+( $template, $loggedinuser, $cookies ) = get_template_and_user( >+ { >+ template_name => "opac-user.tt", >+ query => $query, >+ type => "opac", >+ authnotrequired => 0, >+ debug => 1 >+ } >+); >+ >+$result2 = $schema->resultset('SearchHistory')->search()->count; >+is($result2, $result+1, 'new search added to borrower'); >+}; >+ > $dbh->rollback; > > done_testing; >-- >2.7.4
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 8010
:
60158
|
60183
|
60187
|
61223
|
61251
|
61256
|
61257
|
61258
|
61288
|
61289
|
61290