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