ActionBlockTest.php in User Merge 2.x
File
tests/src/Kernel/ActionBlockTest.php
View source
<?php
namespace Drupal\Tests\usermerge\Kernel;
use Drupal\user\Entity\User;
use Drupal\usermerge\Exception\UserMergeException;
class ActionBlockTest extends ActionBase {
public $action;
protected function setUp() {
parent::setUp();
$this->action = $this->userMergeActionManager
->createInstance('action_block');
}
public function testDeleteAdministrationAccount() {
$this
->setExpectedException(UserMergeException::class, 'You can not retire user 1.');
$this->action
->process($this->users['user1'], $this->users['user2']);
}
public function testDeleteSelf() {
$this
->setExpectedException(UserMergeException::class, 'You can not retire self.');
$this->action
->process($this->currentUser, $this->users['user2']);
}
public function testAlreadyBlocked() {
$user2 = $this->users['user2'];
$user2
->block();
$user2
->save();
$this
->setExpectedException(UserMergeException::class, 'The retire user is already blocked.');
$this->action
->process($this->users['user2'], $this->users['user2']);
}
public function testProcess() {
$retired_id = $this->users['user3']
->id();
$retained_id = $this->users['user4']
->id();
$this->action
->process($this->users['user3'], $this->users['user4']);
$retired = User::load($retired_id);
$retained = User::load($retained_id);
$this
->assertInstanceOf(User::class, $retired);
$this
->assertInstanceOf(User::class, $retained);
$this
->assertTrue($retired
->isBlocked());
$this
->assertFalse($retained
->isBlocked());
}
}