PaymentMethodConfigurationTest.php in Payment 8.2
File
tests/src/Unit/Entity/PaymentMethodConfigurationTest.php
View source
<?php
namespace Drupal\Tests\payment\Unit\Entity;
use Drupal\Core\Config\Entity\ConfigEntityTypeInterface;
use Drupal\Core\Config\TypedConfigManagerInterface;
use Drupal\Core\Entity\EntityTypeManagerInterface;
use Drupal\payment\Entity\PaymentMethodConfiguration;
use Drupal\Tests\UnitTestCase;
use Drupal\user\UserInterface;
use Drupal\user\UserStorageInterface;
class PaymentMethodConfigurationTest extends UnitTestCase {
protected $bundle;
protected $entityTypeManager;
protected $entityTypeId;
protected $sut;
protected $typedConfigManager;
protected $userStorage;
public function setUp() : void {
$this->bundle = $this
->randomMachineName();
$this->entityTypeManager = $this
->createMock(EntityTypeManagerInterface::class);
$this->entityTypeId = $this
->randomMachineName();
$this->typedConfigManager = $this
->createMock(TypedConfigManagerInterface::class);
$this->userStorage = $this
->createMock(UserStorageInterface::class);
$this->sut = new PaymentMethodConfiguration([
'pluginId' => $this->bundle,
], $this->entityTypeId);
$this->sut
->setEntityTypeManager($this->entityTypeManager);
$this->sut
->setTypedConfig($this->typedConfigManager);
$this->sut
->setUserStorage($this->userStorage);
}
public function testBundle() {
$this
->assertSame($this->bundle, $this->sut
->bundle());
}
public function testPluginId() {
$this
->assertSame($this->bundle, $this->sut
->getPluginId());
}
public function testGetConfiguration() {
$configuration = [
$this
->randomMachineName(),
];
$this
->assertSame($this->sut, $this->sut
->setPluginConfiguration($configuration));
$this
->assertSame($configuration, $this->sut
->getPluginConfiguration());
}
public function testLabel() {
$entity_type = $this
->createMock(ConfigEntityTypeInterface::class);
$entity_type
->expects($this
->atLeastOnce())
->method('getKey')
->with('label')
->willReturn('label');
$this->entityTypeManager
->expects($this
->atLeastOnce())
->method('getDefinition')
->with($this->entityTypeId)
->willReturn($entity_type);
$label = $this
->randomMachineName();
$this
->assertSame($this->sut, $this->sut
->setLabel($label));
$this
->assertSame($label, $this->sut
->label());
}
public function testGetOwnerId() {
$id = mt_rand();
$this
->assertSame($this->sut, $this->sut
->setOwnerId($id));
$this
->assertSame($id, $this->sut
->getOwnerId());
}
public function testGetOwner() {
$owner = $this
->createMock(UserInterface::class);
$id = mt_rand();
$this->userStorage
->expects($this
->atLeastOnce())
->method('load')
->with($id)
->willReturn($owner);
$this->sut
->setOwnerId($id);
$this
->assertSame($owner, $this->sut
->getOwner());
}
public function testSetOwner() {
$id = mt_rand();
$owner = $this
->createMock(UserInterface::class);
$owner
->expects($this
->atLeastOnce())
->method('id')
->willReturn($id);
$this->sut
->setOwner($owner);
$this
->assertSame($id, $this->sut
->getOwnerId());
}
public function testId() {
$id = mt_rand();
$this
->assertSame($this->sut, $this->sut
->setId($id));
$this
->assertSame($id, $this->sut
->id());
}
public function testUuid() {
$uuid = $this
->randomMachineName();
$this
->assertSame($this->sut, $this->sut
->setUuid($uuid));
$this
->assertSame($uuid, $this->sut
->uuid());
}
public function testEntityTypeManager() {
$method = new \ReflectionMethod($this->sut, 'entityTypeManager');
$method
->setAccessible(TRUE);
$this
->assertSame($this->entityTypeManager, $method
->invoke($this->sut));
}
public function testGetTypedConfig() {
$method = new \ReflectionMethod($this->sut, 'getTypedConfig');
$method
->setAccessible(TRUE);
$this
->assertSame($this->typedConfigManager, $method
->invoke($this->sut));
}
public function testGetUserStorage() {
$method = new \ReflectionMethod($this->sut, 'getUserStorage');
$method
->setAccessible(TRUE);
$this
->assertSame($this->userStorage, $method
->invoke($this->sut));
}
}