File: id_exists.t

package info (click to toggle)
libtest-www-mechanize-perl 1.52-1
  • links: PTS, VCS
  • area: main
  • in suites: buster
  • size: 372 kB
  • sloc: perl: 2,570; makefile: 4
file content (56 lines) | stat: -rw-r--r-- 1,425 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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
#!perl -T

use strict;
use warnings;

use Test::More tests => 23;
use Test::Builder::Tester;

use Test::WWW::Mechanize ();

use URI::file ();

my @valid_ids = ( 'user-block', 'name', 'address' );
my @invalid_ids = ( 'bingo', 'bongo' );

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

my $uri = URI::file->new_abs( 't/id_exists.html' )->as_string;
$mech->get_ok( $uri );

for my $id ( @valid_ids ) {
    ok( $mech->id_exists( $id ), "$id found" );
    $mech->id_exists_ok( $id );
    $mech->ids_exist_ok( [$id] );
}
for my $id ( @invalid_ids ) {
    ok( !$mech->id_exists( $id ), "$id not found" );
    $mech->lacks_id_ok( $id );
    $mech->lacks_ids_ok( [$id] );
}

$mech->ids_exist_ok( [@valid_ids], 'Valid IDs found' );
$mech->lacks_ids_ok( [@invalid_ids], 'Valid IDs found' );


# Now test output specifics.
# id_exists_ok
test_out( 'not ok 1 - ID "bongo" should exist' );
test_fail( +1 );
$mech->id_exists_ok( 'bongo' );
test_test( 'Proper id_exists_ok results for nonexistent ID' );

# lacks_id_ok
test_out( 'not ok 1 - ID "name" should not exist' );
test_fail( +1 );
$mech->lacks_id_ok( 'name' );
test_test( 'Proper lacks_id_ok results for ID that is there' );


# Now go get a new page and do tests again.
$mech->update_html( '<html><body><p id="boring">Very boring page</p></body></html' );
$mech->id_exists_ok( 'boring' );
$mech->lacks_ids_ok( [@valid_ids, @invalid_ids] );

exit 0