diff --git a/masquerade.links.menu.yml b/masquerade.links.menu.yml index 65a48d02..22190e60 100644 --- a/masquerade.links.menu.yml +++ b/masquerade.links.menu.yml @@ -4,3 +4,4 @@ masquerade.unmasquerade: description: 'Switch back to your user account.' route_name: masquerade.unmasquerade weight: -50 + class: \Drupal\masquerade\Plugin\Menu\UnmasqueradeMenuLink diff --git a/src/Plugin/Menu/UnmasqueradeMenuLink.php b/src/Plugin/Menu/UnmasqueradeMenuLink.php new file mode 100644 index 000000000..5b3936c38 --- /dev/null +++ b/src/Plugin/Menu/UnmasqueradeMenuLink.php @@ -0,0 +1,21 @@ +isMasquerading()) { + return 'Unmasquerade'; + } + else { + return ''; + } + } + +} diff --git a/tests/src/Functional/MasqueradeAccessTest.php b/tests/src/Functional/MasqueradeAccessTest.php index b04960f3..715366ec 100644 --- a/tests/src/Functional/MasqueradeAccessTest.php +++ b/tests/src/Functional/MasqueradeAccessTest.php @@ -110,7 +110,7 @@ public function testAccess() { $this->submitForm($edit, 'Switch'); $this->assertSession() ->responseContains($this->t('You cannot masquerade as yourself. Please choose a different user to masquerade as.')); - $this->assertSession()->pageTextNotContains('Unmasquerade'); + $this->assertSession()->pageTextNotContains('Switch back to your user account.'); // Basic 'masquerade' permission check. $this->drupalLogin($this->auth_user); @@ -136,7 +136,7 @@ protected function assertCanMasqueradeAs(AccountInterface $target_account) { ->responseNotContains($this->t('You are not allowed to masquerade as %name.', [ '%name' => $target_account->getDisplayName(), ])); - $this->clickLink('Unmasquerade'); + $this->unmasquerade($this->auth_user); } /** @@ -158,7 +158,7 @@ protected function assertCanNotMasqueradeAs(AccountInterface $target_account) { ->responseContains($this->t('You are not allowed to masquerade as %name.', [ '%name' => $target_account->getDisplayName(), ])); - $this->assertSession()->pageTextNotContains('Unmasquerade'); + $this->assertSession()->pageTextNotContains('Switch back to your user account.'); } } diff --git a/tests/src/Functional/MasqueradeWebTestBase.php b/tests/src/Functional/MasqueradeWebTestBase.php index 146527dc..ad20c6f0 100644 --- a/tests/src/Functional/MasqueradeWebTestBase.php +++ b/tests/src/Functional/MasqueradeWebTestBase.php @@ -5,6 +5,7 @@ use Drupal\Component\Render\FormattableMarkup; use Drupal\Component\Utility\Crypt; use Drupal\Core\Session\AccountInterface; +use Drupal\Core\Url; use Drupal\Core\Site\Settings; use Drupal\Core\StringTranslation\StringTranslationTrait; use Drupal\Tests\block\Functional\AssertBlockAppearsTrait; @@ -208,13 +210,9 @@ protected function masqueradeAs(AccountInterface $account) { */ protected function unmasquerade(AccountInterface $account) { $this->drupalGet('user/' . $account->id()); - $this->clickLink('Unmasquerade'); - //$this->drupalGet('unmasquerade', [ - // 'query' => [ - // 'token' => $this->drupalGetToken('unmasquerade'), - // ], - //]); - //$this->assertSession()->statusCodeEquals(200); + //$this->clickLink('Unmasquerade'); + $this->drupalGet(Url::fromRoute('masquerade.unmasquerade')->toString()); + $this->assertSession()->statusCodeEquals(200); $this->assertSession() ->pageTextContains('You are no longer masquerading as ' . $account->label());