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

(-)a/t/db_dependent/Circulation.t (-6 / +6 lines)
Lines 433-439 my ( $reused_itemnumber_1, $reused_itemnumber_2 ); Link Here
433
subtest "CanBookBeRenewed tests" => sub {
433
subtest "CanBookBeRenewed tests" => sub {
434
    plan tests => 113;
434
    plan tests => 113;
435
435
436
    C4::Context->set_preference('ItemsDeniedRenewal','');
436
    Koha::Config::SysPrefs->set_preference('ItemsDeniedRenewal','');
437
    # Generate test biblio
437
    # Generate test biblio
438
    my $biblio = $builder->build_sample_biblio();
438
    my $biblio = $builder->build_sample_biblio();
439
439
Lines 1183-1191 subtest "CanBookBeRenewed tests" => sub { Link Here
1183
                }
1183
                }
1184
            }
1184
            }
1185
        );
1185
        );
1186
        C4::Context->set_preference('OPACFineNoRenewalsBlockAutoRenew','1');
1186
        Koha::Config::SysPrefs->set_preference('OPACFineNoRenewalsBlockAutoRenew','1');
1187
        C4::Context->set_preference('OPACFineNoRenewals','10');
1187
        Koha::Config::SysPrefs->set_preference('OPACFineNoRenewals','10');
1188
        C4::Context->set_preference('OPACFineNoRenewalsIncludeCredit','1');
1188
        Koha::Config::SysPrefs->set_preference('OPACFineNoRenewalsIncludeCredit','1');
1189
        my $fines_amount = 5;
1189
        my $fines_amount = 5;
1190
        my $account = Koha::Account->new({patron_id => $renewing_borrowernumber});
1190
        my $account = Koha::Account->new({patron_id => $renewing_borrowernumber});
1191
        $account->add_debit(
1191
        $account->add_debit(
Lines 1243-1256 subtest "CanBookBeRenewed tests" => sub { Link Here
1243
        is( $renewokay, 1, 'Renew, even if renewal is automatic' );
1243
        is( $renewokay, 1, 'Renew, even if renewal is automatic' );
1244
        is( $error, 'auto_renew', 'Can auto renew, OPACFineNoRenewals=10, OPACFineNoRenewalsIncludeCredit=1, patron has 15 debt, 5 credit'  );
1244
        is( $error, 'auto_renew', 'Can auto renew, OPACFineNoRenewals=10, OPACFineNoRenewalsIncludeCredit=1, patron has 15 debt, 5 credit'  );
1245
1245
1246
        C4::Context->set_preference('OPACFineNoRenewalsIncludeCredit','0');
1246
        Koha::Config::SysPrefs->set_preference('OPACFineNoRenewalsIncludeCredit','0');
1247
        ( $renewokay, $error ) =
1247
        ( $renewokay, $error ) =
1248
          CanBookBeRenewed( $renewing_borrower_obj, $issue );
1248
          CanBookBeRenewed( $renewing_borrower_obj, $issue );
1249
        is( $renewokay, 0, 'Do not renew, renewal is automatic' );
1249
        is( $renewokay, 0, 'Do not renew, renewal is automatic' );
1250
        is( $error, 'auto_too_much_oweing', 'Cannot auto renew, OPACFineNoRenewals=10, OPACFineNoRenewalsIncludeCredit=1, patron has 15 debt, 5 credit'  );
1250
        is( $error, 'auto_too_much_oweing', 'Cannot auto renew, OPACFineNoRenewals=10, OPACFineNoRenewalsIncludeCredit=1, patron has 15 debt, 5 credit'  );
1251
1251
1252
        $dbh->do('DELETE FROM accountlines WHERE borrowernumber=?', undef, $renewing_borrowernumber);
1252
        $dbh->do('DELETE FROM accountlines WHERE borrowernumber=?', undef, $renewing_borrowernumber);
1253
        C4::Context->set_preference('OPACFineNoRenewalsIncludeCredit','1');
1253
        Koha::Config::SysPrefs->set_preference('OPACFineNoRenewalsIncludeCredit','1');
1254
    };
1254
    };
1255
1255
1256
    subtest "auto_account_expired | BlockExpiredPatronOpacActions" => sub {
1256
    subtest "auto_account_expired | BlockExpiredPatronOpacActions" => sub {
(-)a/t/db_dependent/Context.t (-7 / +8 lines)
Lines 20-25 use Test::More tests => 5; Link Here
20
use Test::MockModule;
20
use Test::MockModule;
21
21
22
use C4::Context;
22
use C4::Context;
23
use Koha::Config::SysPrefs;
23
use Koha::Database;
24
use Koha::Database;
24
25
25
our $schema;
26
our $schema;
Lines 41-66 subtest 'Tests with preferences' => sub { Link Here
41
    my $dbh;
42
    my $dbh;
42
    ok($dbh = C4::Context->dbh(), 'Getting dbh from C4::Context');
43
    ok($dbh = C4::Context->dbh(), 'Getting dbh from C4::Context');
43
44
44
    C4::Context->set_preference('OPACBaseURL','junk');
45
    Koha::Config::SysPrefs->set_preference('OPACBaseURL','junk');
45
    C4::Context->clear_syspref_cache();
46
    C4::Context->clear_syspref_cache();
46
    my $OPACBaseURL = C4::Context->preference('OPACBaseURL');
47
    my $OPACBaseURL = C4::Context->preference('OPACBaseURL');
47
    is($OPACBaseURL,'http://junk','OPACBaseURL saved with http:// when missing it');
48
    is($OPACBaseURL,'http://junk','OPACBaseURL saved with http:// when missing it');
48
49
49
    C4::Context->set_preference('OPACBaseURL','https://junk');
50
    Koha::Config::SysPrefs->set_preference('OPACBaseURL','https://junk');
50
    C4::Context->clear_syspref_cache();
51
    C4::Context->clear_syspref_cache();
51
    $OPACBaseURL = C4::Context->preference('OPACBaseURL');
52
    $OPACBaseURL = C4::Context->preference('OPACBaseURL');
52
    is($OPACBaseURL,'https://junk','OPACBaseURL saved with https:// as specified');
53
    is($OPACBaseURL,'https://junk','OPACBaseURL saved with https:// as specified');
53
54
54
    C4::Context->set_preference('OPACBaseURL','http://junk2');
55
    Koha::Config::SysPrefs->set_preference('OPACBaseURL','http://junk2');
55
    C4::Context->clear_syspref_cache();
56
    C4::Context->clear_syspref_cache();
56
    $OPACBaseURL = C4::Context->preference('OPACBaseURL');
57
    $OPACBaseURL = C4::Context->preference('OPACBaseURL');
57
    is($OPACBaseURL,'http://junk2','OPACBaseURL saved with http:// as specified');
58
    is($OPACBaseURL,'http://junk2','OPACBaseURL saved with http:// as specified');
58
59
59
    C4::Context->set_preference('OPACBaseURL', '');
60
    Koha::Config::SysPrefs->set_preference('OPACBaseURL', '');
60
    $OPACBaseURL = C4::Context->preference('OPACBaseURL');
61
    $OPACBaseURL = C4::Context->preference('OPACBaseURL');
61
    is($OPACBaseURL,'','OPACBaseURL saved empty as specified');
62
    is($OPACBaseURL,'','OPACBaseURL saved empty as specified');
62
63
63
    C4::Context->set_preference('SillyPreference','random');
64
    Koha::Config::SysPrefs->set_preference('SillyPreference','random');
64
    C4::Context->clear_syspref_cache();
65
    C4::Context->clear_syspref_cache();
65
    my $SillyPeference = C4::Context->preference('SillyPreference');
66
    my $SillyPeference = C4::Context->preference('SillyPreference');
66
    is($SillyPeference,'random','SillyPreference saved as specified');
67
    is($SillyPeference,'random','SillyPreference saved as specified');
Lines 73-79 subtest 'Tests with preferences' => sub { Link Here
73
    open my $trace, '>', \$trace_read or die "Can't open variable: $!";
74
    open my $trace, '>', \$trace_read or die "Can't open variable: $!";
74
    $schema->storage->debugfh( $trace );
75
    $schema->storage->debugfh( $trace );
75
76
76
    C4::Context->set_preference('SillyPreference', 'thing1');
77
    Koha::Config::SysPrefs->set_preference('SillyPreference', 'thing1');
77
    my $silly_preference = Koha::Config::SysPrefs->find('SillyPreference');
78
    my $silly_preference = Koha::Config::SysPrefs->find('SillyPreference');
78
    is( $silly_preference->variable, 'SillyPreference', 'set_preference should have kept the case sensitivity' );
79
    is( $silly_preference->variable, 'SillyPreference', 'set_preference should have kept the case sensitivity' );
79
80
Lines 114-120 subtest 'Tests with preferences' => sub { Link Here
114
    $silly_preference->delete();
115
    $silly_preference->delete();
115
116
116
    # AutoEmailNewUser should be a YesNo pref
117
    # AutoEmailNewUser should be a YesNo pref
117
    C4::Context->set_preference('AutoEmailNewUser', '');
118
    Koha::Config::SysPrefs->set_preference('AutoEmailNewUser', '');
118
    my $yesno_pref = Koha::Config::SysPrefs->find('AutoEmailNewUser');
119
    my $yesno_pref = Koha::Config::SysPrefs->find('AutoEmailNewUser');
119
    is( $yesno_pref->value(), 0, 'set_preference should have set the value to 0, instead of an empty string' );
120
    is( $yesno_pref->value(), 0, 'set_preference should have set the value to 0, instead of an empty string' );
120
121
(-)a/t/db_dependent/Koha/Item.t (-7 / +7 lines)
Lines 2213-2224 subtest 'is_denied_renewal' => sub { Link Here
2213
    });
2213
    });
2214
2214
2215
    my $idr_rules = "";
2215
    my $idr_rules = "";
2216
    C4::Context->set_preference('ItemsDeniedRenewal', $idr_rules);
2216
    Koha::Config::SysPrefs->set_preference('ItemsDeniedRenewal', $idr_rules);
2217
    is( $deny_book->is_denied_renewal, 0, 'Renewal allowed when no rules' );
2217
    is( $deny_book->is_denied_renewal, 0, 'Renewal allowed when no rules' );
2218
2218
2219
    # The wrong column delete should be silently ignored and not trigger item delete
2219
    # The wrong column delete should be silently ignored and not trigger item delete
2220
    $idr_rules="delete: [yes]\nwithdrawn: [1]";
2220
    $idr_rules="delete: [yes]\nwithdrawn: [1]";
2221
    C4::Context->set_preference('ItemsDeniedRenewal', $idr_rules);
2221
    Koha::Config::SysPrefs->set_preference('ItemsDeniedRenewal', $idr_rules);
2222
    is( $deny_book->is_denied_renewal, 1, 'Renewal blocked when 1 rules (withdrawn)' );
2222
    is( $deny_book->is_denied_renewal, 1, 'Renewal blocked when 1 rules (withdrawn)' );
2223
    is( $allow_book->is_denied_renewal, 0, 'Renewal allowed when 1 rules not matched (withdrawn)' );
2223
    is( $allow_book->is_denied_renewal, 0, 'Renewal allowed when 1 rules not matched (withdrawn)' );
2224
2224
Lines 2227-2250 subtest 'is_denied_renewal' => sub { Link Here
2227
    is( $allow_book->is_denied_renewal, 0, 'Renewal allowed when 2 rules not matched (withdrawn, itype)' );
2227
    is( $allow_book->is_denied_renewal, 0, 'Renewal allowed when 2 rules not matched (withdrawn, itype)' );
2228
2228
2229
    $idr_rules="withdrawn: [1]\nitype: [HIDE,INVISIBLE]\nlocation: [PROC]";
2229
    $idr_rules="withdrawn: [1]\nitype: [HIDE,INVISIBLE]\nlocation: [PROC]";
2230
    C4::Context->set_preference('ItemsDeniedRenewal', $idr_rules);
2230
    Koha::Config::SysPrefs->set_preference('ItemsDeniedRenewal', $idr_rules);
2231
    is( $deny_book->is_denied_renewal, 1, 'Renewal blocked when 3 rules matched (withdrawn, itype, location)' );
2231
    is( $deny_book->is_denied_renewal, 1, 'Renewal blocked when 3 rules matched (withdrawn, itype, location)' );
2232
    is( $allow_book->is_denied_renewal, 0, 'Renewal allowed when 3 rules not matched (withdrawn, itype, location)' );
2232
    is( $allow_book->is_denied_renewal, 0, 'Renewal allowed when 3 rules not matched (withdrawn, itype, location)' );
2233
2233
2234
    $idr_rules="itemcallnumber: [null]";
2234
    $idr_rules="itemcallnumber: [null]";
2235
    C4::Context->set_preference('ItemsDeniedRenewal', $idr_rules);
2235
    Koha::Config::SysPrefs->set_preference('ItemsDeniedRenewal', $idr_rules);
2236
    is( $deny_book->is_denied_renewal, 1, 'Renewal blocked for undef when null in pref' );
2236
    is( $deny_book->is_denied_renewal, 1, 'Renewal blocked for undef when null in pref' );
2237
2237
2238
    $idr_rules="itemcallnumber: ['']";
2238
    $idr_rules="itemcallnumber: ['']";
2239
    C4::Context->set_preference('ItemsDeniedRenewal', $idr_rules);
2239
    Koha::Config::SysPrefs->set_preference('ItemsDeniedRenewal', $idr_rules);
2240
    is( $deny_book->is_denied_renewal, 0, 'Renewal not blocked for undef when "" in pref' );
2240
    is( $deny_book->is_denied_renewal, 0, 'Renewal not blocked for undef when "" in pref' );
2241
2241
2242
    $idr_rules="itemnotes: [null]";
2242
    $idr_rules="itemnotes: [null]";
2243
    C4::Context->set_preference('ItemsDeniedRenewal', $idr_rules);
2243
    Koha::Config::SysPrefs->set_preference('ItemsDeniedRenewal', $idr_rules);
2244
    is( $deny_book->is_denied_renewal, 0, 'Renewal not blocked for "" when null in pref' );
2244
    is( $deny_book->is_denied_renewal, 0, 'Renewal not blocked for "" when null in pref' );
2245
2245
2246
    $idr_rules="itemnotes: ['']";
2246
    $idr_rules="itemnotes: ['']";
2247
    C4::Context->set_preference('ItemsDeniedRenewal', $idr_rules);
2247
    Koha::Config::SysPrefs->set_preference('ItemsDeniedRenewal', $idr_rules);
2248
    is( $deny_book->is_denied_renewal, 1, 'Renewal blocked for empty string when "" in pref' );
2248
    is( $deny_book->is_denied_renewal, 1, 'Renewal blocked for empty string when "" in pref' );
2249
2249
2250
    $schema->storage->txn_rollback;
2250
    $schema->storage->txn_rollback;
(-)a/t/db_dependent/Koha/REST/Plugin/PluginRoutes.t (-2 / +2 lines)
Lines 165-177 subtest 'Permissions and access to plugin routes tests' => sub { Link Here
165
    ok( exists $routes->{'/contrib/testplugin/patrons/bother'}, 'Route exists' );
165
    ok( exists $routes->{'/contrib/testplugin/patrons/bother'}, 'Route exists' );
166
    ok( exists $routes->{'/contrib/testplugin/public/patrons/bother'}, 'Route exists' );
166
    ok( exists $routes->{'/contrib/testplugin/public/patrons/bother'}, 'Route exists' );
167
167
168
    C4::Context->set_preference( 'RESTPublicAnonymousRequests', 0 );
168
    Koha::Config::SysPrefs->set_preference( 'RESTPublicAnonymousRequests', 0 );
169
169
170
    $t->get_ok('/api/v1/contrib/testplugin/public/patrons/bother')
170
    $t->get_ok('/api/v1/contrib/testplugin/public/patrons/bother')
171
      ->status_is(200, 'Plugin routes not affected by RESTPublicAnonymousRequests')
171
      ->status_is(200, 'Plugin routes not affected by RESTPublicAnonymousRequests')
172
      ->json_is( { bothered => Mojo::JSON->true } );
172
      ->json_is( { bothered => Mojo::JSON->true } );
173
173
174
    C4::Context->set_preference( 'RESTPublicAnonymousRequests', 1 );
174
    Koha::Config::SysPrefs->set_preference( 'RESTPublicAnonymousRequests', 1 );
175
175
176
    $t->get_ok('/api/v1/contrib/testplugin/public/patrons/bother')
176
    $t->get_ok('/api/v1/contrib/testplugin/public/patrons/bother')
177
      ->status_is(200, 'Plugin routes not affected by RESTPublicAnonymousRequests')
177
      ->status_is(200, 'Plugin routes not affected by RESTPublicAnonymousRequests')
(-)a/t/db_dependent/cronjobs/advance_notices_digest.t (-1 / +1 lines)
Lines 155-161 DELETESQL Link Here
155
        }
155
        }
156
    });
156
    });
157
157
158
    C4::Context->set_preference('EnhancedMessagingPreferences', 1);
158
    Koha::Config::SysPrefs->set_preference('EnhancedMessagingPreferences', 1);
159
}
159
}
160
160
161
sub run_script {
161
sub run_script {
(-)a/t/db_dependent/selenium/00-onboarding.t (-2 / +2 lines)
Lines 162-169 SKIP: { Link Here
162
    $s->submit_form;
162
    $s->submit_form;
163
163
164
    # Get the interface in the correct language
164
    # Get the interface in the correct language
165
    C4::Context->set_preference('language', $languages->{$lang} );
165
    Koha::Config::SysPrefs->set_preference('language', $languages->{$lang} );
166
    C4::Context->set_preference('opaclanguages', $languages->{$lang} );
166
    Koha::Config::SysPrefs->set_preference('opaclanguages', $languages->{$lang} );
167
167
168
    $s->click( { href => '/mainpage.pl', main => 'onboarding-step5' } );
168
    $s->click( { href => '/mainpage.pl', main => 'onboarding-step5' } );
169
169
(-)a/t/db_dependent/selenium/01-installation.t (-6 / +6 lines)
Lines 132-139 SKIP: { Link Here
132
132
133
    my $RequireStrongPassword = C4::Context->preference('RequireStrongPassword');
133
    my $RequireStrongPassword = C4::Context->preference('RequireStrongPassword');
134
    my $minPasswordLength     = C4::Context->preference('minPasswordLength');
134
    my $minPasswordLength     = C4::Context->preference('minPasswordLength');
135
    C4::Context->set_preference('RequireStrongPassword', 0 );
135
    Koha::Config::SysPrefs->set_preference('RequireStrongPassword', 0 );
136
    C4::Context->set_preference('minPasswordLength', 3 );
136
    Koha::Config::SysPrefs->set_preference('minPasswordLength', 3 );
137
137
138
    # Installation complete
138
    # Installation complete
139
    $s->click( { href => '/installer/onboarding.pl', main => 'installer-step3' } );
139
    $s->click( { href => '/installer/onboarding.pl', main => 'installer-step3' } );
Lines 141-156 SKIP: { Link Here
141
    # Create Koha administrator patron
141
    # Create Koha administrator patron
142
    $s->fill_form({ %$superlibrarian, password2 => $superlibrarian->{password} });
142
    $s->fill_form({ %$superlibrarian, password2 => $superlibrarian->{password} });
143
    $s->submit_form;
143
    $s->submit_form;
144
    C4::Context->set_preference('RequireStrongPassword', $RequireStrongPassword );
144
    Koha::Config::SysPrefs->set_preference('RequireStrongPassword', $RequireStrongPassword );
145
    C4::Context->set_preference('minPasswordLength', $minPasswordLength );
145
    Koha::Config::SysPrefs->set_preference('minPasswordLength', $minPasswordLength );
146
146
147
    # Create a new circulation rule
147
    # Create a new circulation rule
148
    # Keep default values
148
    # Keep default values
149
    $s->submit_form;
149
    $s->submit_form;
150
150
151
    # Get the interface in the correct language
151
    # Get the interface in the correct language
152
    C4::Context->set_preference('language', $languages->{$lang} );
152
    Koha::Config::SysPrefs->set_preference('language', $languages->{$lang} );
153
    C4::Context->set_preference('opaclanguages', $languages->{$lang} );
153
    Koha::Config::SysPrefs->set_preference('opaclanguages', $languages->{$lang} );
154
154
155
    $s->click( { href => '/mainpage.pl', main => 'onboarding-step5' } );
155
    $s->click( { href => '/mainpage.pl', main => 'onboarding-step5' } );
156
156
(-)a/t/db_dependent/selenium/authentication_2fa.t (-4 / +4 lines)
Lines 55-61 SKIP: { Link Here
55
        $driver->get($mainpage);
55
        $driver->get($mainpage);
56
        like( $driver->get_title, qr(Log in to Koha), 'Hitting the main page should redirect to the login form');
56
        like( $driver->get_title, qr(Log in to Koha), 'Hitting the main page should redirect to the login form');
57
57
58
        C4::Context->set_preference('TwoFactorAuthentication', 'disabled');
58
        Koha::Config::SysPrefs->set_preference('TwoFactorAuthentication', 'disabled');
59
59
60
        fill_login_form($s);
60
        fill_login_form($s);
61
        like( $driver->get_title, qr(Koha staff interface), 'Patron with flags superlibrarian should be able to login' );
61
        like( $driver->get_title, qr(Koha staff interface), 'Patron with flags superlibrarian should be able to login' );
Lines 63-69 SKIP: { Link Here
63
        $driver->get($s->base_url . q|members/two_factor_auth.pl|);
63
        $driver->get($s->base_url . q|members/two_factor_auth.pl|);
64
        like( $driver->get_title, qr(Error 404), 'Must be redirected to 404 is the pref is off' );
64
        like( $driver->get_title, qr(Error 404), 'Must be redirected to 404 is the pref is off' );
65
65
66
        C4::Context->set_preference('TwoFactorAuthentication', 'enabled');
66
        Koha::Config::SysPrefs->set_preference('TwoFactorAuthentication', 'enabled');
67
        $driver->get($s->base_url . q|members/two_factor_auth.pl|);
67
        $driver->get($s->base_url . q|members/two_factor_auth.pl|);
68
        like( $driver->get_title, qr(Two-factor authentication), 'Must be on the page with the pref on' );
68
        like( $driver->get_title, qr(Two-factor authentication), 'Must be on the page with the pref on' );
69
69
Lines 236-242 SKIP: { Link Here
236
    subtest "Enforce 2FA setup on first login" => sub {
236
    subtest "Enforce 2FA setup on first login" => sub {
237
        plan tests => 7;
237
        plan tests => 7;
238
238
239
        C4::Context->set_preference( 'TwoFactorAuthentication', 'enforced' );
239
        Koha::Config::SysPrefs->set_preference( 'TwoFactorAuthentication', 'enforced' );
240
240
241
        # Make sure the send won't fail because of invalid email addresses
241
        # Make sure the send won't fail because of invalid email addresses
242
        $patron->library->set(
242
        $patron->library->set(
Lines 344-350 SKIP: { Link Here
344
344
345
END {
345
END {
346
    $_->delete for @data_to_cleanup;
346
    $_->delete for @data_to_cleanup;
347
    C4::Context->set_preference('TwoFactorAuthentication', $pref_value);
347
    Koha::Config::SysPrefs->set_preference('TwoFactorAuthentication', $pref_value);
348
};
348
};
349
349
350
350
(-)a/t/db_dependent/selenium/patrons_search.t (-13 / +13 lines)
Lines 26-35 our $DT_delay = 1; Link Here
26
26
27
END {
27
END {
28
    unless ( @cleanup ) { say "WARNING: Cleanup failed!" }
28
    unless ( @cleanup ) { say "WARNING: Cleanup failed!" }
29
    C4::Context->set_preference( 'dateformat',                $original_dateformat );
29
    Koha::Config::SysPrefs->set_preference( 'dateformat',                $original_dateformat );
30
    C4::Context->set_preference( 'DefaultPatronSearchFields', $original_DefaultPatronSearchFields );
30
    Koha::Config::SysPrefs->set_preference( 'DefaultPatronSearchFields', $original_DefaultPatronSearchFields );
31
    C4::Context->set_preference( 'DefaultPatronSearchMethod', $original_DefaultPatronSearchMethod );
31
    Koha::Config::SysPrefs->set_preference( 'DefaultPatronSearchMethod', $original_DefaultPatronSearchMethod );
32
    C4::Context->set_preference( 'PatronsPerPage',            $original_PatronsPerPage );
32
    Koha::Config::SysPrefs->set_preference( 'PatronsPerPage',            $original_PatronsPerPage );
33
    $_->delete for @cleanup;
33
    $_->delete for @cleanup;
34
};
34
};
35
35
Lines 187-198 subtest 'Search patrons' => sub { Link Here
187
    my $table_id = "memberresultst";
187
    my $table_id = "memberresultst";
188
188
189
    $s->auth;
189
    $s->auth;
190
    C4::Context->set_preference('DefaultPatronSearchFields',"");
190
    Koha::Config::SysPrefs->set_preference('DefaultPatronSearchFields',"");
191
    C4::Context->set_preference('DefaultPatronSearchMethod',"contains");
191
    Koha::Config::SysPrefs->set_preference('DefaultPatronSearchMethod',"contains");
192
    my $searchable_attributes = Koha::Patron::Attribute::Types->search({ staff_searchable => 1 })->count();
193
    my $PatronsPerPage = 15;
192
    my $PatronsPerPage = 15;
194
    my $nb_standard_fields = 13 + $searchable_attributes; # Standard fields, plus one searchable attribute
193
    my $nb_standard_fields = 13;
195
    C4::Context->set_preference('PatronsPerPage', $PatronsPerPage);
194
    Koha::Config::SysPrefs->set_preference('PatronsPerPage', $PatronsPerPage);
196
    $driver->get( $base_url . "/members/members-home.pl" );
195
    $driver->get( $base_url . "/members/members-home.pl" );
197
    my @adv_options = $driver->find_elements('//select[@id="searchfieldstype"]/option');
196
    my @adv_options = $driver->find_elements('//select[@id="searchfieldstype"]/option');
198
    is( scalar @adv_options, $nb_standard_fields + 1, 'All standard fields are searchable if DefaultPatronSearchFields not set. middle_name is there.');
197
    is( scalar @adv_options, $nb_standard_fields + 1, 'All standard fields are searchable if DefaultPatronSearchFields not set. middle_name is there.');
Lines 200-206 subtest 'Search patrons' => sub { Link Here
200
    my @filter_options = $driver->find_elements('//select[@id="searchfieldstype_filter"]/option');
199
    my @filter_options = $driver->find_elements('//select[@id="searchfieldstype_filter"]/option');
201
    is( scalar @filter_options, $nb_standard_fields + 1, 'All standard fields + middle_name are searchable by filter if DefaultPatronSearchFields not set');
200
    is( scalar @filter_options, $nb_standard_fields + 1, 'All standard fields + middle_name are searchable by filter if DefaultPatronSearchFields not set');
202
    is( $filter_options[0]->get_value(), 'standard', 'Standard filter uses hard coded value "standard" DefaultPatronSearchFields not set');
201
    is( $filter_options[0]->get_value(), 'standard', 'Standard filter uses hard coded value "standard" DefaultPatronSearchFields not set');
203
    C4::Context->set_preference('DefaultPatronSearchFields',"firstname|initials");
202
    Koha::Config::SysPrefs->set_preference('DefaultPatronSearchFields',"firstname|initials");
204
    $driver->get( $base_url . "/members/members-home.pl" );
203
    $driver->get( $base_url . "/members/members-home.pl" );
205
    @adv_options = $driver->find_elements('//select[@id="searchfieldstype"]/option');
204
    @adv_options = $driver->find_elements('//select[@id="searchfieldstype"]/option');
206
    is( scalar @adv_options, $nb_standard_fields, 'New option added when DefaultPatronSearchFields is populated with a field. Note that middle_name disappears, we do not want it if not part of DefaultPatronSearchFields');
205
    is( scalar @adv_options, $nb_standard_fields, 'New option added when DefaultPatronSearchFields is populated with a field. Note that middle_name disappears, we do not want it if not part of DefaultPatronSearchFields');
Lines 208-213 subtest 'Search patrons' => sub { Link Here
208
    @filter_options = $driver->find_elements('//select[@id="searchfieldstype_filter"]/option');
207
    @filter_options = $driver->find_elements('//select[@id="searchfieldstype_filter"]/option');
209
    is( scalar @filter_options, $nb_standard_fields, 'New filter option added when DefaultPatronSearchFields is populated with a field');
208
    is( scalar @filter_options, $nb_standard_fields, 'New filter option added when DefaultPatronSearchFields is populated with a field');
210
    is( $filter_options[0]->get_value(), 'standard', 'Standard filter uses value "standard"');
209
    is( $filter_options[0]->get_value(), 'standard', 'Standard filter uses value "standard"');
210
    Koha::Config::SysPrefs->set_preference('DefaultPatronSearchFields',"firstname|initials|horses");
211
    $driver->get( $base_url . "/members/members-home.pl" );
211
    $driver->get( $base_url . "/members/members-home.pl" );
212
    @adv_options = $driver->find_elements('//select[@id="searchfieldstype"]/option');
212
    @adv_options = $driver->find_elements('//select[@id="searchfieldstype"]/option');
213
    @filter_options = $driver->find_elements('//select[@id="searchfieldstype_filter"]/option');
213
    @filter_options = $driver->find_elements('//select[@id="searchfieldstype_filter"]/option');
Lines 215-221 subtest 'Search patrons' => sub { Link Here
215
    is( scalar @filter_options, $nb_standard_fields, 'Invalid filter option not added when DefaultPatronSearchFields is populated with an invalid field');
215
    is( scalar @filter_options, $nb_standard_fields, 'Invalid filter option not added when DefaultPatronSearchFields is populated with an invalid field');
216
216
217
    # NOTE: We should probably ensure the bad field is removed from 'standard' search here, else searches are broken
217
    # NOTE: We should probably ensure the bad field is removed from 'standard' search here, else searches are broken
218
    C4::Context->set_preference('DefaultPatronSearchFields',"");
218
    Koha::Config::SysPrefs->set_preference('DefaultPatronSearchFields',"");
219
    $driver->get( $base_url . "/members/members-home.pl" );
219
    $driver->get( $base_url . "/members/members-home.pl" );
220
    $s->fill_form( { search_patron_filter => 'test_patron' } );
220
    $s->fill_form( { search_patron_filter => 'test_patron' } );
221
    $s->submit_form;
221
    $s->submit_form;
Lines 328-334 subtest 'Search patrons' => sub { Link Here
328
328
329
        plan tests => 7;
329
        plan tests => 7;
330
330
331
        C4::Context->set_preference( 'PatronsPerPage', 5 );
331
        Koha::Config::SysPrefs->set_preference( 'PatronsPerPage', 5 );
332
        $driver->get( $base_url . "/members/members-home.pl" );
332
        $driver->get( $base_url . "/members/members-home.pl" );
333
        $s->fill_form( { search_patron_filter => 'test_patron' } );
333
        $s->fill_form( { search_patron_filter => 'test_patron' } );
334
        $s->submit_form;
334
        $s->submit_form;
Lines 378-384 subtest 'Search patrons' => sub { Link Here
378
    subtest 'filter by date of birth' => sub {
378
    subtest 'filter by date of birth' => sub {
379
        plan tests => 7;
379
        plan tests => 7;
380
380
381
        C4::Context->set_preference( 'dateformat', 'metric' );
381
        Koha::Config::SysPrefs->set_preference( 'dateformat', 'metric' );
382
382
383
        # We have a patron with date of birth=1980-06-17 => formatted as 17/06/1980
383
        # We have a patron with date of birth=1980-06-17 => formatted as 17/06/1980
384
384
(-)a/t/db_dependent/selenium/regressions.t (-6 / +6 lines)
Lines 48-57 my $builder = t::lib::TestBuilder->new; Link Here
48
48
49
# It seems that we do not have enough records indexed with ES
49
# It seems that we do not have enough records indexed with ES
50
my $SearchEngine_value = C4::Context->preference('SearchEngine');
50
my $SearchEngine_value = C4::Context->preference('SearchEngine');
51
C4::Context->set_preference('SearchEngine', 'Zebra');
51
Koha::Config::SysPrefs->set_preference('SearchEngine', 'Zebra');
52
52
53
my $AudioAlerts_value = C4::Context->preference('AudioAlerts');
53
my $AudioAlerts_value = C4::Context->preference('AudioAlerts');
54
C4::Context->set_preference('AudioAlerts', '1');
54
Koha::Config::SysPrefs->set_preference('AudioAlerts', '1');
55
55
56
our @cleanup;
56
our @cleanup;
57
subtest 'OPAC - borrowernumber, branchcode and categorycode as html attributes' => sub {
57
subtest 'OPAC - borrowernumber, branchcode and categorycode as html attributes' => sub {
Lines 279-285 subtest 'Encoding in session variables' => sub { Link Here
279
279
280
    my $original_SessionStorage = C4::Context->preference('SessionStorage');
280
    my $original_SessionStorage = C4::Context->preference('SessionStorage');
281
    for my $SessionStorage ( qw( memcached mysql tmp ) ) {
281
    for my $SessionStorage ( qw( memcached mysql tmp ) ) {
282
        C4::Context->set_preference( 'SessionStorage', $SessionStorage );
282
        Koha::Config::SysPrefs->set_preference( 'SessionStorage', $SessionStorage );
283
        for my $branchname (qw( Test1 Test2❤️ Test3ä )) {
283
        for my $branchname (qw( Test1 Test2❤️ Test3ä )) {
284
            my $library =
284
            my $library =
285
              Koha::Libraries->find($branchname) || $builder->build_object(
285
              Koha::Libraries->find($branchname) || $builder->build_object(
Lines 333-339 subtest 'Encoding in session variables' => sub { Link Here
333
        }
333
        }
334
    }
334
    }
335
335
336
    C4::Context->set_preference('SessionStorage', $original_SessionStorage);
336
    Koha::Config::SysPrefs->set_preference('SessionStorage', $original_SessionStorage);
337
    push @cleanup, $item, $biblio, $patron, $patron->category, $patron->library;
337
    push @cleanup, $item, $biblio, $patron, $patron->category, $patron->library;
338
    push @cleanup, Koha::Libraries->find($_) for qw( Test1 Test2❤️ Test3ä );
338
    push @cleanup, Koha::Libraries->find($_) for qw( Test1 Test2❤️ Test3ä );
339
339
Lines 375-382 subtest 'OPAC - Suggest for purchase' => sub { Link Here
375
$driver->quit();
375
$driver->quit();
376
376
377
END {
377
END {
378
    C4::Context->set_preference('SearchEngine', $SearchEngine_value);
378
    Koha::Config::SysPrefs->set_preference('SearchEngine', $SearchEngine_value);
379
    C4::Context->set_preference('AudioAlerts', $AudioAlerts_value);
379
    Koha::Config::SysPrefs->set_preference('AudioAlerts', $AudioAlerts_value);
380
    $_->delete for @cleanup;
380
    $_->delete for @cleanup;
381
};
381
};
382
382
(-)a/t/db_dependent/selenium/remove_from_cart.t (-2 / +2 lines)
Lines 46-52 my $builder = t::lib::TestBuilder->new; Link Here
46
my $marcflavour = C4::Context->preference('marcflavour') || 'MARC21';
46
my $marcflavour = C4::Context->preference('marcflavour') || 'MARC21';
47
47
48
my $SearchEngine_value = C4::Context->preference('SearchEngine');
48
my $SearchEngine_value = C4::Context->preference('SearchEngine');
49
C4::Context->set_preference('SearchEngine', 'Zebra');
49
Koha::Config::SysPrefs->set_preference('SearchEngine', 'Zebra');
50
50
51
my $mock_zebra = t::lib::Mocks::Zebra->new(
51
my $mock_zebra = t::lib::Mocks::Zebra->new(
52
    {
52
    {
Lines 104-109 subtest 'OPAC - Remove from cart' => sub { Link Here
104
};
104
};
105
105
106
END {
106
END {
107
    C4::Context->set_preference('SearchEngine', $SearchEngine_value);
107
    Koha::Config::SysPrefs->set_preference('SearchEngine', $SearchEngine_value);
108
    $mock_zebra->cleanup if $mock_zebra;
108
    $mock_zebra->cleanup if $mock_zebra;
109
};
109
};
(-)a/t/db_dependent/selenium/self_registration.t (-4 / +4 lines)
Lines 43-49 my $opac_base_url = $s->opac_base_url; Link Here
43
my $builder = t::lib::TestBuilder->new;
43
my $builder = t::lib::TestBuilder->new;
44
44
45
my $PatronSelfRegistration_value = C4::Context->preference('PatronSelfRegistration');
45
my $PatronSelfRegistration_value = C4::Context->preference('PatronSelfRegistration');
46
C4::Context->set_preference('PatronSelfRegistration', '1');
46
Koha::Config::SysPrefs->set_preference('PatronSelfRegistration', '1');
47
47
48
my $PatronSelfRegistrationDefaultCategory_value = C4::Context->preference('PatronSelfRegistrationDefaultCategory');
48
my $PatronSelfRegistrationDefaultCategory_value = C4::Context->preference('PatronSelfRegistrationDefaultCategory');
49
49
Lines 60-66 subtest 'Set flags' => sub { Link Here
60
    plan tests => 2;
60
    plan tests => 2;
61
61
62
    my $default_category = $builder->build_object( { class => 'Koha::Patron::Categories' } );
62
    my $default_category = $builder->build_object( { class => 'Koha::Patron::Categories' } );
63
    C4::Context->set_preference( 'PatronSelfRegistrationDefaultCategory', $default_category->categorycode );
63
    Koha::Config::SysPrefs->set_preference( 'PatronSelfRegistrationDefaultCategory', $default_category->categorycode );
64
64
65
    $driver->get($opac_base_url . 'opac-memberentry.pl');
65
    $driver->get($opac_base_url . 'opac-memberentry.pl');
66
    like( $driver->get_title(), qr(Register a new account), );
66
    like( $driver->get_title(), qr(Register a new account), );
Lines 83-89 subtest 'Set flags' => sub { Link Here
83
$driver->quit();
83
$driver->quit();
84
84
85
END {
85
END {
86
    C4::Context->set_preference('PatronSelfRegistration', $PatronSelfRegistration_value);
86
    Koha::Config::SysPrefs->set_preference('PatronSelfRegistration', $PatronSelfRegistration_value);
87
    C4::Context->set_preference('PatronSelfRegistration', $PatronSelfRegistrationDefaultCategory_value);
87
    Koha::Config::SysPrefs->set_preference('PatronSelfRegistration', $PatronSelfRegistrationDefaultCategory_value);
88
    $_->delete for @cleanup;
88
    $_->delete for @cleanup;
89
};
89
};
(-)a/t/db_dependent/sysprefs.t (-6 / +7 lines)
Lines 22-27 use Modern::Perl; Link Here
22
use Test::More tests => 8;
22
use Test::More tests => 8;
23
use C4::Context;
23
use C4::Context;
24
use Koha::Database;
24
use Koha::Database;
25
use Koha::Config::SysPrefs;
25
26
26
my $schema = Koha::Database->new->schema;
27
my $schema = Koha::Database->new->schema;
27
$schema->storage->txn_begin;
28
$schema->storage->txn_begin;
Lines 30-39 my $dbh = C4::Context->dbh; Link Here
30
my $URLLinkText    = C4::Context->preference('URLLinkText');
31
my $URLLinkText    = C4::Context->preference('URLLinkText');
31
my $newURLLinkText = "newURLLinkText";
32
my $newURLLinkText = "newURLLinkText";
32
33
33
C4::Context->set_preference( 'URLLINKTEXT', $newURLLinkText );
34
Koha::Config::SysPrefs->set_preference( 'URLLINKTEXT', $newURLLinkText );
34
is( C4::Context->preference('URLLinkText'), $newURLLinkText, 'The pref should have been set correctly' );
35
is( C4::Context->preference('URLLinkText'), $newURLLinkText, 'The pref should have been set correctly' );
35
36
36
C4::Context->set_preference( 'URLLinkText', $URLLinkText );
37
Koha::Config::SysPrefs->set_preference( 'URLLinkText', $URLLinkText );
37
is( C4::Context->preference('URLLINKTEXT'), $URLLinkText, 'A pref name should be case insensitive');
38
is( C4::Context->preference('URLLINKTEXT'), $URLLinkText, 'A pref name should be case insensitive');
38
39
39
$ENV{OVERRIDE_SYSPREF_URLLinkText} = 'this is an override';
40
$ENV{OVERRIDE_SYSPREF_URLLinkText} = 'this is an override';
Lines 46-59 is( Link Here
46
47
47
is( C4::Context->preference('IDoNotExist'), undef, 'Get a non-existent system preference should return undef');
48
is( C4::Context->preference('IDoNotExist'), undef, 'Get a non-existent system preference should return undef');
48
49
49
C4::Context->set_preference( 'IDoNotExist', 'NonExistent' );
50
Koha::Config::SysPrefs->set_preference( 'IDoNotExist', 'NonExistent' );
50
is( C4::Context->preference('IDoNotExist'), 'NonExistent', 'Test creation of non-existent system preference' );
51
is( C4::Context->preference('IDoNotExist'), 'NonExistent', 'Test creation of non-existent system preference' );
51
52
52
C4::Context->set_preference('testpreference', 'abc');
53
Koha::Config::SysPrefs->set_preference('testpreference', 'abc');
53
C4::Context->delete_preference('testpreference');
54
Koha::Config::SysPrefs->delete_preference('testpreference');
54
is(C4::Context->preference('testpreference'), undef, 'deleting preferences');
55
is(C4::Context->preference('testpreference'), undef, 'deleting preferences');
55
56
56
C4::Context->set_preference('testpreference', 'def');
57
Koha::Config::SysPrefs->set_preference('testpreference', 'def');
57
# Delete from the database, it should still be in cache
58
# Delete from the database, it should still be in cache
58
$dbh->do("DELETE FROM systempreferences WHERE variable='testpreference'");
59
$dbh->do("DELETE FROM systempreferences WHERE variable='testpreference'");
59
is(C4::Context->preference('testpreference'), 'def', 'caching preferences');
60
is(C4::Context->preference('testpreference'), 'def', 'caching preferences');
(-)a/t/db_dependent/www/regressions.t (-4 / +3 lines)
Lines 97-103 subtest 'open redirection vulnerabilities in tracklinks' => sub { Link Here
97
97
98
    Koha::Caches->flush_L1_caches;
98
    Koha::Caches->flush_L1_caches;
99
    # Don't Track
99
    # Don't Track
100
    C4::Context->set_preference( 'TrackClicks', '' );
100
    Koha::Config::SysPrefs->set_preference( 'TrackClicks', '' );
101
    $t->get_ok( $opac . $no_biblionumber )
101
    $t->get_ok( $opac . $no_biblionumber )
102
      ->status_is( 404, "404 for no biblionumber" );
102
      ->status_is( 404, "404 for no biblionumber" );
103
    $t->get_ok( $opac . $bad_biblionumber1 )
103
    $t->get_ok( $opac . $bad_biblionumber1 )
Lines 112-118 subtest 'open redirection vulnerabilities in tracklinks' => sub { Link Here
112
      ->status_is( 404, "404 for itemnumber with matching URI - pref off" );
112
      ->status_is( 404, "404 for itemnumber with matching URI - pref off" );
113
113
114
    # Track
114
    # Track
115
    C4::Context->set_preference( 'TrackClicks', 'track' );
115
    Koha::Config::SysPrefs->set_preference( 'TrackClicks', 'track' );
116
    $t->get_ok( $opac . $no_biblionumber )
116
    $t->get_ok( $opac . $no_biblionumber )
117
      ->status_is( 404, "404 for no biblionumber" );
117
      ->status_is( 404, "404 for no biblionumber" );
118
    $t->get_ok( $opac . $bad_biblionumber1 )
118
    $t->get_ok( $opac . $bad_biblionumber1 )
Lines 127-133 subtest 'open redirection vulnerabilities in tracklinks' => sub { Link Here
127
      ->status_is( 302, "302 for itemnumber with matching URI" );
127
      ->status_is( 302, "302 for itemnumber with matching URI" );
128
128
129
    # Track Anonymous
129
    # Track Anonymous
130
    C4::Context->set_preference( 'TrackClicks', 'anonymous' );
130
    Koha::Config::SysPrefs->set_preference( 'TrackClicks', 'anonymous' );
131
    $t->get_ok( $opac . $no_biblionumber )
131
    $t->get_ok( $opac . $no_biblionumber )
132
      ->status_is( 404, "404 for no biblionumber" );
132
      ->status_is( 404, "404 for no biblionumber" );
133
    $t->get_ok( $opac . $bad_biblionumber1 )
133
    $t->get_ok( $opac . $bad_biblionumber1 )
134
- 

Return to bug 35250