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

« back to all changes in this revision

Viewing changes to t/1a-generate.t

  • Committer: Bazaar Package Importer
  • Author(s): Jonas Smedegaard
  • Date: 2008-06-28 20:29:04 UTC
  • mfrom: (2.1.7 intrepid)
  • Revision ID: james.westby@ubuntu.com-20080628202904-81kzjon8e8silx88
Tags: 3.05.01-6
Set urgency=medium as 3.05.01-6 included a FTBFS bugfix.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
#!/usr/bin/perl -Ilib -I../lib
 
1
#!/usr/bin/perl
2
2
 
3
3
# Copyright (c) 2000-2006 Nathan Wiger <nate@wiger.org>.
4
4
# All Rights Reserved. If you're reading this, you're bored.
5
5
# 1a-generate.t - test FormBuilder generation of forms
6
6
 
7
7
use strict;
8
 
use vars qw($TESTING $DEBUG);
9
8
 
10
 
$TESTING = 1;
11
 
$DEBUG = $ENV{DEBUG} || 0;
 
9
our $TESTING = 1;
 
10
our $DEBUG = $ENV{DEBUG} || 0;
 
11
our $VERSION;
 
12
BEGIN { $VERSION = '3.0501'; }
12
13
 
13
14
use Test;
 
15
use FindBin;
14
16
 
15
17
# use a BEGIN block so we print our plan before CGI::FormBuilder is loaded
16
18
BEGIN {
17
 
    my $numtests = 30;
 
19
    unshift @INC, "$FindBin::Bin/../lib";
 
20
    my $numtests = 36;
18
21
 
19
 
    plan tests => $numtests;
 
22
    plan tests => $numtests + 1;
20
23
 
21
24
    # success if we said NOTEST
22
25
    if ($ENV{NOTEST}) {
27
30
 
28
31
# Need to fake a request or else we stall
29
32
$ENV{REQUEST_METHOD} = 'GET';
30
 
$ENV{QUERY_STRING}   = 'ticket=111&user=pete&replacement=TRUE&action=Unsubscribe&name=Pete+Peteson&email=pete%40peteson.com&extra=junk';
 
33
$ENV{QUERY_STRING}   = 'ticket=111&user=pete&replacement=TRUE&action=Unsubscribe&name=Pete+Peteson&email=pete%40peteson.com&extra=junk&other_test=_other_other_test&_other_other_test=42';
31
34
 
32
 
use CGI::FormBuilder;
 
35
use CGI::FormBuilder 3.0501;
33
36
use CGI::FormBuilder::Test;
34
37
 
35
38
# What options we want to use, and what we expect to see
401
404
        },
402
405
    },
403
406
 
 
407
    #31 - Backbase tagname support (experiemental)
 
408
    {
 
409
        opt => {
 
410
            stylesheet => 'fbstyle.css',
 
411
            submit     => [qw(Update Delete)],
 
412
            reset      => 'Showme',
 
413
            method     => 'POST',
 
414
            fields     => [qw(fullname gender fav_color lover)],    # need hash order
 
415
            header     => 1,
 
416
            columns    => 1,
 
417
            messages   => 'auto',
 
418
            tagnames => {
 
419
                name   => 'b:name',
 
420
                select => 'b:select',
 
421
                value  => 'b:value',
 
422
                option => 'b:option',
 
423
                input  => 'b:input',
 
424
                table  => 'div',
 
425
                tr     => 'div',
 
426
                th     => 'div',
 
427
                td     => 'div',
 
428
            },
 
429
        },
 
430
        mod => {
 
431
            fullname => {
 
432
                label => 'Full Name',
 
433
                type  => 'text',
 
434
                required => 1,
 
435
            },
 
436
            gender => {
 
437
                label => 'Sex',
 
438
                options => [qw(M F)],
 
439
                comment => "It's one or the other",
 
440
            },
 
441
            fav_color => {
 
442
                label => 'Favy Colour',
 
443
                options => [qw(Red Green Blue Orange Yellow Purple)],
 
444
                comment => 'Choose just one, even if you have more than one',
 
445
                invalid => 1,   # tricky
 
446
            },
 
447
            lover => {
 
448
                label => 'Things you love',
 
449
                options => [qw(Sex Drugs Rock+Roll)],
 
450
                multiple => 1,
 
451
            },
 
452
        },
 
453
    },
 
454
 
 
455
    #32 - fieldsets
 
456
    {
 
457
        opt => {
 
458
            name => 'account',
 
459
            fieldsets => [[acct=>'Account Information'],
 
460
                          [prefs=>'User Preferences'],
 
461
                          [phone=>'Phone Number(s)']],
 
462
            stylesheet => 1,
 
463
            fields => [qw/first_name last_name outside_1 email home_phone new_set
 
464
                          work_phone call_me email_me outside_2 sex outside_3/],
 
465
        },
 
466
        mod => {
 
467
            first_name => { fieldset => 'acct' },
 
468
            last_name  => { fieldset => 'acct' },
 
469
            email      => { fieldset => 'acct' },
 
470
            home_phone => { fieldset => 'phone' },
 
471
            work_phone => { fieldset => 'phone' },
 
472
            new_set    => { fieldset => 'Inline Created' },
 
473
            call_me    => { fieldset => 'prefs' },
 
474
            email_me   => { fieldset => 'prefs' },
 
475
            first_name => { fieldset => 'acct' },
 
476
            sex        => { fieldset => 'acct', 
 
477
                            options  => [qw/Yes No/] },
 
478
        },
 
479
    },
 
480
 
 
481
    #33 - builtin Div.pm "template" support
 
482
    {
 
483
        opt => {
 
484
            name => 'parts',
 
485
            fields => [qw/ticket user email part_number/],
 
486
            fieldsets => [[acct=>'Account Information'],
 
487
                          [prefs=>'Part Information']],
 
488
            method => 'post',
 
489
            keepextras => 1,
 
490
            validate => { ticket => '/^\d+$/' },
 
491
            submit => [qw/Update Delete Cancel/],
 
492
            lalign => 'left',
 
493
            template => {type => 'div'},
 
494
            stylesheet => 1,
 
495
        },
 
496
        mod => {
 
497
            ticket => { fieldset => 'acct' },
 
498
            email  => { fieldset => 'prefs' },
 
499
        },
 
500
    },
 
501
 
 
502
    # Older tests moved from 1b-fields
 
503
    #34 - misc checkboxes
 
504
    {
 
505
        opt => {
 
506
            fields => [qw/name color/],
 
507
            labels => {color => 'Favorite Color'},
 
508
            validate => {email => 'EMAIL'},
 
509
            required => [qw/name/],
 
510
            sticky => 0, columns => 1,
 
511
            action => 'TEST', title => 'TEST',
 
512
        },
 
513
        mod => {
 
514
            color => {
 
515
                options => [qw(red> green& blue")],
 
516
                multiple => 1, cleanopts => 0,
 
517
            },
 
518
            name => {
 
519
                options => [qw(lower UPPER)], nameopts => 1,
 
520
            },
 
521
        },
 
522
    },
 
523
 
 
524
    #35
 
525
    {
 
526
        # check individual fields as static
 
527
        opt => {
 
528
            fields => [qw/name email color/],
 
529
            action => 'TEST',
 
530
            columns => 1
 
531
        },
 
532
        mod => {
 
533
            name  => { static => 1 },
 
534
            email => { type => 'static' },
 
535
        },
 
536
    },
 
537
 
 
538
    #36
 
539
    {
 
540
        opt => {
 
541
            fields => [qw/name color hid1 hid2/],
 
542
            action => 'TEST',
 
543
            columns => 1,
 
544
            values => { hid1 => 'Val1a' },
 
545
        },
 
546
        mod => {
 
547
            name => { static => 1, type => 'text' },
 
548
            hid1 => { type => 'hidden', value => 'Val1b' },  # should replace Val1a
 
549
            hid2 => { type => 'hidden', value => 'Val2' },
 
550
            color => { value => 'blew', options => [qw(read blew yell)] },
 
551
            Tummy => { value => [qw(lg xxl)], options => [qw(sm med lg xl xxl xxxl)] },
 
552
        },
 
553
    },
404
554
);
405
555
 
406
556
sub refsort {
413
563
 
414
564
$ENV{HTTP_ACCEPT_LANGUAGE} = 'en_US';
415
565
 
 
566
# To test local %TAGNAMES
 
567
$CGI::FormBuilder::Util::TAGNAMES{name} = 'yellow';
 
568
 
416
569
# Cycle thru and try it out
417
570
for (@test) {
418
571
 
419
572
    my $form = CGI::FormBuilder->new(
420
573
                    debug  => $DEBUG,
 
574
                    header => $ENV{HEADER} || 0,
421
575
                    action => 'TEST',  # testing
422
576
                    title  => 'TEST',
423
577
                    %{ $_->{opt} }
436
590
    my $ok  = ok($ren, $out);
437
591
 
438
592
    if (! $ok && $ENV{LOGNAME} eq 'nwiger') {
439
 
        open(O, ">/tmp/fb.1.out");
 
593
        open(O, ">/tmp/fb.1.html");
440
594
        print O $out;
441
595
        close O;
442
596
 
443
 
        open(O, ">/tmp/fb.2.out");
 
597
        open(O, ">/tmp/fb.2.html");
444
598
        print O $ren;
445
599
        close O;
446
600
 
447
 
        system "diff /tmp/fb.1.out /tmp/fb.2.out";
 
601
        system "diff /tmp/fb.1.html /tmp/fb.2.html";
448
602
        exit 1;
449
603
    }
450
604
}
 
605
ok($CGI::FormBuilder::Util::TAGNAMES{name}, 'yellow');
451
606