-
-
Notifications
You must be signed in to change notification settings - Fork 825
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add ability to temporarily override logged in user
Allows api4 to specify a different acting user
- Loading branch information
Showing
4 changed files
with
115 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
<?php | ||
|
||
namespace E2E\Core; | ||
|
||
/** | ||
* Class UserOverrideTest | ||
* | ||
* Check that overriding session user behaves as expected. | ||
* | ||
* @package E2E\Core | ||
* @group e2e | ||
*/ | ||
class UserOverrideTest extends \CiviEndToEndTestCase { | ||
|
||
protected function setUp() { | ||
parent::setUp(); | ||
} | ||
|
||
protected function tearDown() { | ||
while (\CRM_Core_Session::singleton()->restoreCurrentUser()) { | ||
} | ||
} | ||
|
||
public function testOverride() { | ||
$session = \CRM_Core_Session::singleton(); | ||
$originalUser = $session::getLoggedInContactID(); | ||
$o1 = $session->overrideCurrentUser(2); | ||
$this->assertEquals(2, $session::getLoggedInContactID()); | ||
$o2 = $session->overrideCurrentUser(3); | ||
$this->assertEquals(3, $session::getLoggedInContactID()); | ||
$o3 = $session->overrideCurrentUser(4); | ||
$session->restoreCurrentUser($o2); | ||
$this->assertEquals(4, $session::getLoggedInContactID()); | ||
$session->restoreCurrentUser(); | ||
$this->assertEquals(2, $session::getLoggedInContactID()); | ||
$session->restoreCurrentUser(); | ||
$this->assertEquals($originalUser, $session::getLoggedInContactID()); | ||
} | ||
|
||
} |