4 use Test::More tests => 36;
6 use_ok( 'WWW::OpenSearch::Description' );
7 use_ok( 'WWW::OpenSearch::Url' );
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}&pw={startPage?}&format=rss"/>
14 </OpenSearchDescription>
17 my $osd = WWW::OpenSearch::Description->new( $description );
18 isa_ok( $osd, 'WWW::OpenSearch::Description' );
19 is( $osd->version, '1.1', 'version' );
20 is( $osd->ns, 'http://a9.com/-/spec/opensearch/1.1/', 'namespace' );
21 is( $osd->urls, 1, 'number of urls' );
23 my ( $url ) = $osd->urls;
24 isa_ok( $url, 'WWW::OpenSearch::Url' );
25 is( $url->type, 'application/rss+xml', 'content type' );
26 is( lc $url->method, 'get', 'method' );
28 'http://example.com/?q={searchTerms}&pw={startPage}&format=rss',
31 = $url->prepare_query( { searchTerms => 'x', startPage => 1 } );
32 is( $result, 'http://example.com/?q=x&pw=1&format=rss', 'prepare_query' );
36 my $description = q(<?xml version="1.0" encoding="UTF-8"?>
37 <OpenSearchDescription xmlns="http://a9.com/-/spec/opensearch/1.1/">
38 <Url type="application/rss+xml"
39 template="http://example.com/?q={searchTerms}&pw={startPage}&format=rss"/>
40 <Url type="application/atom+xml"
41 template="http://example.com/?q={searchTerms}&pw={startPage?}&format=atom"/>
44 template="https://intranet/search?format=html">
45 <Param name="s" value="{searchTerms}"/>
46 <Param name="o" value="{startIndex?}"/>
47 <Param name="c" value="{itemsPerPage?}"/>
48 <Param name="l" value="{language?}"/>
50 </OpenSearchDescription>
53 my $osd = WWW::OpenSearch::Description->new( $description );
54 isa_ok( $osd, 'WWW::OpenSearch::Description' );
55 is( $osd->urls, 3, 'number of urls' );
56 is( $osd->get_best_url, $osd->url->[ 1 ], 'get_best_url' );
59 my $url = $osd->url->[ 0 ];
60 isa_ok( $url, 'WWW::OpenSearch::Url' );
61 is( $url->type, 'application/rss+xml', 'content type' );
62 is( lc $url->method, 'get', 'method' );
64 'http://example.com/?q={searchTerms}&pw={startPage}&format=rss',
69 my $url = $osd->url->[ 1 ];
70 isa_ok( $url, 'WWW::OpenSearch::Url' );
71 is( $url->type, 'application/atom+xml', 'content type' );
72 is( lc $url->method, 'get', 'method' );
74 'http://example.com/?q={searchTerms}&pw={startPage}&format=atom',
80 my $url = $osd->url->[ 2 ];
81 isa_ok( $url, 'WWW::OpenSearch::Url' );
82 is( $url->type, 'text/html', 'content type' );
83 is( lc $url->method, 'post', 'method' );
84 is( $url->template, 'https://intranet/search?format=html',
88 { s => '{searchTerms}',
90 c => '{itemsPerPage}',
95 my ( $result, $post ) = $url->prepare_query(
103 'https://intranet/search?format=html',
104 'prepare_query (uri)'
109 { s => 'x', o => 1, c => 1, l => 'en' },
110 'prepare_query (params)'
116 my $description = q(<?xml version="1.0" encoding="UTF-8"?>
117 <OpenSearchDescription xmlns="http://a9.com/-/spec/opensearchdescription/1.0/">
118 <Url>http://www.unto.net/aws?q={searchTerms}&searchindex=Electronics&flavor=osrss&itempage={startPage}</Url>
119 </OpenSearchDescription>
122 my $osd = WWW::OpenSearch::Description->new( $description );
123 isa_ok( $osd, 'WWW::OpenSearch::Description' );
124 is( $osd->version, '1.0', 'version' );
125 is( $osd->ns, 'http://a9.com/-/spec/opensearchrss/1.0/', 'namespace' );
126 is( $osd->urls, 1, 'number of urls' );
128 my ( $url ) = $osd->urls;
129 isa_ok( $url, 'WWW::OpenSearch::Url' );
130 is( lc $url->method, 'get', 'method' );
132 'http://www.unto.net/aws?q={searchTerms}&searchindex=Electronics&flavor=osrss&itempage={startPage}',