"Fossies" - the Fresh Open Source Software Archive

Member "RT-Extension-Assets-1.05/xt/lib/RT/Extension/Assets/Test.pm.in" (24 May 2013, 2327 Bytes) of package /linux/misc/RT-Extension-Assets-1.05.tar.gz:


As a special service "Fossies" has tried to format the requested text file into HTML format (style: standard) with prefixed line numbers. Alternatively you can here view or download the uninterpreted source code file.

    1 use strict;
    2 use warnings;
    3 
    4 ### after: use lib qw(@RT_LIB_PATH@);
    5 use lib qw(/opt/rt4/local/lib /opt/rt4/lib);
    6 
    7 package RT::Extension::Assets::Test;
    8 use base 'RT::Test';
    9 
   10 our @EXPORT = qw(create_catalog create_asset create_assets create_cf apply_cfs);
   11 
   12 sub import {
   13     my $class = shift;
   14     my %args  = @_;
   15 
   16     $args{'requires'} ||= [];
   17     if ( $args{'testing'} ) {
   18         unshift @{ $args{'requires'} }, 'RT::Extension::Assets';
   19     } else {
   20         $args{'testing'} = 'RT::Extension::Assets';
   21     }
   22 
   23     $class->SUPER::import( %args );
   24 
   25     require RT::Extension::Assets;
   26     require RT::Asset;
   27     __PACKAGE__->export_to_level(1);
   28 }
   29 
   30 sub diag {
   31     Test::More::diag(@_) if $ENV{TEST_VERBOSE};
   32 }
   33 
   34 sub create_catalog {
   35     my %info  = @_;
   36     my $catalog = RT::Catalog->new( RT->SystemUser );
   37     my ($id, $msg) = $catalog->Create( %info );
   38     if ($id) {
   39         diag("Created catalog #$id: " . $catalog->Name);
   40         return $catalog;
   41     } else {
   42         my $spec = join "/", map { "$_=$info{$_}" } keys %info;
   43         RT->Logger->error("Failed to create catalog ($spec): $msg");
   44         return;
   45     }
   46 }
   47 
   48 sub create_asset {
   49     my %info  = @_;
   50     my $asset = RT::Asset->new( RT->SystemUser );
   51     my ($id, $msg) = $asset->Create( %info );
   52     if ($id) {
   53         diag("Created asset #$id: " . $asset->Name);
   54         return $asset;
   55     } else {
   56         my $spec = join "/", map { "$_=$info{$_}" } keys %info;
   57         RT->Logger->error("Failed to create asset ($spec): $msg");
   58         return;
   59     }
   60 }
   61 
   62 sub create_assets {
   63     my $error = 0;
   64     for my $info (@_) {
   65         create_asset(%$info)
   66             or $error++;
   67     }
   68     return not $error;
   69 }
   70 
   71 sub create_cf {
   72     my %args = (
   73         Name        => "Test Asset CF ".($$ + rand(1024)),
   74         Type        => "FreeformSingle",
   75         LookupType  => RT::Asset->CustomFieldLookupType,
   76         @_,
   77     );
   78     my $cf = RT::CustomField->new( RT->SystemUser );
   79     my ($ok, $msg) = $cf->Create(%args);
   80     RT->Logger->error("Can't create CF: $msg") unless $ok;
   81     return $cf;
   82 }
   83 
   84 sub apply_cfs {
   85     my $success = 1;
   86     for my $cf (@_) {
   87         my ($ok, $msg) = $cf->AddToObject( RT::Catalog->new(RT->SystemUser) );
   88         if (not $ok) {
   89             RT->Logger->error("Couldn't apply CF: $msg");
   90             $success = 0;
   91         }
   92     }
   93     return $success;
   94 }
   95 
   96 1;