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

NAME

CMS::Drupal::Modules::MembershipEntity::Test - Exports some helper routines for testing

VERSION

version 0.96

SYNOPSIS

  use Test::More;
  use CMS::Drupal;
  use CMS::Drupal::Modules::MembershipEntity::Test qw/ build_test_db build_test_data/;

  my $drupal = CMS::Drupal->new;

  my $dbh = build_test_db( $drupal );

  my $ME = CMS::Drupal::Modules::MembershipEntity->new( dbh => $dbh );

  my $hashref = $ME->fetch_memberships;
  my $cmp_data = build_test_data;

  # or:
 
  my $hashref = $ME->fetch_memberships('1234', '5678');
  my $cmp_data = build_test_data('1234', '5678');

  is_deeply($hashref, $cmp_data, 'Data matches'); 

DESCRIPTION

Use this module when testing the CMS::Drupal::Modules::MembershipEntity modules.

METHODS

build_and_validate_test_db

This method returns a database handle ($dbh) that is connected to an in-memory SQLite database. The database is built by this method using data files that must be contained in the same directory that the calling script lives in.

The method takes one argument, which must be a $drupal object. This is because it calls $drupal->dbh() to generate its database handle, which, because we are using SQLite, contains the database inside the handle itself.

The files are:

  • test_db.sql

  • test_types.dat

  • test_memberships.dat

  • test_terms.dat

Note that this method uses Test::More and Test::Group itself to report success/failures in building the test database. So in your scipt that calls this method you should add one additional test to your plan.

build_test_db

This method does the same as the previous one except it does not run tests itself, in other words it builds the test db and the test data silently.

build_test_data

This method returns a data structure containing the Memberships as they would be returned by CMS::Drupal::Modules::MembershipEntity::fetch_memberships(). It creates the data structure by parsing the same files that were used to build in test database.

The method takes an optional single argument, which is an array containing a list of mids. Only the Memberships associated with the mids provided will be included in the data returned.

  $cmp_data = build_test_data('1234', '5678');

The data structure is a hashref of hashrefs (Membership objects, indexed by mid, containing among their attributes an array of hashrefs (Membership Term objects) ...

  '4086' => bless( {
                    'mid'       => '4086',
                    'uid'       => '12305',
                    'status'    => '1',
                    'member_id' => '01252',
                    'terms' => {
                                '4088' => bless( {
                                                  'mid'            => '4086',
                                                  'array_position' => 2,
                                                  'status'         => '1',
                                                  'modifiers'      => 'a:0:{}',
                                                  'end'            => 1448611200,
                                                  'start'          => 1354089600,
                                                  'term'           => 'import',
                                                  'tid'            => '4088'
                                                 }, 'CMS::Drupal::Modules::MembershipEntity::Term' ),
                                '3920' => bless( {
                                                  'mid'            => '4086',
                                                  'array_position' => 1,
                                                  'status'         => '0',
                                                  'modifiers'      => 'a:0:{}',
                                                  'end'            => 1403247600,
                                                  'start'          => 1308639600,
                                                  'term'           => 'import',
                                                  'tid'            => '3920'
                                                 }, 'CMS::Drupal::Modules::MembershipEntity::Term' )
                               },
                    'type' => 'membership',
                    'created'   => '1354086000',
                    'changed'   => '1400604379'
                   }, 'CMS::Drupal::Modules::MembershipEntity::Membership' ),

SEE ALSO

AUTHOR

Nick Tonkin <tonkin@cpan.org>

COPYRIGHT AND LICENSE

This software is copyright (c) 2015 by Nick Tonkin.

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