NAME
Test::ExtDirect - An easy and convenient way to test Ext.Direct classes
SYNOPSIS
With default imports:
use Test::ExtDirect;
my $data = call_extdirect(client_class => 'My::ExtDirect::Client',
action => 'Action',
method => 'Method',
arg => { foo => 'bar' },
cookies => { bar => 'baz' });
$data = submit_extdirect(action => 'Action',
method => 'form_handler',
arg => { field1 => 'value1' });
$data = poll_extdirect();
Or:
use Test::ExtDirect qw(:all);
my $data = call(...);
$data = submit(...);
$data = poll();
DESCRIPTION
This module provides a set of utility functions for testing Ext.Direct classes. For each test script, an instance of RPC::ExtDirect::Server will be created, and requests will be made with RPC::ExtDirect::Client.
This way you can simulate actual Ext JS or Sencha Touch client code making calls, submitting forms, uploading files, or polling events. Such testing provides additional layer of insurance against Ext.Direct specific problems and errors that may otherwise creep into the codebase.
SUBROUTINES
Test::ExtDirect provides the following subroutines:
- start_server(%params)
-
Starts a new RPC::ExtDirect::Server instance. It is not necessary to call this function directly, call/submit/poll will launch a new server if it's not done yet.
- server_class
-
Specifies server class to be used instead of default RPC::ExtDirect::Server.
- other
-
Other parameters are accepted as hash and passed on to server constructor. See RPC::ExtDirect::Server for details.
Returns port number that server listens on.
- stop_server
-
Stops the server instance used for testing. Again it's not necessary to call this function explicitly, the server will be shut down when all tests are finished.
- get_extdirect_api
-
Returns Ext.Direct API published by the server as RPC::ExtDirect::Client::API object.
- call_extdirect(%params)
-
Call Ext.Direct remoting method. Parameters:
- client_class
-
Client class to use instead of default RPC::ExtDirect::Client.
- action
-
Ext.Direct Action (class) name.
- method
-
Ext.Direct Method name.
- arg
-
Method arguments; either arrayref for Methods that accept ordered arguments or hashref for Methods that request named arguments.
- ...
-
Any other parameters are passed to client constructor. See RPC::ExtDirect::Client for details.
Returns whatever data is returned by Method.
- submit_extdirect
-
Submit an Ext.Direct form request. Takes the following parameters:
- client_class, action, method, arg
-
The same as with "call_extdirect", see above.
- upload
-
Arrayref of file paths to upload with that request.
- ...
-
Any other parameters are passed to client constructor. See RPC::ExtDirect::Client for details.
Returns the data passed on by Method.
- poll_extdirect
-
Poll the server for events. Takes the following parameters:
- client_class
-
The same as with "call_extdirect", see above.
- ...
-
Any other parameters are passed to client constructor. See RPC::ExtDirect::Client for details.
Returns arrayref with event data. When there are no events ready (if you test this case), a single __NONE__ event will be returned. This is to avoid breaking Ext JS code that throws an exception if no events are returned by the server.
EXPORT
By default, the following functions are exported:
- start_server
- stop_server
- call_extdirect
- submit_extdirect
- poll_extdirect
There are short-named versions that are not exported by default to avoid collisions. They can be added with :all tag:
- call
-
Points to call_extdirect.
- submit
-
Points to submit_extdirect.
- poll
-
Points to poll_extdirect.
For each of call*, submit* and poll*, there is similarly named *_ok function that wraps its respective namesake in eval(), passing or failing additional test depending on eval() success.
DEPENDENCIES
Test::ExtDirect is dependent on the following modules: Clone, Test::More, RPC::ExtDirect::Server, RPC::ExtDirect::Client.
BUGS AND LIMITATIONS
There are no known bugs in this module. Please report problems to author, patches are welcome.
SEE ALSO
For more information on developing Ext.Direct code in Perl, see RPC::ExtDirect.
AUTHOR
Alexander Tokarev <tokarev@cpan.org>
ACKNOWLEDGEMENTS
I would like to thank IntelliSurvey, Inc for sponsoring my work on this module.
COPYRIGHT AND LICENSE
Copyright (c) 2012 by Alexander Tokarev
This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself. See "perlartistic".