summaryrefslogtreecommitdiff
path: root/rt/t/ticket/clicky.t
blob: 3a7ec82416ffc5df2ba41cc4957267b4f1152d5c (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
#!/usr/bin/perl

use strict;
use warnings;
use Test::More;
use RT::Test tests => 20;

my $plain = MIME::Entity->build(
    Subject => 'plain mime',
    Type    => 'text/plain',
    Data    => <<END,
If you have some problems with RT you could find help
on http://wiki.bestpractical.com or subscribe to
the rt-users\@lists.bestpractical.com.

to test anchor:
https://wiki.bestpractical.com/test#anchor
--
Best regards. BestPractical Team.
END
);

my $html = MIME::Entity->build(
    Type    => 'text/html',
    Subject => 'html mime',
    Data    => <<END,
If you have some problems with RT you could find help
on <a href="http://wiki.bestpractical.com">wiki</a> 
or find known bugs on http://rt3.fsck.com

to test anchor:
https://wiki.bestpractical.com/test#anchor
--
Best regards. BestPractical Team.
END
);


my $ticket = RT::Ticket->new( RT->SystemUser );

my ($plain_id) = $ticket->Create(
    Subject => 'test',
    Queue => 'General',
    MIMEObj => $plain,
);
ok($plain_id, "We created a ticket #$plain_id");

my ($html_id) = $ticket->Create(
    Subject => 'test',
    Queue => 'General',
    MIMEObj => $html,
);
ok($html_id, "We created a ticket #$html_id");

diag 'test no clicky';
{
    RT->Config->Set( 'Active_MakeClicky' => () );
    my ( $baseurl, $m ) = RT::Test->started_ok;
    ok $m->login, 'logged in';
    $m->goto_ticket($plain_id);

    my @links = $m->find_link(
        tag  => 'a',
        url  => 'http://wiki.bestpractical.com',
    );
    ok( @links == 0, 'no clicky link found with plain message' );

    @links = $m->find_link(
        tag  => 'a',
        url  => 'http://rt3.fsck.com',
    );
    ok( @links == 0, 'no extra clicky link found with html message' );
}

diag 'test httpurl';
{
    RT::Test->stop_server;
    RT->Config->Set( 'Active_MakeClicky' => qw/httpurl/ );
    my ( $baseurl, $m ) = RT::Test->started_ok;
    ok $m->login, 'logged in';
    $m->goto_ticket($plain_id);

    my @links = $m->find_link(
        tag  => 'a',
        url  => 'http://wiki.bestpractical.com',
        text => 'Open URL',
    );
    ok( scalar @links, 'found clicky link' );

    @links = $m->find_link(
        tag  => 'a',
        url  => 'https://wiki.bestpractical.com/test#anchor',
        text => 'Open URL',
    );
    ok( scalar @links, 'found clicky link with anchor' );

    $m->goto_ticket($html_id);
    @links = $m->find_link(
        tag  => 'a',
        url  => 'http://wiki.bestpractical.com',
        text => 'Open URL',
    );
    ok( @links == 0, 'not make clicky links clicky twice' );

    @links = $m->find_link(
        tag  => 'a',
        url  => 'http://rt3.fsck.com',
        text => 'Open URL',
    );
    ok( scalar @links, 'found clicky link' );

    @links = $m->find_link(
        tag  => 'a',
        url  => 'https://wiki.bestpractical.com/test#anchor',
        text => 'Open URL',
    );
    ok( scalar @links, 'found clicky link with anchor' );
}

diag 'test httpurl_overwrite';
{
    RT::Test->stop_server;
    RT->Config->Set( 'Active_MakeClicky' => 'httpurl_overwrite' );
    my ( $baseurl, $m ) = RT::Test->started_ok;
    ok $m->login, 'logged in';
    ok $m->goto_ticket($plain_id), 'opened diplay page of the ticket';

    my @links = $m->find_link(
        tag => 'a',
        url => 'http://wiki.bestpractical.com',
        text => 'http://wiki.bestpractical.com',
    );
    ok( scalar @links, 'found clicky link' );

    @links = $m->find_link(
        tag  => 'a',
        url  => 'https://wiki.bestpractical.com/test#anchor',
        text => 'https://wiki.bestpractical.com/test#anchor',
    );
    ok( scalar @links, 'found clicky link with anchor' );
}