diff --git a/src/Session/MetadataBag.php b/src/Session/MetadataBag.php index f22b0c8..fa447a7 100644 --- a/src/Session/MetadataBag.php +++ b/src/Session/MetadataBag.php @@ -15,7 +15,7 @@ class MetadataBag extends CoreMetadataBag { /** * The key used to store the masquerading user ID in the session. */ - const MASQUERADE = 'masquerade'; + const MASQUERADE = 'masquerading'; /** * Sets the masquerading identifier. diff --git a/tests/src/Functional/MasqueradeTest.php b/tests/src/Functional/MasqueradeTest.php index 1a82ec5..05db341 100644 --- a/tests/src/Functional/MasqueradeTest.php +++ b/tests/src/Functional/MasqueradeTest.php @@ -13,7 +13,7 @@ class MasqueradeTest extends MasqueradeWebTestBase { * Tests masquerade user links. */ public function testMasquerade() { - $original_last_access = $this->getLastAccess($this->auth_user); + $original_last_access = $this->auth_userget->getLastAccessedTime(); $this->drupalLogin($this->admin_user); @@ -48,7 +48,7 @@ class MasqueradeTest extends MasqueradeWebTestBase { // Verify that masquerading as $auth_user did not change the last login // time. - $new_last_access = $this->getLastAccess($this->auth_user); + $new_last_access = $this->auth_user->getLastAccessedTime(); $this->assertEquals($original_last_access, $new_last_access, 'Last access timestamp for impersonated user was not changed.'); } diff --git a/tests/src/Functional/MasqueradeWebTestBase.php b/tests/src/Functional/MasqueradeWebTestBase.php index b221bd6..cc43a61 100644 --- a/tests/src/Functional/MasqueradeWebTestBase.php +++ b/tests/src/Functional/MasqueradeWebTestBase.php @@ -293,20 +293,4 @@ abstract class MasqueradeWebTestBase extends BrowserTestBase { return Crypt::hmacBase64($value, $seed . $private_key . Settings::getHashSalt()); } - /** - * Gets the last access timestamp for a given account. - * - * @param AccountInterface $account - * Account for which to look up the last access timestamp. - * - * @return int - * Timestamp for the last time that account accessed the site. - */ - protected function getLastAccess(AccountInterface $account) { - return \Drupal::database() - ->query("SELECT access FROM {users_field_data} WHERE uid = :uid", [ - ':uid' => $account->id(), - ])->fetchColumn(); - } - } diff --git a/tests/src/Kernel/ServiceDecoratorsTest.php b/tests/src/Kernel/ServiceDecoratorsTest.php new file mode 100644 index 0000000..9bd7601 --- /dev/null +++ b/tests/src/Kernel/ServiceDecoratorsTest.php @@ -0,0 +1,58 @@ +getMetadataBag(); + $this->assertTrue(method_exists($bag, 'setMasquerade')); + $this->assertTrue(method_exists($bag, 'getMasquerade')); + $this->assertTrue(method_exists($bag, 'clearMasquerade')); + + $this->assertNull($bag->getMasquerade()); + $uid = '1000'; + $bag->setMasquerade($uid); + $this->assertIdentical($bag->getMasquerade(), $uid); + $uid = '1'; + $bag->setMasquerade($uid); + $this->assertIdentical($bag->getMasquerade(), $uid); + $bag->clearMasquerade(); + $this->assertNull($bag->getMasquerade()); + } + + /** + * Tests the MasqueradeUserRequestSubscriber methods. + * + * @covers \Drupal\masquerade\EventSubscriber\MasqueradeUserRequestSubscriber::setMasquerade + */ + public function testGetFacetsByFacetSourceId() { + /** @var \Drupal\masquerade\EventSubscriber\MasqueradeUserRequestSubscriber $service */ + $service = \Drupal::service('user_last_access_subscriber'); + $this->assertTrue(method_exists($service, 'setMasquerade')); + } + +}