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