Bug 31183: Unit tests
[koha.git] / t / db_dependent / yaml.t
1 use Modern::Perl;
2 use Test::More;
3
4 use YAML::XS;
5 use Template;
6 use Encode;
7 use utf8;
8
9 my $template = Template->new( ENCODING => 'UTF-8' );
10
11 my $vars;
12 my $output;
13 $template->process( 't/db_dependent/data/syspref.pref', $vars, \$output );
14
15 my $yaml = YAML::XS::Load( Encode::encode_utf8( $output ) );
16 my $syspref_1 = $yaml->{Test}->{Testing}->[0];
17 my $syspref_2 = $yaml->{Test}->{Testing}->[1];
18 my $syspref_3 = $yaml->{Test}->{Testing}->[2];
19 my $syspref_4 = $yaml->{Test}->{Testing}->[3];
20 is_deeply(
21     $syspref_1,
22     [
23         "Do it",
24         {
25             choices => {
26                 on  => "certainly",
27                 off => "I don't think so"
28             },
29             pref => "syspref_1"
30         }
31     ]
32 );
33 is_deeply(
34     $syspref_2,
35     [
36         {
37             choices => {
38                 0    => "really don't do",
39                 ''   => "Do",
40                 dont => "Don't do"
41             },
42             pref => "syspref_2"
43         },
44         "it."
45     ]
46 );
47 is_deeply(
48     $syspref_3,
49     [
50         "We love unicode",
51         {
52             choices => {
53                 no  => "Not really",
54                 '★' => "❤️"
55             },
56             pref => "syspref_3"
57         }
58     ],
59 );
60 is_deeply(
61     $syspref_4,
62     [
63         "List of fields",
64         {
65             choices => {
66                 16    => 16,
67                 "020" => "020",
68                 123   => 123
69             },
70             pref => "syspref_4"
71         }
72     ]
73 );
74 done_testing;