class RequiredByRoleTest in Required by role 8
Tests the requird_by_role plugin.
@group Required API
Hierarchy
- class \Drupal\Tests\UnitTestCase extends \PHPUnit\Framework\TestCase uses PhpunitCompatibilityTrait
- class \Drupal\required_by_role\Tests\Plugin\Required\RequiredByRoleTest
Expanded class hierarchy of RequiredByRoleTest
See also
\Drupal\required_by_role\Plugin\RequiredByRoleTest
File
- src/
Tests/ Plugin/ Required/ RequiredByRoleTest.php, line 22 - Contains \Drupal\required_by_role\Tests\Plugin\Required\RequiredByRoleTest.
Namespace
Drupal\required_by_role\Tests\Plugin\RequiredView source
class RequiredByRoleTest extends UnitTestCase {
/**
* The required plugin.
*
* @var \Drupal\required_by_role\Plugin\Required\RequiredByRole
*/
protected $plugin;
/**
* Method getInfo.
*
* @return array
* Information regarding to the tests.
*/
public static function getInfo() {
return [
'name' => 'Required by role plugin',
'description' => 'Test the required by role logic.',
'group' => 'Required API',
];
}
/**
* Caching the plugin instance in the $plugin property.
*/
public function setUp() {
$this->plugin = $this
->getMockBuilder('Drupal\\required_by_role\\Plugin\\Required\\RequiredByRole')
->disableOriginalConstructor()
->setMethods(NULL)
->getMock();
}
/**
* Tests the required by role behavior.
*
* @dataProvider getRequiredCases
*/
public function testRequiredByRole($result, $user_roles, $required_roles) {
$required = $this->plugin
->getMatches($user_roles, $required_roles);
$this
->assertEquals($result, $required);
}
/**
* Provides a cases to test.
*/
public function getRequiredCases() {
// array(bool $result, array $user_roles, array $required_roles)
return [
// User with matching roles.
[
TRUE,
[
AccountInterface::AUTHENTICATED_ROLE,
'administrator',
],
[
'administrator',
],
],
// User with no matching roles.
[
FALSE,
[
AccountInterface::AUTHENTICATED_ROLE,
'administrator',
],
[
AccountInterface::ANONYMOUS_ROLE,
],
],
// No required roles set.
[
FALSE,
[
AccountInterface::AUTHENTICATED_ROLE,
'administrator',
],
[],
],
// Required roles is not an array.
[
FALSE,
[
AccountInterface::AUTHENTICATED_ROLE,
'administrator',
],
NULL,
],
// The user has no roles.
[
FALSE,
NULL,
[
AccountInterface::AUTHENTICATED_ROLE,
'administrator',
],
],
// The user has no roles and there is no required roles.
[
FALSE,
NULL,
NULL,
],
];
}
}
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. | |
RequiredByRoleTest:: |
protected | property | The required plugin. | |
RequiredByRoleTest:: |
public static | function | Method getInfo. | |
RequiredByRoleTest:: |
public | function | Provides a cases to test. | |
RequiredByRoleTest:: |
public | function |
Caching the plugin instance in the $plugin property. Overrides UnitTestCase:: |
|
RequiredByRoleTest:: |
public | function | Tests the required by role behavior. | |
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. |