File: cgi.t

package info (click to toggle)
libspoon-perl 0.24-2
  • links: PTS, VCS
  • area: main
  • in suites: wheezy
  • size: 296 kB
  • sloc: perl: 2,640; makefile: 2
file content (97 lines) | stat: -rw-r--r-- 2,092 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
use lib 't', 'lib';
use strict;
use warnings;
use Test::More;

eval "use Encode";
my $enc = ! $@;

use Spoon::CGI;
use URI::Escape;

plan tests => 10;

{
    package Test1;
    use Spoon::CGI -base;

    cgi 'param1';
    cgi 'param2' => '-utf8';
    cgi 'trimmed' => '-trim';
    cgi 'nl' => '-newlines';
}

$ENV{REQUEST_METHOD} = 'GET';

{
    $ENV{QUERY_STRING} = "param1=2;foo=bar";

    my $test1 = Test1->new;
    SKIP: {
        skip "Encode not installed", 1  unless($enc);
        ok( Encode::is_utf8($test1->param1), 'param1 is marked as utf8' );
    }

    is( $test1->param1, 2, 'param1 value is 2' );
}

{
    CGI->_reset_globals;

    $ENV{QUERY_STRING} = 'param1=%E1%9A%A0%E1%9B%87%E1%9A%BB;foo=bar';

    my $test1 = Test1->new;
    SKIP: {
        skip "Encode not installed", 1  unless($enc);
        ok( Encode::is_utf8($test1->param1), 'param1 is marked as utf8' );
    }

    is( $test1->param1, "\x{16A0}\x{16C7}\x{16BB}",
        'param1 value is \x{16A0}\x{16C7}\x{16BB}' );
}

{
    CGI->_reset_globals;

    $ENV{QUERY_STRING} = 'param2=%E1%9A%A0%E1%9B%87%E1%9A%BB;foo=bar';

    my $test1 = Test1->new;
    SKIP: {
        skip "Encode not installed", 1  unless($enc);
        ok( Encode::is_utf8($test1->param2), 'param2 is marked as utf8' );
    }

    is( $test1->param2, "\x{16A0}\x{16C7}\x{16BB}",
        'param2 value is \x{16A0}\x{16C7}\x{16BB}' );
}

{
    CGI->_reset_globals;

    $ENV{QUERY_STRING} = 'trimmed=%20%20trim%20me%20%20;foo=bar';

    my $test1 = Test1->new;
    SKIP: {
        skip "Encode not installed", 1  unless($enc);
        ok( Encode::is_utf8($test1->trimmed), 'trimmed is marked as utf8' );
    }

    is( $test1->trimmed, "trim me",
        'trimmed value is "trim me"' );
}

{
    CGI->_reset_globals;

    $ENV{QUERY_STRING} = 'nl=line1%0d%0aline2%0dline3;foo=bar';

    my $test1 = Test1->new;
    SKIP: {
        skip "Encode not installed", 1  unless($enc);
        ok( Encode::is_utf8($test1->nl), 'nl is marked as utf8' );
    }

    is( $test1->nl, "line1\nline2\nline3\n",
        'nl only contains unix newlines' );
}