File: new.t

package info (click to toggle)
libwww-mechanize-perl 2.03-1
  • links: PTS, VCS
  • area: main
  • in suites: bullseye, sid
  • size: 988 kB
  • sloc: perl: 4,088; makefile: 6
file content (47 lines) | stat: -rw-r--r-- 1,210 bytes parent folder | download | duplicates (2)
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
#!perl -T

use warnings;
use strict;
use Test::More tests => 15;

BEGIN {
    use_ok( 'WWW::Mechanize' );
}

RES_ON_NEW: {
    my $m = WWW::Mechanize->new;
    isa_ok( $m, 'WWW::Mechanize' );

    ok( !$m->success, 'success() is false before any get' );

    my $res = $m->res;
    ok( !defined $res, 'res() is undef' );
}


NO_AGENT: {
    my $m = WWW::Mechanize->new;
    isa_ok( $m, 'WWW::Mechanize' );
    can_ok( $m, 'request' );
    like( $m->agent, qr/WWW-Mechanize/, 'Set user agent string' );
    like( $m->agent, qr/$WWW::Mechanize::VERSION/, 'Set user agent version' );

    $m->agent( 'foo/bar v1.23' );
    is( $m->agent, 'foo/bar v1.23', 'Can set the agent' );

    like( $m->_agent, qr/WWW-Mechanize/, '_agent() is static' );
}

USER_AGENT: {
    my $alias = 'Windows IE 6';
    my $m = WWW::Mechanize->new( agent => $alias );
    isa_ok( $m, 'WWW::Mechanize' );
    can_ok( $m, 'request' );
    is( $m->agent, $alias, q{Aliases don't get translated in the constructor} );

    $m->agent_alias( $alias );
    like( $m->agent, qr/^Mozilla.+compatible.+Windows/, 'Alias sets the agent' );

    $m->agent( 'ratso/bongo v.43' );
    is( $m->agent, 'ratso/bongo v.43', 'Can still set the agent' );
}