The Perl Toolchain Summit needs more sponsors. If your company depends on Perl, please support this very important event.

NAME

WWW::Shopify::Test - A subclass of WWW::Shopify which represents a testing environment.

DESCRIPTION

A WWW::Shopify object that instead of making calls to a particular URL uses a database to represent an instance of a shopify store.

In addition to providing a method to access the database, the test subclass also provides a method to generate entries in the database for testing purposes using the generate method.

EXAMPLES

Should be used as WWW::Shopify as a normal store. Prior to doing this, the object must be 'associated' with a particular store on our fake database.

It can be done like the following:

        my $db = WWW::Shopify::Model::DBIx::Schema->connect('dbi:SQLite:dbname=' . tmpnam(), { RaiseError => 1, AutoCommit => 1 });
        $db->generate([WWW::Shopify::Model::Shop]);
        my $sa = new WWW::Shopify::Test($db);
        $sa->associate_randomly();

METHODS

A bunch of methods are unique to the WWW::Shopify::Test, and not part of the normal WWW::Shopify, namely the associate methods and the generate method; they are listed here.

ASSOCIATION METHODS

associate

Takes in a Model::DBIx::Model::Shop. Associate this object with the shop, meaning that every call you make on this object will target that particular shop.

This must be called (directly or indirectly) before any calls can be made to the shop.

associate_randomly

Calls associate with a random shop from the database.

associate_unlinked

Calls associate with a shop that is NOT in the list of urls that you pass into this function.

        $SA->associate_unlinked('hostname1', 'hostname2');

associate_linked

Calls associate with a shop that is in the list of urls that you pass in to this function.

        $SA->associate_linked('hostname1', 'hostname2');

GENERATION METHODS

As of now, there's only one generation function. These functions generate objects for the underlying database.

generate

The generate method. Generates a whole ton of stuff for your database. Doesn't have to be associate with a shop; generates shops as well.

Essentially, what you want to do when you call this is pass in a list of class names (WWW::Shopify::Model:: style, not the DBIx ones) in an array, and this funciton will generate them, and if necessary their dependencies.

It'll generate 50*(:: count - 2)^2 of the class (so WWW::Shopify::Model::Product'll get 50, but there'll be 200 WWW::Shopify::Model::Product::Variants)

WWW::Shopify::Model::Shop is a special case, that's set to 6, basically for lulz.

Calls go like so:

        $SA->generate(['WWW::Shopify::Model::Shop', 'WWW::Shopify::Model::Product']);

Note, this can take a while, depending on the speed of your computer/virtual machine. Once it's finished, you should have a nice little database full of bogus data of the proper type.

authorize_url([scope], redirect)

When the shop doesn't have an access_token, this is what you should be redirecting your client to. Inputs should be your scope, as an array, and the url you want to redirect to.

exchange_token(shared_secret, code)

When you have a temporary code, which you should get from authorize_url's redirect and you want to exchange it for a token, you call this.

SEE ALSO

WWW::Shopify

AUTHOR

Adam Harrison

LICENSE

See LICENSE in the main directory.