File: clone.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 (42 lines) | stat: -rw-r--r-- 1,075 bytes parent folder | download | duplicates (3)
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
#!perl -T

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

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

my $mech = WWW::Mechanize->new();
isa_ok( $mech, 'WWW::Mechanize' );
my $clone;

INITIAL_CLONE: {
    $mech->cookie_jar->set_cookie( 1, 2, 3, '/4', '5', 6, '7', 8, 9, 10 );
    my $old_cookies = $mech->cookie_jar->as_string;

    $clone = $mech->clone();
    isa_ok( $clone, 'WWW::Mechanize' );
    my $new_cookies = $clone->cookie_jar->as_string;

    is( $old_cookies, $new_cookies, 'Cookie jar contents are the same' );
}

COOKIE_SHARING: {
    # Now see if we're still working on the same jar
    $clone->cookie_jar->set_cookie( 10, 20, 30, '/40', '50', 60, '70', 80, 90, 10 );
    my $old_cookies = $mech->cookie_jar->as_string;
    my $new_cookies = $clone->cookie_jar->as_string;

    is( $old_cookies, $new_cookies, 'Adding cookies adds to both jars' );
}

HEADERS_NOT_SHARING: {
    # headers should be independent
    $clone->add_header(foo=>'bar');
    ok(
        not($mech->{headers}{foo}),
        'Adding headers does not add to both agents',
    );
}