~ubuntu-branches/ubuntu/edgy/libcgi-formbuilder-perl/edgy

« back to all changes in this revision

Viewing changes to t/1d-messages.t

  • Committer: Bazaar Package Importer
  • Author(s): Jonas Smedegaard
  • Date: 2006-05-28 15:47:27 UTC
  • mfrom: (1.1.2 upstream) (2.1.1 etch)
  • Revision ID: james.westby@ubuntu.com-20060528154727-u26u5nqd0btamxpm
Tags: 3.03.01-1
* New upstream release.
  + optgroups bugfix for complex arrays.
  + removal of HTML::Entities support due to utf8 issues. Closes:
    bug#338369 (thanks to Todd Charron <tcharron@badkarma.mine.nu> for
    reporting, and to several others for working on workarounds).
  + new es_ES Messages module with better translations
  + a patch from Mark Hedges to enable plugin modules for mailresults()
* Update local cdbs snippet copyright-check.mk:
  + Broaden scan to also look for "(c)" by default.
  + Make egrep options configurable.
* Bump up standards-version to 3.7.2 (no changes needed).
* Update debian/copyright_hints (nothing remarkable).
* Bump up debian/watch to version 3 syntax, and use uversionmangle
  instead of multiple parantheses (both work using uscan locally, but
  the later hopefully works with qa.debian.org too).

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#!/usr/bin/perl -Ilib -I../lib
 
2
 
 
3
# Copyright (c) 2000-2006 Nathan Wiger <nate@wiger.org>.
 
4
# All Rights Reserved. If you're reading this, you're bored.
 
5
# 1d-messages.t - messages and localization
 
6
 
 
7
use strict;
 
8
use vars qw($TESTING $DEBUG);
 
9
$TESTING = 1;
 
10
$DEBUG = $ENV{DEBUG} || 0;
 
11
use Test;
 
12
 
 
13
# use a BEGIN block so we print our plan before CGI::FormBuilder is loaded
 
14
my @pm;
 
15
BEGIN { 
 
16
    # try to load all the .pm's except templates from MANIFEST
 
17
    open(M, "<MANIFEST") || warn "Can't open MANIFEST ($!) - skipping imports";
 
18
    chomp(@pm = grep m#Messages/[a-z]+_.*#, grep /\.pm$/, <M>);
 
19
    close(M);
 
20
 
 
21
    #
 
22
    # There are 34 keys, times the number of modules, plus one load of the module.
 
23
    # Then, also add in our 30 custom tests as well.
 
24
    #
 
25
 
 
26
    my $numtests = (34 * @pm) + @pm + 34;
 
27
 
 
28
    plan tests => $numtests;
 
29
 
 
30
    # success if we said NOTEST
 
31
    if ($ENV{NOTEST}) {
 
32
        ok(1) for 1..$numtests;
 
33
        exit;
 
34
    }
 
35
}
 
36
 
 
37
# Messages, both inline and file
 
38
my %messages = (
 
39
    form_invalid_text   => 'You fucked up',
 
40
    js_invalid_text     => 'Yep, shit sucks!',
 
41
    form_select_default => '*<- choose ->*',
 
42
    taco_salad          => 'is delicious',
 
43
    parade              => [1,2,3],
 
44
 
 
45
    form_invalid_opentag  => '<font color="red"><b>',
 
46
    form_invalid_closetag => '</b></font>',
 
47
    form_invalid_input    => 'Invalid entry',
 
48
    form_invalid_select   => 'Select an option from this list',
 
49
    form_invalid_checkbox => 'Check one or more options',
 
50
    form_invalid_radio    => 'Choose an option',
 
51
    form_invalid_password => 'Invalid entry',
 
52
    form_invalid_textarea => 'Please fill this in',
 
53
    form_invalid_file     => 'Invalid filename',
 
54
    form_invalid_default  => 'Invalid entry',
 
55
);
 
56
 
 
57
my $locale = "fb_FAKE";
 
58
my $messages = "messages.$locale";
 
59
open(M, ">$messages") || warn "Can't write $messages: $!";
 
60
while (my($k,$v) = each %messages) {
 
61
    print M join(' ', $k, ref($v) ? @$v : $v), "\n";
 
62
}
 
63
close(M);
 
64
 
 
65
# Fake a submission request
 
66
$ENV{REQUEST_METHOD} = 'GET';
 
67
$ENV{QUERY_STRING}   = 'ticket=111&user=pete&replacement=TRUE&action=Unsubscribe&name=Pete+Peteson&email=pete%40peteson.com&extra=junk&_submitted=1&blank=&two=&two=';
 
68
 
 
69
use CGI::FormBuilder;
 
70
 
 
71
# Now manually try a whole bunch of things
 
72
my $hash = CGI::FormBuilder->new(
 
73
                debug => $DEBUG,
 
74
                fields => [qw/user name email/],
 
75
                messages => \%messages
 
76
           );
 
77
 
 
78
for my $k (sort keys %messages) {
 
79
    #local $" = ', ';
 
80
    ok($hash->messages->$k, ref($messages{$k}) ? "@{$messages{$k}}" : $messages{$k});
 
81
}
 
82
 
 
83
my $file = CGI::FormBuilder->new(
 
84
                debug => $DEBUG,
 
85
                fields => [qw/user name email/],
 
86
                messages => $messages,
 
87
           );
 
88
 
 
89
for my $k (sort keys %messages) {
 
90
    #local $" = ', ';
 
91
    ok($file->messages->$k, ref($messages{$k}) ? "@{$messages{$k}}" : $messages{$k});
 
92
}
 
93
 
 
94
unlink $messages;
 
95
 
 
96
# Check to ensure our lang and charset work correctly
 
97
{   local $TESTING = 0;
 
98
    ok($file->charset, 'iso-8859-1');
 
99
    ok($file->lang,    'en_US');
 
100
    ok($file->dtd, <<EOD);
 
101
<?xml version="1.0" encoding="iso-8859-1"?>
 
102
<!DOCTYPE html
 
103
        PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
 
104
         "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
 
105
<html xmlns="http://www.w3.org/1999/xhtml" lang="en_US" xml:lang="en_US">
 
106
EOD
 
107
    ok($file->charset('yo.momma'), 'yo.momma');
 
108
}
 
109
 
 
110
# Final test set is to just make sure we have all the keys for all modules
 
111
require CGI::FormBuilder::Messages::default;
 
112
my %need = CGI::FormBuilder::Messages::locale->messages;
 
113
my @keys = keys %need;
 
114
for my $pm (@pm) {
 
115
    my($lang) = $pm =~ /([a-z]+_[A-Z]+)/;
 
116
    my $skip = $lang ? undef : "skip: Can't get language from $pm";
 
117
    my $form;
 
118
    eval { $form = CGI::FormBuilder->new(messages => ":$lang"); };
 
119
    skip($skip, !$@);
 
120
    for (@keys) {
 
121
        skip($skip, $form->{messages}{$_}) || warn "Locale $lang: missing $_\n";
 
122
    }
 
123
}
 
124
 
 
125