rt 4.0.6
[freeside.git] / rt / t / web / query_builder_queue_limits.t
1 use strict;
2 use warnings;
3
4 use RT::Test tests => 34;
5
6 my $lifecycles = RT->Config->Get('Lifecycles');
7 $lifecycles->{foo} = {
8     initial  => ['initial'],
9     active   => ['open'],
10     inactive => ['resolved'],
11
12 };
13
14 RT::Lifecycle->FillCache();
15
16 my $general = RT::Test->load_or_create_queue( Name => 'General' );
17 my $foo = RT::Test->load_or_create_queue( Name => 'foo', Lifecycle => 'foo' );
18
19 my $global_cf = RT::Test->load_or_create_custom_field(
20     Name  => 'global_cf',
21     Queue => 0,
22     Type  => 'FreeformSingle',
23 );
24
25 my $general_cf = RT::Test->load_or_create_custom_field(
26     Name  => 'general_cf',
27     Queue => 'General',
28     Type  => 'FreeformSingle',
29 );
30
31 my $foo_cf = RT::Test->load_or_create_custom_field(
32     Name  => 'foo_cf',
33     Queue => 'foo',
34     Type  => 'FreeformSingle'
35 );
36
37 my $root = RT::Test->load_or_create_user( Name => 'root', );
38 my $user_a = RT::Test->load_or_create_user(
39     Name     => 'user_a',
40     Password => 'password',
41 );
42 my $user_b = RT::Test->load_or_create_user(
43     Name     => 'user_b',
44     Password => 'password',
45 );
46
47 ok(
48     RT::Test->set_rights(
49         {
50             Principal => $user_a,
51             Object    => $general,
52             Right     => ['OwnTicket'],
53         },
54         {
55             Principal => $user_b,
56             Object    => $foo,
57             Right     => ['OwnTicket'],
58         },
59     ),
60     'granted OwnTicket right for user_a and user_b'
61 );
62
63 my ( $url, $m ) = RT::Test->started_ok;
64 ok( $m->login, 'logged in' );
65
66 $m->get_ok( $url . '/Search/Build.html' );
67
68 diag "check default statuses, cf and owners";
69 my $form = $m->form_name('BuildQuery');
70 ok( $form,                                     'found BuildQuery form' );
71 ok( $form->find_input("ValueOf'CF.{global_cf}'"), 'found global_cf by default' );
72 ok( !$form->find_input("ValueOf'CF.{general_cf}'"), 'no general_cf by default' );
73 ok( !$form->find_input("ValueOf'CF.{foo_cf}'"), 'no foo_cf by default' );
74
75 my $status_input = $form->find_input('ValueOfStatus');
76 my @statuses     = sort $status_input->possible_values;
77 is_deeply(
78     \@statuses, [ '', qw/initial new open rejected resolved stalled/], 'found all statuses'
79 );
80
81 my $owner_input = $form->find_input('ValueOfActor');
82 my @owners     = sort $owner_input->possible_values;
83 is_deeply(
84     \@owners, [ '', qw/Nobody root user_a user_b/], 'found all users'
85 );
86
87 diag "limit queue to foo";
88 $m->submit_form(
89     fields => { ValueOfQueue => 'foo' },
90     button => 'AddClause',
91 );
92
93 $form = $m->form_name('BuildQuery');
94 ok( $form->find_input("ValueOf'CF.{foo_cf}'"), 'found foo_cf' );
95 ok( $form->find_input("ValueOf'CF.{global_cf}'"), 'found global_cf' );
96 ok( !$form->find_input("ValueOf'CF.{general_cf}'"), 'still no general_cf' );
97 $status_input = $form->find_input('ValueOfStatus');
98 @statuses     = sort $status_input->possible_values;
99 is_deeply(
100     \@statuses,
101     [ '', qw/initial open resolved/ ],
102     'found statuses from foo only'
103 );
104
105 $owner_input = $form->find_input('ValueOfActor');
106 @owners     = sort $owner_input->possible_values;
107 is_deeply(
108     \@owners, [ '', qw/Nobody root user_b/], 'no user_a'
109 );
110
111 diag "limit queue to general too";
112
113 $m->submit_form(
114     fields => { ValueOfQueue => 'General' },
115     button => 'AddClause',
116 );
117
118 $form = $m->form_name('BuildQuery');
119 ok( $form->find_input("ValueOf'CF.{general_cf}'"), 'found general_cf' );
120 ok( $form->find_input("ValueOf'CF.{foo_cf}'"), 'found foo_cf' );
121 ok( $form->find_input("ValueOf'CF.{global_cf}'"), 'found global_cf' );
122 $status_input = $form->find_input('ValueOfStatus');
123 @statuses     = sort $status_input->possible_values;
124 is_deeply(
125     \@statuses,
126     [ '', qw/initial new open rejected resolved stalled/ ],
127     'found all statuses again'
128 );
129 $owner_input = $form->find_input('ValueOfActor');
130 @owners     = sort $owner_input->possible_values;
131 is_deeply(
132     \@owners, [ '', qw/Nobody root user_a user_b/], 'found all users again'
133 );
134
135 diag "limit queue to != foo";
136 $m->get_ok( $url . '/Search/Build.html?NewQuery=1' );
137 $m->submit_form(
138     form_name => 'BuildQuery',
139     fields => { ValueOfQueue => 'foo', QueueOp => '!=' },
140     button => 'AddClause',
141 );
142
143 $form = $m->form_name('BuildQuery');
144 ok( $form->find_input("ValueOf'CF.{global_cf}'"), 'found global_cf' );
145 ok( !$form->find_input("ValueOf'CF.{foo_cf}'"), 'no foo_cf' );
146 ok( !$form->find_input("ValueOf'CF.{general_cf}'"), 'no general_cf' );
147 $status_input = $form->find_input('ValueOfStatus');
148 @statuses     = sort $status_input->possible_values;
149 is_deeply(
150     \@statuses, [ '', qw/initial new open rejected resolved stalled/],
151     'found all statuses'
152 );
153 $owner_input = $form->find_input('ValueOfActor');
154 @owners     = sort $owner_input->possible_values;
155 is_deeply(
156     \@owners, [ '', qw/Nobody root user_a user_b/], 'found all users'
157 );
158
159 diag "limit queue to General OR foo";
160 $m->get_ok( $url . '/Search/Edit.html' );
161 $m->submit_form(
162     form_name => 'BuildQueryAdvanced',
163     fields => { Query => q{Queue = 'General' OR Queue = 'foo'} },
164 );
165 $form = $m->form_name('BuildQuery');
166 ok( $form->find_input("ValueOf'CF.{general_cf}'"), 'found general_cf' );
167 ok( $form->find_input("ValueOf'CF.{foo_cf}'"), 'found foo_cf' );
168 ok( $form->find_input("ValueOf'CF.{global_cf}'"), 'found global_cf' );
169 $status_input = $form->find_input('ValueOfStatus');
170 @statuses     = sort $status_input->possible_values;
171 is_deeply(
172     \@statuses,
173     [ '', qw/initial new open rejected resolved stalled/ ],
174     'found all statuses'
175 );
176 $owner_input = $form->find_input('ValueOfActor');
177 @owners     = sort $owner_input->possible_values;
178 is_deeply(
179     \@owners, [ '', qw/Nobody root user_a user_b/], 'found all users'
180 );