Bug 19489: Koha::Account::Line->issue method and Unit test
[koha.git] / t / db_dependent / Auth.t
index c8fb1f1..e0b6036 100644 (file)
@@ -10,7 +10,7 @@ use CGI qw ( -utf8 );
 use Test::MockObject;
 use Test::MockModule;
 use List::MoreUtils qw/all any none/;
-use Test::More tests => 22;
+use Test::More tests => 20;
 use Test::Warn;
 use t::lib::Mocks;
 use t::lib::TestBuilder;
@@ -115,28 +115,27 @@ subtest 'track_login_daily tests' => sub {
 
 };
 
-my $hash1 = hash_password('password');
-my $hash2 = hash_password('password');
+subtest 'no_set_userenv parameter tests' => sub {
 
-{ # tests no_set_userenv parameter
-    my $patron = $builder->build( { source => 'Borrower' } );
-    Koha::Patrons->find( $patron->{borrowernumber} )->update_password( $patron->{userid}, $hash1 );
-    my $library = $builder->build(
-        {
-            source => 'Branch',
-        }
-    );
+    plan tests => 7;
+
+    my $library = $builder->build_object( { class => 'Koha::Libraries' } );
+    my $patron  = $builder->build_object( { class => 'Koha::Patrons' } );
+    my $password = 'password';
 
-    ok( checkpw( $dbh, $patron->{userid}, 'password', undef, undef, 1 ), 'checkpw returns true' );
+    t::lib::Mocks::mock_preference( 'RequireStrongPassword', 0 );
+    $patron->set_password({ password => $password });
+
+    ok( checkpw( $dbh, $patron->userid, $password, undef, undef, 1 ), 'checkpw returns true' );
     is( C4::Context->userenv, undef, 'Userenv should be undef as required' );
     C4::Context->_new_userenv('DUMMY SESSION');
-    C4::Context->set_userenv(0,0,0,'firstname','surname', $library->{branchcode}, 'Library 1', 0, '', '');
-    is( C4::Context->userenv->{branch}, $library->{branchcode}, 'Userenv gives correct branch' );
-    ok( checkpw( $dbh, $patron->{userid}, 'password', undef, undef, 1 ), 'checkpw returns true' );
-    is( C4::Context->userenv->{branch}, $library->{branchcode}, 'Userenv branch is preserved if no_set_userenv is true' );
-    ok( checkpw( $dbh, $patron->{userid}, 'password', undef, undef, 0 ), 'checkpw still returns true' );
-    isnt( C4::Context->userenv->{branch}, $library->{branchcode}, 'Userenv branch is overwritten if no_set_userenv is false' );
-}
+    C4::Context->set_userenv(0,0,0,'firstname','surname', $library->branchcode, 'Library 1', 0, '', '');
+    is( C4::Context->userenv->{branch}, $library->branchcode, 'Userenv gives correct branch' );
+    ok( checkpw( $dbh, $patron->userid, $password, undef, undef, 1 ), 'checkpw returns true' );
+    is( C4::Context->userenv->{branch}, $library->branchcode, 'Userenv branch is preserved if no_set_userenv is true' );
+    ok( checkpw( $dbh, $patron->userid, $password, undef, undef, 0 ), 'checkpw still returns true' );
+    isnt( C4::Context->userenv->{branch}, $library->branchcode, 'Userenv branch is overwritten if no_set_userenv is false' );
+};
 
 # get_template_and_user tests
 
@@ -153,7 +152,7 @@ my $hash2 = hash_password('password');
             borrowers         => 0,
             catalogue         => 1, circulate         => 0,
             coursereserves    => 0, editauthorities   => 0,
-            editcatalogue     => 0, management        => 0,
+            editcatalogue     => 0,
             parameters        => 0, permissions       => 0,
             plugins           => 0, reports           => 0,
             reserveforothers  => 0, serials           => 0,
@@ -253,6 +252,34 @@ my $hash2 = hash_password('password');
     );
     my $file_exists = ( -f $template->{filename} ) ? 1 : 0;
     is ( $file_exists, 1, 'The file errors/errorpage.tt should be accessible (contains integers)' );
+
+    # Regression test for env opac search limit override
+    $ENV{"OPAC_SEARCH_LIMIT"} = "branch:CPL";
+    $ENV{"OPAC_LIMIT_OVERRIDE"} = 1;
+
+    ( $template, $loggedinuser, $cookies) = get_template_and_user(
+        {
+            template_name => 'opac-main.tt',
+            query => $query,
+            type => 'opac',
+            authnotrequired => 1,
+        }
+    );
+    is($template->{VARS}->{'opac_name'}, "CPL", "Opac name was set correctly");
+    is($template->{VARS}->{'opac_search_limit'}, "branch:CPL", "Search limit was set correctly");
+
+    $ENV{"OPAC_SEARCH_LIMIT"} = "branch:multibranch-19";
+
+    ( $template, $loggedinuser, $cookies) = get_template_and_user(
+        {
+            template_name => 'opac-main.tt',
+            query => $query,
+            type => 'opac',
+            authnotrequired => 1,
+        }
+    );
+    is($template->{VARS}->{'opac_name'}, "multibranch-19", "Opac name was set correctly");
+    is($template->{VARS}->{'opac_search_limit'}, "branch:multibranch-19", "Search limit was set correctly");
 }
 
 # Check that there is always an OPACBaseURL set.
@@ -283,5 +310,8 @@ my ( $template2 );
 ok( ( any { 'OPACBaseURL' eq $_ } keys %{$template2->{VARS}} ),
     'OPACBaseURL is in Staff template' );
 
+my $hash1 = hash_password('password');
+my $hash2 = hash_password('password');
+
 ok(C4::Auth::checkpw_hash('password', $hash1), 'password validates with first hash');
 ok(C4::Auth::checkpw_hash('password', $hash2), 'password validates with second hash');