File: request_mojo.t

package info (click to toggle)
libwww-oauth-perl 1.003-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 228 kB
  • sloc: perl: 480; makefile: 2
file content (65 lines) | stat: -rw-r--r-- 2,553 bytes parent folder | download | duplicates (5)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
use strict;
use warnings;
use utf8;
use Test::More;
use Test::Needs { 'Mojolicious' => '6.0' };

use Mojo::Content::MultiPart;
use Mojo::Message::Request;
use Mojo::Parameters;
use Mojo::URL;
use WWW::OAuth::Util 'form_urlencode';

use WWW::OAuth::Request::Mojo;

my $mojo_request = Mojo::Message::Request->new;
$mojo_request->method('GET')->url->parse('http://example.com');
my $req = WWW::OAuth::Request::Mojo->new(request => $mojo_request);

is $req->method, 'GET', 'method is GET';
$req->method('POST');
is $req->method, 'POST', 'method is POST';

is $req->url, 'http://example.com', 'url is set';
$req->url('https://example.com?foo=bar');
is $req->url, 'https://example.com?foo=bar', 'url is changed';

is $req->content, '', 'content is not set';
$req->content('foo=bar&baz=1');
is $req->content, 'foo=bar&baz=1', 'content is set';

is $req->header('FooBar'), undef, 'header FooBar is not set';
$req->header(FooBar => '☃');
is $req->header('FooBar'), '☃', 'header FooBar is set';
is $req->header('FOOBAR'), '☃', 'header FOOBAR is set';
is $req->header('foobar'), '☃', 'header foobar is set';

ok !$req->content_is_form, 'content is not a form';
$req->header('content-type' => 'application/x-www-form-urlencoded');
ok $req->content_is_form, 'content is a form';
$req->header('content-type' => 'application/not-a-form');
ok !$req->content_is_form, 'content is not a form';
$req->header('Content-Type' => 'application/x-www-form-urlencoded');
ok $req->content_is_form, 'content is a form';
$req->request->content(Mojo::Content::MultiPart->new);
ok !$req->content_is_form, 'content is not a form';

is $req->header('MultiFoo'), undef, 'header MultiFoo is not set';
$req->header(MultiFoo => ['a', 'b', 'c']);
is $req->header('MultiFoo'), 'a, b, c', 'header MultiFoo has multiple values';
$req->header(MultiFoo => 'abc');
is $req->header('MultiFoo'), 'abc', 'header MultiFoo has one value';

$req->url('http://example.com');
$req->content('');

is_deeply $req->query_pairs, [], 'no query parameters';
is_deeply $req->body_pairs, [], 'no body parameters';

$req->url('http://example.com?' . form_urlencode [foo => ['☃', '❤'], '❤' => 'a b c', baz => 0, bar => '☃']);
is_deeply $req->query_pairs, ['foo', '☃', 'foo', '❤', '❤', 'a b c', 'baz', '0', 'bar', '☃'], 'URL has query parameters';

$req->content(form_urlencode [foo => ['☃', '❤'], '❤' => 'a b c', baz => 0, bar => '☃']);
is_deeply $req->body_pairs, ['foo', '☃', 'foo', '❤', '❤', 'a b c', 'baz', '0', 'bar', '☃'], 'Request has body parameters';

done_testing;