ActionDeleteTest.php in User Merge 2.x        
                          
                  
                        
  
  
  
  
  
File
  tests/src/Kernel/ActionDeleteTest.php
  
    View source  
  <?php
namespace Drupal\Tests\usermerge\Kernel;
use Drupal\user\Entity\User;
use Drupal\usermerge\Exception\UserMergeException;
class ActionDeleteTest extends ActionBase {
  
  public $action;
  
  protected function setUp() {
    parent::setUp();
    $this->action = $this->userMergeActionManager
      ->createInstance('action_delete');
  }
  
  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 testProcess() {
    $retired_id = $this->users['user3']
      ->id();
    $retained_id = $this->users['user4']
      ->id();
    $this->action
      ->process($this->users['user3'], $this->users['user4']);
    $this
      ->assertNull(User::load($retired_id));
    $this
      ->assertInstanceOf(User::class, User::load($retained_id));
  }
}