1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112
|
use strict;
use warnings;
use RT::Test tests => undef;
RT->Config->Set( 'CustomFieldGroupings',
'RT::User' => {
Identity => ['TestIdentity'],
'Access control' => ['TestAccessControl'],
Location => ['TestLocation'],
Phones => ['TestPhones'],
More => ['TestMore'],
},
);
RT->Config->PostLoadCheck;
my %CF;
my @config = @{ RT->Config->Get('CustomFieldGroupings')->{'RT::User'}{Default} };
while (my $group = shift @config) {
my $cfs = shift @config;
my $name = $cfs->[0];
my $cf = RT::CustomField->new( RT->SystemUser );
my ($id, $msg) = $cf->Create(
Name => $name,
Description => 'A custom field',
LookupType => RT::User->new( $RT::SystemUser )->CustomFieldLookupType,
Type => 'FreeformSingle',
Pattern => '^(?!bad value).*$',
);
ok $id, "custom field '$name' correctly created";
($id, $msg) = $cf->AddToObject( RT::User->new( $cf->CurrentUser ) );
ok $id, "applied custom field" or diag "error: $msg";
$group =~ s/\W//g;
$CF{$name} = "$group-" . $cf->Id;
}
my ( $baseurl, $m ) = RT::Test->started_ok;
ok $m->login, 'logged in as root';
my %location = (
Identity => ".user-info-identity",
AccessControl => ".user-info-access-control",
Location => ".user-info-location",
Phones => ".user-info-phones",
More => ".user-info-cfs",
);
{
note "testing Create";
$m->follow_link_ok({id => 'admin-users-create'}, 'Create ');
my $dom = $m->dom;
$m->form_name('UserCreate');
$m->field( 'Name', 'user1' );
my $prefix = 'Object-RT::User--CustomField:';
for my $name (keys %location) {
my $input_name = $prefix . $CF{"Test$name"} .'-Value';
is $dom->find(qq{input[name="$input_name"]})->size, 1, "only one CF input on the page";
ok $dom->at(qq{$location{$name} input[name="$input_name"]}), "CF is in the right place";
$m->field( $input_name, "Test${name}Value" );
}
$m->submit;
$m->content_like(qr{User created});
}
my ($id) = ($m->uri =~ /id=(\d+)/);
ok $id, "found user's id #$id";
{
note "testing values on Modify page and on the object";
my $user = RT::User->new( RT->SystemUser );
$user->Load( $id );
ok $user->id, "loaded user";
my $dom = $m->dom;
$m->form_name('UserModify');
my $prefix = "Object-RT::User-$id-CustomField:";
foreach my $name ( keys %location ) {
is $user->FirstCustomFieldValue("Test$name"), "Test${name}Value",
"correct value of Test$name CF";
my $input_name = $prefix . $CF{"Test$name"} .'-Value';
is $m->value($input_name), "Test${name}Value",
"correct value in UI";
$m->field( $input_name, "Test${name}Changed" );
ok $dom->at(qq{$location{$name} input[name="$input_name"]}), "CF is in the right place";
}
$m->submit;
}
{
note "testing that update works";
my $user = RT::User->new( RT->SystemUser );
$user->Load( $id );
ok $user->id, "loaded user";
$m->form_name('UserModify');
my $prefix = "Object-RT::User-$id-CustomField:";
foreach my $name ( keys %location ) {
is $user->FirstCustomFieldValue("Test$name"), "Test${name}Changed",
"correct value of Test$name CF";
my $input = $prefix . $CF{"Test$name"} .'-Value';
is $m->value($input), "Test${name}Changed",
"correct value in UI";
}
}
done_testing;
|