class RolesRidTest
Same name in other branches
- 9 core/modules/user/tests/src/Unit/Views/Argument/RolesRidTest.php \Drupal\Tests\user\Unit\Views\Argument\RolesRidTest
- 10 core/modules/user/tests/src/Unit/Views/Argument/RolesRidTest.php \Drupal\Tests\user\Unit\Views\Argument\RolesRidTest
- 11.x core/modules/user/tests/src/Unit/Views/Argument/RolesRidTest.php \Drupal\Tests\user\Unit\Views\Argument\RolesRidTest
@coversDefaultClass \Drupal\user\Plugin\views\argument\RolesRid @group user
Hierarchy
- class \Drupal\Tests\UnitTestCase extends \PHPUnit\Framework\TestCase uses \Drupal\Tests\PhpunitCompatibilityTrait
- class \Drupal\Tests\user\Unit\Views\Argument\RolesRidTest extends \Drupal\Tests\UnitTestCase
Expanded class hierarchy of RolesRidTest
File
-
core/
modules/ user/ tests/ src/ Unit/ Views/ Argument/ RolesRidTest.php, line 15
Namespace
Drupal\Tests\user\Unit\Views\ArgumentView source
class RolesRidTest extends UnitTestCase {
/**
* Tests the titleQuery method.
*
* @covers ::titleQuery
*
* @group legacy
*
* Note this is only a legacy test because it triggers a call to
* \Drupal\Core\Entity\EntityTypeInterface::getLabelCallback() which is mocked
* and triggers a deprecation error. Remove when ::getLabelCallback() is
* removed.
*/
public function testTitleQuery() {
$role1 = new Role([
'id' => 'test_rid_1',
'label' => 'test rid 1',
], 'user_role');
$role2 = new Role([
'id' => 'test_rid_2',
'label' => 'test <strong>rid 2</strong>',
], 'user_role');
// Creates a stub entity storage;
$role_storage = $this->getMockForAbstractClass('Drupal\\Core\\Entity\\EntityStorageInterface');
$role_storage->expects($this->any())
->method('loadMultiple')
->will($this->returnValueMap([
[
[],
[],
],
[
[
'test_rid_1',
],
[
'test_rid_1' => $role1,
],
],
[
[
'test_rid_1',
'test_rid_2',
],
[
'test_rid_1' => $role1,
'test_rid_2' => $role2,
],
],
]));
$entity_type = $this->createMock('Drupal\\Core\\Entity\\EntityTypeInterface');
$entity_type->expects($this->any())
->method('getKey')
->with('label')
->will($this->returnValue('label'));
$entity_type_manager = $this->createMock(EntityTypeManagerInterface::class);
$entity_type_manager->expects($this->any())
->method('getDefinition')
->with($this->equalTo('user_role'))
->will($this->returnValue($entity_type));
$entity_type_manager->expects($this->once())
->method('getStorage')
->with($this->equalTo('user_role'))
->will($this->returnValue($role_storage));
// Set up a minimal container to satisfy Drupal\Core\Entity\EntityBase's
// dependency on it.
$container = new ContainerBuilder();
$container->set('entity_type.manager', $entity_type_manager);
\Drupal::setContainer($container);
$roles_rid_argument = new RolesRid([], 'user__roles_rid', [], $entity_type_manager);
$roles_rid_argument->value = [];
$titles = $roles_rid_argument->titleQuery();
$this->assertEquals([], $titles);
$roles_rid_argument->value = [
'test_rid_1',
];
$titles = $roles_rid_argument->titleQuery();
$this->assertEquals([
'test rid 1',
], $titles);
$roles_rid_argument->value = [
'test_rid_1',
'test_rid_2',
];
$titles = $roles_rid_argument->titleQuery();
$this->assertEquals([
'test rid 1',
'test <strong>rid 2</strong>',
], $titles);
}
}
Members
Title Sort descending | Deprecated | Modifiers | Object type | Summary | Overrides |
---|---|---|---|---|---|
PhpunitCompatibilityTrait::getMock | Deprecated | public | function | Returns a mock object for the specified class using the available method. | |
PhpunitCompatibilityTrait::setExpectedException | Deprecated | public | function | Compatibility layer for PHPUnit 6 to support PHPUnit 4 code. | |
RolesRidTest::testTitleQuery | public | function | Tests the titleQuery method. | ||
UnitTestCase::$randomGenerator | protected | property | The random generator. | ||
UnitTestCase::$root | protected | property | The app root. | 1 | |
UnitTestCase::assertArrayEquals | protected | function | Asserts if two arrays are equal by sorting them first. | ||
UnitTestCase::getBlockMockWithMachineName | Deprecated | protected | function | Mocks a block with a block plugin. | 1 |
UnitTestCase::getClassResolverStub | protected | function | Returns a stub class resolver. | ||
UnitTestCase::getConfigFactoryStub | public | function | Returns a stub config factory that behaves according to the passed array. | ||
UnitTestCase::getConfigStorageStub | public | function | Returns a stub config storage that returns the supplied configuration. | ||
UnitTestCase::getContainerWithCacheTagsInvalidator | protected | function | Sets up a container with a cache tags invalidator. | ||
UnitTestCase::getRandomGenerator | protected | function | Gets the random generator for the utility methods. | ||
UnitTestCase::getStringTranslationStub | public | function | Returns a stub translation manager that just returns the passed string. | ||
UnitTestCase::randomMachineName | public | function | Generates a unique random string containing letters and numbers. | ||
UnitTestCase::setUp | protected | function | 340 |
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.