File: 002-encoding.t

package info (click to toggle)
libapp-nopaste-perl 1.013-1
  • links: PTS, VCS
  • area: main
  • in suites: bullseye, sid
  • size: 456 kB
  • sloc: perl: 1,334; makefile: 2
file content (131 lines) | stat: -rw-r--r-- 5,313 bytes parent folder | download | duplicates (3)
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
use strict;
use warnings;
use Test::More 0.88;

my @content = (
    <<FORM,
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
  <head>
    <title>pasting to magnet_web</title>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
  </head>
  <body>
    <table>
      <tr>
      <td>
       <img src="http://paste.scsys.co.uk/static/nopaste.gif" alt="POE Paste with lovely alien head...">
        </td>
        <td align="left">
         <h1><font face="courier new">No paste!</font></h1>
         <font face="courier new" size="-1">
          1. Select the channel for the URL announcment.<br>
          2. Supply a nick for the announcement.<br>
          3. Supply an summary of the paste for the announcement<br>
          4. <b>Paste!</b><br>
          5. Submit the form with the Paste it! button.<br>
        </font>
       </td>
      </tr>
     </table>
    <form method='post' action='http://paste.scsys.co.uk/paste' enctype='application/x-www-from-urlencoded' name="pasteForm">
     <font face="courier new" size="-1"><br><br>
      1. channel: <select name='channel'><option value="" selected>(none)</option> <option value="#angerwhale">#angerwhale</option> <option value="#axkit-dahut">#axkit-dahut</option> <option value="#catalyst">#catalyst</option> <option value="#catalyst-dev">#catalyst-dev</option> <option value="#cometd">#cometd</option> <option value="#dbix-class">#dbix-class</option> <option value="#distzilla">#distzilla</option> <option value="#formhandler">#formhandler</option> <option value="#handel">#handel</option> <option value="#iusethis">#iusethis</option> <option value="#killtrac">#killtrac</option> <option value="#london.pm">#london.pm</option> <option value="#miltonkeynes.pm">#miltonkeynes.pm</option> <option value="#moose">#moose</option> <option value="#p5p">#p5p</option> <option value="#padre">#padre</option> <option value="#pdl">#pdl</option> <option value="#perl">#perl</option> <option value="#perl-help">#perl-help</option> <option value="#perlde">#perlde</option> <option value="#pita">#pita</option> <option value="#poe">#poe</option> <option value="#reaction">#reaction</option> <option value="#rt">#rt</option> <option value="#soap-lite">#soap-lite</option> <option value="#spb.pm">#spb.pm</option> <option value="#tt">#tt</option> <option value="#web-simple">#web-simple</option></select>&nbsp; &nbsp;
      2. your nick: <input type='text' name='nick' size='25' maxlength='25'><br><br>
      3. summary: <input type='text' name='summary' size='80' maxlength='160'><br><br>
      4. paste: <textarea name='paste' rows=25 cols=75 style='width:100%'></textarea><br><br>
      5. <input type='submit' name='Paste it' value='Paste it'><input type='reset' name='Clear form' value='Clear form'>
     </font>
    </form><br>
    <div align="right">
     <a href="http://validator.w3.org/check/referer"><img border="0" src="http://www.w3.org/Icons/valid-html401" alt="Valid HTML 4.01!" height="31" width="88"></a><br><br>
    </div>
    <div>
     <div align=right><font size='-1'><a href='http://sf.net/projects/pastebot/'>Pastebot</a> is powered by <a href='http://poe.perl.org/'>POE</a>.</font></div>
    </div>
    <!-- Automatically put the clipboard contents into the paste field and select it. -->
    <script language="jscript" type="">
      onload=function () {
        try {
          document.pasteForm.paste.value=clipboardData.getData("Text") || "";
          document.pasteForm.paste.select();
        }
        catch (oErr) {}
      }
    </script>
  </body>
</html>
FORM
    <<RETURN,
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
 <head>
  <title>Your paste, number 211360...</title>
  <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
  <meta http-equiv="refresh" content="5;url=http://paste.scsys.co.uk/211360">
 </head>
 <body>

  <p>
   This content is stored as
   <a href='http://paste.scsys.co.uk/211360'>http://paste.scsys.co.uk/211360</a>. You will be redirected
   shortly.
  </p>
  <p>
   From: Someone at 217.168.150.38
   <br>
   Summary: ‘test’
  </p>
  <p>
   <pre>‘test’</pre>
  </p>
  <p>
   <div align=right><font size='-1'><a href='http://sf.net/projects/pastebot/'>Pastebot</a> is powered by <a href='http://poe.perl.org/'>POE</a>.</font></div>
  </p>
 </body>
</html>
RETURN
);

my @requests;
{
    package LWP::Protocol::test;
    use parent 'LWP::Protocol';
    sub request {
        my $self = shift;
        my ($req) = @_;
        push @requests, $req;
        return HTTP::Response->new(200, 'OK', [], shift @content);
    }
}
LWP::Protocol::implementor('http' => 'LWP::Protocol::test');

{
    package App::Nopaste::Service::MyTest;
    use parent 'App::Nopaste::Service';

    sub uri { 'http://localhost/' }
}

{
    package MyTest::Cmd;
    use parent 'App::Nopaste::Command';

    sub read_text { '‘test’' }
}

my $input = {
    nick       => '',
    services   => ['App::Nopaste::Service::MyTest'],
    extra_argv => []
};

my $cmd = MyTest::Cmd->new($input);
isa_ok($cmd,'App::Nopaste::Command');

my $ret = $cmd->run;
is($ret, 'http://paste.scsys.co.uk/211360');
my ($post) = grep { $_->method eq 'POST' } @requests;
is($post->content, 'channel=&nick=&summary=&paste=%E2%80%98test%E2%80%99&private=0');

done_testing;