4 use Test::More qw/no_plan/;
10 #### Generate some number of RT accounts. Come up with random
11 #### usernames if requested, otherwise use provided ones. Take
12 #### $subdomain argument so that we can generate customer accounts,
13 #### etc. Group memberships should also be provided.
19 This subroutine creates a number of RT users, if they don't already
20 exist, and places them in the specified group. It also creates the
21 group if it needs to. Returns a ref to a list containing the user
24 If a list of names is specified, users with those names are created.
25 Otherwise, it will make names up, checking to be sure that a user with
26 the random name does not yet exist. Each user will have an email
27 address in "example.com".
29 Takes a hash of the following arguments:
30 number => How many users to create. Default is 1.
31 names => A ref to a list of usernames to use. Optional.
32 subdomain => The subdomain of example.com which should be used for
34 group => The name of the group these users should belong to. Creates
35 the group if it does not yet exist.
36 privileged => Whether the users should be able to be granted rights.
38 attributes => a ref to a list of hashrefs containing the arguments for
39 any unsupported attribute we should add to the user (for example, a
47 my %ARGS = (number => 1,
51 my $lorem = Text::Lorem->new();
57 @usernames = @{$ARGS{'users'}};
60 @usernames = split(/\s+/, $lorem->words($ARGS{'number'}));
64 my $domain = 'example.com';
65 $domain = $ARGS{'subdomain'} . ".$domain" if $ARGS{'subdomain'};
67 foreach my $user (@usernames) {
68 my $user_obj = RT::User->new($RT::SystemUser);
69 $user_obj->Load($user);
70 if ($user_obj->Id() && !$anon) {
71 # Use this user; assume we know what we're doing. Don't
72 # modify it, other than adding it to any group specified.
73 push(@users_returned, $user_obj);
74 } elsif ($user_obj->Id()) {
75 # Oops. Get a different username and stick it on the back
77 append(@users, $lorem->words(1));
79 $user_obj->Create(Name => $user,
80 Password => $user."pass",
81 EmailAddress => $user.'@'.$domain,
82 RealName => "$user ipsum",
83 Privileged => $ARGS{'privileged'},
85 push(@users_returned, $user_obj);
89 # Now we have our list of users. Did we have groups to add them
92 if ($ARGS{'groups'}) {
93 my @groups = @{$ARGS{'groups'}};
94 foreach my $group (@groups) {
95 my $group_obj = RT::Group->new();
96 $group_obj->LoadUserDefinedGroup($group);
97 unless ($group_obj->Id()) {
99 $group_obj->CreateUserDefinedGroup(
101 Description => "lorem defined group $group",
104 foreach (@users_returned) {
105 $group_obj->AddMember($_->Id);
110 # Do we have attributes to apply to the users?
111 if ($ARGS{'attributes'}) {
112 foreach my $attrib (@{$ARGS{'attributes'}}) {
113 my %attr_args = %{$attrib};
114 foreach (@users_returned) {
115 $_->AddAttribute(%attr_args);
120 # Return our list of users.
121 return \@users_returned;
124 #### Generate any RT groups. These ought to be named, by function.
125 #### The group names should be given either as part of user creation,
126 #### or as a name with a number of subgroups which should be members.
129 #### Generate some queues. Users/groups who have permissions on
130 #### queues need to be specified on this point. Permissions can be
131 #### specified by role, e.g. "client" or "staffmember" or "admin" for
132 #### each queue. If the queue should have anything special like a
133 #### custom field, say so here.
136 #### Generate some tickets and transactions.