Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
There are currently no tests for the actions that system.module provides. Add them.
Related issues: #714190: system_send_email_action uses $account without initializing it: It would have shown up on a test long ago. The set of tests I provide here will test that.
However, these are basically untestable until we get #601398: Simpletest does not allow assigning actions to triggers. I'll provide a beginning patch here, but since it will fail, I will wait to flesh out the rest until that goes in.
Comment | File | Size | Author |
---|---|---|---|
#52 | 721086-system-actions-tests-d7.patch | 27.61 KB | andypost |
#48 | drupal.system_actions_721086_48.patch | 26.71 KB | rfay |
#44 | drupal.system_actions_721086_44.patch | 26.12 KB | aspilicious |
#43 | drupal.system_actions_721086_43.patch | 25.85 KB | aspilicious |
#42 | drupal.system_actions_721086_42.patch | 26.17 KB | rfay |
Comments
Comment #1
rfayHere is a first run. This one tests system_message_action and system_send_mail_action.
It won't actually pass the testbot until #601398: Simpletest does not allow assigning actions to triggers lands, as without that it's not possible to assign advanced actions to triggers. It will also have assertions until #714190: system_send_email_action uses $account without initializing it lands.
When those prereqs are met we can add support for the remaining actions: system_block_ip_action and system_goto_action.
Comment #3
andypostThere is another test in #286668: Trigger "User logging in" doesn't work with Action "Forward to URL" but it depends on #601398: Simpletest does not allow assigning actions to triggers
Comment #4
rfayHere's the patch rerolled after various things have moved around. After #601398: Simpletest does not allow assigning actions to triggers lands, this should be added in. See #1.
Comment #5
andypostdoc-blocks should be formatted as proposed Doxygen formatting conventions
The first line of the block should contain a brief description of what the function does, limited to 80 characters
There should be a blank line between the @param section and @return directive.
Something wrong with brief description and need a new line after
All the above
Comment #6
forestmars CreditAttribution: forestmars commentedsubscribing.
Comment #7
andypostRe-roll with fixes for doc-block
Comment #8
andypostAnd patch
Comment #9
rfayThanks. I don't think it can pass until #714190: system_send_email_action uses $account without initializing it is committed. Or unless we comment that out for now, or something.
Comment #11
andypostThere's a bug introduced in #601398: Simpletest does not allow assigning actions to triggers
I found it when working on #403446: Increase default weight of trigger module
Most of all tests are used
Without pointing which hook is used, so I plan to file another issue
Comment #12
rfay#8: 721086-system_actions-d7.patch queued for re-testing.
Comment #14
rfayThis is andypost's #8 rerolled to please the bot. No changes made. #714190: system_send_email_action uses $account without initializing it has been committed, so maybe we can get on with this one.
Comment #16
rfayWhoops, somehow a piece of an old version of #714190: system_send_email_action uses $account without initializing it had snuck into this. Removed in this roll.
Comment #18
andypostrfay this caused by http://drupal.org/cvs?commit=346054
This path not wrong
admin/structure/taxonomy/1/addshould be something likeadmin/structure/taxonomy/tags/add
There's no IDs - it's machine readable names
Comment #19
rfayThis patch expands the scope of this issue quite a bit.
It is truly astonishing how many errors can be discovered by writing tests. Just how did I get sucked into this anyway?
Comment #20
andypost$edit is undefined
http://api.drupal.org/api/function/drupal_html_id/7 uses
$id = strtr(drupal_strtolower($id), array(' ' => '-', '_' => '-', '[' => '-', ']' => ''));
which is much faster then preg_*
EDIT: in this test only "_" is used so I recommend strtr($form_name, '_', '-')
Comment #21
rfayThis patch addresses @andypost's #20, and in addition
There's probably quite a bit left to go to clean up this stuff, but I'd rather tackle it in a follow-up. I never intended to spend the rest of my life cleaning up code that has apparently? never been executed. I wonder if all this cruft is new in D7 or if it was never executed/tested/debugged in D6... D5... D4.7?
Essentially: Every action needs to be tested, with token replacement, perhaps like the user triggers tests the system actions. The patterns that are in place here make that easier to do, but since you have to keep stopping to fix breakage, it takes a while.
Note: There is a change to drupalLogout() here that is also in #363580: OpenID login fails when in maintenance mode, so whichever one goes in second will need a reroll. Essentially, it changes from trying to do the logout in one hit to doing 'user/logout' and following with 'user'.
Comment #22
andypost@rfay patch is getting bigger, are you really sure that it'a good idea to put all trigger fixes in in one tremendous patch? Much harder to review but I'll try.
Also there are some another issues with actions/triggers
#420124: DX: Remove module actions on uninstall
#241013: Actions only trigger one action per node page load
#403446: Increase default weight of trigger module
Comment #23
andypostThis change a bit strange because it calls to user_save()
This probably could lead to circular action loop so I think it's definition and maybe implementation should be changed with
Same way as http://api.drupal.org/api/function/node_action_info/7 http://api.drupal.org/api/function/node_unpublish_action/7
Comment #24
rfayThanks, Andypost. I definitely don't want to add more. This was all an accident: All I was trying to do was write some tests. And every test uncovered a bug.
Let's not add more to this. We might have to do another omnibus one after this, but let's try to finish this one. Thanks for playing along.
Comment #25
rfayre: #23: I just went back to the old database-manipulation technique. I think you were right that the user_save() route was not right. Nice catch, and thanks for your patience with this mongo-patch.
Comment #26
andypostjust a remark about changing logout link #144538: User logout is vulnerable to CSRF
Comment #27
andypost#25: drupal.system_actions_721086_25.patch queued for re-testing.
Comment #28
andyposttests for tokens are commited #701818: Several tokens are broken, especially file tokens; test coverage of every core token
Comment #29
rfayI'm just assuming this should wait for #732542: system_goto_action breaks core APIs. Do you agree, @andypost? It seems to me there was a dependency.
Comment #30
andypost@rfay Exactly, let's wait for commit #732542: system_goto_action breaks core APIs
Comment #31
rfayI think we should probably give up on #732542: system_goto_action breaks core APIs.
I note that #655252: Custom e-mail action fails to accept token [node:author:mail] or [comment:author:mail] just went in, which probably conflicts with this.
Probably time to just finish this one.
Comment #32
rfay#25: drupal.system_actions_721086_25.patch queued for re-testing.
Comment #34
rfayReroll - See what the bot says. After the test I'll take another look to see if I did the merge right.
Comment #36
rfay#34: drupal.system_actions_721086_34.patch queued for re-testing.
Comment #38
andypostmd5 replaced with sha1 in #723802: convert to sha-256 and hmac from md5 and sha1
Comment #39
rfayI think this has it all cleaned up, with the patch rerolled properly, and using drupal_hash_base64().
If the bot thinks this is OK, I'll write an issue summary.
Comment #40
rfayIssue Summary
First and foremost, this adds badly needed tests for system actions and some user actions, and tests token replacement. However, along the way writing tests uncovered all manner of little problems. Since they were small (and perhaps have been here through several Drupal releases) it seemed worth it to just fix them here.
I do apologize for so much ending up in this patch, but the small size of the fixes, infrequent use of the features (obviously), and inability to get things done due to dependencies among the fixes argued for doing it. Even though this touches a number of areas, it doesn't make things worse and probably makes them quite a bit better for the very few Drupal instances that will ever exercise this code.
trigger_user_presave() could not present usable information in most cases because the interesting information is almost always in the $edit. Merged $edit into $account so that the expected information would be available.. Removed the trigger for user_presave() as no information was available for its use.Comment #41
aspilicious CreditAttribution: aspilicious commentedPlease reroll this once more and read the much improvement doc standards. ==> http://drupal.org/node/1354
... there should be a blank line between the @param section and @return directive. ...
... The first line of the block should contain a brief description of what the function does, limited to 80 characters, and beginning with a verb in the form "Does such and such" (third person, as in "This function does such and such", rather than second person imperative "Do such and such"). ...
Comment #42
rfay@aspilicious, it's a good thing you're on the prowl. This patch was sitting waiting during the time your campaign started. I think I fixed all instances of that issue in the two files drupal_web_test_case.php and trigger.test, which I believe is what you were seeing. That expands the scope of this patch slightly, as I've noted in the issue summary, #40.
#40 contains the issue summary for reviewers.
Comment #43
aspilicious CreditAttribution: aspilicious commented1)
After the summary we also put a newline. (Even if the sentence behind it is really short)
OR
you can place and @see generateMessageWithTokens() after the @return (with a newline)
*** I chose the second option feel free to correct ***
Found more of these:
and
2)
Even removed an unneeded newline ;)
3)
#40 Still covers the summary
*** thnx for appreciating me being anoying ;). Trigger test file looks awsome now ;) ***
Comment #44
aspilicious CreditAttribution: aspilicious commentedAfter reviewing my own patch I found another style issue.
Comment #45
andypostShould we RTBC this?
Same
I think it's a bad idea to merge $account and form values!
$edit passed to actions_do() as $content['form_values']
Comment #46
rfay@andypost, thanks for the review.
On the first two: I am torn. Commented-out code is not normal in core, but on the other hand we'll want it there in the future. I'd rather leave it, but not sure the committers will agree. I hate to lose the logic.
On merging account and form values to provide information for presave, I'm not sure that there is an option if we want to provide a presave option. Basically, without doing this, there is no information for a presave trigger. Do you have an alternate proposal? We could certainly get rid of the user presave trigger, as it's (almost) useless without any information. We can also probably rewrite it so that it's different from all the other triggers so doesn't create all the "uninitialized" warnings.
Comment #47
andypost@rfay because hook_user_presave mostly used for adding module's values to user[data] we should not merge! I think it's better to replace $account with $edit.
Comment #48
rfayAfter reading the intent of hook_user_presave() I'm convinced that it should not be an available trigger. It should just be removed. This patch removes the user_presave trigger.
This is in fact an obscure API change, but a necessary one, as there is no reason that it's a viable trigger. hook_user_presave() is usually used for adding data to the user object, which an action has no business doing (and I don't think it can, can it?)
So two changes in this patch from #44:
1. Remove the user_presave trigger
2. Remove the @todo's - They are now waiting for us in #754560-5: Messages are lost if set just prior to logout
Comment #49
rfay@andypost: Reactions?
Comment #50
andypostPatch looks solid and well tested. So I glad to RTBC but I think removing _user_presave should be discused with @fago to ensure that this does not break RULES2
Comment #51
fagoThanks, but no problem - Rules doesn't rely on the triggers at all.
This looks wrong to me, as the usual case here should be that $entity is a user account object. If not, it gets the author.
This comment doesn't really fit to user_tokens() - what is user_presave? The hook, or the removed trigger? Anyway I'd suggest writing it more generic, as there is there is no uid for any unsaved user account that's passed to token.
Comment #52
andypostRe-roll with changed comments
Because mostly it's a really user account object === user entity since #707724-13: Call them entities instead of objects
This patch removes user_presave trigger but some contrib could introduce it back So we should care about UID emptiness
Comment #53
rfayThanks, @andypost. I think we've been pretty well over this one.
The issue summary with all the nits addressed is in #40.
Comment #54
andypostAnother one is #420124: DX: Remove module actions on uninstall
Comment #55
Dries CreditAttribution: Dries commentedThis looks good to me -- extra test and some subtle but important clean-ups/fixes. Committed to CVS HEAD. Thanks all!