Bug 26384: Fix executable flags
[koha.git] / t / db_dependent / Koha / Config / SysPrefs.t
1 # This file is part of Koha.
2 #
3 # Copyright 2018 Koha Development Team
4 #
5 # Koha is free software; you can redistribute it and/or modify it
6 # under the terms of the GNU General Public License as published by
7 # the Free Software Foundation; either version 3 of the License, or
8 # (at your option) any later version.
9 #
10 # Koha is distributed in the hope that it will be useful, but
11 # WITHOUT ANY WARRANTY; without even the implied warranty of
12 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 # GNU General Public License for more details.
14 #
15 # You should have received a copy of the GNU General Public License
16 # along with Koha; if not, see <http://www.gnu.org/licenses>.
17
18 use Modern::Perl;
19 use Test::More tests => 4;
20
21 use t::lib::Mocks;
22 use t::lib::TestBuilder;
23 use Koha::Config::SysPrefs;
24
25 my $schema = Koha::Database->new->schema;
26 $schema->storage->txn_begin;
27
28 my $builder = t::lib::TestBuilder->new;
29
30 my $nb_of_prefs = Koha::Config::SysPrefs->search->count;
31 my $new_pref = Koha::Config::SysPref->new({
32     variable => 'ShouldNotBeDone',
33     value    => 'but a good test?',
34     options  => undef,
35     explanation => 'just for CRUD sake',
36     type     => 'Free'
37 })->store;
38
39 is( Koha::Config::SysPrefs->search->count, $nb_of_prefs + 1, 'The 1 pref should have been added' );
40 my $retrieved_pref = Koha::Config::SysPrefs->find('ShouldNotBeDone');
41 is( $retrieved_pref->value, $new_pref->value, 'Find a pref by variable should return the correct pref' );
42
43 $retrieved_pref->delete;
44 is( Koha::Config::SysPrefs->search->count, $nb_of_prefs, 'Delete should have deleted the pref' );
45
46 subtest 'get_yaml_pref_hash' => sub {
47
48     plan tests => 1;
49
50     my $the_pref = Koha::Config::SysPrefs->find({variable=>'ItemsDeniedRenewal'});
51     $the_pref->value(q{
52         nulled: [NULL,'']
53         this: [just_that]
54         multi_this: [that,another]
55     });
56
57     my $expected_hash = {
58         nulled => [undef,""],
59         this     => ['just_that'],
60         multi_this => ['that','another'],
61     };
62     my $got_hash = $the_pref->get_yaml_pref_hash();
63     is_deeply($got_hash,$expected_hash,"Pref fetched and converted correctly");
64
65 };
66
67 $schema->storage->txn_rollback;