~ubuntu-branches/ubuntu/lucid/libtest-www-mechanize-perl/lucid

« back to all changes in this revision

Viewing changes to t/link_content.t

  • Committer: Bazaar Package Importer
  • Author(s): gregor herrmann
  • Date: 2008-03-17 02:27:43 UTC
  • mfrom: (1.1.3 upstream) (2.1.1 lenny)
  • Revision ID: james.westby@ubuntu.com-20080317022743-0juvqm5dx5zo70bj
Tags: 1.20-1
* New upstream release.
* debian/copyright: update years of copyright.
* debian/rules: let install-stamp target depend on build-stamp.

Show diffs side-by-side

added added

removed removed

Lines of Context:
2
2
 
3
3
use strict;
4
4
use warnings;
5
 
use Test::More tests => 10;
 
5
use Test::More tests => 12;
6
6
use Test::Builder::Tester;
7
7
use URI::file;
8
8
 
17
17
my $server = TWMServer->new(PORT);
18
18
my $pid = $server->background;
19
19
ok( $pid, 'HTTP Server started' ) or die "Can't start the server";
 
20
# HTTP::Server::Simple->background() may return prematurely.
 
21
sleep 1;
20
22
 
21
23
sub cleanup { kill(9,$pid) if !$^S };
22
24
$SIG{__DIE__}=\&cleanup;
24
26
my $mech=Test::WWW::Mechanize->new();
25
27
isa_ok($mech,'Test::WWW::Mechanize');
26
28
 
27
 
# HTTP::Server::Simple->background() may return prematurely.
28
 
sleep 1;
29
29
$mech->get('http://localhost:'.PORT.'/goodlinks.html');
30
30
my @urls=$mech->links();
31
31
ok(@urls, 'Got links from the HTTP server');
33
33
# test regex
34
34
test_out('not ok 1 - link_content_like');
35
35
test_fail(+2);
36
 
test_diag("     'blah' doesn't look much like a regex to me.");
 
36
test_diag(q{     "blah" doesn't look much like a regex to me.});
37
37
$mech->link_content_like(\@urls,'blah','Testing the regex');
38
38
test_test('Handles bad regexs');
39
39
 
42
42
$mech->link_content_like(\@urls,qr/Test/,'Checking all page links contain: Test');
43
43
test_test('Handles All page links contents successful');
44
44
 
 
45
# like - default desc
 
46
test_out('ok 1 - ' . scalar(@urls) . ' links are like \'(?-xism:Test)\'');
 
47
$mech->link_content_like(\@urls,qr/Test/);
 
48
test_test('Handles All page links contents successful - default desc');
 
49
 
45
50
test_out('not ok 1 - Checking all page link content failures');
46
51
test_fail(+4);
47
52
test_diag('goodlinks.html');
52
57
 
53
58
# unlike
54
59
# test regex
55
 
test_out('not ok 1 - link_content_unlike'); 
 
60
test_out('not ok 1 - link_content_unlike');
56
61
test_fail(+2);
57
 
test_diag("     'blah' doesn't look much like a regex to me.");
 
62
test_diag(q{     "blah" doesn't look much like a regex to me.});
58
63
$mech->link_content_unlike(\@urls,'blah','Testing the regex');
59
64
test_test('Handles bad regexs');
60
65
 
62
67
$mech->link_content_unlike(\@urls,qr/BadTest/,'Checking all page links do not contain: BadTest');
63
68
test_test('Handles All page links unlike contents successful');
64
69
 
 
70
# unlike - default desc
 
71
test_out('ok 1 - ' . scalar(@urls) . ' links are not like "(?-xism:BadTest)"');
 
72
$mech->link_content_unlike(\@urls,qr/BadTest/);
 
73
test_test('Handles All page links unlike contents successful - default desc');
 
74
 
65
75
test_out('not ok 1 - Checking all page link unlike content failures');
66
76
test_fail(+4);
67
77
test_diag('goodlinks.html');