]> Sergey Matveev's repositories - public-inbox.git/blob - t/view.t
cgi: update feed/view and tests for shorter URLs
[public-inbox.git] / t / view.t
1 # Copyright (C) 2013, Eric Wong <normalperson@yhbt.net> and all contributors
2 # License: AGPLv3 or later (https://www.gnu.org/licenses/agpl-3.0.txt)
3 use strict;
4 use warnings;
5 use Test::More;
6 use Email::MIME;
7 use PublicInbox::View;
8
9 # plain text
10 {
11         my $body = <<EOF;
12 So and so wrote:
13 > keep this inline
14
15 OK
16
17 > Long and wordy reply goes here and it is split across multiple lines.
18 > We generate links to a separate full page where quoted-text is inline.
19
20 hello world
21 EOF
22         my $s = Email::Simple->create(
23                 header => [
24                         From => 'a@example.com',
25                         To => 'b@example.com',
26                         'Content-Type' => 'text/plain',
27                         'Message-ID' => '<hello@example.com>',
28                         Subject => 'this is a subject',
29                 ],
30                 body => $body,
31         );
32         $s = Email::MIME->new($s->as_string);
33         my $html = PublicInbox::View->as_html($s);
34
35         # ghetto
36         like($html, qr/<a href="?hello%40/s, "MID link present");
37         like($html, qr/hello world\b/, "body present");
38         like($html, qr/&gt; keep this inline/, "short quoted text is inline");
39         like($html, qr/<a name=[^>]+>&gt; Long and wordy/,
40                 "long quoted text is anchored");
41
42         # short page
43         my $pfx = "http://example.com/test/f";
44         my $short = PublicInbox::View->as_html($s, $pfx);
45         like($short, qr/\n&gt; keep this inline/,
46                 "short quoted text is inline");
47         like($short, qr/<a href=\Q$pfx\E#[^>]+>Long and wordy/,
48                 "long quoted text is made into a link");
49         ok(length($short) < length($html), "short page is shorter");
50 }
51
52 # multipart crap
53 {
54         my $parts = [
55                 Email::MIME->create(
56                         attributes => { content_type => 'text/plain', },
57                         body => 'hi',
58                 ),
59                 Email::MIME->create(
60                         attributes => { content_type => 'text/plain', },
61                         body => 'bye',
62                 )
63         ];
64         my $mime = Email::MIME->create(
65                 header_str => [
66                         From => 'a@example.com',
67                         Subject => 'blargh',
68                         'Message-ID' => '<blah@example.com>',
69                         'In-Reply-To' => '<irp@example.com>',
70                         ],
71                 parts => $parts,
72         );
73
74         my $html = PublicInbox::View->as_html($mime);
75         like($html, qr/hi\n-+ part #2 -+\nbye\n/, "multipart split");
76 }
77
78 # multipart email with attached patch
79 {
80         my $parts = [
81                 Email::MIME->create(
82                         attributes => { content_type => 'text/plain', },
83                         body => 'hi, see attached patch',
84                 ),
85                 Email::MIME->create(
86                         attributes => {
87                                 content_type => 'text/plain',
88                                 filename => "foo.patch",
89                         },
90                         body => "--- a/file\n+++ b/file\n" .
91                                 "@@ -49, 7 +49,34 @@\n",
92                 ),
93         ];
94         my $mime = Email::MIME->create(
95                 header_str => [
96                         From => 'a@example.com',
97                         Subject => '[PATCH] asdf',
98                         'Message-ID' => '<patch@example.com>',
99                         ],
100                 parts => $parts,
101         );
102
103         my $html = PublicInbox::View->as_html($mime);
104         like($html, qr!see attached patch\n-+ foo\.patch -+\n--- a/file\n!,
105                 "parts split with filename");
106 }
107
108 done_testing();