import torrus 1.0.9
[freeside.git] / rt / t / ticket / deferred_owner.t
1
2 use strict;
3 use warnings;
4
5 use RT::Test tests => 18;
6 use_ok('RT');
7 use_ok('RT::Ticket');
8 use Test::Warn;
9
10
11 my $tester = RT::Test->load_or_create_user(
12     EmailAddress => 'tester@localhost',
13 );
14 ok $tester && $tester->id, 'loaded or created user';
15
16 my $queue = RT::Test->load_or_create_queue( Name => 'General' );
17 ok $queue && $queue->id, 'loaded or created queue';
18
19 my $owner_role_group = RT::Group->new( $RT::SystemUser );
20 $owner_role_group->LoadQueueRoleGroup( Type => 'Owner', Queue => $queue->id );
21 ok $owner_role_group->id, 'loaded owners role group of the queue';
22
23 diag "check that deffering owner doesn't regress" if $ENV{'TEST_VERBOSE'};
24 {
25     RT::Test->set_rights(
26         { Principal => $tester->PrincipalObj,
27           Right => [qw(SeeQueue ShowTicket CreateTicket OwnTicket)],
28         },
29         { Principal => $owner_role_group->PrincipalObj,
30           Object => $queue,
31           Right => [qw(ModifyTicket)],
32         },
33     );
34     my $ticket = RT::Ticket->new( $tester );
35     # tester is owner, owner has right to modify owned tickets,
36     # this right is required to set somebody as AdminCc
37     my ($tid, $txn_id, $msg) = $ticket->Create(
38         Queue   => $queue->id,
39         Owner   => $tester->id,
40         AdminCc => 'root@localhost',
41     );
42     diag $msg if $msg && $ENV{'TEST_VERBOSE'};
43     ok $tid, "created a ticket";
44     is $ticket->Owner, $tester->id, 'correct owner';
45     like $ticket->AdminCcAddresses, qr/root\@localhost/, 'root is there';
46 }
47
48 diag "check that previous trick doesn't work without sufficient rights"
49     if $ENV{'TEST_VERBOSE'};
50 {
51     RT::Test->set_rights(
52         { Principal => $tester->PrincipalObj,
53           Right => [qw(SeeQueue ShowTicket CreateTicket OwnTicket)],
54         },
55     );
56     my $ticket = RT::Ticket->new( $tester );
57     # tester is owner, owner has right to modify owned tickets,
58     # this right is required to set somebody as AdminCc
59     my ($tid, $txn_id, $msg) = $ticket->Create(
60         Queue   => $queue->id,
61         Owner   => $tester->id,
62         AdminCc => 'root@localhost',
63     );
64     diag $msg if $msg && $ENV{'TEST_VERBOSE'};
65     ok $tid, "created a ticket";
66     is $ticket->Owner, $tester->id, 'correct owner';
67     unlike $ticket->AdminCcAddresses, qr/root\@localhost/, 'root is there';
68 }
69
70 diag "check that deffering owner really works" if $ENV{'TEST_VERBOSE'};
71 {
72     RT::Test->set_rights(
73         { Principal => $tester->PrincipalObj,
74           Right => [qw(SeeQueue ShowTicket CreateTicket)],
75         },
76         { Principal => $queue->Cc->PrincipalObj,
77           Object => $queue,
78           Right => [qw(OwnTicket TakeTicket)],
79         },
80     );
81     my $ticket = RT::Ticket->new( $tester );
82     # set tester as Cc, Cc role group has right to own and take tickets
83     my ($tid, $txn_id, $msg) = $ticket->Create(
84         Queue => $queue->id,
85         Owner => $tester->id,
86         Cc    => 'tester@localhost',
87     );
88     diag $msg if $msg && $ENV{'TEST_VERBOSE'};
89     ok $tid, "created a ticket";
90     like $ticket->CcAddresses, qr/tester\@localhost/, 'tester is in the cc list';
91     is $ticket->Owner, $tester->id, 'tester is also owner';
92 }
93
94 diag "check that deffering doesn't work without correct rights" if $ENV{'TEST_VERBOSE'};
95 {
96     RT::Test->set_rights(
97         { Principal => $tester->PrincipalObj,
98           Right => [qw(SeeQueue ShowTicket CreateTicket)],
99         },
100     );
101
102     my $ticket = RT::Ticket->new( $tester );
103     # set tester as Cc, Cc role group has right to own and take tickets
104     my ($tid, $txn_id, $msg);
105     warning_like {
106         ($tid, $txn_id, $msg) = $ticket->Create(
107             Queue => $queue->id,
108             Owner => $tester->id,
109             Cc    => 'tester@localhost',
110         );
111     } qr/User .* was proposed as a ticket owner but has no rights to own tickets in General/;
112
113     diag $msg if $msg && $ENV{'TEST_VERBOSE'};
114     ok $tid, "created a ticket";
115     like $ticket->CcAddresses, qr/tester\@localhost/, 'tester is in the cc list';
116     isnt $ticket->Owner, $tester->id, 'tester is also owner';
117 }
118
119
120