Update to Drupal 8.2.6. For more information, see https://www.drupal.org/project/drupal/releases/8.2.6

This commit is contained in:
Pantheon Automation 2017-02-02 16:28:38 -08:00 committed by Greg Anderson
parent db56c09587
commit f1e72395cb
588 changed files with 26857 additions and 2777 deletions

View file

@ -8,6 +8,8 @@ use Drupal\KernelTests\Core\Entity\EntityKernelTestBase;
/**
* Tests for configuration dependencies.
*
* @coversDefaultClass \Drupal\Core\Config\ConfigManager
*
* @group config
*/
class ConfigDependencyTest extends EntityKernelTestBase {
@ -346,6 +348,123 @@ class ConfigDependencyTest extends EntityKernelTestBase {
$this->assertFalse($storage->load($entity_4->id()), 'Entity 4 deleted');
}
/**
* @covers ::uninstall
* @covers ::getConfigEntitiesToChangeOnDependencyRemoval
*/
public function testConfigEntityUninstallThirdParty() {
/** @var \Drupal\Core\Config\ConfigManagerInterface $config_manager */
$config_manager = \Drupal::service('config.manager');
/** @var \Drupal\Core\Config\Entity\ConfigEntityStorage $storage */
$storage = $this->container->get('entity_type.manager')
->getStorage('config_test');
// Entity 1 will be fixed because it only has a dependency via third-party
// settings, which are fixable.
$entity_1 = $storage->create([
'id' => 'entity_1',
'dependencies' => [
'enforced' => [
'module' => ['config_test'],
],
],
'third_party_settings' => [
'node' => [
'foo' => 'bar',
],
],
]);
$entity_1->save();
// Entity 2 has a dependency on entity 1.
$entity_2 = $storage->create([
'id' => 'entity_2',
'dependencies' => [
'enforced' => [
'config' => [$entity_1->getConfigDependencyName()],
],
],
'third_party_settings' => [
'node' => [
'foo' => 'bar',
],
],
]);
$entity_2->save();
// Entity 3 will be unchanged because it is dependent on entity 2 which can
// be fixed. The ConfigEntityInterface::onDependencyRemoval() method will
// not be called for this entity.
$entity_3 = $storage->create([
'id' => 'entity_3',
'dependencies' => [
'enforced' => [
'config' => [$entity_2->getConfigDependencyName()],
],
],
]);
$entity_3->save();
// Entity 4's config dependency will be fixed but it will still be deleted
// because it also depends on the node module.
$entity_4 = $storage->create([
'id' => 'entity_4',
'dependencies' => [
'enforced' => [
'config' => [$entity_1->getConfigDependencyName()],
'module' => ['node', 'config_test'],
],
],
]);
$entity_4->save();
\Drupal::state()->set('config_test.fix_dependencies', []);
\Drupal::state()->set('config_test.on_dependency_removal_called', []);
// Do a dry run using
// \Drupal\Core\Config\ConfigManager::getConfigEntitiesToChangeOnDependencyRemoval().
$config_entities = $config_manager->getConfigEntitiesToChangeOnDependencyRemoval('module', ['node']);
$config_entity_ids = [
'update' => [],
'delete' => [],
'unchanged' => [],
];
foreach ($config_entities as $type => $config_entities_by_type) {
foreach ($config_entities_by_type as $config_entity) {
$config_entity_ids[$type][] = $config_entity->id();
}
}
$expected = [
'update' => [$entity_1->id(), $entity_2->id()],
'delete' => [$entity_4->id()],
'unchanged' => [$entity_3->id()],
];
$this->assertSame($expected, $config_entity_ids);
$called = \Drupal::state()->get('config_test.on_dependency_removal_called', []);
$this->assertFalse(in_array($entity_3->id(), $called), 'ConfigEntityInterface::onDependencyRemoval() is not called for entity 3.');
$this->assertSame([$entity_1->id(), $entity_4->id(), $entity_2->id()], $called, 'The most dependent entities have ConfigEntityInterface::onDependencyRemoval() called first.');
// Perform a module rebuild so we can know where the node module is located
// and uninstall it.
// @todo Remove as part of https://www.drupal.org/node/2186491
system_rebuild_module_data();
// Perform the uninstall.
$config_manager->uninstall('module', 'node');
// Test that expected actions have been performed.
$entity_1 = $storage->load($entity_1->id());
$this->assertTrue($entity_1, 'Entity 1 not deleted');
$this->assertSame($entity_1->getThirdPartySettings('node'), [], 'Entity 1 third party settings updated.');
$entity_2 = $storage->load($entity_2->id());
$this->assertTrue($entity_2, 'Entity 2 not deleted');
$this->assertSame($entity_2->getThirdPartySettings('node'), [], 'Entity 2 third party settings updated.');
$this->assertSame($entity_2->calculateDependencies()->getDependencies()['config'], [$entity_1->getConfigDependencyName()], 'Entity 2 still depends on entity 1.');
$entity_3 = $storage->load($entity_3->id());
$this->assertTrue($entity_3, 'Entity 3 not deleted');
$this->assertSame($entity_3->calculateDependencies()->getDependencies()['config'], [$entity_2->getConfigDependencyName()], 'Entity 3 still depends on entity 2.');
$this->assertFalse($storage->load($entity_4->id()), 'Entity 4 deleted');
}
/**
* Tests deleting a configuration entity and dependency management.
*/

View file

@ -0,0 +1,115 @@
<?php
namespace Drupal\KernelTests\Core\Entity;
use Drupal\comment\Entity\CommentType;
use Drupal\Core\Entity\Entity\EntityViewDisplay;
use Drupal\field\Entity\FieldConfig;
use Drupal\field\Entity\FieldStorageConfig;
use Drupal\KernelTests\KernelTestBase;
/**
* @coversDefaultClass \Drupal\Core\Entity\EntityDisplayBase
*
* @group Entity
*/
class EntityDisplayBaseTest extends KernelTestBase {
/**
* {@inheritdoc}
*/
public static $modules = ['entity_test', 'entity_test_third_party', 'field', 'system', 'comment'];
/**
* @covers ::onDependencyRemoval
*/
public function testOnDependencyRemoval() {
// Create a comment field for entity_test.
$comment_bundle = CommentType::create([
'id' => 'entity_test',
'label' => 'entity_test',
'description' => '',
'target_entity_type_id' => 'entity_test',
]);
$comment_bundle->save();
$comment_display = EntityViewDisplay::create([
'targetEntityType' => 'comment',
'bundle' => 'entity_test',
'mode' => 'default',
'status' => TRUE,
'third_party_settings' => [
'entity_test_third_party' => [
'key' => 'value',
],
],
]);
$comment_display->save();
$field_storage = FieldStorageConfig::create([
'entity_type' => 'entity_test',
'field_name' => 'test_field',
'type' => 'comment',
'settings' => [
'comment_type' => 'entity_test',
],
]);
$field_storage->save();
$field = FieldConfig::create([
'field_storage' => $field_storage,
'label' => $this->randomMachineName(),
'bundle' => 'entity_test',
]);
$field->save();
// Create an entity view display for entity_test.
$entity_display = EntityViewDisplay::create([
'targetEntityType' => 'entity_test',
'bundle' => 'entity_test',
'mode' => 'default',
'status' => TRUE,
'content' => [
'test_field' => ['type' => 'comment_default', 'settings' => ['view_mode' => 'default'], 'label' => 'hidden', 'third_party_settings' => []],
],
'third_party_settings' => [
'entity_test_third_party' => [
'key' => 'value',
],
],
]);
$entity_display->save();
$expected_component = [
'type' => 'comment_default',
'settings' => ['view_mode' => 'default'],
'label' => 'hidden',
'third_party_settings' => [],
];
$entity_display->getComponent('test_field');
$this->assertEquals($expected_component, $entity_display->getComponent('test_field'));
$expected_dependencies = [
'config' => [
'core.entity_view_display.comment.entity_test.default',
'field.field.entity_test.entity_test.test_field',
],
'module' => [
'comment',
'entity_test',
'entity_test_third_party',
],
];
$this->assertSame($expected_dependencies, $entity_display->getDependencies());
// Uninstall the third-party settings provider and reload the display.
$this->container->get('module_installer')->uninstall(['entity_test_third_party']);
$entity_display = EntityViewDisplay::load('entity_test.entity_test.default');
// The component should remain unchanged.
$this->assertEquals($expected_component, $entity_display->getComponent('test_field'));
// The dependencies should no longer contain 'entity_test_third_party'.
$expected_dependencies['module'] = [
'comment',
'entity_test',
];
$this->assertSame($expected_dependencies, $entity_display->getDependencies());
}
}

View file

@ -0,0 +1,96 @@
<?php
namespace Drupal\KernelTests\Core\Field;
use Drupal\Component\Utility\Unicode;
use Drupal\entity_test\Entity\EntityTestMulRev;
use Drupal\field\Entity\FieldConfig;
use Drupal\field\Entity\FieldStorageConfig;
use Drupal\KernelTests\Core\Entity\EntityKernelTestBase;
/**
* Tests the exception when missing a field type.
*
* @group Field
*/
class FieldMissingTypeTest extends EntityKernelTestBase {
/**
* Set to FALSE because we are hacking a field storage to use a fake type.
*
* @see \Drupal\Core\Config\Development\ConfigSchemaChecker
*
* @var bool
*/
protected $strictConfigSchema = FALSE;
/**
* @var string
*/
protected $fieldName;
/**
* {@inheritdoc}
*/
protected function setUp() {
parent::setUp();
$entity_type_id = 'entity_test_mulrev';
$this->installEntitySchema($entity_type_id);
$this->fieldName = Unicode::strtolower($this->randomMachineName());
/** @var \Drupal\field\Entity\FieldStorageConfig $field_storage */
FieldStorageConfig::create([
'field_name' => $this->fieldName,
'type' => 'text',
'entity_type' => $entity_type_id,
'cardinality' => 1,
])->save();
FieldConfig::create([
'entity_type' => $entity_type_id,
'field_name' => $this->fieldName,
'bundle' => $entity_type_id,
'label' => 'Test field',
])->save();
}
/**
* Tests the exception thrown when missing a field type in field storages.
*
* @see \Drupal\field\FieldStorageConfigStorage::mapFromStorageRecords()
*/
public function testFieldStorageMissingType() {
$this->setExpectedException(\RuntimeException::class, "Unable to determine class for field type 'foo_field_storage' found in the 'field.storage.entity_test_mulrev.{$this->fieldName}' configuration");
$entity = EntityTestMulRev::create([
'name' => $this->randomString(),
'field_test_item' => $this->randomString(),
$this->fieldName => $this->randomString(),
]);
$entity->save();
// Hack the field storage to use a non-existent field type.
$this->config('field.storage.entity_test_mulrev.' . $this->fieldName)->set('type', 'foo_field_storage')->save();
\Drupal::service('entity_field.manager')->clearCachedFieldDefinitions();
EntityTestMulRev::load($entity->id());
}
/**
* Tests the exception thrown when missing a field type in fields.
*
* @see \Drupal\field\FieldConfigStorageBase::mapFromStorageRecords()
*/
public function testFieldMissingType() {
$this->setExpectedException(\RuntimeException::class, "Unable to determine class for field type 'foo_field' found in the 'field.field.entity_test_mulrev.entity_test_mulrev.{$this->fieldName}' configuration");
$entity = EntityTestMulRev::create([
'name' => $this->randomString(),
'field_test_item' => $this->randomString(),
$this->fieldName => $this->randomString(),
]);
$entity->save();
// Hack the field to use a non-existent field type.
$this->config('field.field.entity_test_mulrev.entity_test_mulrev.' . $this->fieldName)->set('field_type', 'foo_field')->save();
\Drupal::service('entity_field.manager')->clearCachedFieldDefinitions();
EntityTestMulRev::load($entity->id());
}
}