NAME

Test::ExtDirect - An easy and convenient way to test Ext.Direct code

SYNOPSIS

With default imports:

use Test::ExtDirect;

my $data = call_extdirect_ok(
    client_class => 'My::ExtDirect::Client',
    action       => 'Action',
    method       => 'Method',
    arg          => { foo => 'bar' },
    cookies      => { bar => 'baz' }
);

$data = submit_extdirect_ok(
    action => 'Action',
    method => 'form_handler',
    arg    => { field1 => 'value1' }
);

my @events = poll_extdirect_ok();

Or:

use Test::ExtDirect qw(:all);

my $data   = call_ok(...);
$data      = submit_ok(...);
my @events = poll_ok();

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 - all without having to set up a browser testing environment.

This kind of testing provides additional layer of insurance against Ext.Direct specific problems and errors that may otherwise creep into the codebase over time.

PACKAGE INTERFACE

Test::ExtDirect provides the following public subroutines that are imported to the caller namespace by default:

start_server

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 has not been started yet.

This function is an alias to "start_server" in RPC::ExtDirect::Server::Util.

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.

This function is an alias to "stop_server" in RPC::ExtDirect::Server::Util.

maybe_start_server

Process command line options and optionally start a new Server instance.

This function is an alias to "maybe_start_server" in RPC::ExtDirect::Server::Util.

get_extdirect_api

Create a new Client instance, retrieve the Ext.Direct API published by it and return it as an RPC::ExtDirect::Client::API object. Accepts named arguments in a hash.

Parameters:

type

Optional Ext.Direct API type, defaults to 'remoting'; another possible value is 'polling'.

client_class

Optional client class to use instead of default RPC::ExtDirect::Client.

...

Any other argument is passed to the RPC::ExtDirect::Client constructor.

call_extdirect

Start a Server instance if it has not been already started, then call Ext.Direct remoting Method using a new Client instance and return the execution Result or Exception. Accepts named arguments in a hash.

See "call" in RPC::ExtDirect::Client for more information.

Parameters:

client_class

Optional 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. See more in "METHODS AND CALLING CONVENTIONS" in RPC::ExtDirect.

...

Any other parameters are passed to the Client constructor. See "new" in RPC::ExtDirect::Client for details.

call_extdirect_ok

Wrap "call_extdirect" in an eval block and pass or fail an additional test depending on whether the call was successful or not.

submit_extdirect

Start a Server instance if it has not been already started, then submit an Ext.Direct form request using a new Client instance and return the Result or Exception. Accepts named arguments in a hash.

See "submit" in RPC::ExtDirect::Client for more information.

Parameters:

client_class, action, method, arg

Same as with "call_extdirect", see above.

upload

Arrayref of file paths to upload with that request.

...

Any other parameters are passed to the Client constructor. See "new" in RPC::ExtDirect::Client for details.

submit_extdirect_ok

Wrap "submit_extdirect" in an eval block and pass or fail an additional test depending on whether the submit was successul or not.

poll_extdirect

Start a Server instance if it has not been already started, then poll it for Ext.Direct events. In list context, returns a list of event hashrefs; in scalar context, returns either an event hashref if there was only one event, or an arrayref with event hashrefs if there was more than one event. Accepts named arguments in a hash.

See "poll" in RPC::ExtDirect::Client for more information.

Parameters:

client_class

Optional client class to use instead of default RPC::ExtDirect::Client.

...

Any other parameters are passed to the Client constructor. See "new" in RPC::ExtDirect::Client for details.

poll_extdirect_ok

Wrap "poll_extdirect" in an eval block and pass or fail an additional test depending on whether the poll request was successful or not.

EXPORTS

By default, the following functions are exported:

There are shorter named aliases for these functions that are not exported by default to avoid potential collisions with similarly named functions from other modules. You can specify the :all tag to export these aliases:

use Test::ExtDirect ':all';

Here is the list of aliases:

call

Same as "call_extdirect".

call_ok

Same as "call_extdirect_ok".

submit

Same as "submit_extdirect".

submit_ok

Same as "submit_extdirect_ok".

poll

Same as "poll_extdirect".

poll_ok

Same as "poll_extdirect_ok".

SEE ALSO

This module makes heavy use of RPC::ExtDirect::Server and RPC::ExtDirect::Client.

For general information on developing Ext.Direct code in Perl, see RPC::ExtDirect.

ACKNOWLEDGEMENTS

I would like to thank IntelliSurvey, Inc for sponsoring my work on this module.

BUGS AND LIMITATIONS

At this time there are no known bugs in this module. Please report problems to the author, patches are always welcome.

Use Github tracker to open bug reports, this is the easiest and quickest way to get your issue fixed.

COPYRIGHT AND LICENSE

Copyright (c) 2012-2014 by Alex Tokarev <tokarev@cpan.org>.

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