]> git.decadent.org.uk Git - maypole.git/blob - t/headers.t
made setting user() and session() backward compatible
[maypole.git] / t / headers.t
1 #!/usr/bin/perl -w
2 use strict;
3 use Test::More tests => 22;
4
5 require_ok('Maypole::Headers');
6 ok($Maypole::Headers::VERSION, 'defines $VERSION');
7 ok($INC{'HTTP/Headers.pm'}, 'requires HTTP::Headers');
8 ok(Maypole::Headers->isa('HTTP::Headers'), '@ISA = HTTP::Headers');
9 ok(Maypole::Headers->can('new'), 'can new()');
10 my $h = Maypole::Headers->new;
11 isa_ok($h, 'Maypole::Headers');
12
13 # set()
14 can_ok($h => 'set');
15 $h->set(hello_world => 1);
16 $h->set(JAPH => [qw(Just Another Perl Hacker!)]);
17 $h->set(Content_Type => 'text/plain', Referer => 'http://localhost/');
18
19 # get()
20 can_ok($h => 'get');
21 is($h->get('Hello-World'), 1, '... name is normalised, fetches value');
22 ok($h->get('Content_Type') eq 'text/plain'
23    && $h->get('Referer') eq 'http://localhost/',
24    '... fetches values set() in the same call');
25 is($h->get('JAPH'), 'Just, Another, Perl, Hacker!',
26    '... fetches comma-separated multiple values');
27 is($h->get('non-existant'), undef,
28    '... returns undef for non-existant header');
29
30 # push()
31 can_ok($h, 'push');
32 $h->push(japh => 'TMTOWTDI');
33 is($h->get('JAPH'), 'Just, Another, Perl, Hacker!, TMTOWTDI',
34    '... appends to a header');
35 $h->push(H2G2 => 42);
36 is($h->get('H2G2'), 42,
37    "...can be used like in place of set() if the field doesn't already exist");
38
39 # push()
40 can_ok($h, 'init');
41 $h->init(X_Server_Software => 'Maypole');
42 is($h->get('X-Server-Software'), 'Maypole',
43    "... Sets a value if it doesn't already exist");
44 $h->init(X_Server_Software => 'Maypole-XP');
45 is($h->get('X-Server-Software'), 'Maypole',
46    "... subsequent init()s don't replace previous values");
47
48 # remove()
49 can_ok($h, 'remove');
50 $h->remove('H2G2');
51 is($h->get('H2G2'), undef, 'removes a previously defined field');
52
53 # field_names()
54 can_ok($h, 'field_names');
55 is_deeply([$h->field_names],
56           [qw(Referer Content-Type Hello-World JAPH X-Server-Software)],
57           '... returns a list of field names');
58
59 # print $h->as_string;