ReviewFormSwitcherTest.php in User Merge 2.x
File
tests/src/Unit/ReviewFormSwitcherTest.php
View source
<?php
namespace Drupal\Tests\usermerge\Unit;
use Drupal\Component\Plugin\PluginManagerBase;
use Drupal\Tests\UnitTestCase;
use Drupal\usermerge\Exception\UserMergeException;
use Drupal\usermerge\ReviewFormSwitcher;
class ReviewFormSwitcherTest extends UnitTestCase {
private $sampleDefinition;
private $reviewFormSwitcher;
public function setUp() {
parent::setUp();
$this->sampleDefinition = [
[
'review' => '\\Drupal\\usermerge\\Form\\ReviewUserForm',
'id' => 'random_id',
],
];
$property_manager = $this
->getMockBuilder(PluginManagerBase::class)
->disableOriginalConstructor()
->getMock();
$property_manager
->expects($this
->any())
->method('getDefinitions')
->willReturn($this->sampleDefinition);
$this->reviewFormSwitcher = new ReviewFormSwitcher($property_manager);
}
public function testHasNext() {
$this
->assertFalse($this->reviewFormSwitcher
->hasNext('Drupal\\usermerge\\Form\\ReviewUserForm'));
$this
->assertTrue($this->reviewFormSwitcher
->hasNext('Drupal\\usermerge\\Form\\PickAccountsForm'));
}
public function testHasPrevious() {
$this
->assertFalse($this->reviewFormSwitcher
->hasPrevious('Drupal\\usermerge\\Form\\PickAccountsForm'));
$this
->assertTrue($this->reviewFormSwitcher
->hasPrevious('Drupal\\usermerge\\Form\\ReviewUserForm'));
}
public function testGetFormFromPropertyExeption() {
$this
->expectException(UserMergeException::class);
$this->reviewFormSwitcher
->getFormFromProperty('nonExistingArrayKey');
}
public function testGetFormFromProperty() {
$return = $this->reviewFormSwitcher
->getFormFromProperty('random_id');
$this
->assertEquals($this->sampleDefinition[0]['review'], $return);
}
public function testGetPreviousProperty() {
$return = $this->reviewFormSwitcher
->getPreviousProperty('Drupal\\usermerge\\Form\\ReviewUserForm');
$this
->assertEquals('', $return);
$return = $this->reviewFormSwitcher
->getPreviousProperty('NotExisting');
$this
->assertEquals('random_id', $return);
}
public function testGetNextProperty() {
$return = $this->reviewFormSwitcher
->getNextProperty('Drupal\\usermerge\\Form\\PickAccountsForm');
$this
->assertEquals('random_id', $return);
$return = $this->reviewFormSwitcher
->getNextProperty('Drupal\\usermerge\\Form\\ReviewUserForm');
$this
->assertEquals('', $return);
}
public function testGetPropertyFromForm() {
$return = $this->reviewFormSwitcher
->getPropertyFromForm('Drupal\\usermerge\\Form\\PickAccountsForm');
$this
->assertEquals('', $return);
$return = $this->reviewFormSwitcher
->getPropertyFromForm('Drupal\\usermerge\\Form\\ReviewUserForm');
$this
->assertEquals('random_id', $return);
}
}