Imported Upstream version 0.0602
[libwww-opensearch-perl.git] / t / 11-url.t
1 use strict;
2 use warnings;
3
4 use Test::More tests => 27;
5
6 use_ok( 'WWW::OpenSearch::Description' );
7 use_ok( 'WWW::OpenSearch::Url' );
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 </OpenSearchDescription>
15 );
16
17     my $osd = WWW::OpenSearch::Description->new( $description );
18     isa_ok( $osd, 'WWW::OpenSearch::Description' );
19     is( $osd->urls, 1 );
20
21     my( $url ) = $osd->urls;
22     isa_ok( $url, 'WWW::OpenSearch::Url' );
23     is( $url->type, 'application/rss+xml' );
24     is( lc $url->method, 'get' );
25     is( $url->template, 'http://example.com/?q=%7BsearchTerms%7D&pw=%7BstartPage%7D&format=rss' );
26 }
27
28 {
29     my $description = q(<?xml version="1.0" encoding="UTF-8"?>
30 <OpenSearchDescription xmlns="http://a9.com/-/spec/opensearch/1.1/">
31   <Url type="application/rss+xml"
32        template="http://example.com/?q={searchTerms}&amp;pw={startPage}&amp;format=rss"/>
33   <Url type="application/atom+xml"
34        template="http://example.com/?q={searchTerms}&amp;pw={startPage?}&amp;format=atom"/>
35   <Url type="text/html" 
36        method="post"
37        template="https://intranet/search?format=html">
38     <Param name="s" value="{searchTerms}"/>
39     <Param name="o" value="{startIndex?}"/>
40     <Param name="c" value="{itemsPerPage?}"/>
41     <Param name="l" value="{language?}"/>
42   </Url>
43 </OpenSearchDescription>
44 );
45
46     my $osd = WWW::OpenSearch::Description->new( $description );
47     isa_ok( $osd, 'WWW::OpenSearch::Description' );
48     is( $osd->urls, 3 );
49
50     {
51         my $url = $osd->url->[ 0 ];
52         isa_ok( $url, 'WWW::OpenSearch::Url' );
53         is( $url->type, 'application/rss+xml' );
54         is( lc $url->method, 'get' );
55         is( $url->template, 'http://example.com/?q=%7BsearchTerms%7D&pw=%7BstartPage%7D&format=rss' );
56     }
57
58     {
59         my $url = $osd->url->[ 1 ];
60         isa_ok( $url, 'WWW::OpenSearch::Url' );
61         is( $url->type, 'application/atom+xml' );
62         is( lc $url->method, 'get' );
63         is( $url->template, 'http://example.com/?q=%7BsearchTerms%7D&pw=%7BstartPage%7D&format=atom' );
64     }
65
66     {
67         my $url = $osd->url->[ 2 ];
68         isa_ok( $url, 'WWW::OpenSearch::Url' );
69         is( $url->type, 'text/html' );
70         is( lc $url->method, 'post' );
71         is( $url->template, 'https://intranet/search?format=html' );
72     }
73 }
74
75 {
76     my $description = q(<?xml version="1.0" encoding="UTF-8"?>
77 <OpenSearchDescription xmlns="http://a9.com/-/spec/opensearchdescription/1.0/">
78   <Url>http://www.unto.net/aws?q={searchTerms}&amp;searchindex=Electronics&amp;flavor=osrss&amp;itempage={startPage}</Url>
79 </OpenSearchDescription>
80 );
81
82     my $osd = WWW::OpenSearch::Description->new( $description );
83     isa_ok( $osd, 'WWW::OpenSearch::Description' );
84     is( $osd->urls, 1 );
85
86     my( $url ) = $osd->urls;
87     isa_ok( $url, 'WWW::OpenSearch::Url' );
88     is( lc $url->method, 'get' );
89     is( $url->template, 'http://www.unto.net/aws?q=%7BsearchTerms%7D&searchindex=Electronics&flavor=osrss&itempage=%7BstartPage%7D' );
90 }
91