RT 4.0.13
[freeside.git] / rt / t / customfields / sort_order.t
1
2 use strict;
3 use warnings;
4
5 use RT::Test tests => 20;
6 use RT::Ticket;
7 use RT::CustomField;
8
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");
12
13 diag "create multiple CFs: B, A and C";
14 my @cfs = ();
15 {
16     my $cf = RT::CustomField->new( RT->SystemUser );
17     my ($ret, $msg) = $cf->Create(
18         Name  => "CF B",
19         Queue => $queue->id,
20         Type  => 'FreeformSingle',
21     );
22     ok($ret, "Custom Field Order created");
23     push @cfs, $cf;
24 }
25 {
26     my $cf = RT::CustomField->new( RT->SystemUser );
27     my ($ret, $msg) = $cf->Create(
28         Name  => "CF A",
29         Queue => $queue->id,
30         Type  => 'FreeformSingle',
31     );
32     ok($ret, "Custom Field Order created");
33     push @cfs, $cf;
34 }
35 {
36     my $cf = RT::CustomField->new( RT->SystemUser );
37     my ($ret, $msg) = $cf->Create(
38         Name  => "CF C",
39         Queue => $queue->id,
40         Type  => 'FreeformSingle',
41     );
42     ok($ret, "Custom Field Order created");
43     push @cfs, $cf;
44 }
45
46 my ($baseurl, $m) = RT::Test->started_ok;
47 ok $m->login( root => 'password' ), 'logged in';
48
49 diag "reorder CFs: C, A and B";
50 {
51     $m->get( '/Admin/Queues/' );
52     $m->follow_link_ok( {text => $queue->id} );
53     $m->follow_link_ok( {id  => 'page-ticket-custom-fields'} );
54     my @tmp = ($m->content =~ /(CF [ABC])/g);
55     is_deeply(\@tmp, ['CF B', 'CF A', 'CF C']);
56
57     $m->follow_link_ok( {text => '[Up]', n => 3} );
58     $m->follow_link_ok( {text => '[Up]', n => 2} );
59     $m->follow_link_ok( {text => '[Up]', n => 3} );
60
61     @tmp = ($m->content =~ /(CF [ABC])/g);
62     is_deeply(\@tmp, ['CF C', 'CF A', 'CF B']);
63 }
64
65 diag "check ticket create, display and edit pages";
66 {
67     $m->submit_form(
68         form_name => "CreateTicketInQueue",
69         fields => { Queue => $queue->Name },
70     );
71
72     my @tmp = ($m->content =~ /(CF [ABC])/g);
73     is_deeply(\@tmp, ['CF C', 'CF A', 'CF B']);
74
75     $m->submit_form(
76         form_name => "TicketCreate",
77         fields => { Subject => 'test' },
78     );
79     my ($tid) = ($m->content =~ /Ticket (\d+) created/i);
80     ok $tid, "created a ticket succesfully";
81     
82     @tmp = ($m->content =~ /(CF [ABC])/g);
83     is_deeply(\@tmp, ['CF C', 'CF A', 'CF B']);
84     $m->follow_link_ok( {id => 'page-basics'});
85
86     @tmp = ($m->content =~ /(CF [ABC])/g);
87     is_deeply(\@tmp, ['CF C', 'CF A', 'CF B']);
88 }
89