fix ticketing system error on bootstrap of new install
[freeside.git] / rt / t / api / system.t
1
2 use strict;
3 use warnings;
4 use RT;
5 use RT::Test nodata => 1, tests => 16;
6
7 BEGIN{
8   use_ok('RT::System');
9 }
10
11 # Skipping most of the methods added just to make RT::System
12 # look like RT::Record.
13
14 can_ok('RT::System', qw( AvailableRights RightCategories AddRight
15                          id Id SubjectTag Name QueueCacheNeedsUpdate AddUpgradeHistory
16                          UpgradeHistory ));
17
18 {
19
20 my $s = RT::System->new(RT->SystemUser);
21 my $rights = $s->AvailableRights;
22 ok ($rights, "Rights defined");
23 ok ($rights->{'AdminUsers'},"AdminUsers right found");
24 ok ($rights->{'CreateTicket'},"CreateTicket right found");
25 ok ($rights->{'AdminGroupMembership'},"ModifyGroupMembers right found");
26 ok (!$rights->{'CasdasdsreateTicket'},"bogus right not found");
27
28 }
29
30 {
31
32 my $sys = RT::System->new();
33 is( $sys->Id, 1, 'Id is 1');
34 is ($sys->id, 1, 'id is 1');
35
36 }
37
38 {
39
40 # Test upgrade history methods.
41
42 my $sys = RT::System->new(RT->SystemUser);
43 isa_ok($sys, 'RT::System');
44
45 my $file = 'test_file.txt';
46 my $content = 'Some file contents.';
47 my $upgrade_history = RT->System->UpgradeHistory();
48
49 is( keys %$upgrade_history, 0, 'No history in test DB');
50
51 RT->System->AddUpgradeHistory(RT =>{
52         action   => 'insert',
53         filename => $file,
54         content  => $content,
55         stage    => 'before',
56     });
57
58 $upgrade_history = RT->System->UpgradeHistory();
59 ok( exists($upgrade_history->{'RT'}), 'History has an RT key.');
60 is( @{$upgrade_history->{'RT'}}, 1, '1 item in history array');
61 is($upgrade_history->{RT}[0]{stage}, 'before', 'stage is before for item 1');
62
63 RT->System->AddUpgradeHistory(RT =>{
64         action   => 'insert',
65         filename => $file,
66         content  => $content,
67         stage    => 'after',
68     });
69
70 $upgrade_history = RT->System->UpgradeHistory();
71 is( @{$upgrade_history->{'RT'}}, 2, '2 item in history array');
72 is($upgrade_history->{RT}[1]{stage}, 'after', 'stage is after for item 2');
73
74 }