fix ticketing system error on bootstrap of new install
[freeside.git] / rt / t / web / mobile.t
1 use strict;
2 use warnings;
3 use RT::Test tests => 170;
4
5 my ( $url, $m ) = RT::Test->started_ok;
6 my $root = RT::Test->load_or_create_user( Name => 'root' );
7
8 diag "create another queue";
9 my $test_queue = RT::Queue->new( $RT::SystemUser );
10 ok( $test_queue->Create( Name => 'foo' ) );
11
12 diag "create cf cfbar";
13 my $cfbar = RT::CustomField->new( $RT::SystemUser );
14 ok(
15     $cfbar->Create(
16         Name       => 'cfbar',
17         Type       => 'Freeform',
18         LookupType => 'RT::Queue-RT::Ticket'
19     )
20 );
21
22 $cfbar->AddToObject( $test_queue );
23
24 diag "create some tickets to link";
25 # yep, create 3 tickets for DependsOn
26 my @tickets = map { { Subject => "link of $_" } }
27   qw/DependsOn DependsOn DependsOn DependedOnBy HasMember HasMember
28   MemberOf RefersTo RefersTo ReferredToBy/;
29 RT::Test->create_tickets( { Status => 'resolved' },  @tickets );
30
31 diag "test different mobile agents";
32 my @agents = (
33     'hiptop',       'Blazer',     'Novarra',  'Vagabond',
34     'SonyEricsson', 'Symbian',    'NetFront', 'UP.Browser',
35     'UP.Link',      'Windows CE', 'MIDP',     'J2ME',
36     'DoCoMo',       'J-PHONE',    'PalmOS',   'PalmSource',
37     'iPhone',       'iPod',       'AvantGo',  'Nokia',
38     'Android',      'WebOS',      'S60'
39 );
40
41 for my $agent (@agents) {
42     $m->agent($agent);
43     $m->get_ok($url);
44     $m->content_contains( 'Not using a mobile browser',
45         "mobile login page for agent $agent" );
46 }
47
48 $m->submit_form( fields => { user => 'root', pass => 'password' } );
49 is( $m->uri, $url . '/m/', 'logged in via mobile ui' );
50 ok( $m->find_link( text => 'Home' ), 'has homepage link, so really logged in' );
51
52 diag "create some tickets";
53 $m->follow_link_ok( { text => 'New ticket' } );
54 like( $m->uri, qr'/m/ticket/select_create_queue', 'queue select page' );
55 $m->follow_link_ok( { text => 'General' } );
56 like( $m->uri, qr'/m/ticket/create', 'ticket create page' );
57 $m->submit_form(
58     fields => {
59         Subject                   => 'ticket1',
60         Content                   => 'content 1',
61         Status                    => 'open',
62         Cc                        => 'cc@example.com',
63         AdminCc                   => 'admincc@example.com',
64         InitialPriority           => 13,
65         FinalPriority             => 93,
66         TimeEstimated             => 2,
67         'TimeEstimated-TimeUnits' => 'hours',
68         TimeWorked                => 30,
69         TimeLeft                  => 60,
70         Starts                    => '2011-01-11 11:11:11',
71         Due                       => '2011-02-12 12:12:12',
72         'new-DependsOn'           => '1 2 3',
73         'DependsOn-new'           => '4',
74         'new-MemberOf'            => '5 6',
75         'MemberOf-new'            => '7',
76         'new-RefersTo'            => '8 9',
77         'RefersTo-new'            => '10',
78     }
79 );
80 like( $m->uri, qr'/m/ticket/show', 'ticket show page' );
81 $m->content_contains( 'ticket1', 'subject' );
82 $m->content_contains( 'open', 'status' );
83 $m->content_contains( 'cc@example.com', 'cc' );
84 $m->content_contains( 'admincc@example.com', 'admincc' );
85 $m->content_contains( '13/93', 'priority' );
86 $m->content_contains( '2 hour', 'time estimates' );
87 $m->content_contains( '30 min', 'time worked' );
88 $m->content_contains( '60 min', 'time left' );
89 $m->content_contains( 'Tue Jan 11 11:11:11', 'starts' );
90 $m->content_contains( 'Sat Feb 12 12:12:12', 'due' );
91 $m->content_like( qr/(link of DependsOn).*\1.*\1/s, 'depends on' );
92 $m->content_contains( 'link of DependedOnBy', 'depended on by' );
93 $m->content_like( qr/(link of HasMember).*\1/s, 'has member' );
94 $m->content_contains( 'link of MemberOf', 'member of' );
95 $m->content_like( qr/(link of RefersTo).*\1/s, 'refers to' );
96 $m->content_contains( 'link of ReferredToBy', 'referred to by' );
97
98 diag "test ticket reply";
99 $m->follow_link_ok( { text => 'Reply' } );
100 like( $m->uri, qr'/m/ticket/reply', 'ticket reply page' );
101 $m->submit_form(
102     fields => {
103         UpdateContent    => 'reply 1',
104         UpdateTimeWorked => '30',
105         UpdateStatus     => 'resolved',
106         UpdateType       => 'response',
107     },
108     button => 'SubmitTicket',
109 );
110 like( $m->uri, qr'/m/ticket/show', 'back to ticket show page' );
111 $m->content_contains( '1 hour', 'time worked' );
112 $m->content_contains( 'resolved', 'status' );
113 $m->follow_link_ok( { text => 'Reply' } );
114 like( $m->uri, qr'/m/ticket/reply', 'ticket reply page' );
115 $m->submit_form(
116     fields => {
117         UpdateContent    => 'reply 2',
118         UpdateSubject    => 'ticket1',
119         UpdateStatus     => 'open',
120         UpdateType       => 'private',
121     },
122     button => 'SubmitTicket',
123 );
124 $m->no_warnings_ok;
125 $m->content_contains( 'ticket1', 'subject' );
126 $m->content_contains( 'open', 'status' );
127
128 like( $m->uri, qr'/m/ticket/show', 'back to ticket show page' );
129
130 diag "test ticket history";
131 $m->follow_link_ok( { text => 'History' } );
132 like( $m->uri, qr'/m/ticket/history', 'ticket history page' );
133 $m->content_contains( 'content 1', 'has main content' );
134 $m->content_contains( 'reply 1', 'has replied content' );
135 $m->content_contains( 'reply 2', 'has replied content' );
136
137 diag "create another ticket in queue foo";
138 $m->follow_link_ok( { text => 'Home' } );
139 is( $m->uri, "$url/m/", 'main mobile page' );
140 $m->follow_link_ok( { text => 'New ticket' } );
141 like( $m->uri, qr'/m/ticket/select_create_queue', 'queue select page' );
142 $m->follow_link_ok( { text => 'foo' } );
143 like( $m->uri, qr'/m/ticket/create', 'ticket create page' );
144 $m->content_contains( 'cfbar', 'has cf name' );
145 $m->content_contains( 'Object-RT::Ticket--CustomField-' . $cfbar->id .  '-Value', 'has cf input name' );
146 $m->submit_form(
147     fields => {
148         Subject => 'ticket2',
149         Content => 'content 2',
150         Owner   => $root->id,
151         'Object-RT::Ticket--CustomField-' . $cfbar->id . '-Value' => 'cfvalue',
152     }
153 );
154 $m->no_warnings_ok;
155 like( $m->uri, qr'/m/ticket/show', 'ticket show page' );
156 $m->content_contains( 'cfbar', 'has cf name' );
157 $m->content_contains( 'cfvalue', 'has cf value' );
158
159 $m->follow_link_ok( { text => 'Home' } );
160 is( $m->uri, "$url/m/", 'main mobile page' );
161
162 diag "test unowned tickets link";
163 $m->follow_link_ok( { text => 'Unowned tickets' } );
164 $m->content_contains( 'Found 1 ticket', 'found 1 ticket' );
165 $m->content_contains( 'ticket1', 'has ticket1' );
166 $m->content_lacks( 'ticket2', 'no ticket2' );
167 $m->back;
168
169 diag "test tickets I own link";
170 $m->follow_link_ok( { text => 'Tickets I own' } );
171 $m->content_contains( 'Found 1 ticket', 'found 1 ticket' );
172 $m->content_lacks( 'ticket1', 'no ticket1' );
173 ok( $m->find_link( text_regex => qr/ticket2/ ), 'has ticket2 link' );
174 $m->back;
175
176 diag "test all tickets link";
177 $m->follow_link_ok( { text => 'All tickets' } );
178 $m->content_contains( 'Found 12 tickets', 'found 12 tickets' );
179 ok( $m->find_link( text_regex => qr/ticket1/ ), 'has ticket1 link' );
180 ok( $m->find_link( text_regex => qr/ticket2/ ), 'has ticket2 link' );
181 $m->back;
182
183 diag "test bookmarked tickets link";
184 my $ticket = RT::Ticket->new(RT::CurrentUser->new('root'));
185 $ticket->Load(11);
186 $root->ToggleBookmark($ticket);
187
188 $m->follow_link_ok( { text => 'Bookmarked tickets' } );
189 $m->content_contains( 'Found 1 ticket', 'found 1 ticket' );
190 ok( $m->find_link( text_regex => qr/ticket1/ ), 'has ticket1 link' );
191 $m->content_lacks( 'ticket2', 'no ticket2' );
192 $m->back;
193
194 diag "test tickets search";
195 $m->submit_form( fields => { q => 'ticket2' } );
196 $m->content_contains( 'Found 1 ticket', 'found 1 ticket' );
197 $m->content_lacks( 'ticket1', 'no ticket1' );
198 ok( $m->find_link( text_regex => qr/ticket2/ ), 'has ticket2 link' );
199 $m->back;
200
201 diag "test logout link";
202 $m->follow_link_ok( { text => 'Logout' } );
203 is( $m->uri, "$url/m/", 'still in mobile' );
204 $m->submit_form( fields => { user => 'root', pass => 'password' } );
205
206 diag "test notmobile link";
207 $m->follow_link_ok( { text => 'Home' } );
208 $m->follow_link_ok( { text => 'Not using a mobile browser?' } );
209 is( $m->uri, $url . '/', 'got full ui' );
210