• I am developing this drupal site that has a lot of roles and with different functionality provided for users belonging to different roles.
  • During the development phase I need to create dummy user accounts belonging to these different roles to test all functionality and its separation.
  • Both the client and myself will need to use the site as users from different roles quite often to test the functionality. This means a lot of "Please login to the site as a 'manager' (or an 'executive', or a 'developer') and check foobar" kind of conversations.
  • The default way of generating user accounts with gibberish names and no passwords and the switch users block is not the most ideal way to work for this project.
  • This is why I am creating this "feature addon" as a patch on top of the current stable release of devel. This will allow you to -
    • Generate users with role based usernames and passwords
    • Allow tokens for 'role machine name' and 'count'
    • Provide you dummy user accounts with say user/pass = dev_1/dev_1 editor_1/editor_1 etc

I will submit the patch here when it is ready and I hope others with similar development use-case will find it useful. It will certainly come in handy for me in the future projects :-)

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

salvis’s picture

For Devel there is no such thing as a stable release. Devel is continuously in development, but the -dev version is usually better than any given release. Posting a patch for anything but HEAD pretty much ensures that no one will use it...

I see your use case, but requiring such a large number of roles and users that you need to use devel_generate to create them, is a very special requirement that isn't of general interest, so we will probably not accept it into the repository, but as you write, it can certainly be useful for some people.

Sumeet.Pareek’s picture

Thanks for your comment @salvis. Both things you say make sense.
- I have made the patch against the HEAD
- It is perfectly fine not to have it in the repo if this is not a popular/generic use-case.

Trying not to change (a lot) the way devel goes about generating users, adding this feature got a little quirky and I almost thought of not putting up the patch here for fear of major embarrassment. But I guess I have it close to the cleanest it could get :-)

Sumeet.Pareek’s picture

Status: Active » Needs review

This is working for me already. Will mark as fixed after a few days so others looking for something similar can find it.

srlawr’s picture

Whilst I am aware that the Devel maintainers are incredibly busy working on one of the most useful and dynamic suites of development tools for Drupal, I thought I would just throw my +1 into this issue, because there is nothing worse than just grombling silently.

I am developing a community website (not for the first time) and in order to be able to demo it to the client, it's useful to be able to stuff it with users and content. Whilst I fully appreciate content can be nothing more than basically jibberish, I do find it frustrating and a little embarrassing that the users are always called

Mr. ozCKmXxbycu5DdxhmReJwxuSRaqiBSR8HEVGWvEm ouYqGUirNhWJsDyjyiQVVkUUgvxzxJvQBe9FviEZmAKqDHyF5pKSvjg9ksJ7rWZHbhtEd5Z9fsbnhXm7

and, his friend:

Dr. BJAewXqSec4JMuTknKgs7HCuy93K9JF3Kv28FDeF izWZFn5H45xMhaLYoT6SnhzrLfupbvuUH777LdBHMbCvTBit6wjeertVncgmQwHuiB2qyyc3H9CxXom7

:D

Using this patch I was eventually able to get the user names and human names sequentially "portal user n" which was brilliant, also with valid passwords, but my hack of this patch of the original module is a little... shakey to say the least! Would it be a wildly inappropriate to "pretty please" the developers into looking at token driven key fields, or "random string length" so we can at least humorously attempt to pronounce the names?! Cheers for a great module (and patch) though.

salvis’s picture

@wikidkaka: Thank you for your patch — I hope it continues to be useful for others.

@srlawr: Thank you for your kind comments. The picture is not quite as rosy as you paint it, though. We're not toiling away at Devel all day. Devel thrives on users like you identifying functionality that you (and lots of others!) need and posting patches. Probably the most important part of the maintainer's job is to keep things out of their modules that would endanger their long-term survival (read: maintenance).

This means we'll have to judge for every proposed feature whether it has a broad enough appeal to warrant burdening the module with it now, and whether we're ready to spend part of our own lives to take that feature into the future (such as porting it to the next version of Drupal) or whether we can be confident that others will readily jump in and devote their time and energy to the cause.

For a widely used module like Devel, we must be especially picky. Lots of users means lots of new ideas, but the module cannot just keep growing indefinitely. One type of request gets special treatment though: if you can make a case that a certain hook at some strategic point would enable add-on modules to provide additional functionality/customizability, then your chances are good to get what you need.

Here this could be a drupal_alter('devel_generate_username', ...) call that would enable you to implement hook_devel_generate_username_alter() where you could customize your user names as you wish.

JacobSingh’s picture

Status: Needs review » Needs work

Quick review shows a few minor errors:

+++ b/devel_generate/devel_generate.incundefined
@@ -12,7 +12,7 @@
-function devel_create_users($num, $kill, $age = 0, $roles = array()) {

new argument should have new @param docs

+++ b/devel_generate/devel_generate.incundefined
@@ -33,23 +33,65 @@ function devel_create_users($num, $kill, $age = 0, $roles = array()) {
-      $name = devel_generate_word(mt_rand(6, 12));
-      $names[$name] = '';
+    	$roles_map = drupal_map_assoc($roles);
+    	$role_rand = NULL;
+    	// Check for patterns entered only when generated users are to be assigned to a role type.
+    	if (count($roles_map) > 1) {

indentation is not following standards

Sumeet.Pareek’s picture

Realizing your patch (especially a small one) does not follow Drupal coding standards feels like - 'No way! I had it all clean. Did you just mess it secretly?'.

Even though I have been told this patch is not a generic enough use-case to make it into devel, for the love of drupal coding practices, here is a new patch thats cleaned up, with a couple of commented dsm() calls removed too =)

Interestingly, my own patch would not apply to the 7.x-1.x HEAD or the checkout which was the HEAD when I had uploaded the earlier patch. Had to do a
git apply --whitespace=fix --reject ../devel-friendly_generated_usernames-1400840-0.patch
and then manually apply changes from one of the failed hunks.

As I did the cleanup quickly by cloning devel in /tmp directory, I thought this (http://drupal.org/project/drupalcs) could be my quick fault finder and then validator. But it threw me hundreds of coding standard violations which the project already had.

--------------------------------------------------------------------------------
FOUND 198 ERROR(S) AND 25 WARNING(S) AFFECTING 175 LINE(S)
--------------------------------------------------------------------------------
    2 | ERROR   | You must use "/**" style comments for a file comment
    2 | ERROR   | You must use "/**" style comments for a file comment
    4 | ERROR   | There must be no blank line following an inline comment
    6 | WARNING | Line exceeds 80 characters; contains 82 characters
    6 | ERROR   | There must be no blank line following an inline comment
   19 | WARNING | Format should be "* Implements hook_foo()." or "Implements
      |         | hook_foo_BAR_ID_bar() for xyz_bar()."
   24 | ERROR   | Concat operator must be surrounded by spaces
   24 | ERROR   | Concat operator must be surrounded by spaces
   26 | ERROR   | Concat operator must be surrounded by spaces
   26 | ERROR   | Concat operator must be surrounded by spaces
.
.
.
hundreds more ...

All of these seem like they could be fixed by a tool. I am just not sure which one.
Is anybody aware of one?

Sumeet.Pareek’s picture

Status: Needs work » Needs review

needs review

Status: Needs review » Needs work

The last submitted patch, devel-friendly_generated_usernames-1400840-7.patch, failed testing.

Sumeet.Pareek’s picture

Anybody? Why did the patch failed to apply? What am I missing?
* I am on the dev branch tip
* I have the changes done and doing a simple git diff


kaka@Shambhu:/tmp/devel$ git branch
* 7.x-1.x
kaka@Shambhu:/tmp/devel$ git status
# On branch 7.x-1.x
# Changes not staged for commit:
#   (use "git add <file>..." to update what will be committed)
#   (use "git checkout -- <file>..." to discard changes in working directory)
#
#	modified:   devel_generate/devel_generate.inc
#	modified:   devel_generate/devel_generate.module
#
no changes added to commit (use "git add" and/or "git commit -a")
kaka@Shambhu:/tmp/devel$ git diff > filename.patch

willzyx’s picture

Issue summary: View changes
Status: Needs work » Closed (outdated)

Closing for lack of activity. Feel free to reopen if the issue still exists