root/WWW-OpenSearch/trunk/t/13-request.t

Revision 2407 (checked in by bricas, 13 years ago)

perltidy

Line 
1 use Test::More tests => 9;
2
3 use strict;
4 use warnings;
5
6 use_ok( 'WWW::OpenSearch::Description' );
7 use_ok( 'WWW::OpenSearch::Request' );
8
9 {
10     my $description = q(<?xml version="1.0" encoding="UTF-8"?>
11 <OpenSearchDescription xmlns="http://a9.com/-/spec/opensearch/1.1/">
12   <Url type="application/rss+xml"
13        template="http://example.com/?q={searchTerms}&amp;pw={startPage}&amp;format=rss"/>
14   <Url type="application/atom+xml"
15        template="http://example.com/?q={searchTerms}&amp;pw={startPage?}&amp;format=atom"/>
16   <Url type="text/html"
17        method="post"
18        template="https://intranet/search?format=html">
19     <Param name="s" value="{searchTerms}"/>
20     <Param name="o" value="{startIndex?}"/>
21     <Param name="c" value="{itemsPerPage?}"/>
22     <Param name="l" value="{language?}"/>
23   </Url>
24 </OpenSearchDescription>
25 );
26
27     my $osd = WWW::OpenSearch::Description->new( $description );
28
29     {
30         my $req = WWW::OpenSearch::Request->new( $osd->url->[ 2 ],
31             { searchTerms => 'iPod' } );
32         isa_ok( $req, 'WWW::OpenSearch::Request' );
33         is( lc $req->method, 'post', 'method' );
34         is( $req->uri, 'https://intranet/search?format=html', 'uri' );
35         is( $req->content, 'l=*&c=&s=iPod&o=1', 'content' );
36     }
37
38     {
39         my $req = WWW::OpenSearch::Request->new( $osd->url->[ 1 ],
40             { searchTerms => 'iPod' } );
41         isa_ok( $req, 'WWW::OpenSearch::Request' );
42         is( lc $req->method, 'get', 'method' );
43         is( $req->uri, 'http://example.com/?q=iPod&pw=1&format=atom', 'uri' );
44     }
45 }
Note: See TracBrowser for help on using the browser.