File: signatures.t

package info (click to toggle)
request-tracker5 5.0.7%2Bdfsg-4
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 80,216 kB
  • sloc: javascript: 191,898; perl: 87,146; sh: 1,412; makefile: 487; python: 37; php: 15
file content (158 lines) | stat: -rw-r--r-- 3,713 bytes parent folder | download | duplicates (2)
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
use strict;
use warnings;

use RT::Test tests => undef;
use HTML::Entities qw/decode_entities/;

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

my $root = RT::Test->load_or_create_user( Name => 'root' );
my ($ok) = $root->SetSignature("Signature one\nSignature two\n");
ok($ok, "Set signature");

my $t = RT::Test->create_ticket(
    Queue   => 'General',
    Subject => 'Signature quoting',
    Content => "First\nSecond\nThird\n",
);

my $initial = $t->Transactions->First->id;

sub template_is {
    my (%args) = (
        HTML        => 0,
        Quote       => 0,
        BeforeQuote => 0,
    );
    my $expected = pop(@_);
    $args{$_}++ for @_;

    my $prefs = $root->Preferences($RT::System);
    $prefs->{SignatureAboveQuote} = $args{BeforeQuote};
    $prefs->{MessageBoxRichText}  = $args{HTML};
    ($ok) = $root->SetPreferences($RT::System, $prefs);
    ok($ok, "Preferences updated");

    my $url = "/Ticket/Update.html?id=" . $t->id;
    $url .= "&QuoteTransaction=$initial" if $args{Quote};
    $m->get_ok($url);

    $m->form_name('TicketUpdate');
    my $value = $m->value("UpdateContent");

    # Work around a bug in Mechanize, wherein it thinks newlines
    # following textareas are significant -- browsers do not.
    $value =~ s/^\n//;

    # For ease of interpretation, replace blank lines with dots, and
    # put a $ after trailing whitespace.
    my $display = $value;
    $display =~ s/^$/./mg;
    $display =~ s/([ ]+)$/$1\$/mg;

    # Remove the timestamp from the quote header
    $display =~ s/On \w\w\w \w\w\w+ \d\d \d\d:\d\d:\d\d \d\d\d\d, \w+ wrote:/Someone wrote:/;

    is($display, $expected, "Content matches expected");

    my $trim = RT::Interface::Web::StripContent(
        CurrentUser    => RT::CurrentUser->new($root),
        Content        => $value,
        ContentType    => $args{HTML} ? "text/html" : "text/plain",
        StripSignature => 1,
    );
    if ($args{Quote}) {
        ok($trim, "Counts as not empty");
    } else {
        is($trim, '', "Counts as empty");
    }
}


### Text

subtest "Non-HTML, no reply" => sub {
    template_is(<<'EOT') };
.
.
-- $
Signature one
Signature two
EOT


subtest "Non-HTML, no reply, before quote (which is irrelevant)" => sub {
    template_is(qw/BeforeQuote/, <<'EOT') };
.
.
-- $
Signature one
Signature two
EOT

subtest "Non-HTML, reply" => sub {
    template_is(qw/Quote/, <<'EOT') };
Someone wrote:
> First
> Second
> Third
.
.
.
-- $
Signature one
Signature two
EOT

subtest "Non-HTML, reply, before quote" => sub {
    template_is(qw/Quote BeforeQuote/, <<'EOT') };
.
.
-- $
Signature one
Signature two
.
Someone wrote:
> First
> Second
> Third
EOT



### HTML

my $quote = '<div class="gmail_quote">Someone wrote:<br />'
    .'<blockquote class="gmail_quote" type="cite">'
    .'<pre style="white-space: pre-wrap; font-family: monospace;">'
    ."First\nSecond\nThird\n"
    .'</pre></blockquote></div>';

subtest "HTML, no reply" => sub {
    template_is(
        qw/HTML/,
        '<p>&nbsp;</p><p>--&nbsp;<br />Signature one<br />Signature two</p>',
    ) };

subtest "HTML, no reply, before quote (which is irrelevant)" => sub {
    template_is(
        qw/HTML BeforeQuote/,
        '<p>&nbsp;</p><p>--&nbsp;<br />Signature one<br />Signature two</p>',
    ) };

subtest "HTML, reply" => sub {
    template_is(
        qw/HTML Quote/,
        $quote.'<p>&nbsp;</p><p>--&nbsp;<br />Signature one<br />Signature two</p>',
    ) };

subtest "HTML, reply, before quote" => sub {
    template_is(
        qw/HTML Quote BeforeQuote/,
        '<p>&nbsp;</p><p>--&nbsp;<br />Signature one<br />Signature two</p>'
            . "<p>&nbsp;</p>" . $quote,
    ) };


done_testing;