Imported Upstream version 0.0602
[libwww-opensearch-perl.git] / t / 10-description.t
1 use strict;
2 use warnings;
3
4 use Test::More tests => 38;
5
6 use_ok( 'WWW::OpenSearch::Description' );
7
8 # simple 1.1 OSD
9 {
10     my $description = q(<?xml version="1.0" encoding="UTF-8"?>
11 <OpenSearchDescription xmlns="http://a9.com/-/spec/opensearch/1.1/">
12   <ShortName>Web Search</ShortName>
13   <Description>Use Example.com to search the Web.</Description>
14   <Tags>example web</Tags>
15   <Contact>admin@example.com</Contact>
16   <Url type="application/rss+xml" 
17        template="http://example.com/?q={searchTerms}&amp;pw={startPage?}&amp;format=rss"/>
18 </OpenSearchDescription>
19 );
20
21     my $osd = WWW::OpenSearch::Description->new( $description );
22     isa_ok( $osd, 'WWW::OpenSearch::Description' );
23     is( $osd->shortname, 'Web Search' );
24     ok( !defined $osd->longname );
25     is( $osd->description, 'Use Example.com to search the Web.' );
26     is( $osd->tags, 'example web' );
27     is( $osd->contact, 'admin@example.com' );
28
29     # count the urls
30     is( $osd->urls, 1 );
31 }
32
33 # complex 1.1 OSD
34 {
35     my $description = q(<?xml version="1.0" encoding="UTF-8"?>
36 <OpenSearchDescription xmlns="http://a9.com/-/spec/opensearch/1.1/">
37   <ShortName>Web Search</ShortName>
38   <Description>Use Example.com to search the Web.</Description>
39   <Tags>example web</Tags>
40   <Contact>admin@example.com</Contact>
41   <Url type="application/rss+xml"
42        template="http://example.com/?q={searchTerms}&amp;pw={startPage}&amp;format=rss"/>
43   <Url type="application/atom+xml"
44        template="http://example.com/?q={searchTerms}&amp;pw={startPage?}&amp;format=atom"/>
45   <Url type="text/html" 
46        method="post"
47        template="https://intranet/search?format=html">
48     <Param name="s" value="{searchTerms}"/>
49     <Param name="o" value="{startIndex?}"/>
50     <Param name="c" value="{itemsPerPage?}"/>
51     <Param name="l" value="{language?}"/>
52   </Url>
53   <LongName>Example.com Web Search</LongName>
54   <Image height="64" width="64" type="image/png">http://example.com/websearch.png</Image>
55   <Image height="16" width="16" type="image/vnd.microsoft.icon">http://example.com/websearch.ico</Image>
56   <Query role="example" searchTerms="cat" />
57   <Developer>Example.com Development Team</Developer>
58   <Attribution>
59     Search data &amp;copy; 2005, Example.com, Inc., All Rights Reserved
60   </Attribution>
61   <SyndicationRight>open</SyndicationRight>
62   <AdultContent>false</AdultContent>
63   <Language>en-us</Language>
64   <OutputEncoding>UTF-8</OutputEncoding>
65   <InputEncoding>UTF-8</InputEncoding>
66 </OpenSearchDescription>
67 );
68
69     my $osd = WWW::OpenSearch::Description->new( $description );
70     isa_ok( $osd, 'WWW::OpenSearch::Description' );
71     is( $osd->shortname, 'Web Search' );
72     is( $osd->longname, 'Example.com Web Search' );
73     is( $osd->description, 'Use Example.com to search the Web.' );
74     is( $osd->tags, 'example web' );
75     is( $osd->contact, 'admin@example.com' );
76     is( $osd->developer, 'Example.com Development Team' );
77     is( $osd->attribution, '
78     Search data &copy; 2005, Example.com, Inc., All Rights Reserved
79   ' );
80     is( $osd->inputencoding, 'UTF-8' );
81     is( $osd->outputencoding, 'UTF-8' );
82     is( $osd->language, 'en-us' );
83     is( $osd->adultcontent, 'false' );
84     is( $osd->syndicationright, 'open' );
85
86     TODO: {
87         local $TODO = 'Test Query and Image';
88
89         is( $osd->query, undef );
90         is( $osd->image, undef );
91     };
92
93     # count the urls
94     is( $osd->urls, 3 );
95 }
96
97 # 1.0 OSD
98 {
99     my $description = q(<?xml version="1.0" encoding="UTF-8"?>
100 <OpenSearchDescription xmlns="http://a9.com/-/spec/opensearchdescription/1.0/">
101   <Url>http://www.unto.net/aws?q={searchTerms}&amp;searchindex=Electronics
102    &amp;flavor=osrss&amp;itempage={startPage}</Url>
103   <Format>http://a9.com/-/spec/opensearchrss/1.0/</Format>
104   <ShortName>Electronics</ShortName>
105   <LongName>Amazon Electronics</LongName>
106   <Description>Search for electronics on Amazon.com.</Description>
107   <Tags>amazon electronics</Tags>
108   <Image>http://www.unto.net/search/amazon_electronics.gif</Image>
109   <SampleSearch>ipod</SampleSearch>
110   <Developer>DeWitt Clinton</Developer>
111   <Contact>dewitt@unto.net</Contact>
112   <Attribution>Product and search data &amp;copy; 2005, Amazon, Inc.,
113    All Rights Reserved</Attribution>
114   <SyndicationRight>open</SyndicationRight>
115   <AdultContent>false</AdultContent>
116 </OpenSearchDescription>
117 );
118
119     my $osd = WWW::OpenSearch::Description->new( $description );
120     isa_ok( $osd, 'WWW::OpenSearch::Description' );
121     is( $osd->shortname, 'Electronics' );
122     is( $osd->longname, 'Amazon Electronics' );
123     is( $osd->description, 'Search for electronics on Amazon.com.' );
124     is( $osd->tags, 'amazon electronics' );
125     is( $osd->contact, 'dewitt@unto.net' );
126     is( $osd->format, 'http://a9.com/-/spec/opensearchrss/1.0/' );
127     is( $osd->image, 'http://www.unto.net/search/amazon_electronics.gif' );
128     is( $osd->samplesearch, 'ipod' );
129     is( $osd->developer, 'DeWitt Clinton' );
130     is( $osd->attribution, 'Product and search data &copy; 2005, Amazon, Inc.,
131    All Rights Reserved' );
132     is( $osd->syndicationright, 'open' );
133     is( $osd->adultcontent, 'false' );
134
135     # count the urls
136     is( $osd->urls, 1 );
137 }
138