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