CMS-Drupal-Modules-MembershipEntity

 view release on metacpan or  search on metacpan

t/55_term_object_functions.t  view on Meta::CPAN

#! perl
use strict;
use warnings;

BEGIN {
  ## Make sure we don't connect to our real DB if we
  ## have given the credentials for it
  $ENV{'DRUPAL_IGNORE_TEST_CREDS'} = 1;
}

use Test::More tests => 1;
use Test::Group;

use CMS::Drupal;
use CMS::Drupal::Modules::MembershipEntity;
use CMS::Drupal::Modules::MembershipEntity::Test;

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

# test the object functions

subtest 'Test a Term object', sub {

  my %params = ( 
    tid            => 666,
    mid            => 999,
    status         => 1,
    term           => '1 year',
    modifiers      => 'a:0:{}',
    start          => time - (180 * 24 * 3600), # functions are relative to "now"
    end            => time + (180 * 24 * 3600), # so test data must be, too.
    array_position => 1
  );  
 
  my $term = CMS::Drupal::Modules::MembershipEntity::Term->new( %params );
  
  isa_ok( $term, 'CMS::Drupal::Modules::MembershipEntity::Term',
    'Created a Term object ' );

  subtest 'Check static properties', sub {
    plan tests => 8;
    foreach my $prop (keys %params) {
      is( $term->{ $prop }, $params{ $prop }, $prop );
    }
  };

  subtest 'can_ok methods', sub {
    plan tests => 4;
    foreach my $method ( qw/ is_active is_current is_future was_renewal / ) {
      can_ok( $term, $method );
    }
  };

  subtest 'Validate methods', sub {
    plan tests => 16;

    is( $term->is_active, 1, 'is_active when status = 1' );
    
    for (0, 2, 3) {
      $term->{'status'} = $_;
      isnt( $term->is_active, 1, '! is_active when status = '. $_ );
    }

    my @periods = (
      [ (time - (180 * 24 * 3600)), (time + (180 * 24 * 3600)) ],



( run in 1.070 second using v1.01-cache-2.11-cpan-39bf76dae61 )