Esempio n. 1
0
 /**
  * {@inheritdoc}
  */
 public function execute()
 {
     /**
      * @var $user \Drupal\user\UserInterface
      */
     $user = $this->getContextValue('user');
     // Do nothing if user is anonymous or already blocked.
     if ($user->isAuthenticated() && $user->isActive()) {
         $user->block();
         $this->sessionManager->delete($user->id());
         // Set flag that indicates if the entity should be auto-saved later.
         $this->saveLater = TRUE;
     }
 }
Esempio n. 2
0
 /**
  * Test execute() method for blocked and anonymous users.
  *
  * @covers ::execute
  */
 public function testBlockUserWithBlockedAnonymousUser()
 {
     $user = $this->getUserMock(self::BLOCKED, self::ANONYMOUS);
     $user->block()->shouldNotBeCalled();
     $this->sessionManager->delete()->shouldNotBeCalled();
     $this->action->setContextValue('user', $user->reveal());
     $this->action->execute();
     $this->assertEquals($this->action->autoSaveContext(), [], 'Action returns nothing for auto saving since the user has not been altered.');
 }