View | Details | Raw Unified | Return to bug 8010
Collapse All | Expand All

(-)a/C4/Auth.pm (-1 / +1 lines)
Lines 330-336 sub get_template_and_user { Link Here
330
                # We show the link in opac
330
                # We show the link in opac
331
                $template->param( EnableOpacSearchHistory => 1 );
331
                $template->param( EnableOpacSearchHistory => 1 );
332
            }
332
            }
333
            if (C4::Context->preference('addSearchHistoryToTheFirstLoggedUser'))
333
            if (C4::Context->preference('LoadSearchHistoryToTheFirstLoggedUser'))
334
            {
334
            {
335
                # And if there are searches performed when the user was not logged in,
335
                # And if there are searches performed when the user was not logged in,
336
                # we add them to the logged-in search history
336
                # we add them to the logged-in search history
(-)a/installer/data/mysql/atomicupdate/bug_8010-add_LoadSearchHistoryToTheFirstLoggedUser_syspref.sql (-1 / +1 lines)
Lines 1-2 Link Here
1
INSERT INTO systempreferences ( `variable`, `value`, `options`, `explanation`, `type` ) VALUES
1
INSERT INTO systempreferences ( `variable`, `value`, `options`, `explanation`, `type` ) VALUES
2
('addSearchHistoryToTheFirstLoggedUser', '1', NULL, 'If ON, the next user will automatically get the last seaches in his history', 'YesNo');
2
('LoadSearchHistoryToTheFirstLoggedUser', '1', NULL, 'If ON, the next user will automatically get the last searches in his history', 'YesNo');
(-)a/installer/data/mysql/sysprefs.sql (-1 / +1 lines)
Lines 234-240 INSERT INTO systempreferences ( `variable`, `value`, `options`, `explanation`, ` Link Here
234
('LinkerModule','Default','Default|FirstMatch|LastMatch','Chooses which linker module to use (see documentation).','Choice'),
234
('LinkerModule','Default','Default|FirstMatch|LastMatch','Chooses which linker module to use (see documentation).','Choice'),
235
('LinkerOptions','','','A pipe-separated list of options for the linker.','free'),
235
('LinkerOptions','','','A pipe-separated list of options for the linker.','free'),
236
('LinkerRelink','1',NULL,'If ON the authority linker will relink headings that have previously been linked every time it runs.','YesNo'),
236
('LinkerRelink','1',NULL,'If ON the authority linker will relink headings that have previously been linked every time it runs.','YesNo'),
237
('LoadSearchHistoryToTheFirstLoggedUser', '1', NULL, 'If ON, the next user will automatically get the last seaches in his history', 'YesNo'),
237
('LoadSearchHistoryToTheFirstLoggedUser', '1', NULL, 'If ON, the next user will automatically get the last searches in his history', 'YesNo'),
238
('LocalCoverImages','0','1','Display local cover images on intranet details pages.','YesNo'),
238
('LocalCoverImages','0','1','Display local cover images on intranet details pages.','YesNo'),
239
('LocalHoldsPriority',  '0', NULL,  'Enables the LocalHoldsPriority feature',  'YesNo'),
239
('LocalHoldsPriority',  '0', NULL,  'Enables the LocalHoldsPriority feature',  'YesNo'),
240
('LocalHoldsPriorityItemControl',  'holdingbranch',  'holdingbranch|homebranch',  'decides if the feature operates using the item''s home or holding library.',  'Choice'),
240
('LocalHoldsPriorityItemControl',  'holdingbranch',  'holdingbranch|homebranch',  'decides if the feature operates using the item''s home or holding library.',  'Choice'),
(-)a/t/db_dependent/Search/History.t (-2 / +128 lines)
Lines 2-8 Link Here
2
2
3
use Modern::Perl;
3
use Modern::Perl;
4
4
5
use Test::More tests => 26;
5
use CGI qw ( -utf8 );
6
use Test::MockModule;
7
use List::MoreUtils qw/all any none/;
8
use t::lib::Mocks;
9
use t::lib::TestBuilder;
10
11
use C4::Auth;
12
use Koha::AuthUtils qw/hash_password/;
13
use Koha::Database;
14
15
use Test::More tests => 27;
6
use Test::Warn;
16
use Test::Warn;
7
use URI::Escape;
17
use URI::Escape;
8
use List::Util qw( shuffle );
18
use List::Util qw( shuffle );
Lines 345-350 sub delete_all { Link Here
345
    });
355
    });
346
}
356
}
347
357
358
subtest 'LoadSearchHistoryToTheFirstLoggedUser working' => sub {
359
plan tests =>2;
360
361
my $query = new CGI;
362
363
my $schema = Koha::Database->schema;
364
my $builder = t::lib::TestBuilder->new;
365
366
# Borrower Creation
367
my $hash = hash_password('password');
368
our $patron = $builder->build( { source => 'Borrower' } );
369
Koha::Patrons->find( $patron->{borrowernumber} )->update_password( $patron->{userid}, $hash );
370
371
my $session = C4::Auth::get_session("");
372
$session->flush;
373
374
sub myMockedget_from_session {
375
    my $expected_recent_searches = [
376
        {
377
            'time' => 1374978877,
378
            'query_cgi' => 'cgi_test',
379
            'total' => 2,
380
            'query_desc' => 'kw,wrdl: history, '
381
        }
382
    ];
383
    return @{$expected_recent_searches};
384
385
}
386
387
my $getfrom = new Test::MockModule( 'C4::Search::History' );
388
$getfrom->mock( 'get_from_session', \&myMockedget_from_session );
389
390
my $cgi = new Test::MockModule( 'CGI');
391
$cgi->mock('cookie', sub {
392
   my ($self, $key) = @_;
393
  if (!ref($key) && $key eq 'CGISESSID'){
394
         return 'ID';
395
   }
396
});
397
398
sub MockedCheckauth {
399
    my ($query,$authnotrequired,$flagsrequired,$type) = @_;
400
    my $userid = $patron->{userid};
401
    my $sessionID = 234;
402
    my $flags = {
403
        superlibrarian    => 1, acquisition       => 0,
404
        borrowers         => 0,
405
        catalogue         => 1, circulate         => 0,
406
        coursereserves    => 0, editauthorities   => 0,
407
        editcatalogue     => 0, management        => 0,
408
        parameters        => 0, permissions       => 0,
409
        plugins           => 0, reports           => 0,
410
        reserveforothers  => 0, serials           => 0,
411
        staffaccess       => 0, tools             => 0,
412
        updatecharges     => 0
413
    };
414
415
    my $session_cookie = $query->cookie(
416
        -name => 'CGISESSID',
417
        -value    => '9884013ae2c441d12e0bc9376242d2a8',
418
        -HttpOnly => 1
419
    );
420
    return ( $userid, $session_cookie, $sessionID, $flags );
421
}
422
423
# Mock checkauth
424
my $auth = new Test::MockModule( 'C4::Auth' );
425
$auth->mock( 'checkauth', \&MockedCheckauth );
426
427
$query->param('koha_login_context', 'opac');
428
$query->param('userid', $patron->{userid});
429
$query->param('password', 'password');
430
431
# Test when the syspref is disabled
432
t::lib::Mocks::mock_preference('LoadSearchHistoryToTheFirstLoggedUser', 0);
433
my $result = $schema->resultset('SearchHistory')->search()->count;
434
435
my ( $template, $loggedinuser, $cookies ) = get_template_and_user(
436
    {
437
        template_name   => "opac-user.tt",
438
        query           => $query,
439
        type            => "opac",
440
        authnotrequired => 0,
441
        debug           => 1
442
    }
443
);
444
445
my $result2 = $schema->resultset('SearchHistory')->search()->count;
446
is($result2, $result, 'no new search added to borrower');
447
448
# Test when the syspref is enabled
449
t::lib::Mocks::mock_preference('LoadSearchHistoryToTheFirstLoggedUser', 1);
450
$query->param('koha_login_context', 'opac');
451
$query->param('userid', $patron->{userid});
452
$query->param('password', 'password');
453
$query->cookie(
454
        -name     => 'CGISESSID',
455
        -value    => $session->id,
456
        -HttpOnly => 1
457
);
458
459
$result = $schema->resultset('SearchHistory')->search()->count;
460
461
( $template, $loggedinuser, $cookies ) = get_template_and_user(
462
    {
463
        template_name   => "opac-user.tt",
464
        query           => $query,
465
        type            => "opac",
466
        authnotrequired => 0,
467
        debug           => 1
468
    }
469
);
470
471
$result2 = $schema->resultset('SearchHistory')->search()->count;
472
is($result2, $result+1, 'new search added to borrower');
473
};
474
348
$dbh->rollback;
475
$dbh->rollback;
349
476
350
done_testing;
477
done_testing;
351
- 

Return to bug 8010