Merge branch 'master' of git.freeside.biz:/home/git/freeside
[freeside.git] / rt / t / api / config.t
1 use strict;
2 use warnings;
3 use RT;
4 use RT::Test nodb => 1, tests => 11;
5 use Test::Warn;
6
7 ok(
8     RT::Config->AddOption(
9         Name    => 'foo',
10         Section => 'bar',
11     ),
12     'added option foo'
13 );
14
15 my $meta = RT::Config->Meta('foo');
16 is( $meta->{Section}, 'bar', 'Section is bar' );
17 is( $meta->{Widget}, '/Widgets/Form/String', 'default Widget is string' );
18 is_deeply( $meta->{WidgetArguments},
19     {},, 'default WidgetArguments is empty hashref' );
20
21 ok(
22     RT::Config->UpdateOption(
23         Name    => 'foo',
24         Section => 'baz',
25         Widget => '/Widgets/Form/Boolean',
26     ),
27     'updated option foo to section baz'
28 );
29 is( $meta->{Section}, 'baz', 'section is updated to baz' );
30 is( $meta->{Widget}, '/Widgets/Form/Boolean', 'widget is updated to boolean' );
31
32 ok( RT::Config->DeleteOption( Name => 'foo' ), 'removed option foo' );
33 is( RT::Config->Meta('foo'), undef, 'foo is indeed deleted' );
34
35 # Test EmailInputEncodings PostLoadCheck code
36 RT::Config->Set('EmailInputEncodings', qw(utf-8 iso-8859-1 us-ascii foo));
37 my @encodings = qw(utf-8-strict iso-8859-1 ascii);
38
39 warning_is {RT::Config->PostLoadCheck} "Unknown encoding 'foo' in \@EmailInputEncodings option",
40   'Correct warning for encoding foo';
41
42 my @canonical_encodings = RT::Config->Get('EmailInputEncodings');
43 is_deeply(\@encodings, \@canonical_encodings, 'Got correct encoding list');