class GroupRoleSynchronizerTest in Group 8
Same name and namespace in other branches
- 2.0.x tests/src/Unit/GroupRoleSynchronizerTest.php \Drupal\Tests\group\Unit\GroupRoleSynchronizerTest
Tests the outsider group role synchronizer service.
@coversDefaultClass \Drupal\group\GroupRoleSynchronizer @group group
Hierarchy
- class \Drupal\Tests\UnitTestCase extends \PHPUnit\Framework\TestCase uses PhpunitCompatibilityTrait
- class \Drupal\Tests\group\Unit\GroupRoleSynchronizerTest
Expanded class hierarchy of GroupRoleSynchronizerTest
File
- tests/
src/ Unit/ GroupRoleSynchronizerTest.php, line 19
Namespace
Drupal\Tests\group\UnitView source
class GroupRoleSynchronizerTest extends UnitTestCase {
/**
* The entity type manager.
*
* @var \Drupal\Core\Entity\EntityTypeManagerInterface|\Prophecy\Prophecy\ProphecyInterface
*/
protected $entityTypeManager;
/**
* The group role synchronizer service.
*
* @var \Drupal\group\GroupRoleSynchronizer
*/
protected $groupRoleSynchronizer;
/**
* {@inheritdoc}
*/
public function setUp() {
parent::setUp();
$this->entityTypeManager = $this
->prophesize(EntityTypeManagerInterface::class);
$this->groupRoleSynchronizer = new GroupRoleSynchronizer($this->entityTypeManager
->reveal());
}
/**
* @covers ::getGroupRoleId
*/
public function testGetGroupRoleId() {
$expected = 'foo-' . substr(md5('group_role_sync.bar'), 0, 9);
$this
->assertEquals($expected, $this->groupRoleSynchronizer
->getGroupRoleId('foo', 'bar'));
}
/**
* @covers ::getGroupRoleIdsByGroupType
* @depends testGetGroupRoleId
*/
public function testGetGroupRoleIdsByGroupType() {
$this
->setUpConfigEntityStorage('user_role', [
'bar',
'baz',
]);
$expected = [
$this->groupRoleSynchronizer
->getGroupRoleId('foo', 'bar'),
$this->groupRoleSynchronizer
->getGroupRoleId('foo', 'baz'),
];
$this
->assertEquals($expected, $this->groupRoleSynchronizer
->getGroupRoleIdsByGroupType('foo'));
}
/**
* @covers ::getGroupRoleIdsByGroupTypes
* @depends testGetGroupRoleId
*/
public function testGetGroupRoleIdsByGroupTypes() {
$this
->setUpConfigEntityStorage('user_role', [
'bar',
'baz',
]);
$expected = [
$this->groupRoleSynchronizer
->getGroupRoleId('foo', 'bar'),
$this->groupRoleSynchronizer
->getGroupRoleId('bee', 'bar'),
$this->groupRoleSynchronizer
->getGroupRoleId('foo', 'baz'),
$this->groupRoleSynchronizer
->getGroupRoleId('bee', 'baz'),
];
$this
->assertEquals($expected, $this->groupRoleSynchronizer
->getGroupRoleIdsByGroupTypes([
'foo',
'bee',
]));
}
/**
* @covers ::getGroupRoleIdsByUserRole
* @depends testGetGroupRoleId
*/
public function testGetGroupRoleIdsByUserRole() {
$this
->setUpConfigEntityStorage('group_type', [
'foo',
'bar',
]);
$expected = [
$this->groupRoleSynchronizer
->getGroupRoleId('foo', 'baz'),
$this->groupRoleSynchronizer
->getGroupRoleId('bar', 'baz'),
];
$this
->assertEquals($expected, $this->groupRoleSynchronizer
->getGroupRoleIdsByUserRole('baz'));
}
/**
* @covers ::getGroupRoleIdsByUserRoles
* @depends testGetGroupRoleId
*/
public function testGetGroupRoleIdsByUserRoles() {
$this
->setUpConfigEntityStorage('group_type', [
'foo',
'bar',
]);
$expected = [
$this->groupRoleSynchronizer
->getGroupRoleId('foo', 'baz'),
$this->groupRoleSynchronizer
->getGroupRoleId('foo', 'ook'),
$this->groupRoleSynchronizer
->getGroupRoleId('bar', 'baz'),
$this->groupRoleSynchronizer
->getGroupRoleId('bar', 'ook'),
];
$this
->assertEquals($expected, $this->groupRoleSynchronizer
->getGroupRoleIdsByUserRoles([
'baz',
'ook',
]));
}
/**
* Mock and set up a config entity type's storage handler.
*
* @param string $entity_type_id
* The ID of the config entity type to mock the storage for.
* @param string[] $entity_ids
* The IDs of the config entities to return from an entity query.
* @param \Drupal\Core\Config\Entity\ConfigEntityInterface[] $entities
* The config entities to return from a loadMultiple() call.
*/
protected function setUpConfigEntityStorage($entity_type_id, $entity_ids = [], $entities = []) {
$storage = $this
->prophesize(ConfigEntityStorageInterface::class);
if (!empty($entity_ids)) {
$query = $this
->prophesize(QueryInterface::class);
$query
->execute()
->willReturn($entity_ids);
$storage
->getQuery()
->willReturn($query
->reveal());
}
if (!empty($entities)) {
$storage
->loadMultiple(NULL)
->willReturn($entities);
$storage
->loadMultiple(array_keys($entities))
->willReturn($entities);
}
$this->entityTypeManager
->getStorage($entity_type_id)
->willReturn($storage
->reveal());
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
GroupRoleSynchronizerTest:: |
protected | property | The entity type manager. | |
GroupRoleSynchronizerTest:: |
protected | property | The group role synchronizer service. | |
GroupRoleSynchronizerTest:: |
public | function |
Overrides UnitTestCase:: |
|
GroupRoleSynchronizerTest:: |
protected | function | Mock and set up a config entity type's storage handler. | |
GroupRoleSynchronizerTest:: |
public | function | @covers ::getGroupRoleId | |
GroupRoleSynchronizerTest:: |
public | function | @covers ::getGroupRoleIdsByGroupType @depends testGetGroupRoleId | |
GroupRoleSynchronizerTest:: |
public | function | @covers ::getGroupRoleIdsByGroupTypes @depends testGetGroupRoleId | |
GroupRoleSynchronizerTest:: |
public | function | @covers ::getGroupRoleIdsByUserRole @depends testGetGroupRoleId | |
GroupRoleSynchronizerTest:: |
public | function | @covers ::getGroupRoleIdsByUserRoles @depends testGetGroupRoleId | |
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. |