KeyTestTrait.php in Key 8
File
tests/src/Functional/KeyTestTrait.php
View source
<?php
namespace Drupal\Tests\key\Functional;
use Drupal\Core\Url;
use Drupal\key\Entity\Key;
use Drupal\key\Entity\KeyConfigOverride;
trait KeyTestTrait {
protected $testKey;
protected $testKeyConfigOverride;
protected function routeAccessTest($routes, $response) {
foreach ($routes as $route => $parameters) {
$url = Url::fromRoute($route, $parameters);
$this
->drupalGet($url);
$this
->assertSession()
->statusCodeEquals($response);
}
}
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;
}
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();
}
}