NAME

Test::MobileAgent - set environmental variables to mock HTTP::MobileAgent

SYNOPSIS

use Test::More;
use Test::MobileAgent ':all';
use HTTP::MobileAgent;

# Case 1: you can simply pass a vendor name in lower case.
{
  local %ENV;
  test_mobile_agent('docomo');

  my $ua = HTTP::MobileAgent->new;
  ok $ua->is_docomo;
}

# Case 2: also with some hint to be more specific.
{
  local %ENV;
  test_mobile_agent('docomo.N503');

  my $ua = HTTP::MobileAgent->new;
  ok $ua->is_docomo;
}

# Case 3: you can pass a full name of an agent.
{
  local %ENV;
  test_mobile_agent('DoCoMo/3.0/N503');

  my $ua = HTTP::MobileAgent->new;
  ok $ua->is_docomo;
}

# Case 4: you can also pass extra headers.
{
  local %ENV;
  test_mobile_agent('DoCoMo/3.0/N503',
    x_dcmguid => 'STFUWSC',
  );

  my $ua = HTTP::MobileAgent->new;
  ok $ua->is_docomo;
  ok $ua->user_id;   # STFUWSC
}

# Case 5: you need an HTTP::Headers compatible object?
my $headers = test_mobile_agent_headers('docomo.N503');
my $ua = HTTP::MobileAgent->new($headers);

# Case 6: or just a hash of environmental variables?
my %env = test_mobile_agent_env('docomo.N503');
my $req = Plack::Request->new({ %plack_env, %env });

DESCRIPTION

This module helps to test applications that use HTTP::MobileAgent. See the SYNOPSIS for usage.

METHODS

test_mobile_agent

takes an agent name and an optional hash, and sets appropriate environmental variables like HTTP_USER_AGENT. This function is exported by default.

If the optional hash has _user_id, _serial_number, or _card_id as its keys, this function tries to set corresponding HTTP::MobileAgent attributes if applicable.

test_mobile_agent_env

takes the same arguments as test_mobile_agent() and returns a hash that can be used to update %ENV.

test_mobile_agent_headers

takes the same arguments as test_mobile_agent() and returns a HTTP::Headers compatible object.

test_mobile_agent_list

takes a carrier name, and returns a list of known agent names.

TO DO

This can be a bit more powerful if you can pass something like an asset file of Moxy to configure.

SEE ALSO

HTTP::MobileAgent, Moxy

REPOSITORY

I am not a heavy user of mobile phones nor HTTP::MobileAgent. Patches are always welcome :)

http://github.com/charsbar/test-mobileagent

AUTHOR

Kenichi Ishigaki, <ishigaki@cpan.org>

COPYRIGHT AND LICENSE

Copyright (C) 2009 by Kenichi Ishigaki.

This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself.