HTML-Widget

 view release on metacpan or  search on metacpan

t/element_radiogroup.t  view on Meta::CPAN

use strict;
use warnings;

use Test::More tests => 6;

use HTML::Widget;
use lib 't/lib';
use HTMLWidget::TestLib;

my $w = HTML::Widget->new;

my $e = $w->element( 'RadioGroup', 'bar' )->values( [ 'opt1', 'opt2', 'opt3' ] )
    ->value('opt1');

# Without query
{
    my $f = $w->process;
    is( "$f", <<EOF, 'XML output is filled out form' );
<form id="widget" method="post"><fieldset class="widget_fieldset"><fieldset class="radiogroup_fieldset" id="widget_bar"><span class="radiogroup"><label for="widget_bar_1" id="widget_bar_1_label"><input checked="checked" class="radio" id="widget_bar_1...
EOF
}

# With mocked basic query
{
    my $query = HTMLWidget::TestLib->mock_query( { bar => 'opt2' } );

    my $f = $w->process($query);
    is( "$f", <<EOF, 'XML output is filled out form' );
<form id="widget" method="post"><fieldset class="widget_fieldset"><fieldset class="radiogroup_fieldset" id="widget_bar"><span class="radiogroup"><label for="widget_bar_1" id="widget_bar_1_label"><input class="radio" id="widget_bar_1" name="bar" type=...
EOF
}

# With legend
$e->legend('Select One');
{
    my $f = $w->process;
    is( "$f", <<EOF, 'XML output is filled out form (label)' );
<form id="widget" method="post"><fieldset class="widget_fieldset"><fieldset class="radiogroup_fieldset" id="widget_bar"><legend class="radiogroup_legend">Select One</legend><span class="radiogroup"><label for="widget_bar_1" id="widget_bar_1_label"><i...
EOF
}

# With label
$e->legend(undef);
$e->label('Choose');

{
    my $f = $w->process;
    is( "$f", <<EOF, 'XML output is filled out form (label)' );
<form id="widget" method="post"><fieldset class="widget_fieldset"><fieldset class="radiogroup_fieldset" id="widget_bar"><span class="radiogroup_label" id="widget_bar_label">Choose</span><span class="radiogroup"><label for="widget_bar_1" id="widget_ba...
EOF
}

# With comment too
$e->comment('Informed');
{
    my $f = $w->process;
    is( "$f", <<EOF, 'XML output is filled out form (label+comment)' );
<form id="widget" method="post"><fieldset class="widget_fieldset"><fieldset class="radiogroup_fieldset" id="widget_bar"><span class="radiogroup_label" id="widget_bar_label">Choose</span><span class="label_comments" id="widget_bar_comment">Informed</s...
EOF
}

# With error
$w->constraint( 'In' => 'bar' )->in('octopus');
{
    my $query = HTMLWidget::TestLib->mock_query( { bar => 'opt2' } );

    my $f = $w->process($query);
    is( "$f", <<EOF, 'XML output is filled out form (label+comment+error)' );
<form id="widget" method="post"><fieldset class="widget_fieldset"><span class="labels_with_errors" id="widget_bar"><fieldset class="radiogroup_fieldset"><span class="radiogroup_label" id="widget_bar_label">Choose</span><span class="label_comments" id...
EOF
}



( run in 1.852 second using v1.01-cache-2.11-cpan-5837b0d9d2c )