"Fossies" - the Fresh Open Source Software Archive

Member "RT-Extension-Assets-1.05/xt/collection.t" (24 May 2013, 2213 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 use lib 'xt/lib';
    5 use RT::Extension::Assets::Test tests => undef;
    6 
    7 my $user = RT::Test->load_or_create_user( Name => 'testuser' );
    8 ok $user->id, "Created user";
    9 
   10 my $catalog  = create_catalog( Name => "BPS" );
   11 ok $catalog && $catalog->id, "Created catalog";
   12 
   13 my $location = create_cf( Name => 'Location' );
   14 ok $location->id, "Created CF";
   15 ok apply_cfs($location), "Applied CF";
   16 
   17 ok(
   18     create_assets(
   19         { Name => "Thinkpad T420s", Catalog => $catalog->id, "CustomField-Location" => "Home" },
   20         { Name => "Standing desk",  Catalog => $catalog->id, "CustomField-Location" => "Office" },
   21         { Name => "Chair",          Catalog => $catalog->id, "CustomField-Location" => "Office" },
   22     ),
   23     "Created assets"
   24 );
   25 
   26 diag "Mark chair as deleted";
   27 {
   28     my $asset = RT::Asset->new( RT->SystemUser );
   29     $asset->LoadByCols( Name => "Chair" );
   30     my ($ok, $msg) = $asset->SetStatus( "deleted" );
   31     ok($ok, "Deleted the chair: $msg");
   32 }
   33 
   34 diag "Basic types of limits";
   35 {
   36     my $assets = RT::Assets->new( RT->SystemUser );
   37     $assets->Limit( FIELD => 'Name', OPERATOR => 'LIKE', VALUE => 'thinkpad' );
   38     is $assets->Count, 1, "Found 1 like thinkpad";
   39     is $assets->First->Name, "Thinkpad T420s";
   40 
   41     $assets = RT::Assets->new( RT->SystemUser );
   42     $assets->UnLimit;
   43     is $assets->Count, 2, "Found 2 total";
   44     ok((!grep { $_->Name eq "Chair" } @{$assets->ItemsArrayRef}), "No chair (disabled)");
   45 
   46     $assets = RT::Assets->new( RT->SystemUser );
   47     $assets->Limit( FIELD => 'Status', VALUE => 'deleted' );
   48     $assets->{allow_deleted_search} = 1;
   49     is $assets->Count, 1, "Found 1 deleted";
   50     is $assets->First->Name, "Chair", "Found chair";
   51 
   52     $assets = RT::Assets->new( RT->SystemUser );
   53     $assets->UnLimit;
   54     $assets->LimitCustomField(
   55         CUSTOMFIELD => $location->id,
   56         VALUE       => "Office",
   57     );
   58     is $assets->Count, 1, "Found 1 in Office";
   59     ok $assets->First, "Got record";
   60     is $assets->First->Name, "Standing desk", "Found standing desk";
   61 }
   62 
   63 diag "Test ACLs";
   64 {
   65     my $assets = RT::Assets->new( RT::CurrentUser->new($user) );
   66     $assets->UnLimit;
   67     is scalar @{$assets->ItemsArrayRef}, 0, "Found none";
   68 }
   69 
   70 done_testing;