trait KeyTestTrait in Key 8
Used for key access tests.
@group key
Hierarchy
- trait \Drupal\Tests\key\Functional\KeyTestTrait
File
- tests/
src/ Functional/ KeyTestTrait.php, line 14
Namespace
Drupal\Tests\key\FunctionalView source
trait KeyTestTrait {
/**
* A key entity to use for testing.
*
* @var \Drupal\key\KeyInterface
*/
protected $testKey;
/**
* A key configuration override entity to use for testing.
*
* @var \Drupal\key\KeyConfigOverrideInterface
*/
protected $testKeyConfigOverride;
/**
* Tests each route for the currently signed-in user.
*/
protected function routeAccessTest($routes, $response) {
foreach ($routes as $route => $parameters) {
$url = Url::fromRoute($route, $parameters);
$this
->drupalGet($url);
$this
->assertSession()
->statusCodeEquals($response);
}
}
/**
* Make a key for testing operations that require a key.
*/
protected function createTestKey($id, $type = NULL, $provider = NULL) {
$keyArgs = [
'id' => $id,
'label' => 'Test key',
];
if ($type != NULL) {
$keyArgs['key_type'] = $type;
}
if ($provider != NULL) {
$keyArgs['key_provider'] = $provider;
}
$this->testKey = Key::create($keyArgs);
$this->testKey
->save();
return $this->testKey;
}
/**
* Make a key configuration override for testing operations.
*/
protected function createTestKeyConfigOverride($override_id, $key_id) {
$this->testKeyConfigOverride = KeyConfigOverride::create([
'id' => $override_id,
'label' => 'Test key configuration override',
'config_type' => 'system.simple',
'config_prefix' => '',
'config_name' => 'system.site',
'config_item' => 'name',
'key_id' => $key_id,
]);
$this->testKeyConfigOverride
->save();
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
KeyTestTrait:: |
protected | property | A key entity to use for testing. | |
KeyTestTrait:: |
protected | property | A key configuration override entity to use for testing. | |
KeyTestTrait:: |
protected | function | Make a key for testing operations that require a key. | |
KeyTestTrait:: |
protected | function | Make a key configuration override for testing operations. | |
KeyTestTrait:: |
protected | function | Tests each route for the currently signed-in user. |