View source
<?php
namespace Drupal\Tests\workbench_email\Kernel;
use Drupal\field\Entity\FieldConfig;
use Drupal\KernelTests\KernelTestBase;
use Drupal\user\Entity\Role;
use Drupal\Tests\node\Traits\ContentTypeCreationTrait;
use Drupal\Tests\workbench_email\Traits\WorkbenchEmailTestTrait;
use Drupal\workbench_email\Entity\Template;
class ConfigDependenciesTest extends KernelTestBase {
use ContentTypeCreationTrait;
use WorkbenchEmailTestTrait;
protected static $modules = [
'node',
'text',
'system',
'user',
'workbench_email',
'workbench_moderation',
'field',
];
protected $template;
protected $editorRole;
protected function setUp() {
parent::setUp();
$this
->installEntitySchema('node');
$this
->installConfig([
'node',
'workbench_moderation',
'workbench_email',
'system',
]);
$this
->installEntitySchema('user');
$this
->installSchema('system', [
'key_value',
'sequences',
]);
$node_type = $this
->createContentType([
'type' => 'test',
]);
$this
->setUpModerationForNodeType($node_type);
$this
->setUpEmailFieldForNodeBundle();
$this->editorRole = Role::create([
'id' => 'editor',
]);
$this->editorRole
->save();
$this->template = $this
->setUpTemplate();
}
public function testSchemeDependencies() {
$this
->assertEquals([
'config' => [
'field.storage.node.field_email',
'user.role.editor',
],
], $this->template
->getDependencies());
$this->editorRole
->delete();
$this->template = $this
->loadUnchangedTemplate($this->template
->id());
$this
->assertEquals([
'config' => [
'field.storage.node.field_email',
],
], $this->template
->getDependencies());
FieldConfig::load('node.test.field_email')
->delete();
$this->template = $this
->loadUnchangedTemplate($this->template
->id());
$this
->assertEquals([], $this->template
->getDependencies());
}
protected function setUpTemplate($id = 'test_template') {
$template = Template::create([
'id' => $id,
'label' => ucfirst(str_replace('_', ' ', $id)),
'recipient_types' => [
'role' => [
'id' => 'role',
'provider' => 'workbench_email',
'status' => 1,
'settings' => [
'roles' => [
'editor' => 'editor',
],
],
],
'author' => [
'id' => 'author',
'provider' => 'workbench_email',
'status' => 1,
'settings' => [],
],
'email' => [
'id' => 'email',
'provider' => 'workbench_email',
'status' => 1,
'settings' => [
'fields' => [
'node:field_email',
],
],
],
],
]);
$template
->save();
return $template;
}
protected function loadUnchangedTemplate($template_id) {
return $this->container
->get('entity_type.manager')
->getStorage('workbench_email_template')
->loadUnchanged($template_id);
}
}