fix ticketing system error on bootstrap of new install
[freeside.git] / rt / t / web / template.t
1 use strict;
2 use warnings;
3
4 use RT::Test tests => 22;
5
6 my $user_a = RT::Test->load_or_create_user(
7     Name => 'user_a', Password => 'password',
8 );
9 ok $user_a && $user_a->id, 'loaded or created user';
10
11 my ($baseurl, $m) = RT::Test->started_ok;
12
13 ok( RT::Test->set_rights(
14     { Principal => $user_a, Right => [qw(ShowConfigTab ShowTemplate ModifyTemplate)] },
15 ), 'set rights');
16
17 ok $m->login('user_a', 'password'), 'logged in as user A';
18
19 # get to the templates screen
20 $m->follow_link( text => 'Admin' );
21 $m->title_is(q{RT Administration}, 'admin screen');
22
23 $m->follow_link( text => 'Global' );
24 $m->title_is(q{Admin/Global configuration}, 'global admin');
25
26 $m->follow_link( text => 'Templates' );
27 $m->title_is(q{Modify templates which apply to all queues}, 'global templates');
28
29 $m->follow_link( text => 'Resolved' ); # template name
30 $m->title_is(q{Modify template Resolved}, 'modifying the Resolved template');
31
32 # now try changing Type back and forth
33 $m->form_name('ModifyTemplate');
34 is($m->value('Type'), 'Perl');
35
36 $m->field(Type => 'Simple');
37 $m->submit;
38
39 $m->title_is(q{Modify template Resolved}, 'modifying the Resolved template');
40 $m->form_name('ModifyTemplate');
41 is($m->value('Type'), 'Simple', 'updated type to simple');
42
43 $m->field(Type => 'Perl');
44 $m->submit;
45
46 $m->title_is(q{Modify template Resolved}, 'modifying the Resolved template');
47 $m->form_name('ModifyTemplate');
48 is($m->value('Type'), 'Simple', 'need the ExecuteCode right to update Type to Perl');
49 $m->content_contains('Permission Denied');
50
51 ok( RT::Test->add_rights(
52     { Principal => $user_a, Right => [qw(ExecuteCode)] },
53 ), 'add ExecuteCode rights');
54
55 $m->field(Type => 'Perl');
56 $m->submit;
57
58 $m->title_is(q{Modify template Resolved}, 'modifying the Resolved template');
59 $m->form_name('ModifyTemplate');
60 is($m->value('Type'), 'Perl', 'now that we have ExecuteCode we can update Type to Perl');
61
62 { # 21152: Each time you save a Template a newline is chopped off the front
63   $m->form_name('ModifyTemplate');
64   my $content;
65
66
67   TODO: {
68
69     local $TODO = "WWW::Mechanize doesn't strip newline following <textarea> tag like browsers do";
70     # this test fails because earlier tests add newlines when using Mech
71     like($content = $m->value('Content'), qr/^Subject: Resolved/, 'got expected Content');
72
73   }
74
75   $content = "\n\n\n" . $content;
76   $m->field(Content => $content);
77   $m->submit;
78
79   $m->content_contains('Template Resolved: Content updated');
80
81   # next submit should not result in an update
82   $m->form_name('ModifyTemplate');
83   $m->submit;
84
85   TODO: {
86
87     local $TODO = "WWW::Mechanize doesn't strip newline following <textarea> tag like browsers do";
88     # this test fails because the template change makes Mech continuously add newlines where browsers dont
89     $m->content_lacks('Template Resolved: Content updated');
90
91   }
92 }
93