X-Git-Url: http://erislabs.net/gitweb/?p=libwww-opensearch-perl.git;a=blobdiff_plain;f=t%2F11-url.t;h=4f90fbe32116ac62a3d4534cc5972e9405c26241;hp=44ccb818a3308df1271aa191132007796ab2f0dc;hb=c95f4fd5ac222dde8e7725ed538020fba1ae7919;hpb=d981e6304039517daa924f126bf85a9c739ecd2c diff --git a/t/11-url.t b/t/11-url.t index 44ccb81..4f90fbe 100644 --- a/t/11-url.t +++ b/t/11-url.t @@ -1,7 +1,7 @@ use strict; use warnings; -use Test::More tests => 27; +use Test::More tests => 36; use_ok( 'WWW::OpenSearch::Description' ); use_ok( 'WWW::OpenSearch::Url' ); @@ -16,13 +16,20 @@ use_ok( 'WWW::OpenSearch::Url' ); my $osd = WWW::OpenSearch::Description->new( $description ); isa_ok( $osd, 'WWW::OpenSearch::Description' ); - is( $osd->urls, 1 ); + is( $osd->version, '1.1', 'version' ); + is( $osd->ns, 'http://a9.com/-/spec/opensearch/1.1/', 'namespace' ); + is( $osd->urls, 1, 'number of urls' ); - my( $url ) = $osd->urls; + my ( $url ) = $osd->urls; isa_ok( $url, 'WWW::OpenSearch::Url' ); - is( $url->type, 'application/rss+xml' ); - is( lc $url->method, 'get' ); - is( $url->template, 'http://example.com/?q=%7BsearchTerms%7D&pw=%7BstartPage%7D&format=rss' ); + is( $url->type, 'application/rss+xml', 'content type' ); + is( lc $url->method, 'get', 'method' ); + is( $url->template->template, + 'http://example.com/?q={searchTerms}&pw={startPage}&format=rss', + 'template' ); + my $result + = $url->prepare_query( { searchTerms => 'x', startPage => 1 } ); + is( $result, 'http://example.com/?q=x&pw=1&format=rss', 'prepare_query' ); } { @@ -45,30 +52,63 @@ use_ok( 'WWW::OpenSearch::Url' ); my $osd = WWW::OpenSearch::Description->new( $description ); isa_ok( $osd, 'WWW::OpenSearch::Description' ); - is( $osd->urls, 3 ); + is( $osd->urls, 3, 'number of urls' ); + is( $osd->get_best_url, $osd->url->[ 1 ], 'get_best_url' ); { my $url = $osd->url->[ 0 ]; isa_ok( $url, 'WWW::OpenSearch::Url' ); - is( $url->type, 'application/rss+xml' ); - is( lc $url->method, 'get' ); - is( $url->template, 'http://example.com/?q=%7BsearchTerms%7D&pw=%7BstartPage%7D&format=rss' ); + is( $url->type, 'application/rss+xml', 'content type' ); + is( lc $url->method, 'get', 'method' ); + is( $url->template->template, + 'http://example.com/?q={searchTerms}&pw={startPage}&format=rss', + 'template' ); } { my $url = $osd->url->[ 1 ]; isa_ok( $url, 'WWW::OpenSearch::Url' ); - is( $url->type, 'application/atom+xml' ); - is( lc $url->method, 'get' ); - is( $url->template, 'http://example.com/?q=%7BsearchTerms%7D&pw=%7BstartPage%7D&format=atom' ); + is( $url->type, 'application/atom+xml', 'content type' ); + is( lc $url->method, 'get', 'method' ); + is( $url->template->template, + 'http://example.com/?q={searchTerms}&pw={startPage}&format=atom', + 'template' + ); } { my $url = $osd->url->[ 2 ]; isa_ok( $url, 'WWW::OpenSearch::Url' ); - is( $url->type, 'text/html' ); - is( lc $url->method, 'post' ); - is( $url->template, 'https://intranet/search?format=html' ); + is( $url->type, 'text/html', 'content type' ); + is( lc $url->method, 'post', 'method' ); + is( $url->template->template, 'https://intranet/search?format=html', + 'template' ); + is_deeply( + $url->params, + { s => '{searchTerms}', + o => '{startIndex}', + c => '{itemsPerPage}', + l => '{language}' + }, + 'params' + ); + my ( $result, $post ) = $url->prepare_query( + { searchTerms => 'x', + startIndex => '1', + itemsPerPage => 1, + language => 'en' + } + ); + is( $result, + 'https://intranet/search?format=html', + 'prepare_query (uri)' + ); + $post = { @$post }; + is_deeply( + $post, + { s => 'x', o => 1, c => 1, l => 'en' }, + 'prepare_query (params)' + ); } } @@ -81,11 +121,16 @@ use_ok( 'WWW::OpenSearch::Url' ); my $osd = WWW::OpenSearch::Description->new( $description ); isa_ok( $osd, 'WWW::OpenSearch::Description' ); - is( $osd->urls, 1 ); + is( $osd->version, '1.0', 'version' ); + is( $osd->ns, 'http://a9.com/-/spec/opensearchrss/1.0/', 'namespace' ); + is( $osd->urls, 1, 'number of urls' ); - my( $url ) = $osd->urls; + my ( $url ) = $osd->urls; isa_ok( $url, 'WWW::OpenSearch::Url' ); - is( lc $url->method, 'get' ); - is( $url->template, 'http://www.unto.net/aws?q=%7BsearchTerms%7D&searchindex=Electronics&flavor=osrss&itempage=%7BstartPage%7D' ); + is( lc $url->method, 'get', 'method' ); + is( $url->template->template, + 'http://www.unto.net/aws?q={searchTerms}&searchindex=Electronics&flavor=osrss&itempage={startPage}', + 'template' + ); }