| 1 | #!/usr/bin/perl -w |
| 2 | use strictscip-perl cpan WWW-Mechanize-Shell 0.62 strict/; |
| 3 | |
| 4 | use Test::Morescip-perl cpan WWW-Mechanize-Shell 0.62 Test/More/; |
| 5 | use File::Tempscip-perl cpan WWW-Mechanize-Shell 0.62 File/Temp/ qw( tempfile ); |
| 6 | use WWW::Mechanize::Linkscip-perl cpan WWW-Mechanize-Shell 0.62 WWW/Mechanize/Link/; |
| 7 | use libscip-perl cpan WWW-Mechanize-Shell 0.62 lib/ './inc'; |
| 8 | use IO::Catchscip-perl cpan WWW-Mechanize-Shell 0.62 IO/Catch/; |
| 9 | |
| 10 | # pre-5.8.0's warns aren't caught by a tied STDERR. |
| 11 | tie *STDOUT, 'IO::Catch', '_STDOUT_' or diescip-perl cpan WWW-Mechanize-Shell 0.62 main/die(). $!scip-perl cpan WWW-Mechanize-Shell 0.62 main/`$!`.; |
| 12 | |
| 13 | BEGIN { |
| 14 | # Disable all ReadLine functionality |
| 15 | $ENVscip-perl cpan WWW-Mechanize-Shell 0.62 main/`%ENV`.{PERL_RL} = 0; |
| 16 | }; |
| 17 | |
| 18 | our %testsscip-perl cpan WWW-Mechanize-Shell 0.62 main/`%tests`. = ( |
| 19 | 'autofill' => 'autofill test Fixed value', |
| 20 | 'back' => 'back', |
| 21 | 'click' => 'click', |
| 22 | 'content' => 'content', |
| 23 | 'eval' => 'eval 1', |
| 24 | 'fillout' => 'fillout', |
| 25 | 'form' => 'form 1', |
| 26 | 'form' => 'form test', |
| 27 | 'get @' => 'get http://[email protected]/', |
| 28 | 'get plain' => 'get http://www.google.com/', |
| 29 | 'open' => 'open "foo link"', |
| 30 | 'reload' => 'reload', |
| 31 | 'referer' => 'referer ""', |
| 32 | 'referrer' => 'referrer ""', |
| 33 | 'save' => 'save /.../', |
| 34 | 'submit' => 'submit', |
| 35 | 'value' => 'value key value', |
| 36 | 'ua' => 'ua foo/1.0', |
| 37 | 'tick' => 'tick key value', |
| 38 | 'tick_all' => 'tick key', |
| 39 | 'timeout' => 'timeout 60', |
| 40 | 'untick' => 'untick key value', |
| 41 | 'untick_all' => 'untick key', |
| 42 | ); |
| 43 | |
| 44 | eval { |
| 45 | requirescip-perl cpan WWW-Mechanize-Shell 0.62 main/require(). HTML::TableExtract; |
| 46 | $testsscip-perl cpan WWW-Mechanize-Shell 0.62 main/`%tests`.{table} = 'table'; |
| 47 | $tests{table params} = 'table foo bar'; |
| 48 | ; |
| 49 | }; |
| 50 | |
| 51 | planscip-perl cpan WWW-Mechanize-Shell 0.62 main/plan(). tests => scalarscip-perl cpan WWW-Mechanize-Shell 0.62 main/scalar(). (keysscip-perl cpan WWW-Mechanize-Shell 0.62 main/keys(). %testsscip-perl cpan WWW-Mechanize-Shell 0.62 main/`%tests`.) +1; |
| 52 | SKIP: { |
| 53 | |
| 54 | eval { |
| 55 | requirescip-perl cpan WWW-Mechanize-Shell 0.62 main/require(). Test::MockObject; |
| 56 | Test::MockObject->importscip-perl cpan WWW-Mechanize-Shell 0.62 Test/MockObject/import().(); |
| 57 | }; |
| 58 | skipscip-perl cpan WWW-Mechanize-Shell 0.62 main/skip(). "Test::MockObject not installed", scalarscip-perl cpan WWW-Mechanize-Shell 0.62 main/scalar(). keysscip-perl cpan WWW-Mechanize-Shell 0.62 main/keys().(%testsscip-perl cpan WWW-Mechanize-Shell 0.62 main/`%tests`.) +1 |
| 59 | if $@scip-perl cpan WWW-Mechanize-Shell 0.62 main/`$@`.; |
| 60 | |
| 61 | my $mock_result = Test::MockObject->newscip-perl cpan WWW-Mechanize-Shell 0.62 Test/MockObject/new().; |
| 62 | $mock_result->set_alwaysscip-perl cpan WWW-Mechanize-Shell 0.62 Test/MockObject/set_always().( code => 200 ); |
| 63 | |
| 64 | my $mock_form = Test::MockObject->newscip-perl cpan WWW-Mechanize-Shell 0.62 Test/MockObject/new().; |
| 65 | $mockscip-perl cpan WWW-Mechanize-Shell 0.62 Test/MockObject/mock()._form->mock( value => sub {} ) |
| 66 | ->set_listscip-perl cpan WWW-Mechanize-Shell 0.62 main/set_list().( inputs => ()) |
| 67 | ->set_list( find_input => ()) |
| 68 | ->mock( dump => sub {} ) |
| 69 | ->set_alwaysscip-perl cpan WWW-Mechanize-Shell 0.62 main/set_always().( form_name => 'foo' ); |
| 70 | |
| 71 | my $mock_uri = Test::MockObject->newscip-perl cpan WWW-Mechanize-Shell 0.62 Test/MockObject/new().; |
| 72 | $mock_uri->set_alwaysscip-perl cpan WWW-Mechanize-Shell 0.62 Test/MockObject/set_always().( abs => 'http://example.com/' ) |
| 73 | ->set_always( path => '/' ); |
| 74 | $mock_uri->fake_modulescip-perl cpan WWW-Mechanize-Shell 0.62 Test/MockObject/fake_module().( 'URI::URL', new => sub {$mock_uri} ); |
| 75 | |
| 76 | my $mock_agent = Test::MockObject->newscip-perl cpan WWW-Mechanize-Shell 0.62 Test/MockObject/new().; |
| 77 | $mock_agent->set_truescip-perl cpan WWW-Mechanize-Shell 0.62 Test/MockObject/set_true().($_scip-perl cpan WWW-Mechanize-Shell 0.62 main/$_.) |
| 78 | for qw( back content get mirror open follow ); |
| 79 | $mock_agent->set_falsescip-perl cpan WWW-Mechanize-Shell 0.62 Test/MockObject/set_false().($_scip-perl cpan WWW-Mechanize-Shell 0.62 main/$_.) |
| 80 | for qw( form forms ); |
| 81 | $mock_agent->set_alwaysscip-perl cpan WWW-Mechanize-Shell 0.62 Test/MockObject/set_always().( res => $mock_result ) |
| 82 | ->set_always( add_header => 1 ) |
| 83 | ->set_always( submit => $mock_result ) |
| 84 | ->set_always( click => $mock_result ) |
| 85 | ->set_always( reload => $mock_result ) |
| 86 | ->set_always( current_form => $mock_form ) |
| 87 | ->set_always( form_name => 'test form name' ) |
| 88 | ->set_always( follow_link => 1 ) |
| 89 | ->set_listscip-perl cpan WWW-Mechanize-Shell 0.62 main/set_list().( links => WWW::Mechanize::Link->newscip-perl cpan WWW-Mechanize-Shell 0.62 WWW/Mechanize/Link/new().('foo','foo link','foo_link',""), |
| 90 | WWW::Mechanize::Link->newscip-perl cpan WWW-Mechanize-Shell 0.62 WWW/Mechanize/Link/new().('foo2','foo2 link','foo2_link',"")) |
| 91 | ->set_always( agent => 'mocked/1.0') |
| 92 | ->set_always( uri => $mock_uri ) |
| 93 | ->set_always( request => $mock_result ) |
| 94 | ->set_always( tick => 1 ) |
| 95 | ->set_always( timeout => 1 ) |
| 96 | ->set_always( untick => 1 ) |
| 97 | ; |
| 98 | |
| 99 | use_okscip-perl cpan WWW-Mechanize-Shell 0.62 main/use_ok().('WWW::Mechanize::Shell'); |
| 100 | my $s = WWW::Mechanize::Shell->newscip-perl cpan WWW-Mechanize-Shell 0.62 WWW/Mechanize/Shell/new().( 'test', rcfile => undef, warnings => undef, watchfiles => undef ); |
| 101 | $s->{agent} = $mock_agent; |
| 102 | |
| 103 | my @history; |
| 104 | { no warnings 'redefine','once'; |
| 105 | *WWW::Mechanize::Shell::add_history = sub { |
| 106 | my $shell = shiftscip-perl cpan WWW-Mechanize-Shell 0.62 main/shift().; |
| 107 | pushscip-perl cpan WWW-Mechanize-Shell 0.62 main/push(). @history, $shell->linescip-perl cpan WWW-Mechanize-Shell 0.62 main/line().; |
| 108 | }; |
| 109 | }; |
| 110 | |
| 111 | sub exactly_one_linescip-perl cpan WWW-Mechanize-Shell 0.62 main/exactly_one_line(). { |
| 112 | my ($command,$testname) = @_scip-perl cpan WWW-Mechanize-Shell 0.62 main/`@_`.; |
| 113 | $testname ||= $command; |
| 114 | @history = (); |
| 115 | $s->cmdscip-perl cpan WWW-Mechanize-Shell 0.62 WWW/Mechanize/Shell/cmd().($command); |
| 116 | is_deeplyscip-perl cpan WWW-Mechanize-Shell 0.62 main/is_deeply().([@history],[$command],"$testname adds one line to history"); |
| 117 | }; |
| 118 | |
| 119 | |
| 120 | foreach my $name (sortscip-perl cpan WWW-Mechanize-Shell 0.62 main/sort(). keysscip-perl cpan WWW-Mechanize-Shell 0.62 main/keys(). %testsscip-perl cpan WWW-Mechanize-Shell 0.62 main/`%tests`.) { |
| 121 | exactly_one_linescip-perl cpan WWW-Mechanize-Shell 0.62 main/exactly_one_line().( $testsscip-perl cpan WWW-Mechanize-Shell 0.62 main/`%tests`.{$name},$name ); |
| 122 | }; |
| 123 | }; |