I have built the ability to stash and restore sessions into the SimpleTests for the session_limit and autologout modules. Since it's now in two places I think it's probably useful to others and so should be part of the standard core SimpleTest module.
Use Case
As a Module maintainer I want to test the behaviour of my module across multiple simultaneous sessions so that I can test how actions in one session can affect the state of another.
For example, in session_limit, a limitation is placed on the number of active sessions such that a user can only have 1 active session and must be either prevented from creating a new one or logged out from the existing.
Tasks
Add stashSession and restoreSession functions to the WebTestBase class:
/**
* Initialise a new unique session.
*
* @return string
* A unique identifier for the session just stored.
*/
protected function stashSession() {}
/**
* Restore a previously stashed session.
*
* @param string $session_id
* The session to restore as returned by stashSession();
*
* @return string
* The old session id that was replaced.
*/
protected function restoreSession($session_id) {}
Comment | File | Size | Author |
---|---|---|---|
#3 | interdiff.txt | 6.77 KB | alansaviolobo |
#3 | add_multiple_session-2017545-2.patch | 6.78 KB | alansaviolobo |
#2 | SimpleTest-multi_session_tests-2017545-7526477.patch | 5.98 KB | johnennew |
#1 | SimpleTest-multi_session_tests-2017545.patch | 6 KB | johnennew |
Comments
Comment #1
johnennew CreditAttribution: johnennew commentedPlease find a Drupal 8 patch attached. This adds the sessionStash() and sessionRestore() functions to the WebTestBase class and adds a new test in Simple test to demonstrate (and test) how the functions work.
If this is of interest I, can provide backports to D7 and D6 - both are currently part of the session_limit module.
Comment #2
johnennew CreditAttribution: johnennew commentedSorry just saw #500866: [META] remove t() from assert message
New patch with unnecessary t() functions removed.
Comment #2.0
johnennew CreditAttribution: johnennew commentedAdded some more explanation and code stubs
Comment #2.1
johnennew CreditAttribution: johnennew commentedtidy spacing
Comment #3
alansaviolobo CreditAttribution: alansaviolobo commentedattempting reroll
Comment #5
jhedstromI'm not 100% certain, but I think
BrowserTestBase
, since it utilizes Mink, already has this ability.Comment #16
smustgrave CreditAttribution: smustgrave at Mobomo commentedClosing as outdated.
I agree with #5 I believe this ability is already there.
If not and still a valid request please reopen.
Thanks