Bug 31870: Context.t: Reorganize subtests

Move a few tests into separate subtests.
Replace the BEGIN block.

Test plan:
Run test again.

Signed-off-by: Marcel de Rooy <m.de.rooy@rijksmuseum.nl>

Signed-off-by: Katrin Fischer <katrin.fischer.83@web.de>
Signed-off-by: Tomas Cohen Arazi <tomascohen@theke.io>
This commit is contained in:
Marcel de Rooy 2022-10-19 12:00:37 +00:00 committed by Tomas Cohen Arazi
parent 3aa5ebab1a
commit 77bd3d94ca
No known key found for this signature in database
GPG Key ID: 0A272EA1B2F3C15F
1 changed files with 41 additions and 35 deletions

View File

@ -7,22 +7,23 @@ use Test::MockModule;
use t::lib::Mocks;
use t::lib::TestBuilder;
use C4::Context;
use Koha::Database;
BEGIN {
my $ret;
# First we need to check your environmental variables
for (qw(KOHA_CONF PERL5LIB)) {
ok( $ret = $ENV{$_}, "ENV{$_} = $ret" );
}
use_ok('C4::Context');
}
our $schema;
$schema = Koha::Database->new->schema;
subtest 'Original tests' => sub {
plan tests => 33;
subtest 'Environment' => sub {
plan tests => 2;
# First we need to check your environmental variables
my $ret;
for (qw(KOHA_CONF PERL5LIB)) {
ok( $ret = $ENV{$_}, "ENV{$_} = $ret" );
}
};
subtest 'Tests with preferences' => sub {
plan tests => 22;
$schema->storage->txn_begin;
my $dbh;
@ -54,25 +55,7 @@ subtest 'Original tests' => sub {
C4::Context->clear_syspref_cache();
C4::Context->enable_syspref_cache();
my $koha;
ok($koha = C4::Context->new, 'C4::Context->new');
my @keys = keys %$koha;
my $width = 0;
ok( @keys, 'Expecting entries in context hash' );
if( @keys ) {
$width = (sort {$a <=> $b} map {length} @keys)[-1];
}
foreach (sort @keys) {
ok(exists $koha->{$_},
'$koha->{' . sprintf('%' . $width . 's', $_) . '} exists '
. ((defined $koha->{$_}) ? "and is defined." : "but is not defined.")
);
}
my $config;
ok($config = $koha->{config}, 'Getting $koha->{config} ');
# Testing syspref caching
$schema->storage->debug(1);
my $trace_read;
open my $trace, '>', \$trace_read or die "Can't open variable: $!";
@ -116,12 +99,6 @@ subtest 'Original tests' => sub {
is(C4::Context->preference("SillyPreference"), 'thing4', "Retrieved syspref (value='thing4') successfully from cache");
is( $trace_read, q{}, 'Did not retrieve syspref from database');
$trace_read = q{};
my $oConnection = C4::Context->Zconn('biblioserver', 0);
isnt($oConnection->option('async'), 1, "ZOOM connection is synchronous");
$oConnection = C4::Context->Zconn('biblioserver', 1);
is($oConnection->option('async'), 1, "ZOOM connection is asynchronous");
$silly_preference->delete();
# AutoEmailNewUser should be a YesNo pref
@ -131,3 +108,32 @@ subtest 'Original tests' => sub {
$schema->storage->txn_rollback;
};
subtest 'Check context hash keys' => sub {
my $koha;
ok($koha = C4::Context->new, 'C4::Context->new');
my @keys = keys %$koha;
my $width = 0;
ok( @keys, 'Expecting entries in context hash' );
if( @keys ) {
$width = (sort {$a <=> $b} map {length} @keys)[-1];
}
foreach (sort @keys) {
ok(exists $koha->{$_},
'$koha->{' . sprintf('%' . $width . 's', $_) . '} exists '
. ((defined $koha->{$_}) ? "and is defined." : "but is not defined.")
);
}
my $config;
ok($config = $koha->{config}, 'Getting $koha->{config} ');
done_testing();
};
subtest 'Zconn' => sub {
plan tests => 2;
my $oConnection = C4::Context->Zconn('biblioserver', 0);
isnt($oConnection->option('async'), 1, "ZOOM connection is synchronous");
$oConnection = C4::Context->Zconn('biblioserver', 1);
is($oConnection->option('async'), 1, "ZOOM connection is asynchronous");
};