first pass RT4 merge, RT#13852
[freeside.git] / rt / t / ticket / clicky.t
1 #!/usr/bin/perl
2
3 use strict;
4 use warnings;
5 use Test::More;
6 use RT::Test tests => 20;
7
8 my $plain = MIME::Entity->build(
9     Subject => 'plain mime',
10     Type    => 'text/plain',
11     Data    => <<END,
12 If you have some problems with RT you could find help
13 on http://wiki.bestpractical.com or subscribe to
14 the rt-users\@lists.bestpractical.com.
15
16 to test anchor:
17 https://wiki.bestpractical.com/test#anchor
18 --
19 Best regards. BestPractical Team.
20 END
21 );
22
23 my $html = MIME::Entity->build(
24     Type    => 'text/html',
25     Subject => 'html mime',
26     Data    => <<END,
27 If you have some problems with RT you could find help
28 on <a href="http://wiki.bestpractical.com">wiki</a> 
29 or find known bugs on http://rt3.fsck.com
30
31 to test anchor:
32 https://wiki.bestpractical.com/test#anchor
33 --
34 Best regards. BestPractical Team.
35 END
36 );
37
38
39 my $ticket = RT::Ticket->new( RT->SystemUser );
40
41 my ($plain_id) = $ticket->Create(
42     Subject => 'test',
43     Queue => 'General',
44     MIMEObj => $plain,
45 );
46 ok($plain_id, "We created a ticket #$plain_id");
47
48 my ($html_id) = $ticket->Create(
49     Subject => 'test',
50     Queue => 'General',
51     MIMEObj => $html,
52 );
53 ok($html_id, "We created a ticket #$html_id");
54
55 diag 'test no clicky';
56 {
57     RT->Config->Set( 'Active_MakeClicky' => () );
58     my ( $baseurl, $m ) = RT::Test->started_ok;
59     ok $m->login, 'logged in';
60     $m->goto_ticket($plain_id);
61
62     my @links = $m->find_link(
63         tag  => 'a',
64         url  => 'http://wiki.bestpractical.com',
65     );
66     ok( @links == 0, 'no clicky link found with plain message' );
67
68     @links = $m->find_link(
69         tag  => 'a',
70         url  => 'http://rt3.fsck.com',
71     );
72     ok( @links == 0, 'no extra clicky link found with html message' );
73 }
74
75 diag 'test httpurl';
76 {
77     RT::Test->stop_server;
78     RT->Config->Set( 'Active_MakeClicky' => qw/httpurl/ );
79     my ( $baseurl, $m ) = RT::Test->started_ok;
80     ok $m->login, 'logged in';
81     $m->goto_ticket($plain_id);
82
83     my @links = $m->find_link(
84         tag  => 'a',
85         url  => 'http://wiki.bestpractical.com',
86         text => 'Open URL',
87     );
88     ok( scalar @links, 'found clicky link' );
89
90     @links = $m->find_link(
91         tag  => 'a',
92         url  => 'https://wiki.bestpractical.com/test#anchor',
93         text => 'Open URL',
94     );
95     ok( scalar @links, 'found clicky link with anchor' );
96
97     $m->goto_ticket($html_id);
98     @links = $m->find_link(
99         tag  => 'a',
100         url  => 'http://wiki.bestpractical.com',
101         text => 'Open URL',
102     );
103     ok( @links == 0, 'not make clicky links clicky twice' );
104
105     @links = $m->find_link(
106         tag  => 'a',
107         url  => 'http://rt3.fsck.com',
108         text => 'Open URL',
109     );
110     ok( scalar @links, 'found clicky link' );
111
112     @links = $m->find_link(
113         tag  => 'a',
114         url  => 'https://wiki.bestpractical.com/test#anchor',
115         text => 'Open URL',
116     );
117     ok( scalar @links, 'found clicky link with anchor' );
118 }
119
120 diag 'test httpurl_overwrite';
121 {
122     RT::Test->stop_server;
123     RT->Config->Set( 'Active_MakeClicky' => 'httpurl_overwrite' );
124     my ( $baseurl, $m ) = RT::Test->started_ok;
125     ok $m->login, 'logged in';
126     ok $m->goto_ticket($plain_id), 'opened diplay page of the ticket';
127
128     my @links = $m->find_link(
129         tag => 'a',
130         url => 'http://wiki.bestpractical.com',
131         text => 'http://wiki.bestpractical.com',
132     );
133     ok( scalar @links, 'found clicky link' );
134
135     @links = $m->find_link(
136         tag  => 'a',
137         url  => 'https://wiki.bestpractical.com/test#anchor',
138         text => 'https://wiki.bestpractical.com/test#anchor',
139     );
140     ok( scalar @links, 'found clicky link with anchor' );
141 }
142