class ViewPaymentsByOwnerTest in Payment 8.2
@coversDefaultClass \Drupal\payment\Plugin\views\argument_validator\ViewPaymentsByOwner
@group Payment
Hierarchy
- class \Drupal\Tests\UnitTestCase extends \PHPUnit\Framework\TestCase uses PhpunitCompatibilityTrait
- class \Drupal\Tests\payment\Unit\Plugin\views\argument_validator\ViewPaymentsByOwnerTest
Expanded class hierarchy of ViewPaymentsByOwnerTest
File
- tests/
src/ Unit/ Plugin/ views/ argument_validator/ ViewPaymentsByOwnerTest.php, line 20
Namespace
Drupal\Tests\payment\Unit\Plugin\views\argument_validatorView source
class ViewPaymentsByOwnerTest extends UnitTestCase {
/**
* The current user
*
* @var \Drupal\Core\Session\AccountInterface|\PHPUnit\Framework\MockObject\MockObject
*/
protected $currentUser;
/**
* The entity type manager.
*
* @var \Drupal\Core\Entity\EntityTypeManagerInterface|\PHPUnit\Framework\MockObject\MockObject
*/
protected $entityTypeManager;
/**
* The plugin definition.
*
* @var mixed[]
*/
protected $pluginDefinition = [];
/**
* The class under test.
*
* @var \Drupal\payment\Plugin\views\argument_validator\ViewPaymentsByOwner
*/
protected $sut;
/**
* {@inheritdoc}
*/
public function setUp() : void {
$this->entityTypeManager = $this
->createMock(EntityTypeManagerInterface::class);
$this->currentUser = $this
->createMock(AccountInterface::class);
$entity_type_bundle_info = $this
->createMock(EntityTypeBundleInfoInterface::class);
$configuration = [];
$plugin_id = $this
->randomMachineName();
$this->pluginDefinition = [
'entity_type' => $this
->randomMachineName(),
];
$this->sut = new ViewPaymentsByOwner($configuration, $plugin_id, $this->pluginDefinition, $this->entityTypeManager, $entity_type_bundle_info);
$this->sut
->setCurrentUser($this->currentUser);
$options = [
'access' => FALSE,
'bundles' => [],
'multiple' => TRUE,
'operation' => NULL,
];
$view_executable = $this
->getMockBuilder(ViewExecutable::class)
->disableOriginalConstructor()
->getMock();
$display = $this
->getMockBuilder(DisplayPluginBase::class)
->disableOriginalConstructor()
->getMockForAbstractClass();
$this->sut
->init($view_executable, $display, $options);
}
/**
* @covers ::validateArgument
*/
public function xtestValidateArgumentWithoutValidEntities() {
$entity_storage = $this
->createMock(EntityStorageInterface::class);
$entity_storage
->expects($this
->atLeastOnce())
->method('loadMultiple')
->willReturn([]);
$this->entityTypeManager
->expects($this
->atLeastOnce())
->method('getStorage')
->with($this->pluginDefinition['entity_type'])
->willReturn($entity_storage);
$argument = mt_rand();
$this
->assertFalse($this->sut
->validateArgument($argument));
}
/**
* @covers ::validateArgument
*
* @dataProvider providerValidateArgument
*/
public function testValidateArgument($expected_validity, $argument, $current_user_id, array $permissions) {
$entity = $this
->createMock(EntityInterface::class);
$entity_storage = $this
->createMock(EntityStorageInterface::class);
$entity_storage
->expects($this
->atLeastOnce())
->method('loadMultiple')
->willReturn([
7 => $entity,
9 => $entity,
]);
$this->entityTypeManager
->expects($this
->atLeastOnce())
->method('getStorage')
->with($this->pluginDefinition['entity_type'])
->willReturn($entity_storage);
$this->currentUser
->expects($this
->any())
->method('id')
->willReturn($current_user_id);
$map = [];
foreach ($permissions as $permission) {
$map[] = [
$permission,
TRUE,
];
}
$this->currentUser
->expects($this
->any())
->method('hasPermission')
->willReturnMap($map);
$this
->assertSame($expected_validity, $this->sut
->validateArgument($argument));
}
/**
* Provides data to self::testValidateArgument().
*/
public function providerValidateArgument() {
return [
// Permissions to view own paymens only.
[
TRUE,
'7',
7,
[
'payment.payment.view.own',
],
],
[
FALSE,
'7+9',
7,
[
'payment.payment.view.own',
],
],
[
FALSE,
'7,9',
7,
[
'payment.payment.view.own',
],
],
[
FALSE,
'9',
7,
[
'payment.payment.view.own',
],
],
// Permissions to view any payment.
[
TRUE,
'7',
7,
[
'payment.payment.view.any',
],
],
[
TRUE,
'7+9',
7,
[
'payment.payment.view.any',
],
],
[
TRUE,
'7,9',
7,
[
'payment.payment.view.any',
],
],
// Permissions to view own and any payments.
[
TRUE,
'7',
7,
[
'payment.payment.view.any',
'payment.payment.view.own',
],
],
[
TRUE,
'7+9',
7,
[
'payment.payment.view.any',
'payment.payment.view.own',
],
],
[
TRUE,
'7,9',
7,
[
'payment.payment.view.any',
'payment.payment.view.own',
],
],
];
}
}
Members
Name![]() |
Modifiers | Type | Description | Overrides |
---|---|---|---|---|
PhpunitCompatibilityTrait:: |
public | function | Returns a mock object for the specified class using the available method. | |
PhpunitCompatibilityTrait:: |
public | function | Compatibility layer for PHPUnit 6 to support PHPUnit 4 code. | |
UnitTestCase:: |
protected | property | The random generator. | |
UnitTestCase:: |
protected | property | The app root. | 1 |
UnitTestCase:: |
protected | function | Asserts if two arrays are equal by sorting them first. | |
UnitTestCase:: |
protected | function | Mocks a block with a block plugin. | 1 |
UnitTestCase:: |
protected | function | Returns a stub class resolver. | |
UnitTestCase:: |
public | function | Returns a stub config factory that behaves according to the passed array. | |
UnitTestCase:: |
public | function | Returns a stub config storage that returns the supplied configuration. | |
UnitTestCase:: |
protected | function | Sets up a container with a cache tags invalidator. | |
UnitTestCase:: |
protected | function | Gets the random generator for the utility methods. | |
UnitTestCase:: |
public | function | Returns a stub translation manager that just returns the passed string. | |
UnitTestCase:: |
public | function | Generates a unique random string containing letters and numbers. | |
ViewPaymentsByOwnerTest:: |
protected | property | The current user | |
ViewPaymentsByOwnerTest:: |
protected | property | The entity type manager. | |
ViewPaymentsByOwnerTest:: |
protected | property | The plugin definition. | |
ViewPaymentsByOwnerTest:: |
protected | property | The class under test. | |
ViewPaymentsByOwnerTest:: |
public | function | Provides data to self::testValidateArgument(). | |
ViewPaymentsByOwnerTest:: |
public | function |
Overrides UnitTestCase:: |
|
ViewPaymentsByOwnerTest:: |
public | function | @covers ::validateArgument | |
ViewPaymentsByOwnerTest:: |
public | function | @covers ::validateArgument |