CGI-Test

 view release on metacpan or  search on metacpan

MANIFEST  view on Meta::CPAN

lib/CGI/Test/Form/Widget/Button/Image.pm
lib/CGI/Test/Form/Widget/Button/Plain.pm
lib/CGI/Test/Form/Widget/Button/Reset.pm
lib/CGI/Test/Form/Widget/Button/Submit.pm
lib/CGI/Test/Form/Widget/Hidden.pm
lib/CGI/Test/Form/Widget/Input.pm
lib/CGI/Test/Form/Widget/Input/File.pm
lib/CGI/Test/Form/Widget/Input/Password.pm
lib/CGI/Test/Form/Widget/Input/Text_Area.pm
lib/CGI/Test/Form/Widget/Input/Text_Field.pm
lib/CGI/Test/Form/Widget/Menu.pm
lib/CGI/Test/Form/Widget/Menu/List.pm
lib/CGI/Test/Form/Widget/Menu/Popup.pm
lib/CGI/Test/Input.pm
lib/CGI/Test/Input/Multipart.pm
lib/CGI/Test/Input/URL.pm
lib/CGI/Test/Page.pm
lib/CGI/Test/Page/Error.pm
lib/CGI/Test/Page/HTML.pm
lib/CGI/Test/Page/Other.pm
lib/CGI/Test/Page/Real.pm
lib/CGI/Test/Page/Text.pm
Makefile.PL

lib/CGI/Test.pm  view on Meta::CPAN


 my $page = $ct->GET("http://some.server:1234/cgi-bin/script?arg=1");
 like $page->content_type, qr|text/html\b|, "Content type";

 my $form = $page->forms->[0];
 is $form->action, "/cgi-bin/some_target", "Form action URI";

 my $menu = $form->menu_by_name("months");
 ok $menu->is_selected("January"), "January selected";
 ok !$menu->is_selected("March"),  "March not selected";
 ok $menu->multiple,               "Menu is multi-choice";

 my $send = $form->submit_by_name("send_form");
 ok defined $send, "Send form defined";

 #
 # Now interact with the CGI
 #

 $menu->select("March");        # "click" on the March label
 my $answer = $send->press;     # "click" on the send button

lib/CGI/Test/Form.pm  view on Meta::CPAN

# them once and for all, on reasonably sized forms.
#
use CGI::Test::Form::Widget::Button::Submit;
use CGI::Test::Form::Widget::Button::Reset;
use CGI::Test::Form::Widget::Button::Image;
use CGI::Test::Form::Widget::Button::Plain;
use CGI::Test::Form::Widget::Input::Text_Field;
use CGI::Test::Form::Widget::Input::Text_Area;
use CGI::Test::Form::Widget::Input::Password;
use CGI::Test::Form::Widget::Input::File;
use CGI::Test::Form::Widget::Menu::List;
use CGI::Test::Form::Widget::Menu::Popup;
use CGI::Test::Form::Widget::Box::Radio;
use CGI::Test::Form::Widget::Box::Check;
use CGI::Test::Form::Widget::Hidden;

######################################################################
#
# ->new
#
# Creation routine
#

lib/CGI/Test/Form.pm  view on Meta::CPAN

        }
        elsif ($tag eq "textarea")
        {
            ($class, $attr) = ("Input::Text_Area", "inputs");
        }
        elsif ($tag eq "select")
        {
            $attr  = "menus";
            $class =
              ($node->attr("multiple") || defined $node->attr("size"))
              ? "Menu::List"
              : "Menu::Popup";
        }
        elsif ($tag eq "button")
        {
            $hlookup = \%button;
        }
        elsif ($tag eq "isindex")
        {
            warn "ISINDEX is deprecated, ignoring %s", $node->starttag;
            next;
        }

lib/CGI/Test/Form.pm  view on Meta::CPAN

be of that type, but can be a descendant.  Types are listed in the
abridged form, and you have to prepend the string C<CGI::Test::Form::>
in front of them to get the real type.

 Expanded List  List Reference  Item Polymorphic Type
 -------------  --------------  ----------------------
 button_list    buttons         Widget::Button
 checkbox_list  checkboxes      Widget::Box::Check
 hidden_list    hidden          Widget::Hidden
 input_list     inputs          Widget::Input
 menu_list      menus           Widget::Menu
 radio_list     radios          Widget::Box::Radio
 submit_list    submits         Widget::Button::Submit
 widget_list    widgets         Widget

For instance:

    my @widgets = @{$form->widgets};     # heavy style
    my @widgets = $form->widget_list;    # light style

A given widget may appear in several lists, i.e.the above do not form a

lib/CGI/Test/Form.pm  view on Meta::CPAN

least be of that type, but can be a descendant.  Types are listed in the
abridged form, and you have to prepend the string C<CGI::Test::Form::>
in front of them to get the real type.

 By-Name Queries   All-Named Queries  Item Polymorphic Type
 ----------------  -----------------  ----------------------
 button_by_name    buttons_named      Widget::Button
 checkbox_by_name  checkboxes_named   Widget::Box::Check
 hidden_by_name    hidden_named       Widget::Hidden
 input_by_name     inputs_named       Widget::Input
 menu_by_name      menus_named        Widget::Menu
 radio_by_name     radios_named       Widget::Box::Radio
 submit_by_name    submits_named      Widget::Button::Submit
 widget_by_name    widgets_named      Widget

=head2 Match Querying Interface

This is a general interface, which invokes a matching callback on each
widget of a particular category.  The signature of the matching routines is:

    my @matching = $form->widgets_matching(sub {code}, $arg);

lib/CGI/Test/Form.pm  view on Meta::CPAN

The following table lists the available matching routines, along with the
polymorphic widget type to be expected in the callback.  As usual, you must
prepend the string C<CGI::Test::Form::> to get the real type.

 Matching Routine     Item Polymorphic Type
 -------------------  ---------------------
 buttons_matching     Widget::Button
 checkboxes_matching  Widget::Box::Check
 hidden_matching      Widget::Hidden
 inputs_matching      Widget::Input
 menus_matching       Widget::Menu
 radios_matching      Widget::Box::Radio
 submits_matching     Widget::Button::Submit
 widgets_matching     Widget

For instance:

    my @menus = $form->widgets_matching(sub { $_[0]->is_menu });
    my @color = $form->widgets_matching(
        sub { $_[0]->is_menu && $_[0]->name eq "color" }
    );

lib/CGI/Test/Form/Widget.pm  view on Meta::CPAN

    . . Widget::Button::Plain
    . . Widget::Button::Submit
    . .   Widget::Button::Image
    . . Widget::Button::Reset
    . Widget::Hidden
    . Widget::Input*
    . . Widget::Input::Text_Area
    . . Widget::Input::Text_Field
    . .   Widget::Input::File
    . .   Widget::Input::Password
    . Widget::Menu*
    . . Widget::Menu::List
    . . Widget::Menu::Popup

Only leaf nodes are concrete classes, and there is one such class for each
known control type that can appear in the <FORM> element.

Those classes are constructed as needed by C<CGI::Test>.  They are the
programmatic artefacts which can be used to manipulate those graphical
elements, on which you would otherwise click and fill within a browser.

=head1 INTERFACE

lib/CGI/Test/Form/Widget.pm  view on Meta::CPAN


Current maintainer is Alexander Tokarev F<E<lt>tokarev@cpan.orgE<gt>>.

=head1 SEE ALSO

CGI::Test::Form(3),
CGI::Test::Form::Widget::Box(3),
CGI::Test::Form::Widget::Button(3),
CGI::Test::Form::Widget::Input(3),
CGI::Test::Form::Widget::Hidden(3),
CGI::Test::Form::Widget::Menu(3).

=cut

lib/CGI/Test/Form/Widget/Menu.pm  view on Meta::CPAN

package CGI::Test::Form::Widget::Menu;
use strict;
use warnings; 
##################################################################
# $Id: Menu.pm 411 2011-09-26 11:19:30Z nohuhu@nohuhu.org $
# $Name: cgi-test_0-104_t1 $
##################################################################
#
#  Copyright (c) 2001, Raphael Manfredi
#
#  You may redistribute only under the terms of the Artistic License,
#  as specified in the README file that comes with the distribution.
#

use Carp;

lib/CGI/Test/Form/Widget/Menu.pm  view on Meta::CPAN

}

#
# Attribute access
#
############################################################
sub multiple
{
    my $this = shift;
    return $this->{multiple};
}    # Set by Menu::List

############################################################
sub option_labels
{
    my $this = shift;
    return $this->{option_labels};
}
############################################################
sub option_values
{

lib/CGI/Test/Form/Widget/Menu.pm  view on Meta::CPAN

    $this->{selected}       = delete $this->{old_selected};
    $this->{selected_count} = scalar keys %{$this->selected()};

    return;
}

1;

=head1 NAME

CGI::Test::Form::Widget::Menu - Abstract representation of a menu

=head1 SYNOPSIS

 # Inherits from CGI::Test::Form::Widget

=head1 DESCRIPTION

This class is the abstract representation of a menu from which one can choose
one or several items, i.e. either a popup menu or a scrollable list
(with possibly multiple selections).

lib/CGI/Test/Form/Widget/Menu.pm  view on Meta::CPAN


Note that this takes a I<value>, not a I<label>.

=item C<unselect> I<value>

Unselect an option I<value>.  It is not possible to do that on a popup
menu: you must C<select> another item to unselect any previously selected one.

=back

=head2  Menu Probing

=over 4

=item C<is_selected> I<value>

Test whether an option I<value> is currently selected or not.  This is
not testing a label, but a value, which is what the script will get back
eventually: labels are there for human consumption only.

=back

lib/CGI/Test/Form/Widget/Menu.pm  view on Meta::CPAN


The original author is Raphael Manfredi.

Steven Hilton was long time maintainer of this module.

Current maintainer is Alexander Tokarev F<E<lt>tokarev@cpan.orgE<gt>>.

=head1 SEE ALSO

CGI::Test::Form::Widget(3),
CGI::Test::Form::Widget::Menu::List(3),
CGI::Test::Form::Widget::Menu::Popup(3).

=cut

lib/CGI/Test/Form/Widget/Menu/List.pm  view on Meta::CPAN

package CGI::Test::Form::Widget::Menu::List;
use strict;
use warnings;
##################################################################
# $Id: List.pm 411 2011-09-26 11:19:30Z nohuhu@nohuhu.org $
# $Name: cgi-test_0-104_t1 $
##################################################################
#
#  Copyright (c) 2001, Raphael Manfredi
#
#  You may redistribute only under the terms of the Artistic License,
#  as specified in the README file that comes with the distribution.
#

use Carp;

#
# This class models a FORM scrollable list.
#

use base qw(CGI::Test::Form::Widget::Menu);

#
# %attr
#
# Defines which HTML attributes we should look at within the node, and how
# to translate that into class attributes.
#

my %attr = ('name'     => 'name',
            'size'     => 'size',

lib/CGI/Test/Form/Widget/Menu/List.pm  view on Meta::CPAN


sub is_popup
{
    return 0;
}

1;

=head1 NAME

CGI::Test::Form::Widget::Menu::List - A scrolling list menu

=head1 SYNOPSIS

 # Inherits from CGI::Test::Form::Widget::Menu
 # $form is a CGI::Test::Form

 my $action = $form->menu_by_name("action");
 $action->unselect("allow-gracetime");
 $action->select("reboot");

=head1 DESCRIPTION

This class models a scrolling list menu, from which items may be selected
and unselected.

=head1 INTERFACE

The interface is the same as the one described in
L<CGI::Test::Form::Widget::Menu>, with the following additional attribute:

=over 4

=item C<size>

The amount of choices displayed.

=back

=head1 AUTHORS

The original author is Raphael Manfredi.

Steven Hilton was long time maintainer of this module.

Current maintainer is Alexander Tokarev F<E<lt>tokarev@cpan.orgE<gt>>.

=head1 SEE ALSO

CGI::Test::Form::Widget::Menu(3).

=cut

lib/CGI/Test/Form/Widget/Menu/Popup.pm  view on Meta::CPAN

package CGI::Test::Form::Widget::Menu::Popup;
use strict;
use warnings; 
##################################################################
# $Id: Popup.pm 411 2011-09-26 11:19:30Z nohuhu@nohuhu.org $
# $Name: cgi-test_0-104_t1 $
##################################################################
#
#  Copyright (c) 2001, Raphael Manfredi
#
#  You may redistribute only under the terms of the Artistic License,
#  as specified in the README file that comes with the distribution.
#

use Carp;

#
# This class models a FORM popup menu.
#

use base qw(CGI::Test::Form::Widget::Menu);

#
# %attr
#
# Defines which HTML attributes we should look at within the node, and how
# to translate that into class attributes.
#

my %attr = ('name'     => 'name',
            'disabled' => 'is_disabled',);

lib/CGI/Test/Form/Widget/Menu/Popup.pm  view on Meta::CPAN


sub is_popup
{
    return 1;
}

1;

=head1 NAME

CGI::Test::Form::Widget::Menu::Popup - A popup menu

=head1 SYNOPSIS

 # Inherits from CGI::Test::Form::Widget::Menu
 # $form is a CGI::Test::Form

 my $action = $form->menu_by_name("action");
 $action->select("reboot");

=head1 DESCRIPTION

This class models a popup menu, from which one item at most may be selected,
and for which there is at least one item selected, i.e. where exactly one
item is chosen.

If no item was explicitely selected, C<CGI::Test> arbitrarily chooses the
first item in the popup (if not empty) and warns you via C<warn>.

=head1 INTERFACE

The interface is the same as the one described in
L<CGI::Test::Form::Widget::Menu>.

=head1 AUTHORS

The original author is Raphael Manfredi.

Steven Hilton was long time maintainer of this module.

Current maintainer is Alexander Tokarev F<E<lt>tokarev@cpan.orgE<gt>>.

=head1 SEE ALSO

CGI::Test::Form::Widget::Menu(3).

=cut



( run in 1.475 second using v1.01-cache-2.11-cpan-49f99fa48dc )