File: cgi.t

package info (click to toggle)
libtemplate-perl 2.14-1
  • links: PTS
  • area: main
  • in suites: etch, etch-m68k, sarge
  • size: 5,496 kB
  • ctags: 667
  • sloc: perl: 15,349; makefile: 62; xml: 7; sh: 5
file content (101 lines) | stat: -rw-r--r-- 2,091 bytes parent folder | download
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
#============================================================= -*-perl-*-
#
# t/cgi.t
#
# Test the CGI plugin.
#
# Written by Andy Wardley <abw@kfs.org>
#
# Copyright (C) 1996-2000 Andy Wardley.  All Rights Reserved.
# Copyright (C) 1998-2000 Canon Research Centre Europe Ltd.
#
# This is free software; you can redistribute it and/or modify it
# under the same terms as Perl itself.
#
# $Id: cgi.t,v 2.7 2002/11/01 16:25:59 abw Exp $
# 
#========================================================================

use strict;
use lib qw( ../lib );
use Template;
use Template::Test;
$^W = 1;

#$Template::Parser::DEBUG = 1;
#$Template::Parser::PRETTY = 1;
#$Template::Stash::DEBUG = 1;

eval "use CGI";
if ($@) {
    skip_all("no CGI module");
}


my $cgi = CGI->new('');
$cgi = join("\n", $cgi->checkbox_group(
		-name     => 'words',
                -values   => [ 'eenie', 'meenie', 'minie', 'moe' ],
	        -defaults => [ 'eenie', 'meenie' ],
)); 


test_expect(\*DATA, undef, { cgicheck => $cgi, barf => \&barf });

sub barf {
    carp('failed');
}


__END__
-- test --
[% USE cgi = CGI('id=abw&name=Andy+Wardley'); global.cgi = cgi -%]
name: [% global.cgi.param('name') %]
-- expect --
name: Andy Wardley

-- test --
name: [% global.cgi.param('name') %]

-- expect --
name: Andy Wardley

-- test --
[% FOREACH key = global.cgi.param.sort -%]
   * [% key %] : [% global.cgi.param(key) %]
[% END %]
-- expect --
   * id : abw
   * name : Andy Wardley

-- test --
[% FOREACH key = global.cgi.param().sort -%]
   * [% key %] : [% global.cgi.param(key) %]
[% END %]
-- expect --
   * id : abw
   * name : Andy Wardley

-- test --
[% FOREACH x = global.cgi.checkbox_group(
		name     => 'words'
                values   => [ 'eenie', 'meenie', 'minie', 'moe' ]
	        defaults => [ 'eenie', 'meenie' ] )   -%]
[% x %]
[% END %]

-- expect --
-- process --
[% cgicheck %]

-- test --
[% USE cgi('item=foo&items=one&items=two') -%]
item: [% cgi.params.item %]
item: [% cgi.params.item.join(', ') %]
items: [% cgi.params.items.join(', ') %]

-- expect --
item: foo
item: foo
items: one, two