File: 07ua.t

package info (click to toggle)
libhtml-html5-parser-perl 0.992-2
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, forky, sid, trixie
  • size: 1,444 kB
  • sloc: perl: 16,129; makefile: 2; sh: 1
file content (74 lines) | stat: -rw-r--r-- 1,524 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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
## skip Test::Tabs
use 5.008;
use strict;
use lib 'lib';
use lib 't/lib';

use Test::More;
use HTML::HTML5::Parser;
use HTML::HTML5::Parser::UA;
use URI::file;

{
	package Test::HTTP::Server::Request;
	sub doc1 {
		shift->{out_headers}{content_type} = 'text/html';
		q{<!doctype html>
		<title>Test!</title>
		<p>Test!</p>
		};
	}
}

eval { require Test::HTTP::Server; 1; }
	or plan skip_all => "Could not use Test::HTTP::Server: $@";

plan skip_all => "Test::HTTP::Server 0.03 fails on Win32"
	if $^O =~ /win/i
	&& Test::HTTP::Server->VERSION lt '0.04';

plan tests => 3;

my $server  = Test::HTTP::Server->new();
my $baseuri = $server->uri;

$HTML::HTML5::Parser::UA::NO_LWP = 1
	if $HTML::HTML5::Parser::UA::NO_LWP eq '0';

my $file_response = HTML::HTML5::Parser::UA->get(URI::file->new_abs("t/01basic.t"));

is(
	$file_response->{status},
	200,
	"simple file response - status 200",
);

my $http_response = HTML::HTML5::Parser::UA->get($baseuri . 'doc1');

is(
	$file_response->{status},
	200,
	"simple HTTP response - status 200",
);

my $dom = HTML::HTML5::Parser->load_html(location => $baseuri.'doc1');
is(
	$dom->getElementsByTagName('title')->shift->textContent,
	'Test!',
	'UA usage by parser',
);

=head1 PURPOSE

Check that L<HTML::HTML5::Parser::UA> works with L<HTTP::Tiny>.

=head1 AUTHOR

Toby Inkster, E<lt>tobyink@cpan.orgE<gt>

=head1 COPYRIGHT AND LICENCE

Copyright (C) 2012 by Toby Inkster

This library is free software; you can redistribute it and/or modify
it under the same terms as Perl itself.