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

(-)a/t/db_dependent/Context.t (-21 / +18 lines)
Lines 1-16 Link Here
1
#!/usr/bin/perl
1
#!/usr/bin/perl
2
2
3
use Modern::Perl;
3
use Modern::Perl;
4
4
use Test::More tests => 4;
5
use Test::More;
6
use Test::MockModule;
5
use Test::MockModule;
7
use vars qw($koha $dbh $config $ret);
6
8
use t::lib::Mocks;
7
use t::lib::Mocks;
8
use t::lib::TestBuilder;
9
9
10
use Koha::Database;
10
use Koha::Database;
11
11
12
BEGIN {
12
BEGIN {
13
13
    my $ret;
14
    # Note: The overall number of tests may vary by configuration.
14
    # Note: The overall number of tests may vary by configuration.
15
    # First we need to check your environmental variables
15
    # First we need to check your environmental variables
16
    for (qw(KOHA_CONF PERL5LIB)) {
16
    for (qw(KOHA_CONF PERL5LIB)) {
Lines 19-27 BEGIN { Link Here
19
    use_ok('C4::Context');
19
    use_ok('C4::Context');
20
}
20
}
21
21
22
our $schema;
23
$schema = Koha::Database->new->schema;
24
25
subtest 'Original tests' => sub {
26
plan tests => 33;
27
$schema->storage->txn_begin;
28
29
my $dbh;
22
ok($dbh = C4::Context->dbh(), 'Getting dbh from C4::Context');
30
ok($dbh = C4::Context->dbh(), 'Getting dbh from C4::Context');
23
31
24
$dbh->begin_work;
25
C4::Context->set_preference('OPACBaseURL','junk');
32
C4::Context->set_preference('OPACBaseURL','junk');
26
C4::Context->clear_syspref_cache();
33
C4::Context->clear_syspref_cache();
27
my $OPACBaseURL = C4::Context->preference('OPACBaseURL');
34
my $OPACBaseURL = C4::Context->preference('OPACBaseURL');
Lines 47-54 my $SillyPeference = C4::Context->preference('SillyPreference'); Link Here
47
is($SillyPeference,'random','SillyPreference saved as specified');
54
is($SillyPeference,'random','SillyPreference saved as specified');
48
C4::Context->clear_syspref_cache();
55
C4::Context->clear_syspref_cache();
49
C4::Context->enable_syspref_cache();
56
C4::Context->enable_syspref_cache();
50
$dbh->rollback;
57
#$dbh->rollback;
51
58
59
my $koha;
52
ok($koha = C4::Context->new,  'C4::Context->new');
60
ok($koha = C4::Context->new,  'C4::Context->new');
53
my @keys = keys %$koha;
61
my @keys = keys %$koha;
54
my $width = 0;
62
my $width = 0;
Lines 62-72 foreach (sort @keys) { Link Here
62
		. ((defined $koha->{$_}) ? "and is defined." : "but is not defined.")
70
		. ((defined $koha->{$_}) ? "and is defined." : "but is not defined.")
63
	);
71
	);
64
}
72
}
73
my $config;
65
ok($config = $koha->{config}, 'Getting $koha->{config} ');
74
ok($config = $koha->{config}, 'Getting $koha->{config} ');
66
75
67
# Testing syspref caching
76
# Testing syspref caching
68
77
69
my $schema = Koha::Database->new()->schema();
78
#my $schema = Koha::Database->new()->schema();
70
$schema->storage->debug(1);
79
$schema->storage->debug(1);
71
my $trace_read;
80
my $trace_read;
72
open my $trace, '>', \$trace_read or die "Can't open variable: $!";
81
open my $trace, '>', \$trace_read or die "Can't open variable: $!";
Lines 131-147 C4::Context->set_preference('AutoEmailNewUser', ''); Link Here
131
my $yesno_pref = Koha::Config::SysPrefs->find('AutoEmailNewUser');
140
my $yesno_pref = Koha::Config::SysPrefs->find('AutoEmailNewUser');
132
is( $yesno_pref->value(), 0, 'set_preference should have set the value to 0, instead of an empty string' );
141
is( $yesno_pref->value(), 0, 'set_preference should have set the value to 0, instead of an empty string' );
133
142
134
done_testing();
135
136
sub TransformVersionToNum {
137
    my $version = shift;
138
143
139
    # remove the 3 last . to have a Perl number
144
    $schema->storage->txn_rollback;
140
    $version =~ s/(.*\..*)\.(.*)\.(.*)/$1$2$3/;
145
};
141
142
    # three X's at the end indicate that you are testing patch with dbrev
143
    # change it into 999
144
    # prevents error on a < comparison between strings (should be: lt)
145
    $version =~ s/XXX$/999/;
146
    return $version;
147
}
148
- 

Return to bug 31870