Debian Codegraph @

t/28-cmd-title.t

raw
1 #!/usr/bin/perl -w
2 use strict;
3 use lib './inc';
4 use IO::Catch;
5
6 our $_STDOUT_;
7 tie *STDOUT, 'IO::Catch', '_STDOUT_' or die $!;
8
9 # Disable all ReadLine functionality
10 $ENV{PERL_RL} = 0;
11 delete $ENV{PAGER}
12 if $ENV{PAGER};
13 $ENV{PERL_HTML_DISPLAY_CLASS}="HTML::Display::Dump";
14
15 use Test::More tests => 6;
16
17 use_ok('WWW::Mechanize::Shell');
18 my $s = WWW::Mechanize::Shell->new( 'test', rcfile => undef, warnings => undef );
19 isa_ok $s, 'WWW::Mechanize::Shell';
20
21 SKIP: {
22 $s->agent->{base} = 'http://example.com';
23 $s->agent->update_html(<<HTML);
24 <html>
25 <head><base href="http://example.com" />
26 <title>An HTML page</title>
27 </head>
28 <body>Some body</body>
29 </html>
30 HTML
31 $s->cmd('title');
32 chomp $_STDOUT_;
33 is($_STDOUT_,"An HTML page", "Title gets output correctly");
34
35 undef $_STDOUT_;
36 $s->agent->update_html(<<HTML);
37 <html>
38 <head><base href="http://example.com" />
39 <title></title>
40 </head>
41 <body>Some body</body>
42 </html>
43 HTML
44 $s->cmd('title');
45 chomp $_STDOUT_;
46 is($_STDOUT_,"<empty title>", "Empty title gets output correctly");
47
48 undef $_STDOUT_;
49 $s->agent->update_html(<<HTML);
50 <html>
51 <head><base href="http://example.com" />
52 <title>0</title>
53 </head>
54 <body>Some body</body>
55 </html>
56 HTML
57 $s->cmd('title');
58 chomp $_STDOUT_;
59 is($_STDOUT_,"0", "False title gets output correctly");
60
61 undef $_STDOUT_;
62 $s->agent->update_html(<<HTML);
63 <html>
64 <head><base href="http://example.com" />
65 </head>
66 <body>Some body</body>
67 </html>
68 HTML
69 $s->cmd('title');
70 chomp $_STDOUT_;
71 is($_STDOUT_,"<missing title>", "A missing title gets output correctly");
72 };