File: 06-Form-Image-Button.t

package info (click to toggle)
libwww-mechanize-formfiller-perl 0.11-1
  • links: PTS, VCS
  • area: main
  • in suites: jessie, jessie-kfreebsd
  • size: 292 kB
  • ctags: 46
  • sloc: perl: 1,504; sh: 6; makefile: 2
file content (51 lines) | stat: -rwxr-xr-x 1,859 bytes parent folder | download | duplicates (6)
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
use strict;

use Test::More tests => 7;

use_ok("WWW::Mechanize::FormFiller");

SKIP: {
  eval { require HTML::Form };
  skip "Need HTML::Form to run the form image value test", 6 if $@;
  eval { require Test::MockObject };
  skip "Need Test::MockObject to run the form image value test", 6 if $@;

  {
    my $f = WWW::Mechanize::FormFiller->new();
    isa_ok($f,"WWW::Mechanize::FormFiller");

    my $value = $f->add_value("image1", Test::MockObject->new()->set_always('value','Returned Value'));
    my $form = HTML::Form->parse(<<HTML,"http://www.nowhere.org");
    <html><body><form>
      <input type='image' name='image1' value='Original Value'/>
    </form></body></html>
HTML

    $f->fill_form($form);
    my ($method,$args) = $value->next_call;
    is($method,"value","Image inputs get called if they are specified");
    my $filled_input = $form->find_input("image1");
    is($filled_input->value, 'Returned Value', "Returned image values get set")
  };

  {
    my $value = Test::MockObject->new()->set_always('value','Returned Value');
    $value->fake_module('WWW::Mechanize::FormFiller::Value::Test');
    $value->fake_new('WWW::Mechanize::FormFiller::Value::Test');

    my $f = WWW::Mechanize::FormFiller->new( default => [ 'Test' ] );
    isa_ok($f,"WWW::Mechanize::FormFiller");

    my $form = HTML::Form->parse(<<HTML,"http://www.nowhere.org");
    <html><body><form>
      <input type='image' name='image1' value='Original Value'/>
    </form></body></html>
HTML

    $f->fill_form($form);
    my ($method,$args) = $value->next_call;
    is($method,undef,"Image inputs don't get called if they are not explicitly specified");
    my $filled_input = $form->find_input("image1");
    is($filled_input->value, 'Original Value', "Returned image values stay what they are set to")
  };
};