File: page_stack.t

package info (click to toggle)
libwww-mechanize-perl 1.71-1
  • links: PTS, VCS
  • area: main
  • in suites: wheezy
  • size: 620 kB
  • sloc: perl: 3,272; makefile: 4
file content (49 lines) | stat: -rw-r--r-- 1,588 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
48
49
#!perl

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

use lib 't/local';
use LocalServer;

BEGIN {
    delete @ENV{ grep { lc eq 'http_proxy' } keys %ENV };
    delete @ENV{ qw( IFS CDPATH ENV BASH_ENV ) };
    use_ok( 'WWW::Mechanize' );
}


my $server = LocalServer->spawn;
isa_ok( $server, 'LocalServer' );

STANDARD_STACK: {
    my $mech = WWW::Mechanize->new;
    isa_ok( $mech, 'WWW::Mechanize', 'Created object' );

    is( scalar @{$mech->{page_stack}}, 0, 'Page stack starts empty' );
    ok( $mech->get($server->url)->is_success, 'Got start page' );
    is( scalar @{$mech->{page_stack}}, 0, 'Page stack starts empty' );
    $mech->_push_page_stack();
    is( scalar @{$mech->{page_stack}}, 1, 'Pushed item onto page stack' );
    $mech->_push_page_stack();
    is( scalar @{$mech->{page_stack}}, 2, 'Pushed item onto page stack' );
    $mech->back();
    is( scalar @{$mech->{page_stack}}, 1, 'Popped item from page stack' );
    $mech->back();
    is( scalar @{$mech->{page_stack}}, 0, 'Popped item from page stack' );
    $mech->back();
    is( scalar @{$mech->{page_stack}}, 0, 'Cannot pop beyond end of page stack' );
}

NO_STACK: {
    my $mech = WWW::Mechanize->new;
    isa_ok( $mech, 'WWW::Mechanize', 'Created object' );
    $mech->stack_depth(0);

    is( scalar @{$mech->{page_stack}}, 0, 'Page stack starts empty' );
    ok( $mech->get($server->url)->is_success, 'Got start page' );
    is( scalar @{$mech->{page_stack}}, 0, 'Page stack starts empty' );
    $mech->_push_page_stack();
    is( scalar @{$mech->{page_stack}}, 0, 'Pushing has no effect' );
}