summaryrefslogtreecommitdiff
path: root/rt/t/web/query_builder_queue_limits.t
blob: 6bbf333860e60bfbca3a3ed2c34d139637dd4dae (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
use strict;
use warnings;

use RT::Test tests => 34;

my $lifecycles = RT->Config->Get('Lifecycles');
$lifecycles->{foo} = {
    initial  => ['initial'],
    active   => ['open'],
    inactive => ['resolved'],

};

# explicitly Set so RT::Test can catch our change
RT->Config->Set( Lifecycles => %$lifecycles );

RT::Lifecycle->FillCache();

my $general = RT::Test->load_or_create_queue( Name => 'General' );
my $foo = RT::Test->load_or_create_queue( Name => 'foo', Lifecycle => 'foo' );

my $global_cf = RT::Test->load_or_create_custom_field(
    Name  => 'global_cf',
    Queue => 0,
    Type  => 'FreeformSingle',
);

my $general_cf = RT::Test->load_or_create_custom_field(
    Name  => 'general_cf',
    Queue => 'General',
    Type  => 'FreeformSingle',
);

my $foo_cf = RT::Test->load_or_create_custom_field(
    Name  => 'foo_cf',
    Queue => 'foo',
    Type  => 'FreeformSingle'
);

my $root = RT::Test->load_or_create_user( Name => 'root', );
my $user_a = RT::Test->load_or_create_user(
    Name     => 'user_a',
    Password => 'password',
);
my $user_b = RT::Test->load_or_create_user(
    Name     => 'user_b',
    Password => 'password',
);

ok(
    RT::Test->set_rights(
        {
            Principal => $user_a,
            Object    => $general,
            Right     => ['OwnTicket'],
        },
        {
            Principal => $user_b,
            Object    => $foo,
            Right     => ['OwnTicket'],
        },
    ),
    'granted OwnTicket right for user_a and user_b'
);

my ( $url, $m ) = RT::Test->started_ok;
ok( $m->login, 'logged in' );

$m->get_ok( $url . '/Search/Build.html' );

diag "check default statuses, cf and owners";
my $form = $m->form_name('BuildQuery');
ok( $form,                                     'found BuildQuery form' );
ok( $form->find_input("ValueOfCF.{global_cf}"), 'found global_cf by default' );
ok( !$form->find_input("ValueOfCF.{general_cf}"), 'no general_cf by default' );
ok( !$form->find_input("ValueOfCF.{foo_cf}"), 'no foo_cf by default' );

my $status_input = $form->find_input('ValueOfStatus');
my @statuses     = sort $status_input->possible_values;
is_deeply(
    \@statuses, [ '', qw/initial new open open rejected resolved resolved stalled/], 'found all statuses'
) or diag "Statuses are: ", explain \@statuses;

my $owner_input = $form->find_input('ValueOfActor');
my @owners     = sort $owner_input->possible_values;
is_deeply(
    \@owners, [ '', qw/Nobody root user_a user_b/], 'found all users'
);

diag "limit queue to foo";
$m->submit_form(
    fields => { ValueOfQueue => 'foo' },
    button => 'AddClause',
);

$form = $m->form_name('BuildQuery');
ok( $form->find_input("ValueOfCF.{foo_cf}"), 'found foo_cf' );
ok( $form->find_input("ValueOfCF.{global_cf}"), 'found global_cf' );
ok( !$form->find_input("ValueOfCF.{general_cf}"), 'still no general_cf' );
$status_input = $form->find_input('ValueOfStatus');
@statuses     = sort $status_input->possible_values;
is_deeply(
    \@statuses,
    [ '', qw/initial open resolved/ ],
    'found statuses from foo only'
);

$owner_input = $form->find_input('ValueOfActor');
@owners     = sort $owner_input->possible_values;
is_deeply(
    \@owners, [ '', qw/Nobody root user_b/], 'no user_a'
);

diag "limit queue to general too";

$m->submit_form(
    fields => { ValueOfQueue => 'General' },
    button => 'AddClause',
);

$form = $m->form_name('BuildQuery');
ok( $form->find_input("ValueOfCF.{general_cf}"), 'found general_cf' );
ok( $form->find_input("ValueOfCF.{foo_cf}"), 'found foo_cf' );
ok( $form->find_input("ValueOfCF.{global_cf}"), 'found global_cf' );
$status_input = $form->find_input('ValueOfStatus');
@statuses     = sort $status_input->possible_values;
is_deeply(
    \@statuses,
    [ '', qw/initial new open open rejected resolved resolved stalled/ ],
    'found all statuses again'
) or diag "Statuses are: ", explain \@statuses;
$owner_input = $form->find_input('ValueOfActor');
@owners     = sort $owner_input->possible_values;
is_deeply(
    \@owners, [ '', qw/Nobody root user_a user_b/], 'found all users again'
);

diag "limit queue to != foo";
$m->get_ok( $url . '/Search/Build.html?NewQuery=1' );
$m->submit_form(
    form_name => 'BuildQuery',
    fields => { ValueOfQueue => 'foo', QueueOp => '!=' },
    button => 'AddClause',
);

$form = $m->form_name('BuildQuery');
ok( $form->find_input("ValueOfCF.{global_cf}"), 'found global_cf' );
ok( !$form->find_input("ValueOfCF.{foo_cf}"), 'no foo_cf' );
ok( !$form->find_input("ValueOfCF.{general_cf}"), 'no general_cf' );
$status_input = $form->find_input('ValueOfStatus');
@statuses     = sort $status_input->possible_values;
is_deeply(
    \@statuses, [ '', qw/initial new open open rejected resolved resolved stalled/],
    'found all statuses'
) or diag "Statuses are: ", explain \@statuses;
$owner_input = $form->find_input('ValueOfActor');
@owners     = sort $owner_input->possible_values;
is_deeply(
    \@owners, [ '', qw/Nobody root user_a user_b/], 'found all users'
);

diag "limit queue to General OR foo";
$m->get_ok( $url . '/Search/Edit.html' );
$m->submit_form(
    form_name => 'BuildQueryAdvanced',
    fields => { Query => q{Queue = 'General' OR Queue = 'foo'} },
);
$form = $m->form_name('BuildQuery');
ok( $form->find_input("ValueOfCF.{general_cf}"), 'found general_cf' );
ok( $form->find_input("ValueOfCF.{foo_cf}"), 'found foo_cf' );
ok( $form->find_input("ValueOfCF.{global_cf}"), 'found global_cf' );
$status_input = $form->find_input('ValueOfStatus');
@statuses     = sort $status_input->possible_values;
is_deeply(
    \@statuses,
    [ '', qw/initial new open open rejected resolved resolved stalled/ ],
    'found all statuses'
) or diag "Statuses are: ", explain \@statuses;
$owner_input = $form->find_input('ValueOfActor');
@owners     = sort $owner_input->possible_values;
is_deeply(
    \@owners, [ '', qw/Nobody root user_a user_b/], 'found all users'
);