3 namespace Drupal\Tests\Core\Menu;
5 use Drupal\Core\Session\AccountInterface;
8 * Defines a mock implementation of a dynamic menu link used in tests only.
10 * Has a dynamic route and title. This is rather contrived, but there are valid
13 * @see \Drupal\user\Plugin\Menu\LoginLogoutMenuLink
15 class DynamicMenuLinkMock extends MenuLinkMock {
20 * @var \Drupal\Core\Session\AccountInterface
22 protected $currentUser;
25 * Sets the current user.
27 * Allows the menu link to return the right title and route.
29 * @param \Drupal\Core\Session\AccountInterface $current_user
34 public function setCurrentUser(AccountInterface $current_user) {
35 $this->currentUser = $current_user;
42 public function getTitle() {
43 if ($this->currentUser->isAuthenticated()) {
54 public function getRouteName() {
55 if ($this->currentUser->isAuthenticated()) {
66 public function getCacheContexts() {
67 return ['user.roles:authenticated'];