From a2d458541c6c235cc3b42462d4bf66555ccedb4f Mon Sep 17 00:00:00 2001 From: Blou Date: Fri, 27 Oct 2023 17:14:38 -0400 Subject: [PATCH] Bug 28411: modify t/db_dependent tests to use Koha::Config::SysPrefs' set_preference insteand of C4::Context Some work left to be done, including missing use at top of files --- t/db_dependent/Circulation.t | 12 +++++----- t/db_dependent/Context.t | 15 ++++++------ t/db_dependent/Koha/Item.t | 14 +++++------ .../Koha/REST/Plugin/PluginRoutes.t | 4 ++-- .../cronjobs/advance_notices_digest.t | 2 +- t/db_dependent/selenium/00-onboarding.t | 4 ++-- t/db_dependent/selenium/01-installation.t | 12 +++++----- t/db_dependent/selenium/authentication_2fa.t | 8 +++---- t/db_dependent/selenium/patrons_search.t | 24 +++++++++---------- t/db_dependent/selenium/regressions.t | 12 +++++----- t/db_dependent/selenium/remove_from_cart.t | 4 ++-- t/db_dependent/selenium/self_registration.t | 8 +++---- t/db_dependent/sysprefs.t | 13 +++++----- t/db_dependent/www/regressions.t | 6 ++--- 14 files changed, 70 insertions(+), 68 deletions(-) diff --git a/t/db_dependent/Circulation.t b/t/db_dependent/Circulation.t index fcd68e9bbe..55dbe44716 100755 --- a/t/db_dependent/Circulation.t +++ b/t/db_dependent/Circulation.t @@ -433,7 +433,7 @@ my ( $reused_itemnumber_1, $reused_itemnumber_2 ); subtest "CanBookBeRenewed tests" => sub { plan tests => 112; - C4::Context->set_preference('ItemsDeniedRenewal',''); + Koha::Config::SysPrefs->set_preference('ItemsDeniedRenewal',''); # Generate test biblio my $biblio = $builder->build_sample_biblio(); @@ -1183,9 +1183,9 @@ subtest "CanBookBeRenewed tests" => sub { } } ); - C4::Context->set_preference('OPACFineNoRenewalsBlockAutoRenew','1'); - C4::Context->set_preference('OPACFineNoRenewals','10'); - C4::Context->set_preference('OPACFineNoRenewalsIncludeCredit','1'); + Koha::Config::SysPrefs->set_preference('OPACFineNoRenewalsBlockAutoRenew','1'); + Koha::Config::SysPrefs->set_preference('OPACFineNoRenewals','10'); + Koha::Config::SysPrefs->set_preference('OPACFineNoRenewalsIncludeCredit','1'); my $fines_amount = 5; my $account = Koha::Account->new({patron_id => $renewing_borrowernumber}); $account->add_debit( @@ -1243,14 +1243,14 @@ subtest "CanBookBeRenewed tests" => sub { is( $renewokay, 1, 'Renew, even if renewal is automatic' ); is( $error, 'auto_renew', 'Can auto renew, OPACFineNoRenewals=10, OPACFineNoRenewalsIncludeCredit=1, patron has 15 debt, 5 credit' ); - C4::Context->set_preference('OPACFineNoRenewalsIncludeCredit','0'); + Koha::Config::SysPrefs->set_preference('OPACFineNoRenewalsIncludeCredit','0'); ( $renewokay, $error ) = CanBookBeRenewed( $renewing_borrower_obj, $issue ); is( $renewokay, 0, 'Do not renew, renewal is automatic' ); is( $error, 'auto_too_much_oweing', 'Cannot auto renew, OPACFineNoRenewals=10, OPACFineNoRenewalsIncludeCredit=1, patron has 15 debt, 5 credit' ); $dbh->do('DELETE FROM accountlines WHERE borrowernumber=?', undef, $renewing_borrowernumber); - C4::Context->set_preference('OPACFineNoRenewalsIncludeCredit','1'); + Koha::Config::SysPrefs->set_preference('OPACFineNoRenewalsIncludeCredit','1'); }; subtest "auto_account_expired | BlockExpiredPatronOpacActions" => sub { diff --git a/t/db_dependent/Context.t b/t/db_dependent/Context.t index 67587b4798..749ceb7ebe 100755 --- a/t/db_dependent/Context.t +++ b/t/db_dependent/Context.t @@ -20,6 +20,7 @@ use Test::More tests => 5; use Test::MockModule; use C4::Context; +use Koha::Config::SysPrefs; use Koha::Database; our $schema; @@ -41,26 +42,26 @@ subtest 'Tests with preferences' => sub { my $dbh; ok($dbh = C4::Context->dbh(), 'Getting dbh from C4::Context'); - C4::Context->set_preference('OPACBaseURL','junk'); + Koha::Config::SysPrefs->set_preference('OPACBaseURL','junk'); C4::Context->clear_syspref_cache(); my $OPACBaseURL = C4::Context->preference('OPACBaseURL'); is($OPACBaseURL,'http://junk','OPACBaseURL saved with http:// when missing it'); - C4::Context->set_preference('OPACBaseURL','https://junk'); + Koha::Config::SysPrefs->set_preference('OPACBaseURL','https://junk'); C4::Context->clear_syspref_cache(); $OPACBaseURL = C4::Context->preference('OPACBaseURL'); is($OPACBaseURL,'https://junk','OPACBaseURL saved with https:// as specified'); - C4::Context->set_preference('OPACBaseURL','http://junk2'); + Koha::Config::SysPrefs->set_preference('OPACBaseURL','http://junk2'); C4::Context->clear_syspref_cache(); $OPACBaseURL = C4::Context->preference('OPACBaseURL'); is($OPACBaseURL,'http://junk2','OPACBaseURL saved with http:// as specified'); - C4::Context->set_preference('OPACBaseURL', ''); + Koha::Config::SysPrefs->set_preference('OPACBaseURL', ''); $OPACBaseURL = C4::Context->preference('OPACBaseURL'); is($OPACBaseURL,'','OPACBaseURL saved empty as specified'); - C4::Context->set_preference('SillyPreference','random'); + Koha::Config::SysPrefs->set_preference('SillyPreference','random'); C4::Context->clear_syspref_cache(); my $SillyPeference = C4::Context->preference('SillyPreference'); is($SillyPeference,'random','SillyPreference saved as specified'); @@ -73,7 +74,7 @@ subtest 'Tests with preferences' => sub { open my $trace, '>', \$trace_read or die "Can't open variable: $!"; $schema->storage->debugfh( $trace ); - C4::Context->set_preference('SillyPreference', 'thing1'); + Koha::Config::SysPrefs->set_preference('SillyPreference', 'thing1'); my $silly_preference = Koha::Config::SysPrefs->find('SillyPreference'); is( $silly_preference->variable, 'SillyPreference', 'set_preference should have kept the case sensitivity' ); @@ -114,7 +115,7 @@ subtest 'Tests with preferences' => sub { $silly_preference->delete(); # AutoEmailNewUser should be a YesNo pref - C4::Context->set_preference('AutoEmailNewUser', ''); + Koha::Config::SysPrefs->set_preference('AutoEmailNewUser', ''); my $yesno_pref = Koha::Config::SysPrefs->find('AutoEmailNewUser'); is( $yesno_pref->value(), 0, 'set_preference should have set the value to 0, instead of an empty string' ); diff --git a/t/db_dependent/Koha/Item.t b/t/db_dependent/Koha/Item.t index 129f63cea4..6dff153d79 100755 --- a/t/db_dependent/Koha/Item.t +++ b/t/db_dependent/Koha/Item.t @@ -2213,12 +2213,12 @@ subtest 'is_denied_renewal' => sub { }); my $idr_rules = ""; - C4::Context->set_preference('ItemsDeniedRenewal', $idr_rules); + Koha::Config::SysPrefs->set_preference('ItemsDeniedRenewal', $idr_rules); is( $deny_book->is_denied_renewal, 0, 'Renewal allowed when no rules' ); # The wrong column delete should be silently ignored and not trigger item delete $idr_rules="delete: [yes]\nwithdrawn: [1]"; - C4::Context->set_preference('ItemsDeniedRenewal', $idr_rules); + Koha::Config::SysPrefs->set_preference('ItemsDeniedRenewal', $idr_rules); is( $deny_book->is_denied_renewal, 1, 'Renewal blocked when 1 rules (withdrawn)' ); is( $allow_book->is_denied_renewal, 0, 'Renewal allowed when 1 rules not matched (withdrawn)' ); @@ -2227,24 +2227,24 @@ subtest 'is_denied_renewal' => sub { is( $allow_book->is_denied_renewal, 0, 'Renewal allowed when 2 rules not matched (withdrawn, itype)' ); $idr_rules="withdrawn: [1]\nitype: [HIDE,INVISIBLE]\nlocation: [PROC]"; - C4::Context->set_preference('ItemsDeniedRenewal', $idr_rules); + Koha::Config::SysPrefs->set_preference('ItemsDeniedRenewal', $idr_rules); is( $deny_book->is_denied_renewal, 1, 'Renewal blocked when 3 rules matched (withdrawn, itype, location)' ); is( $allow_book->is_denied_renewal, 0, 'Renewal allowed when 3 rules not matched (withdrawn, itype, location)' ); $idr_rules="itemcallnumber: [null]"; - C4::Context->set_preference('ItemsDeniedRenewal', $idr_rules); + Koha::Config::SysPrefs->set_preference('ItemsDeniedRenewal', $idr_rules); is( $deny_book->is_denied_renewal, 1, 'Renewal blocked for undef when null in pref' ); $idr_rules="itemcallnumber: ['']"; - C4::Context->set_preference('ItemsDeniedRenewal', $idr_rules); + Koha::Config::SysPrefs->set_preference('ItemsDeniedRenewal', $idr_rules); is( $deny_book->is_denied_renewal, 0, 'Renewal not blocked for undef when "" in pref' ); $idr_rules="itemnotes: [null]"; - C4::Context->set_preference('ItemsDeniedRenewal', $idr_rules); + Koha::Config::SysPrefs->set_preference('ItemsDeniedRenewal', $idr_rules); is( $deny_book->is_denied_renewal, 0, 'Renewal not blocked for "" when null in pref' ); $idr_rules="itemnotes: ['']"; - C4::Context->set_preference('ItemsDeniedRenewal', $idr_rules); + Koha::Config::SysPrefs->set_preference('ItemsDeniedRenewal', $idr_rules); is( $deny_book->is_denied_renewal, 1, 'Renewal blocked for empty string when "" in pref' ); $schema->storage->txn_rollback; diff --git a/t/db_dependent/Koha/REST/Plugin/PluginRoutes.t b/t/db_dependent/Koha/REST/Plugin/PluginRoutes.t index 66746508ed..b9a06b607a 100755 --- a/t/db_dependent/Koha/REST/Plugin/PluginRoutes.t +++ b/t/db_dependent/Koha/REST/Plugin/PluginRoutes.t @@ -165,13 +165,13 @@ subtest 'Permissions and access to plugin routes tests' => sub { ok( exists $routes->{'/contrib/testplugin/patrons/bother'}, 'Route exists' ); ok( exists $routes->{'/contrib/testplugin/public/patrons/bother'}, 'Route exists' ); - C4::Context->set_preference( 'RESTPublicAnonymousRequests', 0 ); + Koha::Config::SysPrefs->set_preference( 'RESTPublicAnonymousRequests', 0 ); $t->get_ok('/api/v1/contrib/testplugin/public/patrons/bother') ->status_is(200, 'Plugin routes not affected by RESTPublicAnonymousRequests') ->json_is( { bothered => Mojo::JSON->true } ); - C4::Context->set_preference( 'RESTPublicAnonymousRequests', 1 ); + Koha::Config::SysPrefs->set_preference( 'RESTPublicAnonymousRequests', 1 ); $t->get_ok('/api/v1/contrib/testplugin/public/patrons/bother') ->status_is(200, 'Plugin routes not affected by RESTPublicAnonymousRequests') diff --git a/t/db_dependent/cronjobs/advance_notices_digest.t b/t/db_dependent/cronjobs/advance_notices_digest.t index b912f2a631..0b6309cd55 100755 --- a/t/db_dependent/cronjobs/advance_notices_digest.t +++ b/t/db_dependent/cronjobs/advance_notices_digest.t @@ -155,7 +155,7 @@ DELETESQL } }); - C4::Context->set_preference('EnhancedMessagingPreferences', 1); + Koha::Config::SysPrefs->set_preference('EnhancedMessagingPreferences', 1); } sub run_script { diff --git a/t/db_dependent/selenium/00-onboarding.t b/t/db_dependent/selenium/00-onboarding.t index e1218011e8..ce370aadd4 100755 --- a/t/db_dependent/selenium/00-onboarding.t +++ b/t/db_dependent/selenium/00-onboarding.t @@ -162,8 +162,8 @@ SKIP: { $s->submit_form; # Get the interface in the correct language - C4::Context->set_preference('language', $languages->{$lang} ); - C4::Context->set_preference('opaclanguages', $languages->{$lang} ); + Koha::Config::SysPrefs->set_preference('language', $languages->{$lang} ); + Koha::Config::SysPrefs->set_preference('opaclanguages', $languages->{$lang} ); $s->click( { href => '/mainpage.pl', main => 'onboarding-step5' } ); diff --git a/t/db_dependent/selenium/01-installation.t b/t/db_dependent/selenium/01-installation.t index ce9841b81f..6a41d25e7c 100755 --- a/t/db_dependent/selenium/01-installation.t +++ b/t/db_dependent/selenium/01-installation.t @@ -132,8 +132,8 @@ SKIP: { my $RequireStrongPassword = C4::Context->preference('RequireStrongPassword'); my $minPasswordLength = C4::Context->preference('minPasswordLength'); - C4::Context->set_preference('RequireStrongPassword', 0 ); - C4::Context->set_preference('minPasswordLength', 3 ); + Koha::Config::SysPrefs->set_preference('RequireStrongPassword', 0 ); + Koha::Config::SysPrefs->set_preference('minPasswordLength', 3 ); # Installation complete $s->click( { href => '/installer/onboarding.pl', main => 'installer-step3' } ); @@ -141,16 +141,16 @@ SKIP: { # Create Koha administrator patron $s->fill_form({ %$superlibrarian, password2 => $superlibrarian->{password} }); $s->submit_form; - C4::Context->set_preference('RequireStrongPassword', $RequireStrongPassword ); - C4::Context->set_preference('minPasswordLength', $minPasswordLength ); + Koha::Config::SysPrefs->set_preference('RequireStrongPassword', $RequireStrongPassword ); + Koha::Config::SysPrefs->set_preference('minPasswordLength', $minPasswordLength ); # Create a new circulation rule # Keep default values $s->submit_form; # Get the interface in the correct language - C4::Context->set_preference('language', $languages->{$lang} ); - C4::Context->set_preference('opaclanguages', $languages->{$lang} ); + Koha::Config::SysPrefs->set_preference('language', $languages->{$lang} ); + Koha::Config::SysPrefs->set_preference('opaclanguages', $languages->{$lang} ); $s->click( { href => '/mainpage.pl', main => 'onboarding-step5' } ); diff --git a/t/db_dependent/selenium/authentication_2fa.t b/t/db_dependent/selenium/authentication_2fa.t index ac9fe9be11..a49fb7750c 100755 --- a/t/db_dependent/selenium/authentication_2fa.t +++ b/t/db_dependent/selenium/authentication_2fa.t @@ -55,7 +55,7 @@ SKIP: { $driver->get($mainpage); like( $driver->get_title, qr(Log in to Koha), 'Hitting the main page should redirect to the login form'); - C4::Context->set_preference('TwoFactorAuthentication', 'disabled'); + Koha::Config::SysPrefs->set_preference('TwoFactorAuthentication', 'disabled'); fill_login_form($s); like( $driver->get_title, qr(Koha staff interface), 'Patron with flags superlibrarian should be able to login' ); @@ -63,7 +63,7 @@ SKIP: { $driver->get($s->base_url . q|members/two_factor_auth.pl|); like( $driver->get_title, qr(Error 404), 'Must be redirected to 404 is the pref is off' ); - C4::Context->set_preference('TwoFactorAuthentication', 'enabled'); + Koha::Config::SysPrefs->set_preference('TwoFactorAuthentication', 'enabled'); $driver->get($s->base_url . q|members/two_factor_auth.pl|); like( $driver->get_title, qr(Two-factor authentication), 'Must be on the page with the pref on' ); @@ -236,7 +236,7 @@ SKIP: { subtest "Enforce 2FA setup on first login" => sub { plan tests => 7; - C4::Context->set_preference( 'TwoFactorAuthentication', 'enforced' ); + Koha::Config::SysPrefs->set_preference( 'TwoFactorAuthentication', 'enforced' ); # Make sure the send won't fail because of invalid email addresses $patron->library->set( @@ -344,7 +344,7 @@ SKIP: { END { $_->delete for @data_to_cleanup; - C4::Context->set_preference('TwoFactorAuthentication', $pref_value); + Koha::Config::SysPrefs->set_preference('TwoFactorAuthentication', $pref_value); }; diff --git a/t/db_dependent/selenium/patrons_search.t b/t/db_dependent/selenium/patrons_search.t index 2b327a30e3..d193c43701 100755 --- a/t/db_dependent/selenium/patrons_search.t +++ b/t/db_dependent/selenium/patrons_search.t @@ -25,10 +25,10 @@ our @cleanup; END { unless ( @cleanup ) { say "WARNING: Cleanup failed!" } - C4::Context->set_preference( 'dateformat', $original_dateformat ); - C4::Context->set_preference( 'DefaultPatronSearchFields', $original_DefaultPatronSearchFields ); - C4::Context->set_preference( 'DefaultPatronSearchMethod', $original_DefaultPatronSearchMethod ); - C4::Context->set_preference( 'PatronsPerPage', $original_PatronsPerPage ); + Koha::Config::SysPrefs->set_preference( 'dateformat', $original_dateformat ); + Koha::Config::SysPrefs->set_preference( 'DefaultPatronSearchFields', $original_DefaultPatronSearchFields ); + Koha::Config::SysPrefs->set_preference( 'DefaultPatronSearchMethod', $original_DefaultPatronSearchMethod ); + Koha::Config::SysPrefs->set_preference( 'PatronsPerPage', $original_PatronsPerPage ); $_->delete for @cleanup; }; @@ -162,11 +162,11 @@ subtest 'Search patrons' => sub { my $table_id = "memberresultst"; $s->auth; - C4::Context->set_preference('DefaultPatronSearchFields',""); - C4::Context->set_preference('DefaultPatronSearchMethod',"contains"); + Koha::Config::SysPrefs->set_preference('DefaultPatronSearchFields',""); + Koha::Config::SysPrefs->set_preference('DefaultPatronSearchMethod',"contains"); my $PatronsPerPage = 15; my $nb_standard_fields = 13; - C4::Context->set_preference('PatronsPerPage', $PatronsPerPage); + Koha::Config::SysPrefs->set_preference('PatronsPerPage', $PatronsPerPage); $driver->get( $base_url . "/members/members-home.pl" ); my @adv_options = $driver->find_elements('//select[@id="searchfieldstype"]/option'); is( scalar @adv_options, $nb_standard_fields + 1, 'All standard fields are searchable if DefaultPatronSearchFields not set. middle_name is there.'); @@ -174,7 +174,7 @@ subtest 'Search patrons' => sub { my @filter_options = $driver->find_elements('//select[@id="searchfieldstype_filter"]/option'); is( scalar @filter_options, $nb_standard_fields + 1, 'All standard fields + middle_name are searchable by filter if DefaultPatronSearchFields not set'); is( $filter_options[0]->get_value(), 'standard', 'Standard filter uses hard coded value "standard" DefaultPatronSearchFields not set'); - C4::Context->set_preference('DefaultPatronSearchFields',"firstname|initials"); + Koha::Config::SysPrefs->set_preference('DefaultPatronSearchFields',"firstname|initials"); $driver->get( $base_url . "/members/members-home.pl" ); @adv_options = $driver->find_elements('//select[@id="searchfieldstype"]/option'); 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'); @@ -182,7 +182,7 @@ subtest 'Search patrons' => sub { @filter_options = $driver->find_elements('//select[@id="searchfieldstype_filter"]/option'); is( scalar @filter_options, $nb_standard_fields, 'New filter option added when DefaultPatronSearchFields is populated with a field'); is( $filter_options[0]->get_value(), 'standard', 'Standard filter uses value "standard"'); - C4::Context->set_preference('DefaultPatronSearchFields',"firstname|initials|horses"); + Koha::Config::SysPrefs->set_preference('DefaultPatronSearchFields',"firstname|initials|horses"); $driver->get( $base_url . "/members/members-home.pl" ); @adv_options = $driver->find_elements('//select[@id="searchfieldstype"]/option'); @filter_options = $driver->find_elements('//select[@id="searchfieldstype_filter"]/option'); @@ -190,7 +190,7 @@ subtest 'Search patrons' => sub { is( scalar @filter_options, $nb_standard_fields, 'Invalid filter option not added when DefaultPatronSearchFields is populated with an invalid field'); # NOTE: We should probably ensure the bad field is removed from 'standard' search here, else searches are broken - C4::Context->set_preference('DefaultPatronSearchFields',""); + Koha::Config::SysPrefs->set_preference('DefaultPatronSearchFields',""); $driver->get( $base_url . "/members/members-home.pl" ); $s->fill_form( { search_patron_filter => 'test_patron' } ); $s->submit_form; @@ -292,7 +292,7 @@ subtest 'Search patrons' => sub { plan tests => 7; - C4::Context->set_preference( 'PatronsPerPage', 5 ); + Koha::Config::SysPrefs->set_preference( 'PatronsPerPage', 5 ); $driver->get( $base_url . "/members/members-home.pl" ); $s->fill_form( { search_patron_filter => 'test_patron' } ); $s->submit_form; @@ -342,7 +342,7 @@ subtest 'Search patrons' => sub { subtest 'filter by date of birth' => sub { plan tests => 7; - C4::Context->set_preference( 'dateformat', 'metric' ); + Koha::Config::SysPrefs->set_preference( 'dateformat', 'metric' ); # We have a patron with date of birth=1980-06-17 => formatted as 17/06/1980 diff --git a/t/db_dependent/selenium/regressions.t b/t/db_dependent/selenium/regressions.t index 04aed37e29..899c03cd2c 100755 --- a/t/db_dependent/selenium/regressions.t +++ b/t/db_dependent/selenium/regressions.t @@ -48,10 +48,10 @@ my $builder = t::lib::TestBuilder->new; # It seems that we do not have enough records indexed with ES my $SearchEngine_value = C4::Context->preference('SearchEngine'); -C4::Context->set_preference('SearchEngine', 'Zebra'); +Koha::Config::SysPrefs->set_preference('SearchEngine', 'Zebra'); my $AudioAlerts_value = C4::Context->preference('AudioAlerts'); -C4::Context->set_preference('AudioAlerts', '1'); +Koha::Config::SysPrefs->set_preference('AudioAlerts', '1'); our @cleanup; subtest 'OPAC - borrowernumber, branchcode and categorycode as html attributes' => sub { @@ -279,7 +279,7 @@ subtest 'Encoding in session variables' => sub { my $original_SessionStorage = C4::Context->preference('SessionStorage'); for my $SessionStorage ( qw( memcached mysql tmp ) ) { - C4::Context->set_preference( 'SessionStorage', $SessionStorage ); + Koha::Config::SysPrefs->set_preference( 'SessionStorage', $SessionStorage ); for my $branchname (qw( Test1 Test2❤️ Test3ä )) { my $library = Koha::Libraries->find($branchname) || $builder->build_object( @@ -333,7 +333,7 @@ subtest 'Encoding in session variables' => sub { } } - C4::Context->set_preference('SessionStorage', $original_SessionStorage); + Koha::Config::SysPrefs->set_preference('SessionStorage', $original_SessionStorage); push @cleanup, $item, $biblio, $patron, $patron->category, $patron->library; push @cleanup, Koha::Libraries->find($_) for qw( Test1 Test2❤️ Test3ä ); @@ -375,8 +375,8 @@ subtest 'OPAC - Suggest for purchase' => sub { $driver->quit(); END { - C4::Context->set_preference('SearchEngine', $SearchEngine_value); - C4::Context->set_preference('AudioAlerts', $AudioAlerts_value); + Koha::Config::SysPrefs->set_preference('SearchEngine', $SearchEngine_value); + Koha::Config::SysPrefs->set_preference('AudioAlerts', $AudioAlerts_value); $_->delete for @cleanup; }; diff --git a/t/db_dependent/selenium/remove_from_cart.t b/t/db_dependent/selenium/remove_from_cart.t index f477e99f63..6efdade130 100755 --- a/t/db_dependent/selenium/remove_from_cart.t +++ b/t/db_dependent/selenium/remove_from_cart.t @@ -46,7 +46,7 @@ my $builder = t::lib::TestBuilder->new; my $marcflavour = C4::Context->preference('marcflavour') || 'MARC21'; my $SearchEngine_value = C4::Context->preference('SearchEngine'); -C4::Context->set_preference('SearchEngine', 'Zebra'); +Koha::Config::SysPrefs->set_preference('SearchEngine', 'Zebra'); my $mock_zebra = t::lib::Mocks::Zebra->new( { @@ -104,6 +104,6 @@ subtest 'OPAC - Remove from cart' => sub { }; END { - C4::Context->set_preference('SearchEngine', $SearchEngine_value); + Koha::Config::SysPrefs->set_preference('SearchEngine', $SearchEngine_value); $mock_zebra->cleanup if $mock_zebra; }; diff --git a/t/db_dependent/selenium/self_registration.t b/t/db_dependent/selenium/self_registration.t index 3a1b0e7929..f665a26822 100755 --- a/t/db_dependent/selenium/self_registration.t +++ b/t/db_dependent/selenium/self_registration.t @@ -43,7 +43,7 @@ my $opac_base_url = $s->opac_base_url; my $builder = t::lib::TestBuilder->new; my $PatronSelfRegistration_value = C4::Context->preference('PatronSelfRegistration'); -C4::Context->set_preference('PatronSelfRegistration', '1'); +Koha::Config::SysPrefs->set_preference('PatronSelfRegistration', '1'); my $PatronSelfRegistrationDefaultCategory_value = C4::Context->preference('PatronSelfRegistrationDefaultCategory'); @@ -60,7 +60,7 @@ subtest 'Set flags' => sub { plan tests => 2; my $default_category = $builder->build_object( { class => 'Koha::Patron::Categories' } ); - C4::Context->set_preference( 'PatronSelfRegistrationDefaultCategory', $default_category->categorycode ); + Koha::Config::SysPrefs->set_preference( 'PatronSelfRegistrationDefaultCategory', $default_category->categorycode ); $driver->get($opac_base_url . 'opac-memberentry.pl'); like( $driver->get_title(), qr(Register a new account), ); @@ -83,7 +83,7 @@ subtest 'Set flags' => sub { $driver->quit(); END { - C4::Context->set_preference('PatronSelfRegistration', $PatronSelfRegistration_value); - C4::Context->set_preference('PatronSelfRegistration', $PatronSelfRegistrationDefaultCategory_value); + Koha::Config::SysPrefs->set_preference('PatronSelfRegistration', $PatronSelfRegistration_value); + Koha::Config::SysPrefs->set_preference('PatronSelfRegistration', $PatronSelfRegistrationDefaultCategory_value); $_->delete for @cleanup; }; diff --git a/t/db_dependent/sysprefs.t b/t/db_dependent/sysprefs.t index f43f8e3d66..89947fb0d0 100755 --- a/t/db_dependent/sysprefs.t +++ b/t/db_dependent/sysprefs.t @@ -22,6 +22,7 @@ use Modern::Perl; use Test::More tests => 8; use C4::Context; use Koha::Database; +use Koha::Config::SysPrefs; my $schema = Koha::Database->new->schema; $schema->storage->txn_begin; @@ -30,10 +31,10 @@ my $dbh = C4::Context->dbh; my $URLLinkText = C4::Context->preference('URLLinkText'); my $newURLLinkText = "newURLLinkText"; -C4::Context->set_preference( 'URLLINKTEXT', $newURLLinkText ); +Koha::Config::SysPrefs->set_preference( 'URLLINKTEXT', $newURLLinkText ); is( C4::Context->preference('URLLinkText'), $newURLLinkText, 'The pref should have been set correctly' ); -C4::Context->set_preference( 'URLLinkText', $URLLinkText ); +Koha::Config::SysPrefs->set_preference( 'URLLinkText', $URLLinkText ); is( C4::Context->preference('URLLINKTEXT'), $URLLinkText, 'A pref name should be case insensitive'); $ENV{OVERRIDE_SYSPREF_URLLinkText} = 'this is an override'; @@ -46,14 +47,14 @@ is( is( C4::Context->preference('IDoNotExist'), undef, 'Get a non-existent system preference should return undef'); -C4::Context->set_preference( 'IDoNotExist', 'NonExistent' ); +Koha::Config::SysPrefs->set_preference( 'IDoNotExist', 'NonExistent' ); is( C4::Context->preference('IDoNotExist'), 'NonExistent', 'Test creation of non-existent system preference' ); -C4::Context->set_preference('testpreference', 'abc'); -C4::Context->delete_preference('testpreference'); +Koha::Config::SysPrefs->set_preference('testpreference', 'abc'); +Koha::Config::SysPrefs->delete_preference('testpreference'); is(C4::Context->preference('testpreference'), undef, 'deleting preferences'); -C4::Context->set_preference('testpreference', 'def'); +Koha::Config::SysPrefs->set_preference('testpreference', 'def'); # Delete from the database, it should still be in cache $dbh->do("DELETE FROM systempreferences WHERE variable='testpreference'"); is(C4::Context->preference('testpreference'), 'def', 'caching preferences'); diff --git a/t/db_dependent/www/regressions.t b/t/db_dependent/www/regressions.t index 8b9c77b07b..fbaad0db4b 100755 --- a/t/db_dependent/www/regressions.t +++ b/t/db_dependent/www/regressions.t @@ -97,7 +97,7 @@ subtest 'open redirection vulnerabilities in tracklinks' => sub { Koha::Caches->flush_L1_caches; # Don't Track - C4::Context->set_preference( 'TrackClicks', '' ); + Koha::Config::SysPrefs->set_preference( 'TrackClicks', '' ); $t->get_ok( $opac . $no_biblionumber ) ->status_is( 404, "404 for no biblionumber" ); $t->get_ok( $opac . $bad_biblionumber1 ) @@ -112,7 +112,7 @@ subtest 'open redirection vulnerabilities in tracklinks' => sub { ->status_is( 404, "404 for itemnumber with matching URI - pref off" ); # Track - C4::Context->set_preference( 'TrackClicks', 'track' ); + Koha::Config::SysPrefs->set_preference( 'TrackClicks', 'track' ); $t->get_ok( $opac . $no_biblionumber ) ->status_is( 404, "404 for no biblionumber" ); $t->get_ok( $opac . $bad_biblionumber1 ) @@ -127,7 +127,7 @@ subtest 'open redirection vulnerabilities in tracklinks' => sub { ->status_is( 302, "302 for itemnumber with matching URI" ); # Track Anonymous - C4::Context->set_preference( 'TrackClicks', 'anonymous' ); + Koha::Config::SysPrefs->set_preference( 'TrackClicks', 'anonymous' ); $t->get_ok( $opac . $no_biblionumber ) ->status_is( 404, "404 for no biblionumber" ); $t->get_ok( $opac . $bad_biblionumber1 ) -- 2.34.1