root/WWW-OpenSearch/trunk/t/10-description.t

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

perltidy

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