5 use RT::Test nodata => 1, tests => 47;
9 my $queue_name = "CFSortQueue-$$";
10 my $queue = RT::Test->load_or_create_queue( Name => $queue_name );
11 ok($queue && $queue->id, "$queue_name - test queue creation");
14 my $cf_name = "Rights$$";
17 $cf = RT::CustomField->new( RT->SystemUser );
18 my ($ret, $msg) = $cf->Create(
21 Type => 'FreeformSingle',
23 ok($ret, "Custom Field Order created");
26 my $tester = RT::Test->load_or_create_user(
27 Name => 'tester', Password => 'password',
29 ok $tester && $tester->id, 'loaded or created user';
31 my $cc_role = $queue->RoleGroup( 'Cc' );
32 my $owner_role = $queue->RoleGroup( 'Owner' );
34 ok( RT::Test->set_rights(
35 { Principal => $tester, Right => [qw(SeeQueue ShowTicket CreateTicket ReplyToTicket Watch OwnTicket TakeTicket)] },
36 { Principal => $cc_role, Object => $queue, Right => [qw(SeeCustomField)] },
37 { Principal => $owner_role, Object => $queue, Right => [qw(ModifyCustomField)] },
41 my $ticket = RT::Ticket->new( $tester );
42 my ($tid, $msg) = $ticket->Create( Queue => $queue, Subject => 'test' );
43 ok $tid, "created ticket";
45 ok !$ticket->CustomFields->First, "see no fields";
49 my $ticket = RT::Ticket->new( $tester );
50 my ($tid, $msg) = $ticket->Create( Queue => $queue, Subject => 'test', Cc => $tester->id );
51 ok $tid, "created ticket";
53 my $cf = $ticket->CustomFields->First;
58 my $ticket = RT::Ticket->new( $tester );
59 my ($tid, $msg) = $ticket->Create( Queue => $queue, Subject => 'test', Cc => $tester->id );
60 ok $tid, "created ticket";
62 (my $status, $msg) = $ticket->AddCustomFieldValue( Field => $cf->Name, Value => 'test' );
63 ok !$status, "Can not change CF";
67 my $ticket = RT::Ticket->new( $tester );
68 my ($tid, $msg) = $ticket->Create( Queue => $queue, Subject => 'test', Cc => $tester->id, Owner => $tester->id );
69 ok $tid, "created ticket";
71 (my $status, $msg) = $ticket->AddCustomFieldValue( Field => $cf->Name, Value => 'test' );
72 ok $status, "Changed CF";
73 is $ticket->FirstCustomFieldValue( $cf->Name ), 'test';
75 ($status, $msg) = $ticket->DeleteCustomFieldValue( Field => $cf->Name, Value => 'test' );
76 ok $status, "Changed CF";
77 is $ticket->FirstCustomFieldValue( $cf->Name ), undef;
81 my $ticket = RT::Ticket->new( $tester );
82 my ($tid, $msg) = $ticket->Create( Queue => $queue, Subject => 'test', Cc => $tester->id, Owner => $tester->id );
83 ok $tid, "created ticket";
85 (my $status, $msg) = $ticket->AddCustomFieldValue( Field => $cf->id, Value => 'test' );
86 ok $status, "Changed CF";
87 is $ticket->FirstCustomFieldValue( $cf->id ), 'test';
89 ($status, $msg) = $ticket->DeleteCustomFieldValue( Field => $cf->id, Value => 'test' );
90 ok $status, "Changed CF";
91 is $ticket->FirstCustomFieldValue( $cf->id ), undef;
94 my ($baseurl, $m) = RT::Test->started_ok;
95 ok $m->login( tester => 'password' ), 'logged in';
97 diag "check that we don't have the cf on create";
100 form_name => "CreateTicketInQueue",
101 fields => { Queue => $queue->Name },
104 my $form = $m->form_name("TicketCreate");
105 my $cf_field = "Object-RT::Ticket--CustomField-". $cf->id ."-Value";
106 ok !$form->find_input( $cf_field ), 'no form field on the page';
109 form_name => "TicketCreate",
110 fields => { Subject => 'test' },
112 my ($tid) = ($m->content =~ /Ticket (\d+) created/i);
113 ok $tid, "created a ticket succesfully";
114 $m->content_lacks($cf_name, "don't see CF");
116 $m->follow_link( id => 'page-basics');
117 $form = $m->form_name('TicketModify');
118 $cf_field = "Object-RT::Ticket-$tid-CustomField-". $cf->id ."-Value";
119 ok !$form->find_input( $cf_field ), 'no form field on the page';
122 diag "check that we see CF as Cc";
124 my $ticket = RT::Ticket->new( $tester );
125 my ($tid, $msg) = $ticket->Create( Queue => $queue, Subject => 'test', Cc => $tester->id );
126 ok $tid, "created ticket";
128 ok $m->goto_ticket( $tid ), "opened ticket";
129 $m->content_contains($cf_name, "see CF");
132 diag "check that owner can see and edit CF";
134 my $ticket = RT::Ticket->new( $tester );
135 my ($tid, $msg) = $ticket->Create( Queue => $queue, Subject => 'test', Cc => $tester->id, Owner => $tester->id );
136 ok $tid, "created ticket";
138 ok $m->goto_ticket( $tid ), "opened ticket";
139 $m->content_contains($cf_name, "see CF");
141 $m->follow_link( id => 'page-basics');
142 my $form = $m->form_name('TicketModify');
143 my $cf_field = "Object-RT::Ticket-$tid-CustomField-". $cf->id ."-Value";
144 ok $form->find_input( $cf_field ), 'form field on the page';
147 form_name => 'TicketModify',
149 $cf_field => "changed cf",
153 ok $m->goto_ticket( $tid ), "opened ticket";
154 $m->content_contains($cf_name, "changed cf");
157 note 'make sure CF is not reset to no value';
159 my $t = RT::Test->create_ticket(
162 'CustomField-'.$cf->id => '2012-02-12',
164 Owner => $tester->id,
166 ok $t && $t->id, 'created ticket';
167 is $t->FirstCustomFieldValue($cf_name), '2012-02-12';
169 $m->goto_ticket($t->id);
170 $m->follow_link_ok({id => 'page-basics'});
171 my $form = $m->form_name('TicketModify');
172 my $input = $form->find_input(
173 'Object-RT::Ticket-'. $t->id .'-CustomField-'. $cf->id .'-Value'
175 ok $input, 'found input';
176 $m->click('SubmitTicket');
179 $t = RT::Ticket->new( $RT::SystemUser );
181 is $t->FirstCustomFieldValue($cf_name), '2012-02-12';