1use strict; 2use warnings; 3 4use RT::Test::Assets tests => undef; 5 6RT->Config->Set("CustomFieldGroupings", 7 "RT::Asset" => { 8 Dates => [qw(Purchased)], 9 }, 10); 11 12my $catalog = create_catalog( Name => "Office" ); 13ok $catalog->id, "Created Catalog"; 14 15my $purchased = create_cf( Name => 'Purchased', Pattern => '(?#Year)^(?:19|20)\d{2}$' ); 16ok $purchased->id, "Created CF"; 17 18my $height = create_cf( Name => 'Height', Pattern => '(?#Inches)^\d+"?$' ); 19ok $height->id, "Created CF"; 20 21my $material = create_cf( Name => 'Material' ); 22ok $material->id, "Created CF"; 23 24my %CF = ( 25 Height => ".CF-" . $height->id . "-Edit", 26 Material => ".CF-" . $material->id . "-Edit", 27 Purchased => ".CF-" . $purchased->id . "-Edit", 28); 29 30my ($base, $m) = RT::Test::Assets->started_ok; 31ok $m->login, "Logged in agent"; 32 33diag "Create basic asset (no CFs)"; 34{ 35 $m->follow_link_ok({ id => "assets-create" }, "Asset create link"); 36 $m->submit_form_ok({ with_fields => { Catalog => $catalog->id } }, "Picked a catalog"); 37 $m->submit_form_ok({ 38 with_fields => { 39 id => 'new', 40 Name => 'Thinkpad T420s', 41 Description => 'A laptop', 42 }, 43 }, "submited create form"); 44 $m->content_like(qr/Asset .* created/, "Found created message"); 45 my ($id) = $m->uri =~ /id=(\d+)/; 46 47 my $asset = RT::Asset->new( RT->SystemUser ); 48 $asset->Load($id); 49 is $asset->id, $id, "id matches"; 50 is $asset->Name, "Thinkpad T420s", "Name matches"; 51 is $asset->Description, "A laptop", "Description matches"; 52} 53 54diag "Create with CFs"; 55{ 56 ok apply_cfs($height, $material), "Applied CFs"; 57 58 $m->follow_link_ok({ id => "assets-create" }, "Asset create link"); 59 $m->submit_form_ok({ with_fields => { Catalog => $catalog->id } }, "Picked a catalog"); 60 61 ok $m->form_with_fields(qw(id Name Description)), "Found form"; 62 $m->submit_form_ok({ 63 fields => { 64 id => 'new', 65 Name => 'Standing desk', 66 $CF{Height} => 'forty-six inches', 67 $CF{Material} => 'pine', 68 }, 69 }, "submited create form"); 70 $m->content_unlike(qr/Asset .* created/, "Lacks created message"); 71 $m->content_like(qr/must match .*?Inches/, "Found validation error"); 72 73 # Intentionally fix only the invalid CF to test the other fields are 74 # preserved across errors 75 ok $m->form_with_fields(qw(id Name Description)), "Found form again"; 76 $m->set_fields( $CF{Height} => '46"' ); 77 $m->submit_form_ok({}, "resubmitted form"); 78 79 $m->content_like(qr/Asset .* created/, "Found created message"); 80 my ($id) = $m->uri =~ /id=(\d+)/; 81 82 my $asset = RT::Asset->new( RT->SystemUser ); 83 $asset->Load($id); 84 is $asset->id, $id, "id matches"; 85 is $asset->FirstCustomFieldValue('Height'), '46"', "Found height"; 86 is $asset->FirstCustomFieldValue('Material'), 'pine', "Found material"; 87} 88 89diag "Create with CFs in other groups"; 90{ 91 ok apply_cfs($purchased), "Applied CF"; 92 93 $m->follow_link_ok({ id => "assets-create" }, "Asset create link"); 94 $m->submit_form_ok({ with_fields => { Catalog => $catalog->id } }, "Picked a catalog"); 95 96 ok $m->form_with_fields(qw(id Name Description)), "Found form"; 97 98 $m->submit_form_ok({ 99 fields => { 100 id => 'new', 101 Name => 'Chair', 102 $CF{Height} => '23', 103 }, 104 }, "submited create form"); 105 106 $m->content_like(qr/Asset .* created/, "Found created message"); 107 $m->content_unlike(qr/Purchased.*?must match .*?Year/, "Lacks validation error for Purchased"); 108} 109 110diag "Bulk update"; 111{ 112 $m->follow_link_ok( { id => 'assets-search' }, "Asset search page" ); 113 $m->submit_form_ok( { form_id => 'AssetSearch' }, "Search assets" ); 114 $m->follow_link_ok( { text => 'Bulk Update' }, "Asset bulk update page" ); 115 116 my $form = $m->form_id('BulkUpdate'); 117 my $status_input = $form->find_input('UpdateStatus'); 118 is_deeply( 119 [ sort $status_input->possible_values ], 120 [ '', 'allocated', 'deleted', 'in-use', 'new', 'recycled', 'stolen' ], 121 'Status options' 122 ); 123 # TODO: test more bulk update actions 124} 125 126# XXX TODO: test other modify pages 127 128done_testing; 129