{% if block.title %}
{{ block.title }}
{% endif %}
diff --git a/core/modules/system/tests/modules/form_test/form_test.routing.yml b/core/modules/system/tests/modules/form_test/form_test.routing.yml
index 0ee125c..9e178cd 100644
--- a/core/modules/system/tests/modules/form_test/form_test.routing.yml
+++ b/core/modules/system/tests/modules/form_test/form_test.routing.yml
@@ -497,3 +497,11 @@ form_test.get_form:
_form: '\Drupal\form_test\Form\FormTestGetForm'
requirements:
_access: 'TRUE'
+
+form_test.optional_container:
+ path: '/form-test/optional-container'
+ defaults:
+ _form: '\Drupal\form_test\Form\FormTestOptionalContainerForm'
+ _title: 'Optional container testing'
+ requirements:
+ _access: 'TRUE'
diff --git a/core/modules/system/tests/modules/form_test/src/Form/FormTestOptionalContainerForm.php b/core/modules/system/tests/modules/form_test/src/Form/FormTestOptionalContainerForm.php
new file mode 100644
index 0000000..7cacf2e
--- /dev/null
+++ b/core/modules/system/tests/modules/form_test/src/Form/FormTestOptionalContainerForm.php
@@ -0,0 +1,60 @@
+ 'container',
+ '#attributes' => ['class' => ['empty_optional']],
+ '#optional' => TRUE,
+ ];
+ $form['empty_nonoptional'] = [
+ '#type' => 'container',
+ '#attributes' => ['class' => ['empty_nonoptional']],
+ '#optional' => FALSE,
+ ];
+
+ // Non-empty containers
+ $form['nonempty_optional'] = [
+ '#type' => 'container',
+ '#attributes' => ['class' => ['nonempty_optional']],
+ '#optional' => TRUE,
+ ];
+ $form['nonempty_optional']['child_1'] = [];
+
+ $form['nonempty_nonoptional'] = [
+ '#type' => 'container',
+ '#attributes' => ['class' => ['nonempty_nonoptional']],
+ '#optional' => FALSE,
+ ];
+ $form['nonempty_nonoptional']['child_2'] = [];
+
+ return $form;
+ }
+
+ /**
+ * {@inheritdoc}
+ */
+ public function submitForm(array &$form, FormStateInterface $form_state) {
+ }
+
+}
diff --git a/core/modules/system/tests/src/Functional/FileTransfer/FileTransferTest.php b/core/modules/system/tests/src/Functional/FileTransfer/FileTransferTest.php
index 76d8be8..04b1f66 100644
--- a/core/modules/system/tests/src/Functional/FileTransfer/FileTransferTest.php
+++ b/core/modules/system/tests/src/Functional/FileTransfer/FileTransferTest.php
@@ -60,7 +60,7 @@ public function _writeDirectory($base, $files = []) {
$this->_writeDirectory($base . DIRECTORY_SEPARATOR . $key, $file);
}
else {
- //just write the filename into the file
+ // just write the filename into the file
file_put_contents($base . DIRECTORY_SEPARATOR . $file, $file);
}
}
diff --git a/core/modules/system/tests/src/Functional/Form/ElementsContainerTest.php b/core/modules/system/tests/src/Functional/Form/ElementsContainerTest.php
new file mode 100644
index 0000000..a7d404b
--- /dev/null
+++ b/core/modules/system/tests/src/Functional/Form/ElementsContainerTest.php
@@ -0,0 +1,33 @@
+drupalGet('form-test/optional-container');
+ $assertSession = $this->assertSession();
+ $assertSession->elementNotExists('css', 'div.empty_optional');
+ $assertSession->elementExists('css', 'div.empty_nonoptional');
+ $assertSession->elementExists('css', 'div.nonempty_optional');
+ $assertSession->elementExists('css', 'div.nonempty_nonoptional');
+ }
+
+}
diff --git a/core/modules/update/update.module b/core/modules/update/update.module
index 32b5b8c..385434a 100644
--- a/core/modules/update/update.module
+++ b/core/modules/update/update.module
@@ -349,7 +349,7 @@ function update_get_available($refresh = FALSE) {
foreach ($projects as $key => $project) {
// If there's no data at all, we clearly need to fetch some.
if (empty($available[$key])) {
- //update_create_fetch_task($project);
+ // update_create_fetch_task($project);
\Drupal::service('update.processor')->createFetchTask($project);
$needs_refresh = TRUE;
continue;
diff --git a/core/modules/user/src/Entity/User.php b/core/modules/user/src/Entity/User.php
index 7529532..f254ccf 100644
--- a/core/modules/user/src/Entity/User.php
+++ b/core/modules/user/src/Entity/User.php
@@ -9,6 +9,7 @@
use Drupal\Core\Field\BaseFieldDefinition;
use Drupal\Core\Language\LanguageInterface;
use Drupal\user\RoleInterface;
+use Drupal\user\TimeZoneItem;
use Drupal\user\UserInterface;
/**
@@ -498,6 +499,7 @@ public static function baseFieldDefinitions(EntityTypeInterface $entity_type) {
->addPropertyConstraints('value', [
'AllowedValues' => ['callback' => __CLASS__ . '::getAllowedTimezones'],
]);
+ $fields['timezone']->getItemDefinition()->setClass(TimeZoneItem::class);
$fields['status'] = BaseFieldDefinition::create('boolean')
->setLabel(t('User status'))
diff --git a/core/modules/user/src/Tests/Views/AccessRoleTest.php b/core/modules/user/src/Tests/Views/AccessRoleTest.php
index 5705557..addda24 100644
--- a/core/modules/user/src/Tests/Views/AccessRoleTest.php
+++ b/core/modules/user/src/Tests/Views/AccessRoleTest.php
@@ -128,8 +128,8 @@ public function testRenderCaching() {
// @todo Fix this in https://www.drupal.org/node/2551037,
// DisplayPluginBase::applyDisplayCacheabilityMetadata() is not invoked when
// using buildBasicRenderable() and a Views access plugin returns FALSE.
- //$this->assertTrue(in_array('user.roles', $build['#cache']['contexts']));
- //$this->assertEqual([], $build['#cache']['tags']);
+ // $this->assertTrue(in_array('user.roles', $build['#cache']['contexts']));
+ // $this->assertEqual([], $build['#cache']['tags']);
$this->assertEqual(Cache::PERMANENT, $build['#cache']['max-age']);
$this->assertEqual($result, '');
}
diff --git a/core/modules/user/src/TimeZoneItem.php b/core/modules/user/src/TimeZoneItem.php
new file mode 100644
index 0000000..f109691
--- /dev/null
+++ b/core/modules/user/src/TimeZoneItem.php
@@ -0,0 +1,24 @@
+installEntitySchema('user');
+ }
+
+ /**
* Tests some of the methods.
*
* @see \Drupal\user\Entity\User::getRoles()
@@ -65,4 +73,22 @@ public function testUserMethods() {
$this->assertEqual([RoleInterface::AUTHENTICATED_ID, 'test_role_two'], $user->getRoles());
}
+ /**
+ * Tests that all user fields validate properly.
+ *
+ * @see \Drupal\Core\Field\FieldItemListInterface::generateSampleItems
+ * @see \Drupal\Core\Field\FieldItemInterface::generateSampleValue()
+ * @see \Drupal\Core\Entity\FieldableEntityInterface::validate()
+ */
+ public function testUserValidation() {
+ $user = User::create([]);
+ foreach ($user as $field_name => $field) {
+ if (!in_array($field_name, ['uid'])) {
+ $user->$field_name->generateSampleItems();
+ }
+ }
+ $violations = $user->validate();
+ $this->assertFalse((bool) $violations->count());
+ }
+
}
diff --git a/core/modules/user/tests/src/Unit/Views/Argument/RolesRidTest.php b/core/modules/user/tests/src/Unit/Views/Argument/RolesRidTest.php
index b8f2888..4e48fba 100644
--- a/core/modules/user/tests/src/Unit/Views/Argument/RolesRidTest.php
+++ b/core/modules/user/tests/src/Unit/Views/Argument/RolesRidTest.php
@@ -3,6 +3,8 @@
namespace Drupal\Tests\user\Unit\Views\Argument;
use Drupal\Core\DependencyInjection\ContainerBuilder;
+use Drupal\Core\Entity\EntityManager;
+use Drupal\Core\Entity\EntityTypeManagerInterface;
use Drupal\Tests\UnitTestCase;
use Drupal\user\Entity\Role;
use Drupal\user\Plugin\views\argument\RolesRid;
@@ -44,23 +46,27 @@ public function testTitleQuery() {
->with('label')
->will($this->returnValue('label'));
- $entity_manager = $this->getMock('Drupal\Core\Entity\EntityManagerInterface');
- $entity_manager->expects($this->any())
+ $entity_manager = new EntityManager();
+ $entity_type_manager = $this->getMock(EntityTypeManagerInterface::class);
+ $entity_type_manager->expects($this->any())
->method('getDefinition')
->with($this->equalTo('user_role'))
->will($this->returnValue($entity_type));
- $entity_manager
+ $entity_type_manager
->expects($this->once())
->method('getStorage')
->with($this->equalTo('user_role'))
->will($this->returnValue($role_storage));
- // @todo \Drupal\Core\Entity\Entity::entityType() uses a global call to
- // entity_get_info(), which in turn wraps \Drupal::entityManager(). Set
- // the entity manager until this is fixed.
+ // Set up a minimal container to satisfy Drupal\Core\Entity\Entity's
+ // dependency on it.
$container = new ContainerBuilder();
$container->set('entity.manager', $entity_manager);
+ $container->set('entity_type.manager', $entity_type_manager);
+ // Inject the container into entity.manager so it can defer to
+ // entity_type.manager.
+ $entity_manager->setContainer($container);
\Drupal::setContainer($container);
$roles_rid_argument = new RolesRid([], 'user__roles_rid', [], $entity_manager);
diff --git a/core/modules/views/src/Plugin/views/PluginBase.php b/core/modules/views/src/Plugin/views/PluginBase.php
index 4b11f07..5f9c978 100644
--- a/core/modules/views/src/Plugin/views/PluginBase.php
+++ b/core/modules/views/src/Plugin/views/PluginBase.php
@@ -355,7 +355,7 @@ protected function viewsTokenReplace($text, $tokens) {
foreach ($tokens as $token => $replacement) {
// Twig wants a token replacement array stripped of curly-brackets.
// Some Views tokens come with curly-braces, others do not.
- //@todo: https://www.drupal.org/node/2544392
+ // @todo: https://www.drupal.org/node/2544392
if (strpos($token, '{{') !== FALSE) {
// Twig wants a token replacement array stripped of curly-brackets.
$token = trim(str_replace(['{{', '}}'], '', $token));
diff --git a/core/modules/views/src/Plugin/views/field/EntityOperations.php b/core/modules/views/src/Plugin/views/field/EntityOperations.php
index 33f37fe..6f08829 100644
--- a/core/modules/views/src/Plugin/views/field/EntityOperations.php
+++ b/core/modules/views/src/Plugin/views/field/EntityOperations.php
@@ -84,7 +84,7 @@ public function defineOptions() {
$options = parent::defineOptions();
$options['destination'] = [
- 'default' => TRUE,
+ 'default' => FALSE,
];
return $options;
@@ -99,7 +99,7 @@ public function buildOptionsForm(&$form, FormStateInterface $form_state) {
$form['destination'] = [
'#type' => 'checkbox',
'#title' => $this->t('Include destination'),
- '#description' => $this->t('Include a
destination
parameter in the link to return the user to the original view upon completing the link action.'),
+ '#description' => $this->t('Enforce a
destination
parameter in the link to return the user to the original view upon completing the link action. Most operations include a destination by default and this setting is no longer needed.'),
'#default_value' => $this->options['destination'],
];
}
diff --git a/core/modules/views/src/Plugin/views/wizard/WizardPluginBase.php b/core/modules/views/src/Plugin/views/wizard/WizardPluginBase.php
index 1771c71..0b3dcc9 100644
--- a/core/modules/views/src/Plugin/views/wizard/WizardPluginBase.php
+++ b/core/modules/views/src/Plugin/views/wizard/WizardPluginBase.php
@@ -3,6 +3,7 @@
namespace Drupal\views\Plugin\views\wizard;
use Drupal\Component\Utility\NestedArray;
+use Drupal\Core\Entity\EntityPublishedInterface;
use Drupal\Core\Entity\EntityTypeBundleInfoInterface;
use Drupal\Core\Form\FormStateInterface;
use Drupal\Core\Routing\UrlGeneratorTrait;
@@ -140,7 +141,7 @@ public function __construct(array $configuration, $plugin_id, $plugin_definition
$entity_types = \Drupal::entityManager()->getDefinitions();
foreach ($entity_types as $entity_type_id => $entity_type) {
- if ($this->base_table == $entity_type->getBaseTable() || $this->base_table == $entity_type->getDataTable()) {
+ if (in_array($this->base_table, [$entity_type->getBaseTable(), $entity_type->getDataTable(), $entity_type->getRevisionTable(), $entity_type->getRevisionDataTable()], TRUE)) {
$this->entityType = $entity_type;
$this->entityTypeId = $entity_type_id;
}
@@ -165,6 +166,21 @@ public function getCreatedColumn() {
public function getFilters() {
$filters = [];
+ // Add a default filter on the publishing status field, if available.
+ if ($this->entityType && is_subclass_of($this->entityType->getClass(), EntityPublishedInterface::class)) {
+ $field_name = $this->entityType->getKey('published');
+ $this->filters = [
+ $field_name => [
+ 'value' => TRUE,
+ 'table' => $this->base_table,
+ 'field' => $field_name,
+ 'plugin_id' => 'boolean',
+ 'entity_type' => $this->entityTypeId,
+ 'entity_field' => $field_name,
+ ]
+ ] + $this->filters;
+ }
+
$default = $this->filter_defaults;
foreach ($this->filters as $name => $info) {
diff --git a/core/modules/views/tests/src/Functional/Handler/FieldEntityOperationsTest.php b/core/modules/views/tests/src/Functional/Handler/FieldEntityOperationsTest.php
index 653ce11..7ced4f7 100644
--- a/core/modules/views/tests/src/Functional/Handler/FieldEntityOperationsTest.php
+++ b/core/modules/views/tests/src/Functional/Handler/FieldEntityOperationsTest.php
@@ -73,7 +73,10 @@ public function testEntityOperations() {
$this->assertTrue(count($operations) > 0, 'There are operations.');
foreach ($operations as $operation) {
$expected_destination = Url::fromUri('internal:/test-entity-operations')->toString();
- $result = $this->xpath('//ul[contains(@class, dropbutton)]/li/a[@href=:path and text()=:title]', [':path' => $operation['url']->toString() . '?destination=' . $expected_destination, ':title' => (string) $operation['title']]);
+ // Update destination property of the URL as generating it in the
+ // test would by default point to the frontpage.
+ $operation['url']->setOption('query', ['destination' => $expected_destination]);
+ $result = $this->xpath('//ul[contains(@class, dropbutton)]/li/a[@href=:path and text()=:title]', [':path' => $operation['url']->toString(), ':title' => (string) $operation['title']]);
$this->assertEqual(count($result), 1, t('Found entity @operation link with destination parameter.', ['@operation' => $operation['title']]));
// Entities which were created in Hungarian should link to the Hungarian
// edit form, others to the English one (which has no path prefix here).
diff --git a/core/modules/views/tests/src/Functional/Plugin/ArgumentDefaultTest.php b/core/modules/views/tests/src/Functional/Plugin/ArgumentDefaultTest.php
index b3956de..ea2f5b2 100644
--- a/core/modules/views/tests/src/Functional/Plugin/ArgumentDefaultTest.php
+++ b/core/modules/views/tests/src/Functional/Plugin/ArgumentDefaultTest.php
@@ -131,7 +131,7 @@ public function testArgumentDefaultFixed() {
/**
* @todo Test php default argument.
*/
- //function testArgumentDefaultPhp() {}
+ // function testArgumentDefaultPhp() {}
/**
* Test node default argument.
diff --git a/core/modules/views/tests/src/Kernel/Handler/SortTranslationTest.php b/core/modules/views/tests/src/Kernel/Handler/SortTranslationTest.php
index 549761d..e49ef7a 100644
--- a/core/modules/views/tests/src/Kernel/Handler/SortTranslationTest.php
+++ b/core/modules/views/tests/src/Kernel/Handler/SortTranslationTest.php
@@ -42,7 +42,7 @@ protected function setUp($import_test_views = TRUE) {
$this->installEntitySchema('node');
$this->installEntitySchema('user');
- //$this->installConfig('node');
+ // $this->installConfig('node');
$this->container->get('kernel')->rebuildContainer();
$node_type = NodeType::create(['type' => 'article']);
diff --git a/core/modules/views/tests/src/Unit/ViewExecutableTest.php b/core/modules/views/tests/src/Unit/ViewExecutableTest.php
index c11e648..e0aada0 100644
--- a/core/modules/views/tests/src/Unit/ViewExecutableTest.php
+++ b/core/modules/views/tests/src/Unit/ViewExecutableTest.php
@@ -311,7 +311,7 @@ public function testBuildThemeFunctions() {
];
$this->assertEquals($expected, $view->buildThemeFunctions('test_hook'));
- //Change the name of the display plugin and make sure that is in the array.
+ // Change the name of the display plugin and make sure that is in the array.
$view->display_handler->display['display_plugin'] = 'default2';
$expected = [
diff --git a/core/modules/workflows/src/WorkflowListBuilder.php b/core/modules/workflows/src/WorkflowListBuilder.php
index eb652ad..c36171a 100644
--- a/core/modules/workflows/src/WorkflowListBuilder.php
+++ b/core/modules/workflows/src/WorkflowListBuilder.php
@@ -93,7 +93,7 @@ public function render() {
$build = parent::render();
$workflow_types_count = count($this->workflowTypeManager->getDefinitions());
if ($workflow_types_count === 0) {
- $build['table']['#empty'] = $this->t('There are no workflow types available. In order to create workflows you need to install a module that provides a workflow type. For example, the Content Moderation module provides a workflow type that enables workflows for content entities.');
+ $build['table']['#empty'] = $this->t('There are no workflow types available. In order to create workflows you need to install a module that provides a workflow type. For example, the
Content Moderation module provides a workflow type that enables workflows for content entities.', [':content-moderation' => '/admin/modules#module-content-moderation']);
}
return $build;
}
diff --git a/core/modules/workflows/tests/src/Functional/WorkflowUiNoTypeTest.php b/core/modules/workflows/tests/src/Functional/WorkflowUiNoTypeTest.php
index c0c7de6..197386e 100644
--- a/core/modules/workflows/tests/src/Functional/WorkflowUiNoTypeTest.php
+++ b/core/modules/workflows/tests/src/Functional/WorkflowUiNoTypeTest.php
@@ -38,6 +38,7 @@ public function testWorkflowUiWithNoType() {
$this->drupalGet('admin/config/workflow/workflows');
$this->assertSession()->pageTextContains('There are no workflow types available. In order to create workflows you need to install a module that provides a workflow type. For example, the Content Moderation module provides a workflow type that enables workflows for content entities.');
+ $this->assertSession()->linkExists('Content Moderation');
$this->assertSession()->pageTextNotContains('Add workflow');
$this->container->get('module_installer')->install(['workflow_type_test']);
diff --git a/core/phpcs.xml.dist b/core/phpcs.xml.dist
index 037e82e..5b07e1e 100644
--- a/core/phpcs.xml.dist
+++ b/core/phpcs.xml.dist
@@ -63,6 +63,15 @@
+
+
+
+
+
+
+
+
+
@@ -143,6 +152,7 @@
0
+
@@ -150,6 +160,7 @@
+
diff --git a/core/scripts/js/babel-es6-watch.js b/core/scripts/js/babel-es6-watch.js
index 9b49482..c9d1b14 100644
--- a/core/scripts/js/babel-es6-watch.js
+++ b/core/scripts/js/babel-es6-watch.js
@@ -39,8 +39,5 @@ watcher
fs.stat(`${fileName}.js`, () => {
fs.unlink(`${fileName}.js`, unlinkHandler);
});
- fs.stat(`${fileName}.js.map`, () => {
- fs.unlink(`${fileName}.js.map`, unlinkHandler);
- });
})
.on('ready', () => log(`Watching '${fileMatch}' for changes.`));
diff --git a/core/tests/Drupal/KernelTests/Core/Config/ConfigSchemaTest.php b/core/tests/Drupal/KernelTests/Core/Config/ConfigSchemaTest.php
index b3dab6d..5ded484 100644
--- a/core/tests/Drupal/KernelTests/Core/Config/ConfigSchemaTest.php
+++ b/core/tests/Drupal/KernelTests/Core/Config/ConfigSchemaTest.php
@@ -504,7 +504,7 @@ public function testSchemaFallback() {
$definition2 = \Drupal::service('config.typed')->getDefinition('config_schema_test.wildcard_fallback.something.something');
// This should be the schema of config_schema_test.wildcard_fallback.* as
- //well.
+ // well.
$this->assertSame($definition, $definition2);
}
diff --git a/core/tests/Drupal/KernelTests/Core/Database/LoggingTest.php b/core/tests/Drupal/KernelTests/Core/Database/LoggingTest.php
index 0216d3e..c262e38 100644
--- a/core/tests/Drupal/KernelTests/Core/Database/LoggingTest.php
+++ b/core/tests/Drupal/KernelTests/Core/Database/LoggingTest.php
@@ -64,7 +64,7 @@ public function testEnableTargetLogging() {
db_query('SELECT name FROM {test} WHERE age > :age', [':age' => 25])->fetchCol();
- db_query('SELECT age FROM {test} WHERE name = :name', [':name' => 'Ringo'], ['target' => 'replica']);//->fetchCol();
+ db_query('SELECT age FROM {test} WHERE name = :name', [':name' => 'Ringo'], ['target' => 'replica']);// ->fetchCol();
$queries1 = Database::getLog('testing1');
diff --git a/core/tests/Drupal/KernelTests/Core/Entity/CreateSampleEntityTest.php b/core/tests/Drupal/KernelTests/Core/Entity/CreateSampleEntityTest.php
new file mode 100644
index 0000000..b5bcd48
--- /dev/null
+++ b/core/tests/Drupal/KernelTests/Core/Entity/CreateSampleEntityTest.php
@@ -0,0 +1,89 @@
+installEntitySchema('file');
+ $this->installEntitySchema('user');
+ $this->installEntitySchema('node');
+ $this->installEntitySchema('node_type');
+ $this->installEntitySchema('file');
+ $this->installEntitySchema('comment');
+ $this->installEntitySchema('comment_type');
+ $this->installEntitySchema('taxonomy_vocabulary');
+ $this->installEntitySchema('taxonomy_term');
+ $this->entityTypeManager = $this->container->get('entity_type.manager');
+ NodeType::create(['type' => 'article', 'name' => 'Article'])->save();
+ NodeType::create(['type' => 'page', 'name' => 'Page'])->save();
+ Vocabulary::create(['name' => 'Tags', 'vid' => 'tags'])->save();
+ }
+
+ /**
+ * Tests sample value content entity creation of all types.
+ *
+ * @covers ::createWithSampleValues
+ */
+ public function testSampleValueContentEntity() {
+ foreach ($this->entityTypeManager->getDefinitions() as $entity_type_id => $definition) {
+ if ($definition->entityClassImplements(FieldableEntityInterface::class)) {
+ $label = $definition->getKey('label');
+ $values = [];
+ if ($label) {
+ $title = $this->randomString();
+ $values[$label] = $title;
+ }
+ // Create sample entities with bundles.
+ if ($bundle_type = $definition->getBundleEntityType()) {
+ foreach ($this->entityTypeManager->getStorage($bundle_type)->loadMultiple() as $bundle) {
+ $entity = $this->entityTypeManager->getStorage($entity_type_id)->createWithSampleValues($bundle->id(), $values);
+ $violations = $entity->validate();
+ $this->assertCount(0, $violations);
+ if ($label) {
+ $this->assertEquals($title, $entity->label());
+ }
+ }
+ }
+ // Create sample entities without bundles.
+ else {
+ $entity = $this->entityTypeManager->getStorage($entity_type_id)->createWithSampleValues(FALSE, $values);
+ $violations = $entity->validate();
+ $this->assertCount(0, $violations);
+ if ($label) {
+ $this->assertEquals($title, $entity->label());
+ }
+ }
+ }
+ }
+ }
+
+}
diff --git a/core/tests/Drupal/KernelTests/Core/Entity/Element/EntityAutocompleteElementFormTest.php b/core/tests/Drupal/KernelTests/Core/Entity/Element/EntityAutocompleteElementFormTest.php
index 255a3be..c18910e 100644
--- a/core/tests/Drupal/KernelTests/Core/Entity/Element/EntityAutocompleteElementFormTest.php
+++ b/core/tests/Drupal/KernelTests/Core/Entity/Element/EntityAutocompleteElementFormTest.php
@@ -353,7 +353,7 @@ public function testEntityAutocompleteAccess() {
public function testEntityAutocompleteIdInput() {
/** @var \Drupal\Core\Form\FormBuilderInterface $form_builder */
$form_builder = $this->container->get('form_builder');
- //$form = $form_builder->getForm($this);
+ // $form = $form_builder->getForm($this);
$form_state = (new FormState())
->setMethod('GET')
->setValues([
diff --git a/core/tests/Drupal/KernelTests/Core/Entity/EntityDefinitionUpdateTest.php b/core/tests/Drupal/KernelTests/Core/Entity/EntityDefinitionUpdateTest.php
index a066616..7d7ea76 100644
--- a/core/tests/Drupal/KernelTests/Core/Entity/EntityDefinitionUpdateTest.php
+++ b/core/tests/Drupal/KernelTests/Core/Entity/EntityDefinitionUpdateTest.php
@@ -115,7 +115,7 @@ public function testEntityTypeUpdateWithoutData() {
t('The %field_name field needs to be installed.', ['%field_name' => 'Revision ID']),
],
];
- $this->assertEqual($this->entityDefinitionUpdateManager->getChangeSummary(), $expected); //, 'EntityDefinitionUpdateManager reports the expected change summary.');
+ $this->assertEqual($this->entityDefinitionUpdateManager->getChangeSummary(), $expected); // , 'EntityDefinitionUpdateManager reports the expected change summary.');
// Run the update and ensure the revision table is created.
$this->entityDefinitionUpdateManager->applyUpdates();
diff --git a/core/tests/Drupal/KernelTests/Core/Field/FieldSettingsTest.php b/core/tests/Drupal/KernelTests/Core/Field/FieldSettingsTest.php
index 583e55b..590a96c 100644
--- a/core/tests/Drupal/KernelTests/Core/Field/FieldSettingsTest.php
+++ b/core/tests/Drupal/KernelTests/Core/Field/FieldSettingsTest.php
@@ -47,6 +47,34 @@ public function testBaseFieldSettings() {
}
/**
+ * Tests the base field settings on a cloned base field definition object.
+ */
+ public function testBaseFieldSettingsOnClone() {
+ $base_field = BaseFieldDefinition::create('test_field');
+
+ // Check that the default settings have been populated.
+ $expected_settings = [
+ 'test_field_storage_setting' => 'dummy test string',
+ 'changeable' => 'a changeable field storage setting',
+ 'unchangeable' => 'an unchangeable field storage setting',
+ 'translatable_storage_setting' => 'a translatable field storage setting',
+ 'test_field_setting' => 'dummy test string',
+ 'translatable_field_setting' => 'a translatable field setting',
+ ];
+ $this->assertEquals($expected_settings, $base_field->getSettings());
+
+ // Clone the base field object and change one single setting using
+ // setSettings() on the cloned base field and check that it has been
+ // changed only on the cloned object.
+ $clone_base_field = clone $base_field;
+ $expected_settings_clone = $expected_settings;
+ $expected_settings_clone['changeable'] = $expected_settings['changeable'] . ' (clone)';
+ $clone_base_field->setSetting('changeable', $expected_settings_clone['changeable']);
+ $this->assertEquals($expected_settings, $base_field->getSettings());
+ $this->assertEquals($expected_settings_clone, $clone_base_field->getSettings());
+ }
+
+ /**
* @covers \Drupal\field\Entity\FieldStorageConfig::getSettings
* @covers \Drupal\field\Entity\FieldStorageConfig::setSettings
*/
diff --git a/core/tests/Drupal/KernelTests/Core/Path/AliasTest.php b/core/tests/Drupal/KernelTests/Core/Path/AliasTest.php
index 7048632..1f49b09 100644
--- a/core/tests/Drupal/KernelTests/Core/Path/AliasTest.php
+++ b/core/tests/Drupal/KernelTests/Core/Path/AliasTest.php
@@ -16,16 +16,16 @@
class AliasTest extends PathUnitTestBase {
public function testCRUD() {
- //Prepare database table.
+ // Prepare database table.
$connection = Database::getConnection();
$this->fixtures->createTables($connection);
- //Create Path object.
+ // Create Path object.
$aliasStorage = new AliasStorage($connection, $this->container->get('module_handler'));
$aliases = $this->fixtures->sampleUrlAliases();
- //Create a few aliases
+ // Create a few aliases
foreach ($aliases as $idx => $alias) {
$aliasStorage->save($alias['source'], $alias['alias'], $alias['langcode']);
@@ -34,11 +34,11 @@ public function testCRUD() {
$this->assertEqual(count($rows), 1, format_string('Created an entry for %alias.', ['%alias' => $alias['alias']]));
- //Cache the pid for further tests.
+ // Cache the pid for further tests.
$aliases[$idx]['pid'] = $rows[0]->pid;
}
- //Load a few aliases
+ // Load a few aliases
foreach ($aliases as $alias) {
$pid = $alias['pid'];
$loadedAlias = $aliasStorage->load(['pid' => $pid]);
@@ -49,7 +49,7 @@ public function testCRUD() {
$loadedAlias = $aliasStorage->load(['source' => '/node/1']);
$this->assertEqual($loadedAlias['alias'], '/alias_for_node_1_und', 'The last created alias loaded by default.');
- //Update a few aliases
+ // Update a few aliases
foreach ($aliases as $alias) {
$fields = $aliasStorage->save($alias['source'], $alias['alias'] . '_updated', $alias['langcode'], $alias['pid']);
@@ -61,7 +61,7 @@ public function testCRUD() {
$this->assertEqual($pid, $alias['pid'], format_string('Updated entry for pid %pid.', ['%pid' => $pid]));
}
- //Delete a few aliases
+ // Delete a few aliases
foreach ($aliases as $alias) {
$pid = $alias['pid'];
$aliasStorage->delete(['pid' => $pid]);
@@ -74,11 +74,11 @@ public function testCRUD() {
}
public function testLookupPath() {
- //Prepare database table.
+ // Prepare database table.
$connection = Database::getConnection();
$this->fixtures->createTables($connection);
- //Create AliasManager and Path object.
+ // Create AliasManager and Path object.
$aliasManager = $this->container->get('path.alias_manager');
$aliasStorage = new AliasStorage($connection, $this->container->get('module_handler'));
diff --git a/core/tests/Drupal/KernelTests/Core/Test/BrowserTestBaseTest.php b/core/tests/Drupal/KernelTests/Core/Test/BrowserTestBaseTest.php
new file mode 100644
index 0000000..c93069c
--- /dev/null
+++ b/core/tests/Drupal/KernelTests/Core/Test/BrowserTestBaseTest.php
@@ -0,0 +1,71 @@
+setName('testRequiresModule');
+
+ // We cannot use $this->setExpectedException() because PHPUnit would skip
+ // the test before comparing the exception type.
+ try {
+ $stub_test->publicCheckRequirements();
+ $this->fail('Missing required module throws skipped test exception.');
+ }
+ catch (\PHPUnit_Framework_SkippedTestError $e) {
+ $this->assertEqual('Required modules: module_does_not_exist', $e->getMessage());
+ }
+ }
+
+ /**
+ * Tests that a test case is skipped when it requires a module not present.
+ *
+ * In order to catch checkRequirements() regressions, we have to make a new
+ * test object and run checkRequirements() here.
+ *
+ * @covers ::checkRequirements
+ * @covers ::checkModuleRequirements
+ */
+ public function testRequiresModule() {
+ require __DIR__ . '/../../../../fixtures/BrowserMissingDependentModuleTest.php';
+
+ $stub_test = new BrowserMissingDependentModuleTest();
+ // We have to setName() to the method name we're concerned with.
+ $stub_test->setName('testRequiresModule');
+
+ // We cannot use $this->setExpectedException() because PHPUnit would skip
+ // the test before comparing the exception type.
+ try {
+ $stub_test->publicCheckRequirements();
+ $this->fail('Missing required module throws skipped test exception.');
+ }
+ catch (\PHPUnit_Framework_SkippedTestError $e) {
+ $this->assertEqual('Required modules: module_does_not_exist', $e->getMessage());
+ }
+ }
+
+}
diff --git a/core/tests/Drupal/KernelTests/KernelTestBase.php b/core/tests/Drupal/KernelTests/KernelTestBase.php
index 09a82c3..d2e61ee 100644
--- a/core/tests/Drupal/KernelTests/KernelTestBase.php
+++ b/core/tests/Drupal/KernelTests/KernelTestBase.php
@@ -21,6 +21,7 @@
use Drupal\Tests\AssertHelperTrait;
use Drupal\Tests\ConfigTestTrait;
use Drupal\Tests\RandomGeneratorTrait;
+use Drupal\Tests\TestRequirementsTrait;
use Drupal\simpletest\TestServiceProvider;
use PHPUnit\Framework\TestCase;
use Symfony\Component\DependencyInjection\Reference;
@@ -46,9 +47,6 @@
*
* @see \Drupal\Tests\KernelTestBase::$modules
* @see \Drupal\Tests\KernelTestBase::enableModules()
- *
- * @todo Extend ::setRequirementsFromAnnotation() and ::checkRequirements() to
- * account for '@requires module'.
*/
abstract class KernelTestBase extends TestCase implements ServiceProviderInterface {
@@ -57,6 +55,7 @@
use AssertHelperTrait;
use RandomGeneratorTrait;
use ConfigTestTrait;
+ use TestRequirementsTrait;
/**
* {@inheritdoc}
@@ -213,15 +212,6 @@ public static function setUpBeforeClass() {
}
/**
- * Returns the drupal root directory.
- *
- * @return string
- */
- protected static function getDrupalRoot() {
- return dirname(dirname(substr(__DIR__, 0, -strlen(__NAMESPACE__))));
- }
-
- /**
* {@inheritdoc}
*/
protected function setUp() {
@@ -814,7 +804,7 @@ protected function enableModules(array $modules) {
foreach ($modules as $module) {
if ($module_handler->moduleExists($module)) {
- throw new \LogicException("$module module is already enabled.");
+ continue;
}
$module_handler->addModule($module, $module_list[$module]->getPath());
// Maintain the list of enabled modules in configuration.
diff --git a/core/tests/Drupal/KernelTests/KernelTestBaseTest.php b/core/tests/Drupal/KernelTests/KernelTestBaseTest.php
index a503019..f44c965 100644
--- a/core/tests/Drupal/KernelTests/KernelTestBaseTest.php
+++ b/core/tests/Drupal/KernelTests/KernelTestBaseTest.php
@@ -9,6 +9,7 @@
/**
* @coversDefaultClass \Drupal\KernelTests\KernelTestBase
+ *
* @group PHPUnit
* @group Test
* @group KernelTests
@@ -223,6 +224,60 @@ public function testLocalTimeZone() {
}
/**
+ * Tests that a test method is skipped when it requires a module not present.
+ *
+ * In order to catch checkRequirements() regressions, we have to make a new
+ * test object and run checkRequirements() here.
+ *
+ * @covers ::checkRequirements
+ * @covers ::checkModuleRequirements
+ */
+ public function testMethodRequiresModule() {
+ require __DIR__ . '/../../fixtures/KernelMissingDependentModuleMethodTest.php';
+
+ $stub_test = new KernelMissingDependentModuleMethodTest();
+ // We have to setName() to the method name we're concerned with.
+ $stub_test->setName('testRequiresModule');
+
+ // We cannot use $this->setExpectedException() because PHPUnit would skip
+ // the test before comparing the exception type.
+ try {
+ $stub_test->publicCheckRequirements();
+ $this->fail('Missing required module throws skipped test exception.');
+ }
+ catch (\PHPUnit_Framework_SkippedTestError $e) {
+ $this->assertEqual('Required modules: module_does_not_exist', $e->getMessage());
+ }
+ }
+
+ /**
+ * Tests that a test case is skipped when it requires a module not present.
+ *
+ * In order to catch checkRequirements() regressions, we have to make a new
+ * test object and run checkRequirements() here.
+ *
+ * @covers ::checkRequirements
+ * @covers ::checkModuleRequirements
+ */
+ public function testRequiresModule() {
+ require __DIR__ . '/../../fixtures/KernelMissingDependentModuleTest.php';
+
+ $stub_test = new KernelMissingDependentModuleTest();
+ // We have to setName() to the method name we're concerned with.
+ $stub_test->setName('testRequiresModule');
+
+ // We cannot use $this->setExpectedException() because PHPUnit would skip
+ // the test before comparing the exception type.
+ try {
+ $stub_test->publicCheckRequirements();
+ $this->fail('Missing required module throws skipped test exception.');
+ }
+ catch (\PHPUnit_Framework_SkippedTestError $e) {
+ $this->assertEqual('Required modules: module_does_not_exist', $e->getMessage());
+ }
+ }
+
+ /**
* {@inheritdoc}
*/
protected function tearDown() {
diff --git a/core/tests/Drupal/Tests/BrowserTestBase.php b/core/tests/Drupal/Tests/BrowserTestBase.php
index 2324316..abdedd9 100644
--- a/core/tests/Drupal/Tests/BrowserTestBase.php
+++ b/core/tests/Drupal/Tests/BrowserTestBase.php
@@ -56,6 +56,7 @@
createContentType as drupalCreateContentType;
}
use ConfigTestTrait;
+ use TestRequirementsTrait;
use UserCreationTrait {
createRole as drupalCreateRole;
createUser as drupalCreateUser;
diff --git a/core/tests/Drupal/Tests/Core/Access/AccessResultTest.php b/core/tests/Drupal/Tests/Core/Access/AccessResultTest.php
index fc3722f..5bd6220 100644
--- a/core/tests/Drupal/Tests/Core/Access/AccessResultTest.php
+++ b/core/tests/Drupal/Tests/Core/Access/AccessResultTest.php
@@ -128,6 +128,9 @@ public function testAccessForbiddenReason() {
$reason = $this->getRandomGenerator()->string();
$b = AccessResult::forbidden($reason);
$verify($b, $reason);
+
+ $b = AccessResult::forbiddenIf(TRUE, $reason);
+ $verify($b, $reason);
}
/**
diff --git a/core/tests/Drupal/Tests/Core/Config/Entity/ConfigEntityBaseUnitTest.php b/core/tests/Drupal/Tests/Core/Config/Entity/ConfigEntityBaseUnitTest.php
index 0a5d3d3..0d417ab 100644
--- a/core/tests/Drupal/Tests/Core/Config/Entity/ConfigEntityBaseUnitTest.php
+++ b/core/tests/Drupal/Tests/Core/Config/Entity/ConfigEntityBaseUnitTest.php
@@ -10,6 +10,7 @@
use Drupal\Component\Plugin\PluginManagerInterface;
use Drupal\Core\Config\Schema\SchemaIncompleteException;
use Drupal\Core\DependencyInjection\ContainerBuilder;
+use Drupal\Core\Entity\EntityTypeManagerInterface;
use Drupal\Core\Language\Language;
use Drupal\Core\Plugin\DefaultLazyPluginCollection;
use Drupal\Tests\Core\Config\Entity\Fixtures\ConfigEntityBaseWithPluginCollections;
@@ -37,11 +38,11 @@ class ConfigEntityBaseUnitTest extends UnitTestCase {
protected $entityType;
/**
- * The entity manager used for testing.
+ * The entity type manager used for testing.
*
- * @var \Drupal\Core\Entity\EntityManagerInterface|\PHPUnit_Framework_MockObject_MockObject
+ * @var \Drupal\Core\Entity\EntityTypeManagerInterface|\PHPUnit_Framework_MockObject_MockObject
*/
- protected $entityManager;
+ protected $entityTypeManager;
/**
* The ID of the type of the entity under test.
@@ -112,8 +113,8 @@ protected function setUp() {
->method('getConfigPrefix')
->willReturn('test_provider.' . $this->entityTypeId);
- $this->entityManager = $this->getMock('\Drupal\Core\Entity\EntityManagerInterface');
- $this->entityManager->expects($this->any())
+ $this->entityTypeManager = $this->getMock(EntityTypeManagerInterface::class);
+ $this->entityTypeManager->expects($this->any())
->method('getDefinition')
->with($this->entityTypeId)
->will($this->returnValue($this->entityType));
@@ -131,7 +132,7 @@ protected function setUp() {
$this->typedConfigManager = $this->getMock('Drupal\Core\Config\TypedConfigManagerInterface');
$container = new ContainerBuilder();
- $container->set('entity.manager', $this->entityManager);
+ $container->set('entity_type.manager', $this->entityTypeManager);
$container->set('uuid', $this->uuid);
$container->set('language_manager', $this->languageManager);
$container->set('cache_tags.invalidator', $this->cacheTagsInvalidator);
@@ -468,7 +469,7 @@ public function testCreateDuplicate() {
* @covers ::sort
*/
public function testSort() {
- $this->entityManager->expects($this->any())
+ $this->entityTypeManager->expects($this->any())
->method('getDefinition')
->with($this->entityTypeId)
->will($this->returnValue([
diff --git a/core/tests/Drupal/Tests/Core/Config/Entity/ConfigEntityStorageTest.php b/core/tests/Drupal/Tests/Core/Config/Entity/ConfigEntityStorageTest.php
index 01dafab..3d86ecd 100644
--- a/core/tests/Drupal/Tests/Core/Config/Entity/ConfigEntityStorageTest.php
+++ b/core/tests/Drupal/Tests/Core/Config/Entity/ConfigEntityStorageTest.php
@@ -17,8 +17,8 @@
use Drupal\Core\Config\TypedConfigManagerInterface;
use Drupal\Core\Entity\EntityInterface;
use Drupal\Core\Entity\EntityMalformedException;
-use Drupal\Core\Entity\EntityManagerInterface;
use Drupal\Core\Entity\EntityStorageException;
+use Drupal\Core\Entity\EntityTypeManagerInterface;
use Drupal\Core\Entity\Query\QueryFactoryInterface;
use Drupal\Core\Entity\Query\QueryInterface;
use Drupal\Core\Extension\ModuleHandlerInterface;
@@ -136,8 +136,8 @@ protected function setUp() {
$this->entityStorage = new ConfigEntityStorage($entity_type, $this->configFactory->reveal(), $this->uuidService->reveal(), $this->languageManager->reveal());
$this->entityStorage->setModuleHandler($this->moduleHandler->reveal());
- $entity_manager = $this->prophesize(EntityManagerInterface::class);
- $entity_manager->getDefinition('test_entity_type')->willReturn($entity_type);
+ $entity_type_manager = $this->prophesize(EntityTypeManagerInterface::class);
+ $entity_type_manager->getDefinition('test_entity_type')->willReturn($entity_type);
$this->cacheTagsInvalidator = $this->prophesize(CacheTagsInvalidatorInterface::class);
@@ -149,7 +149,7 @@ protected function setUp() {
$this->configManager = $this->prophesize(ConfigManagerInterface::class);
$container = new ContainerBuilder();
- $container->set('entity.manager', $entity_manager->reveal());
+ $container->set('entity_type.manager', $entity_type_manager->reveal());
$container->set('entity.query.config', $entity_query_factory->reveal());
$container->set('config.typed', $typed_config_manager->reveal());
$container->set('cache_tags.invalidator', $this->cacheTagsInvalidator->reveal());
diff --git a/core/tests/Drupal/Tests/Core/Config/Entity/EntityDisplayModeBaseUnitTest.php b/core/tests/Drupal/Tests/Core/Config/Entity/EntityDisplayModeBaseUnitTest.php
index 728fdca..0f1ffc4 100644
--- a/core/tests/Drupal/Tests/Core/Config/Entity/EntityDisplayModeBaseUnitTest.php
+++ b/core/tests/Drupal/Tests/Core/Config/Entity/EntityDisplayModeBaseUnitTest.php
@@ -3,6 +3,8 @@
namespace Drupal\Tests\Core\Config\Entity;
use Drupal\Core\DependencyInjection\ContainerBuilder;
+use Drupal\Core\Entity\EntityManager;
+use Drupal\Core\Entity\EntityTypeManagerInterface;
use Drupal\Tests\UnitTestCase;
/**
@@ -33,6 +35,13 @@ class EntityDisplayModeBaseUnitTest extends UnitTestCase {
protected $entityManager;
/**
+ * The entity type manager used for testing.
+ *
+ * @var \Drupal\Core\Entity\EntityTypeManagerInterface|\PHPUnit_Framework_MockObject_MockObject
+ */
+ protected $entityTypeManager;
+
+ /**
* The ID of the type of the entity under test.
*
* @var string
@@ -57,13 +66,21 @@ protected function setUp() {
->method('getProvider')
->will($this->returnValue('entity'));
- $this->entityManager = $this->getMock('\Drupal\Core\Entity\EntityManagerInterface');
+ $this->entityTypeManager = $this->getMock(EntityTypeManagerInterface::class);
+
+ $this->entityManager = new EntityManager();
$this->uuid = $this->getMock('\Drupal\Component\Uuid\UuidInterface');
$container = new ContainerBuilder();
$container->set('entity.manager', $this->entityManager);
+ $container->set('entity_type.manager', $this->entityTypeManager);
$container->set('uuid', $this->uuid);
+
+ // Inject the container into entity.manager so it can defer to
+ // entity_type.manager.
+ $this->entityManager->setContainer($container);
+
\Drupal::setContainer($container);
}
@@ -79,11 +96,11 @@ public function testCalculateDependencies() {
->will($this->returnValue('test_module'));
$values = ['targetEntityType' => $target_entity_type_id];
- $this->entityManager->expects($this->at(0))
+ $this->entityTypeManager->expects($this->at(0))
->method('getDefinition')
->with($target_entity_type_id)
->will($this->returnValue($target_entity_type));
- $this->entityManager->expects($this->at(1))
+ $this->entityTypeManager->expects($this->at(1))
->method('getDefinition')
->with($this->entityType)
->will($this->returnValue($this->entityInfo));
diff --git a/core/tests/Drupal/Tests/Core/Entity/ContentEntityBaseUnitTest.php b/core/tests/Drupal/Tests/Core/Entity/ContentEntityBaseUnitTest.php
index 541ec88..0d56516 100644
--- a/core/tests/Drupal/Tests/Core/Entity/ContentEntityBaseUnitTest.php
+++ b/core/tests/Drupal/Tests/Core/Entity/ContentEntityBaseUnitTest.php
@@ -4,7 +4,12 @@
use Drupal\Core\Access\AccessResult;
use Drupal\Core\DependencyInjection\ContainerBuilder;
+use Drupal\Core\Entity\ContentEntityBase;
use Drupal\Core\Entity\ContentEntityInterface;
+use Drupal\Core\Entity\EntityFieldManagerInterface;
+use Drupal\Core\Entity\EntityManager;
+use Drupal\Core\Entity\EntityTypeBundleInfoInterface;
+use Drupal\Core\Entity\EntityTypeManagerInterface;
use Drupal\Core\Field\BaseFieldDefinition;
use Drupal\Core\Language\LanguageInterface;
use Drupal\Core\TypedData\TypedDataManagerInterface;
@@ -55,6 +60,27 @@ class ContentEntityBaseUnitTest extends UnitTestCase {
protected $entityManager;
/**
+ * The entity field manager used for testing.
+ *
+ * @var \Drupal\Core\Entity\EntityFieldManagerInterface|\PHPUnit_Framework_MockObject_MockObject
+ */
+ protected $entityFieldManager;
+
+ /**
+ * The entity type bundle manager used for testing.
+ *
+ * @var \Drupal\Core\Entity\EntityTypeBundleInfoInterface|\PHPUnit_Framework_MockObject_MockObject
+ */
+ protected $entityTypeBundleInfo;
+
+ /**
+ * The entity type manager used for testing.
+ *
+ * @var \Drupal\Core\Entity\EntityTypeManagerInterface|\PHPUnit_Framework_MockObject_MockObject
+ */
+ protected $entityTypeManager;
+
+ /**
* The type ID of the entity under test.
*
* @var string
@@ -124,12 +150,18 @@ protected function setUp() {
'uuid' => 'uuid',
]));
- $this->entityManager = $this->getMock('\Drupal\Core\Entity\EntityManagerInterface');
- $this->entityManager->expects($this->any())
+ $this->entityManager = new EntityManager();
+
+ $this->entityTypeManager = $this->getMock(EntityTypeManagerInterface::class);
+ $this->entityTypeManager->expects($this->any())
->method('getDefinition')
->with($this->entityTypeId)
->will($this->returnValue($this->entityType));
+ $this->entityFieldManager = $this->getMock(EntityFieldManagerInterface::class);
+
+ $this->entityTypeBundleInfo = $this->getMock(EntityTypeBundleInfoInterface::class);
+
$this->uuid = $this->getMock('\Drupal\Component\Uuid\UuidInterface');
$this->typedDataManager = $this->getMock(TypedDataManagerInterface::class);
@@ -168,10 +200,16 @@ protected function setUp() {
$container = new ContainerBuilder();
$container->set('entity.manager', $this->entityManager);
+ $container->set('entity_field.manager', $this->entityFieldManager);
+ $container->set('entity_type.bundle.info', $this->entityTypeBundleInfo);
+ $container->set('entity_type.manager', $this->entityTypeManager);
$container->set('uuid', $this->uuid);
$container->set('typed_data_manager', $this->typedDataManager);
$container->set('language_manager', $this->languageManager);
$container->set('plugin.manager.field.field_type', $this->fieldTypePluginManager);
+ // Inject the container into entity.manager so it can defer to
+ // entity_type.manager and other services.
+ $this->entityManager->setContainer($container);
\Drupal::setContainer($container);
$this->fieldDefinitions = [
@@ -179,14 +217,14 @@ protected function setUp() {
'revision_id' => BaseFieldDefinition::create('integer'),
];
- $this->entityManager->expects($this->any())
+ $this->entityFieldManager->expects($this->any())
->method('getFieldDefinitions')
->with($this->entityTypeId, $this->bundle)
->will($this->returnValue($this->fieldDefinitions));
- $this->entity = $this->getMockForAbstractClass('\Drupal\Core\Entity\ContentEntityBase', [$values, $this->entityTypeId, $this->bundle], '', TRUE, TRUE, TRUE, ['isNew']);
+ $this->entity = $this->getMockForAbstractClass(ContentEntityBase::class, [$values, $this->entityTypeId, $this->bundle], '', TRUE, TRUE, TRUE, ['isNew']);
$values['defaultLangcode'] = [LanguageInterface::LANGCODE_DEFAULT => LanguageInterface::LANGCODE_NOT_SPECIFIED];
- $this->entityUnd = $this->getMockForAbstractClass('\Drupal\Core\Entity\ContentEntityBase', [$values, $this->entityTypeId, $this->bundle]);
+ $this->entityUnd = $this->getMockForAbstractClass(ContentEntityBase::class, [$values, $this->entityTypeId, $this->bundle]);
}
/**
@@ -283,7 +321,7 @@ public function testGetRevisionId() {
* @covers ::isTranslatable
*/
public function testIsTranslatable() {
- $this->entityManager->expects($this->any())
+ $this->entityTypeBundleInfo->expects($this->any())
->method('getBundleInfo')
->with($this->entityTypeId)
->will($this->returnValue([
@@ -382,7 +420,7 @@ public function testRequiredValidation() {
$entity->preSave($storage);
});
- $this->entityManager->expects($this->any())
+ $this->entityTypeManager->expects($this->any())
->method('getStorage')
->with($this->entityTypeId)
->will($this->returnValue($storage));
@@ -434,7 +472,7 @@ public function testAccess() {
$access->expects($this->at(3))
->method('createAccess')
->will($this->returnValue(AccessResult::allowed()));
- $this->entityManager->expects($this->exactly(4))
+ $this->entityTypeManager->expects($this->exactly(4))
->method('getAccessControlHandler')
->will($this->returnValue($access));
$this->assertTrue($this->entity->access($operation));
diff --git a/core/tests/Drupal/Tests/Core/Entity/EntityLinkTest.php b/core/tests/Drupal/Tests/Core/Entity/EntityLinkTest.php
index 60bd425..38e9502 100644
--- a/core/tests/Drupal/Tests/Core/Entity/EntityLinkTest.php
+++ b/core/tests/Drupal/Tests/Core/Entity/EntityLinkTest.php
@@ -3,6 +3,7 @@
namespace Drupal\Tests\Core\Entity;
use Drupal\Core\DependencyInjection\ContainerBuilder;
+use Drupal\Core\Entity\EntityTypeManagerInterface;
use Drupal\Core\Language\Language;
use Drupal\Core\Link;
use Drupal\Tests\UnitTestCase;
@@ -14,11 +15,11 @@
class EntityLinkTest extends UnitTestCase {
/**
- * The mocked entity manager.
+ * The mocked entity type manager.
*
- * @var \Drupal\Core\Entity\EntityManagerInterface|\PHPUnit_Framework_MockObject_MockObject
+ * @var \Drupal\Core\Entity\EntityTypeManagerInterface|\PHPUnit_Framework_MockObject_MockObject
*/
- protected $entityManager;
+ protected $entityTypeManager;
/**
* The tested link generator.
@@ -40,12 +41,12 @@ class EntityLinkTest extends UnitTestCase {
protected function setUp() {
parent::setUp();
- $this->entityManager = $this->getMock('Drupal\Core\Entity\EntityManagerInterface');
+ $this->entityTypeManager = $this->getMock(EntityTypeManagerInterface::class);
$this->linkGenerator = $this->getMock('Drupal\Core\Utility\LinkGeneratorInterface');
$this->languageManager = $this->getMock('Drupal\Core\Language\LanguageManagerInterface');
$container = new ContainerBuilder();
- $container->set('entity.manager', $this->entityManager);
+ $container->set('entity_type.manager', $this->entityTypeManager);
$container->set('link_generator', $this->linkGenerator);
$container->set('language_manager', $this->languageManager);
\Drupal::setContainer($container);
@@ -86,7 +87,7 @@ public function testLink($entity_label, $link_text, $expected_text, $link_rel =
['langcode', 'langcode'],
]);
- $this->entityManager
+ $this->entityTypeManager
->expects($this->any())
->method('getDefinition')
->with($entity_type_id)
@@ -148,7 +149,7 @@ public function testToLink($entity_label, $link_text, $expected_text, $link_rel
['langcode', 'langcode'],
]);
- $this->entityManager
+ $this->entityTypeManager
->expects($this->any())
->method('getDefinition')
->with($entity_type_id)
diff --git a/core/tests/Drupal/Tests/Core/Entity/EntityListBuilderTest.php b/core/tests/Drupal/Tests/Core/Entity/EntityListBuilderTest.php
index 44e771c..ad68e2d 100644
--- a/core/tests/Drupal/Tests/Core/Entity/EntityListBuilderTest.php
+++ b/core/tests/Drupal/Tests/Core/Entity/EntityListBuilderTest.php
@@ -11,6 +11,7 @@
use Drupal\Core\DependencyInjection\ContainerBuilder;
use Drupal\Core\Entity\EntityInterface;
use Drupal\Core\Entity\EntityListBuilder;
+use Drupal\Core\Routing\RedirectDestinationInterface;
use Drupal\entity_test\EntityTestListBuilder;
use Drupal\Tests\UnitTestCase;
@@ -63,6 +64,13 @@ class EntityListBuilderTest extends UnitTestCase {
protected $role;
/**
+ * The redirect destination service.
+ *
+ * @var \Drupal\Core\Routing\RedirectDestinationInterface|\PHPUnit_Framework_MockObject_MockObject
+ */
+ protected $redirectDestination;
+
+ /**
* The EntityListBuilder object to test.
*
* @var \Drupal\Core\Entity\EntityListBuilder
@@ -80,7 +88,8 @@ protected function setUp() {
$this->moduleHandler = $this->getMock('\Drupal\Core\Extension\ModuleHandlerInterface');
$this->entityType = $this->getMock('\Drupal\Core\Entity\EntityTypeInterface');
$this->translationManager = $this->getMock('\Drupal\Core\StringTranslation\TranslationInterface');
- $this->entityListBuilder = new TestEntityListBuilder($this->entityType, $this->roleStorage, $this->moduleHandler);
+ $this->entityListBuilder = new TestEntityListBuilder($this->entityType, $this->roleStorage);
+ $this->redirectDestination = $this->getMock(RedirectDestinationInterface::class);
$this->container = new ContainerBuilder();
\Drupal::setContainer($this->container);
}
@@ -117,12 +126,20 @@ public function testGetOperations() {
$url->expects($this->any())
->method('toArray')
->will($this->returnValue([]));
+ $url->expects($this->atLeastOnce())
+ ->method('mergeOptions')
+ ->with(['query' => ['destination' => '/foo/bar']]);
$this->role->expects($this->any())
- ->method('urlInfo')
+ ->method('toUrl')
->will($this->returnValue($url));
- $list = new EntityListBuilder($this->entityType, $this->roleStorage, $this->moduleHandler);
+ $this->redirectDestination->expects($this->atLeastOnce())
+ ->method('getAsArray')
+ ->willReturn(['destination' => '/foo/bar']);
+
+ $list = new EntityListBuilder($this->entityType, $this->roleStorage);
$list->setStringTranslation($this->translationManager);
+ $list->setRedirectDestination($this->redirectDestination);
$operations = $list->getOperations($this->role);
$this->assertInternalType('array', $operations);
diff --git a/core/tests/Drupal/Tests/Core/Entity/EntityTypeBundleInfoTest.php b/core/tests/Drupal/Tests/Core/Entity/EntityTypeBundleInfoTest.php
index 1cc5076..2596471 100644
--- a/core/tests/Drupal/Tests/Core/Entity/EntityTypeBundleInfoTest.php
+++ b/core/tests/Drupal/Tests/Core/Entity/EntityTypeBundleInfoTest.php
@@ -100,7 +100,7 @@ protected function setUp() {
$container = $this->prophesize(ContainerInterface::class);
$container->get('cache_tags.invalidator')->willReturn($this->cacheTagsInvalidator->reveal());
- //$container->get('typed_data_manager')->willReturn($this->typedDataManager->reveal());
+ // $container->get('typed_data_manager')->willReturn($this->typedDataManager->reveal());
\Drupal::setContainer($container->reveal());
$this->entityTypeBundleInfo = new EntityTypeBundleInfo($this->entityTypeManager->reveal(), $this->languageManager->reveal(), $this->moduleHandler->reveal(), $this->typedDataManager->reveal(), $this->cacheBackend->reveal());
diff --git a/core/tests/Drupal/Tests/Core/Entity/EntityUnitTest.php b/core/tests/Drupal/Tests/Core/Entity/EntityUnitTest.php
index ad9e49c..1acb20c 100644
--- a/core/tests/Drupal/Tests/Core/Entity/EntityUnitTest.php
+++ b/core/tests/Drupal/Tests/Core/Entity/EntityUnitTest.php
@@ -5,7 +5,11 @@
use Drupal\Core\Access\AccessResult;
use Drupal\Core\Cache\Cache;
use Drupal\Core\DependencyInjection\ContainerBuilder;
+use Drupal\Core\Entity\EntityStorageInterface;
+use Drupal\Core\Entity\EntityTypeManagerInterface;
+use Drupal\Core\Entity\EntityTypeRepositoryInterface;
use Drupal\Core\Language\Language;
+use Drupal\entity_test\Entity\EntityTestMul;
use Drupal\Tests\UnitTestCase;
/**
@@ -30,11 +34,11 @@ class EntityUnitTest extends UnitTestCase {
protected $entityType;
/**
- * The entity manager used for testing.
+ * The entity type manager used for testing.
*
- * @var \Drupal\Core\Entity\EntityManagerInterface|\PHPUnit_Framework_MockObject_MockObject
+ * @var \Drupal\Core\Entity\EntityTypeManagerInterface|\PHPUnit_Framework_MockObject_MockObject
*/
- protected $entityManager;
+ protected $entityTypeManager;
/**
* The ID of the type of the entity under test.
@@ -94,8 +98,8 @@ protected function setUp() {
->method('getListCacheTags')
->willReturn([$this->entityTypeId . '_list']);
- $this->entityManager = $this->getMock('\Drupal\Core\Entity\EntityManagerInterface');
- $this->entityManager->expects($this->any())
+ $this->entityTypeManager = $this->getMockForAbstractClass(EntityTypeManagerInterface::class);
+ $this->entityTypeManager->expects($this->any())
->method('getDefinition')
->with($this->entityTypeId)
->will($this->returnValue($this->entityType));
@@ -111,7 +115,9 @@ protected function setUp() {
$this->cacheTagsInvalidator = $this->getMock('Drupal\Core\Cache\CacheTagsInvalidator');
$container = new ContainerBuilder();
- $container->set('entity.manager', $this->entityManager);
+ // Ensure that Entity doesn't use the deprecated entity.manager service.
+ $container->set('entity.manager', NULL);
+ $container->set('entity_type.manager', $this->entityTypeManager);
$container->set('uuid', $this->uuid);
$container->set('language_manager', $this->languageManager);
$container->set('cache_tags.invalidator', $this->cacheTagsInvalidator);
@@ -186,7 +192,7 @@ public function testLabel() {
// Set a dummy property on the entity under test to test that the label can
// be returned form a property if there is no callback.
- $this->entityManager->expects($this->at(1))
+ $this->entityTypeManager->expects($this->at(1))
->method('getDefinition')
->with($this->entityTypeId)
->will($this->returnValue([
@@ -213,9 +219,10 @@ public function testAccess() {
$access->expects($this->at(1))
->method('createAccess')
->will($this->returnValue(AccessResult::allowed()));
- $this->entityManager->expects($this->exactly(2))
+ $this->entityTypeManager->expects($this->exactly(2))
->method('getAccessControlHandler')
->will($this->returnValue($access));
+
$this->assertEquals(AccessResult::allowed(), $this->entity->access($operation));
$this->assertEquals(AccessResult::allowed(), $this->entity->access('create'));
}
@@ -239,11 +246,11 @@ public function setupTestLoad() {
// Base our mocked entity on a real entity class so we can test if calling
// Entity::load() on the base class will bubble up to an actual entity.
$this->entityTypeId = 'entity_test_mul';
- $methods = get_class_methods('Drupal\entity_test\Entity\EntityTestMul');
+ $methods = get_class_methods(EntityTestMul::class);
unset($methods[array_search('load', $methods)]);
unset($methods[array_search('loadMultiple', $methods)]);
unset($methods[array_search('create', $methods)]);
- $this->entity = $this->getMockBuilder('Drupal\entity_test\Entity\EntityTestMul')
+ $this->entity = $this->getMockBuilder(EntityTestMul::class)
->disableOriginalConstructor()
->setMethods($methods)
->getMock();
@@ -260,21 +267,25 @@ public function testLoad() {
$class_name = get_class($this->entity);
- $this->entityManager->expects($this->once())
+ $entity_type_repository = $this->getMockForAbstractClass(EntityTypeRepositoryInterface::class);
+ $entity_type_repository->expects($this->once())
->method('getEntityTypeFromClass')
->with($class_name)
->willReturn($this->entityTypeId);
- $storage = $this->getMock('\Drupal\Core\Entity\EntityStorageInterface');
+ $storage = $this->getMock(EntityStorageInterface::class);
$storage->expects($this->once())
->method('load')
->with(1)
->will($this->returnValue($this->entity));
- $this->entityManager->expects($this->once())
+
+ $this->entityTypeManager->expects($this->once())
->method('getStorage')
->with($this->entityTypeId)
->will($this->returnValue($storage));
+ \Drupal::getContainer()->set('entity_type.repository', $entity_type_repository);
+
// Call Entity::load statically and check that it returns the mock entity.
$this->assertSame($this->entity, $class_name::load(1));
}
@@ -290,21 +301,25 @@ public function testLoadMultiple() {
$class_name = get_class($this->entity);
- $this->entityManager->expects($this->once())
+ $entity_type_repository = $this->getMockForAbstractClass(EntityTypeRepositoryInterface::class);
+ $entity_type_repository->expects($this->once())
->method('getEntityTypeFromClass')
->with($class_name)
->willReturn($this->entityTypeId);
- $storage = $this->getMock('\Drupal\Core\Entity\EntityStorageInterface');
+ $storage = $this->getMock(EntityStorageInterface::class);
$storage->expects($this->once())
->method('loadMultiple')
->with([1])
->will($this->returnValue([1 => $this->entity]));
- $this->entityManager->expects($this->once())
+
+ $this->entityTypeManager->expects($this->once())
->method('getStorage')
->with($this->entityTypeId)
->will($this->returnValue($storage));
+ \Drupal::getContainer()->set('entity_type.repository', $entity_type_repository);
+
// Call Entity::loadMultiple statically and check that it returns the mock
// entity.
$this->assertSame([1 => $this->entity], $class_name::loadMultiple([1]));
@@ -317,21 +332,26 @@ public function testCreate() {
$this->setupTestLoad();
$class_name = get_class($this->entity);
- $this->entityManager->expects($this->once())
+
+ $entity_type_repository = $this->getMockForAbstractClass(EntityTypeRepositoryInterface::class);
+ $entity_type_repository->expects($this->once())
->method('getEntityTypeFromClass')
->with($class_name)
->willReturn($this->entityTypeId);
- $storage = $this->getMock('\Drupal\Core\Entity\EntityStorageInterface');
+ $storage = $this->getMock(EntityStorageInterface::class);
$storage->expects($this->once())
->method('create')
->with([])
->will($this->returnValue($this->entity));
- $this->entityManager->expects($this->once())
+
+ $this->entityTypeManager->expects($this->once())
->method('getStorage')
->with($this->entityTypeId)
->will($this->returnValue($storage));
+ \Drupal::getContainer()->set('entity_type.repository', $entity_type_repository);
+
// Call Entity::create() statically and check that it returns the mock
// entity.
$this->assertSame($this->entity, $class_name::create([]));
@@ -345,10 +365,12 @@ public function testSave() {
$storage->expects($this->once())
->method('save')
->with($this->entity);
- $this->entityManager->expects($this->once())
+
+ $this->entityTypeManager->expects($this->once())
->method('getStorage')
->with($this->entityTypeId)
->will($this->returnValue($storage));
+
$this->entity->save();
}
@@ -361,10 +383,12 @@ public function testDelete() {
// Testing the argument of the delete() method consumes too much memory.
$storage->expects($this->once())
->method('delete');
- $this->entityManager->expects($this->once())
+
+ $this->entityTypeManager->expects($this->once())
->method('getStorage')
->with($this->entityTypeId)
->will($this->returnValue($storage));
+
$this->entity->delete();
}
diff --git a/core/tests/Drupal/Tests/Core/Entity/EntityUrlTest.php b/core/tests/Drupal/Tests/Core/Entity/EntityUrlTest.php
index ebde776..1e9ee7c 100644
--- a/core/tests/Drupal/Tests/Core/Entity/EntityUrlTest.php
+++ b/core/tests/Drupal/Tests/Core/Entity/EntityUrlTest.php
@@ -4,7 +4,7 @@
use Drupal\Core\Entity\Entity;
use Drupal\Core\Entity\EntityMalformedException;
-use Drupal\Core\Entity\EntityManagerInterface;
+use Drupal\Core\Entity\EntityTypeBundleInfoInterface;
use Drupal\Core\Entity\EntityTypeInterface;
use Drupal\Core\Entity\Exception\UndefinedLinkTemplateException;
use Drupal\Core\Entity\RevisionableInterface;
@@ -21,11 +21,11 @@
class EntityUrlTest extends UnitTestCase {
/**
- * The entity manager mock used in this test.
+ * The entity type bundle info service mock used in this test.
*
- * @var \Prophecy\Prophecy\ProphecyInterface|\Drupal\Core\Entity\EntityManagerInterface
+ * @var \Prophecy\Prophecy\ProphecyInterface|\Drupal\Core\Entity\EntityTypeBundleInfoInterface
*/
- protected $entityManager;
+ protected $entityTypeBundleInfo;
/**
* The ID of the entity type used in this test.
@@ -511,7 +511,7 @@ public function providerTestUrl() {
* @return \Drupal\Core\Entity\Entity|\PHPUnit_Framework_MockObject_MockObject
*/
protected function getEntity($class, array $values, array $methods = []) {
- $methods = array_merge($methods, ['getEntityType', 'entityManager']);
+ $methods = array_merge($methods, ['getEntityType', 'entityManager', 'entityTypeBundleInfo']);
// Prophecy does not allow prophesizing abstract classes while actually
// calling their code. We use Prophecy below because that allows us to
@@ -526,8 +526,8 @@ protected function getEntity($class, array $values, array $methods = []) {
$this->entityType->getKey('langcode')->willReturn(FALSE);
$entity->method('getEntityType')->willReturn($this->entityType->reveal());
- $this->entityManager = $this->prophesize(EntityManagerInterface::class);
- $entity->method('entityManager')->willReturn($this->entityManager->reveal());
+ $this->entityTypeBundleInfo = $this->prophesize(EntityTypeBundleInfoInterface::class);
+ $entity->method('entityTypeBundleInfo')->willReturn($this->entityTypeBundleInfo->reveal());
return $entity;
}
@@ -581,7 +581,7 @@ protected function registerLinkTemplate($link_template) {
* The bundle information to register.
*/
protected function registerBundleInfo($bundle_info) {
- $this->entityManager
+ $this->entityTypeBundleInfo
->getBundleInfo($this->entityTypeId)
->willReturn([$this->entityTypeId => $bundle_info])
;
diff --git a/core/tests/Drupal/Tests/Core/Entity/KeyValueStore/KeyValueEntityStorageTest.php b/core/tests/Drupal/Tests/Core/Entity/KeyValueStore/KeyValueEntityStorageTest.php
index 6f20444..4a2dac5 100644
--- a/core/tests/Drupal/Tests/Core/Entity/KeyValueStore/KeyValueEntityStorageTest.php
+++ b/core/tests/Drupal/Tests/Core/Entity/KeyValueStore/KeyValueEntityStorageTest.php
@@ -4,9 +4,12 @@
use Drupal\Core\Config\Entity\ConfigEntityInterface;
use Drupal\Core\DependencyInjection\ContainerBuilder;
+use Drupal\Core\Entity\EntityFieldManagerInterface;
use Drupal\Core\Entity\EntityInterface;
use Drupal\Core\Entity\EntityMalformedException;
+use Drupal\Core\Entity\EntityManager;
use Drupal\Core\Entity\EntityStorageException;
+use Drupal\Core\Entity\EntityTypeManagerInterface;
use Drupal\Core\Language\Language;
use Drupal\Tests\UnitTestCase;
use Drupal\Core\Entity\KeyValueStore\KeyValueEntityStorage;
@@ -58,13 +61,27 @@ class KeyValueEntityStorageTest extends UnitTestCase {
protected $entityStorage;
/**
- * The mocked entity manager.
+ * The entity manager.
*
* @var \Drupal\Core\Entity\EntityManagerInterface|\PHPUnit_Framework_MockObject_MockObject
*/
protected $entityManager;
/**
+ * The mocked entity type manager.
+ *
+ * @var \Drupal\Core\Entity\EntityTypeManagerInterface|\PHPUnit_Framework_MockObject_MockObject
+ */
+ protected $entityTypeManager;
+
+ /**
+ * The mocked entity field manager.
+ *
+ * @var \Drupal\Core\Entity\EntityFieldManagerInterface|\PHPUnit_Framework_MockObject_MockObject
+ */
+ protected $entityFieldManager;
+
+ /**
* The mocked cache tags invalidator.
*
* @var \Drupal\Core\Cache\CacheTagsInvalidatorInterface|\PHPUnit_Framework_MockObject_MockObject
@@ -102,12 +119,16 @@ protected function setUpKeyValueEntityStorage($uuid_key = 'uuid') {
->method('getListCacheTags')
->willReturn(['test_entity_type_list']);
- $this->entityManager = $this->getMock('Drupal\Core\Entity\EntityManagerInterface');
- $this->entityManager->expects($this->any())
+ $this->entityManager = new EntityManager();
+
+ $this->entityTypeManager = $this->getMock(EntityTypeManagerInterface::class);
+ $this->entityTypeManager->expects($this->any())
->method('getDefinition')
->with('test_entity_type')
->will($this->returnValue($this->entityType));
+ $this->entityFieldManager = $this->getMock(EntityFieldManagerInterface::class);
+
$this->cacheTagsInvalidator = $this->getMock('Drupal\Core\Cache\CacheTagsInvalidatorInterface');
$this->keyValueStore = $this->getMock('Drupal\Core\KeyValueStore\KeyValueStoreInterface');
@@ -127,8 +148,13 @@ protected function setUpKeyValueEntityStorage($uuid_key = 'uuid') {
$container = new ContainerBuilder();
$container->set('entity.manager', $this->entityManager);
+ $container->set('entity_field.manager', $this->entityFieldManager);
+ $container->set('entity_type.manager', $this->entityTypeManager);
$container->set('language_manager', $this->languageManager);
$container->set('cache_tags.invalidator', $this->cacheTagsInvalidator);
+ // Inject the container into entity.manager so it can defer to
+ // entity_type.manager and other services.
+ $this->entityManager->setContainer($container);
\Drupal::setContainer($container);
}
diff --git a/core/tests/Drupal/Tests/Core/Entity/Sql/SqlContentEntityStorageSchemaTest.php b/core/tests/Drupal/Tests/Core/Entity/Sql/SqlContentEntityStorageSchemaTest.php
index aecc3e4..db92ca9 100644
--- a/core/tests/Drupal/Tests/Core/Entity/Sql/SqlContentEntityStorageSchemaTest.php
+++ b/core/tests/Drupal/Tests/Core/Entity/Sql/SqlContentEntityStorageSchemaTest.php
@@ -1151,7 +1151,7 @@ public function providerTestRequiresEntityDataMigration() {
// Case 6: same storage class, ::hasData() === TRUE, no structure changes.
[$updated_entity_type_definition, $original_entity_type_definition, TRUE, FALSE, FALSE],
// Case 7: different storage class, original storage class exists,
- //::hasData() === TRUE, no structure changes.
+ // ::hasData() === TRUE, no structure changes.
[$updated_entity_type_definition, $original_entity_type_definition_other_existing, TRUE, FALSE, FALSE],
];
}
diff --git a/core/tests/Drupal/Tests/Core/Entity/Sql/SqlContentEntityStorageTest.php b/core/tests/Drupal/Tests/Core/Entity/Sql/SqlContentEntityStorageTest.php
index 98f5718..bf3fd46 100644
--- a/core/tests/Drupal/Tests/Core/Entity/Sql/SqlContentEntityStorageTest.php
+++ b/core/tests/Drupal/Tests/Core/Entity/Sql/SqlContentEntityStorageTest.php
@@ -8,8 +8,11 @@
namespace Drupal\Tests\Core\Entity\Sql;
use Drupal\Core\Cache\CacheBackendInterface;
+use Drupal\Core\Entity\EntityFieldManagerInterface;
use Drupal\Core\Entity\EntityInterface;
+use Drupal\Core\Entity\EntityManager;
use Drupal\Core\Entity\EntityStorageInterface;
+use Drupal\Core\Entity\EntityTypeManagerInterface;
use Drupal\Core\Entity\Query\QueryFactoryInterface;
use Drupal\Core\Entity\Sql\SqlContentEntityStorage;
use Drupal\Core\Language\Language;
@@ -51,6 +54,20 @@ class SqlContentEntityStorageTest extends UnitTestCase {
protected $entityManager;
/**
+ * The mocked entity type manager used in this test.
+ *
+ * @var \Drupal\Core\Entity\EntityTypeManagerInterface|\PHPUnit_Framework_MockObject_MockObject
+ */
+ protected $entityTypeManager;
+
+ /**
+ * The mocked entity field manager used in this test.
+ *
+ * @var \Drupal\Core\Entity\EntityFieldManagerInterface|\PHPUnit_Framework_MockObject_MockObject
+ */
+ protected $entityFieldManager;
+
+ /**
* The entity type ID.
*
* @var string
@@ -104,7 +121,12 @@ protected function setUp() {
$this->container = new ContainerBuilder();
\Drupal::setContainer($this->container);
- $this->entityManager = $this->getMock('Drupal\Core\Entity\EntityManagerInterface');
+ $this->entityManager = new EntityManager();
+ // Inject the container into entity.manager so it can defer to
+ // entity_type.manager and other services.
+ $this->entityManager->setContainer($this->container);
+ $this->entityTypeManager = $this->getMock(EntityTypeManagerInterface::class);
+ $this->entityFieldManager = $this->getMock(EntityFieldManagerInterface::class);
$this->moduleHandler = $this->getMock('Drupal\Core\Extension\ModuleHandlerInterface');
$this->cache = $this->getMock('Drupal\Core\Cache\CacheBackendInterface');
$this->languageManager = $this->getMock('Drupal\Core\Language\LanguageManagerInterface');
@@ -114,6 +136,10 @@ protected function setUp() {
$this->connection = $this->getMockBuilder('Drupal\Core\Database\Connection')
->disableOriginalConstructor()
->getMock();
+
+ $this->container->set('entity.manager', $this->entityManager);
+ $this->container->set('entity_type.manager', $this->entityTypeManager);
+ $this->container->set('entity_field.manager', $this->entityFieldManager);
}
/**
@@ -986,7 +1012,6 @@ public function testCreate() {
->will($this->returnValue($language));
$this->container->set('language_manager', $language_manager);
- $this->container->set('entity.manager', $this->entityManager);
$this->container->set('module_handler', $this->moduleHandler);
$entity = $this->getMockBuilder('Drupal\Core\Entity\ContentEntityBase')
@@ -1006,14 +1031,14 @@ public function testCreate() {
// ContentEntityStorageBase iterates over the entity which calls this method
// internally in ContentEntityBase::getProperties().
- $this->entityManager->expects($this->once())
+ $this->entityFieldManager->expects($this->once())
->method('getFieldDefinitions')
->will($this->returnValue([]));
$this->entityType->expects($this->atLeastOnce())
->method('isRevisionable')
->will($this->returnValue(FALSE));
- $this->entityManager->expects($this->atLeastOnce())
+ $this->entityTypeManager->expects($this->atLeastOnce())
->method('getDefinition')
->with($this->entityType->id())
->will($this->returnValue($this->entityType));
@@ -1077,15 +1102,15 @@ protected function setUpEntityStorage() {
->disableOriginalConstructor()
->getMock();
- $this->entityManager->expects($this->any())
+ $this->entityTypeManager->expects($this->any())
->method('getDefinition')
->will($this->returnValue($this->entityType));
- $this->entityManager->expects($this->any())
+ $this->entityFieldManager->expects($this->any())
->method('getFieldStorageDefinitions')
->will($this->returnValue($this->fieldDefinitions));
- $this->entityManager->expects($this->any())
+ $this->entityFieldManager->expects($this->any())
->method('getBaseFieldDefinitions')
->will($this->returnValue($this->fieldDefinitions));
@@ -1259,15 +1284,15 @@ public function testHasData() {
->disableOriginalConstructor()
->getMock();
- $this->entityManager->expects($this->any())
+ $this->entityTypeManager->expects($this->any())
->method('getDefinition')
->will($this->returnValue($this->entityType));
- $this->entityManager->expects($this->any())
+ $this->entityFieldManager->expects($this->any())
->method('getFieldStorageDefinitions')
->will($this->returnValue($this->fieldDefinitions));
- $this->entityManager->expects($this->any())
+ $this->entityFieldManager->expects($this->any())
->method('getBaseFieldDefinitions')
->will($this->returnValue($this->fieldDefinitions));
diff --git a/core/tests/Drupal/Tests/Core/Entity/TypedData/EntityAdapterUnitTest.php b/core/tests/Drupal/Tests/Core/Entity/TypedData/EntityAdapterUnitTest.php
index 2140112..d932993c 100644
--- a/core/tests/Drupal/Tests/Core/Entity/TypedData/EntityAdapterUnitTest.php
+++ b/core/tests/Drupal/Tests/Core/Entity/TypedData/EntityAdapterUnitTest.php
@@ -3,6 +3,9 @@
namespace Drupal\Tests\Core\Entity\TypedData;
use Drupal\Core\DependencyInjection\ContainerBuilder;
+use Drupal\Core\Entity\EntityFieldManagerInterface;
+use Drupal\Core\Entity\EntityManager;
+use Drupal\Core\Entity\EntityTypeManagerInterface;
use Drupal\Core\Entity\Plugin\DataType\EntityAdapter;
use Drupal\Core\Field\BaseFieldDefinition;
use Drupal\Core\Language\LanguageInterface;
@@ -54,6 +57,19 @@ class EntityAdapterUnitTest extends UnitTestCase {
protected $entityManager;
/**
+ * The entity type manager used for testing.
+ *
+ * @var \Drupal\Core\Entity\EntityTypeManagerInterface|\PHPUnit_Framework_MockObject_MockObject
+ */
+ protected $entityTypeManager;
+
+ /**
+ *
+ * @var \Drupal\Core\Entity\EntityFieldManagerInterface|\PHPUnit_Framework_MockObject_MockObject
+ */
+ protected $entityFieldManager;
+
+ /**
* The type ID of the entity under test.
*
* @var string
@@ -130,8 +146,10 @@ protected function setUp() {
'uuid' => 'uuid',
]));
- $this->entityManager = $this->getMock('\Drupal\Core\Entity\EntityManagerInterface');
- $this->entityManager->expects($this->any())
+ $this->entityManager = new EntityManager();
+
+ $this->entityTypeManager = $this->getMock(EntityTypeManagerInterface::class);
+ $this->entityTypeManager->expects($this->any())
->method('getDefinition')
->with($this->entityTypeId)
->will($this->returnValue($this->entityType));
@@ -183,23 +201,30 @@ protected function setUp() {
->method('createFieldItemList')
->willReturn($this->fieldItemList);
+ $this->entityFieldManager = $this->getMockForAbstractClass(EntityFieldManagerInterface::class);
+
$container = new ContainerBuilder();
$container->set('entity.manager', $this->entityManager);
+ $container->set('entity_type.manager', $this->entityTypeManager);
+ $container->set('entity_field.manager', $this->entityFieldManager);
$container->set('uuid', $this->uuid);
$container->set('typed_data_manager', $this->typedDataManager);
$container->set('language_manager', $this->languageManager);
$container->set('plugin.manager.field.field_type', $this->fieldTypePluginManager);
+ // Inject the container into entity.manager so it can defer to
+ // entity_type.manager and other services.
+ $this->entityManager->setContainer($container);
\Drupal::setContainer($container);
$this->fieldDefinitions = [
'id' => BaseFieldDefinition::create('integer'),
'revision_id' => BaseFieldDefinition::create('integer'),
];
-
- $this->entityManager->expects($this->any())
+ $this->entityFieldManager->expects($this->any())
->method('getFieldDefinitions')
->with($this->entityTypeId, $this->bundle)
->will($this->returnValue($this->fieldDefinitions));
+
$this->entity = $this->getMockForAbstractClass('\Drupal\Core\Entity\ContentEntityBase', [$values, $this->entityTypeId, $this->bundle]);
$this->entityAdapter = EntityAdapter::createFromEntity($this->entity);
diff --git a/core/tests/Drupal/Tests/Core/Logger/LoggerChannelTest.php b/core/tests/Drupal/Tests/Core/Logger/LoggerChannelTest.php
index d2b283a..2512602 100644
--- a/core/tests/Drupal/Tests/Core/Logger/LoggerChannelTest.php
+++ b/core/tests/Drupal/Tests/Core/Logger/LoggerChannelTest.php
@@ -113,14 +113,14 @@ public function providerTestLog() {
$request_mock->headers = $this->getMock('Symfony\Component\HttpFoundation\ParameterBag');
// No request or account.
- $cases [] = [
+ $cases[] = [
function ($context) {
return $context['channel'] == 'test' && empty($context['uid']) && empty($context['ip']);
},
];
// With account but not request. Since the request is not available the
// current user should not be used.
- $cases [] = [
+ $cases[] = [
function ($context) {
return $context['uid'] === 0 && empty($context['ip']);
},
@@ -128,14 +128,14 @@ function ($context) {
$account_mock,
];
// With request but not account.
- $cases [] = [
+ $cases[] = [
function ($context) {
return $context['ip'] === '127.0.0.1' && empty($context['uid']);
},
$request_mock,
];
// Both request and account.
- $cases [] = [
+ $cases[] = [
function ($context) {
return $context['ip'] === '127.0.0.1' && $context['uid'] === 1;
},
diff --git a/core/tests/Drupal/Tests/Core/StringTranslation/TranslationManagerTest.php b/core/tests/Drupal/Tests/Core/StringTranslation/TranslationManagerTest.php
index 2cd750b..53a9241 100644
--- a/core/tests/Drupal/Tests/Core/StringTranslation/TranslationManagerTest.php
+++ b/core/tests/Drupal/Tests/Core/StringTranslation/TranslationManagerTest.php
@@ -50,7 +50,7 @@ public function providerTestFormatPlural() {
/**
* @dataProvider providerTestFormatPlural
*/
- public function testFormatPlural($count, $singular, $plural, array $args = [], array $options = [], $expected) {
+ public function testFormatPlural($count, $singular, $plural, array $args, array $options, $expected) {
$langcode = empty($options['langcode']) ? 'fr' : $options['langcode'];
$translator = $this->getMock('\Drupal\Core\StringTranslation\Translator\TranslatorInterface');
$translator->expects($this->once())
@@ -78,7 +78,7 @@ public function testFormatPlural($count, $singular, $plural, array $args = [], a
*
* @dataProvider providerTestTranslatePlaceholder
*/
- public function testTranslatePlaceholder($string, array $args = [], $expected_string) {
+ public function testTranslatePlaceholder($string, array $args, $expected_string) {
$actual = $this->translationManager->translate($string, $args);
$this->assertInstanceOf(MarkupInterface::class, $actual);
$this->assertEquals($expected_string, (string) $actual);
diff --git a/core/tests/Drupal/Tests/TestRequirementsTrait.php b/core/tests/Drupal/Tests/TestRequirementsTrait.php
new file mode 100644
index 0000000..84937ad
--- /dev/null
+++ b/core/tests/Drupal/Tests/TestRequirementsTrait.php
@@ -0,0 +1,91 @@
+getAnnotations();
+ if (!empty($annotations['class']['requires'])) {
+ $this->checkModuleRequirements($root, $annotations['class']['requires']);
+ }
+ if (!empty($annotations['method']['requires'])) {
+ $this->checkModuleRequirements($root, $annotations['method']['requires']);
+ }
+ }
+
+ /**
+ * Checks missing module requirements.
+ *
+ * Iterates through a list of requires annotations and looks for missing
+ * modules. The test will be skipped if any of the required modules is
+ * missing.
+ *
+ * @param string $root
+ * The path to the root of the Drupal installation to scan.
+ * @param string[] $annotations
+ * A list of requires annotations from either a method or class annotation.
+ *
+ * @throws \PHPUnit_Framework_SkippedTestError
+ * Thrown when the requirements are not met, and this test should be
+ * skipped. Callers should not catch this exception.
+ */
+ private function checkModuleRequirements($root, array $annotations) {
+ // drupal_valid_ua() might not be loaded.
+ require_once $root . '/core/includes/bootstrap.inc';
+
+ // Make a list of required modules.
+ $required_modules = [];
+ foreach ($annotations as $requirement) {
+ if (strpos($requirement, 'module ') === 0) {
+ $required_modules[] = trim(str_replace('module ', '', $requirement));
+ }
+ }
+
+ // If there are required modules, check if they're available.
+ if (!empty($required_modules)) {
+ // Scan for modules.
+ $discovery = new ExtensionDiscovery($root, FALSE);
+ $discovery->setProfileDirectories([]);
+ $list = array_keys($discovery->scan('module'));
+ $not_available = array_diff($required_modules, $list);
+ if (!empty($not_available)) {
+ throw new \PHPUnit_Framework_SkippedTestError('Required modules: ' . implode(', ', $not_available));
+ }
+ }
+ }
+
+}
diff --git a/core/tests/Drupal/Tests/UnitTestCase.php b/core/tests/Drupal/Tests/UnitTestCase.php
index 8aaeb85..5139f97 100644
--- a/core/tests/Drupal/Tests/UnitTestCase.php
+++ b/core/tests/Drupal/Tests/UnitTestCase.php
@@ -180,6 +180,12 @@ public function getConfigStorageStub(array $configs) {
*
* @return \Drupal\block\BlockInterface|\PHPUnit_Framework_MockObject_MockObject
* The mocked block.
+ *
+ * @deprecated in Drupal 8.5.x, will be removed before Drupal 9.0.0. Unit test
+ * base classes should not have dependencies on extensions. Set up mocks in
+ * individual tests.
+ *
+ * @see https://www.drupal.org/node/2896072
*/
protected function getBlockMockWithMachineName($machine_name) {
$plugin = $this->getMockBuilder('Drupal\Core\Block\BlockBase')
@@ -195,6 +201,7 @@ protected function getBlockMockWithMachineName($machine_name) {
$block->expects($this->any())
->method('getPlugin')
->will($this->returnValue($plugin));
+ @trigger_error(__METHOD__ . ' is deprecated in Drupal 8.5.x, will be removed before Drupal 9.0.0. Unit test base classes should not have dependencies on extensions. Set up mocks in individual tests.', E_USER_DEPRECATED);
return $block;
}
diff --git a/core/tests/Drupal/Tests/UnitTestCaseDeprecationTest.php b/core/tests/Drupal/Tests/UnitTestCaseDeprecationTest.php
new file mode 100644
index 0000000..8ecb70c
--- /dev/null
+++ b/core/tests/Drupal/Tests/UnitTestCaseDeprecationTest.php
@@ -0,0 +1,22 @@
+getBlockMockWithMachineName('test_name');
+ $this->assertEquals('test_name', $block_mock->getPlugin()->getMachineNameSuggestion());
+ }
+
+}
diff --git a/core/tests/fixtures/BrowserMissingDependentModuleMethodTest.php b/core/tests/fixtures/BrowserMissingDependentModuleMethodTest.php
new file mode 100644
index 0000000..4a94a53
--- /dev/null
+++ b/core/tests/fixtures/BrowserMissingDependentModuleMethodTest.php
@@ -0,0 +1,35 @@
+fail('Running test with missing required module.');
+ }
+
+ /**
+ * Public access for checkRequirements() to avoid reflection.
+ */
+ public function publicCheckRequirements() {
+ return parent::checkRequirements();
+ }
+
+}
diff --git a/core/tests/fixtures/BrowserMissingDependentModuleTest.php b/core/tests/fixtures/BrowserMissingDependentModuleTest.php
new file mode 100644
index 0000000..9650fc1
--- /dev/null
+++ b/core/tests/fixtures/BrowserMissingDependentModuleTest.php
@@ -0,0 +1,37 @@
+fail('Running test with missing required module.');
+ }
+
+ /**
+ * Public access for checkRequirements() to avoid reflection.
+ */
+ public function publicCheckRequirements() {
+ return parent::checkRequirements();
+ }
+
+}
diff --git a/core/tests/fixtures/KernelMissingDependentModuleMethodTest.php b/core/tests/fixtures/KernelMissingDependentModuleMethodTest.php
new file mode 100644
index 0000000..33dc793
--- /dev/null
+++ b/core/tests/fixtures/KernelMissingDependentModuleMethodTest.php
@@ -0,0 +1,33 @@
+fail('Running test with missing required module.');
+ }
+
+ /**
+ * Public access for checkRequirements() to avoid reflection.
+ */
+ public function publicCheckRequirements() {
+ return parent::checkRequirements();
+ }
+
+}
diff --git a/core/tests/fixtures/KernelMissingDependentModuleTest.php b/core/tests/fixtures/KernelMissingDependentModuleTest.php
new file mode 100644
index 0000000..3b8f316
--- /dev/null
+++ b/core/tests/fixtures/KernelMissingDependentModuleTest.php
@@ -0,0 +1,35 @@
+fail('Running test with missing required module.');
+ }
+
+ /**
+ * Public access for checkRequirements() to avoid reflection.
+ */
+ public function publicCheckRequirements() {
+ return parent::checkRequirements();
+ }
+
+}
diff --git a/core/themes/bartik/css/components/form.css b/core/themes/bartik/css/components/form.css
index 672e591..8ec05a3 100644
--- a/core/themes/bartik/css/components/form.css
+++ b/core/themes/bartik/css/components/form.css
@@ -172,7 +172,7 @@ input.form-submit:focus {
.node-form .form-wrapper {
margin-bottom: 2em;
}
-.node-form .node-form-footer,
+.node-form .entity-content-form-footer,
.node-form .field--name-status {
margin-bottom: 0;
}
diff --git a/core/themes/seven/css/components/colors.css b/core/themes/seven/css/components/colors.css
deleted file mode 100644
index 54358d8..0000000
--- a/core/themes/seven/css/components/colors.css
+++ /dev/null
@@ -1,16 +0,0 @@
-/**
- * Reusable colors.
- */
-.color-success {
- color: #325e1c;
- background-color: #f3faef;
-}
-.color-warning {
- color: #734c00;
- background-color: #fdf8ed;
-}
-.color-error {
- color: #a51b00;
- background-color: #fcf4f2;
-}
-
diff --git a/core/themes/seven/css/theme/colors.css b/core/themes/seven/css/theme/colors.css
new file mode 100644
index 0000000..54358d8
--- /dev/null
+++ b/core/themes/seven/css/theme/colors.css
@@ -0,0 +1,16 @@
+/**
+ * Reusable colors.
+ */
+.color-success {
+ color: #325e1c;
+ background-color: #f3faef;
+}
+.color-warning {
+ color: #734c00;
+ background-color: #fdf8ed;
+}
+.color-error {
+ color: #a51b00;
+ background-color: #fcf4f2;
+}
+
diff --git a/core/themes/seven/seven.libraries.yml b/core/themes/seven/seven.libraries.yml
index 21ac5bc..75e8c1a 100644
--- a/core/themes/seven/seven.libraries.yml
+++ b/core/themes/seven/seven.libraries.yml
@@ -10,7 +10,6 @@ global-styling:
css/components/content-header.css: {}
css/components/breadcrumb.css: {}
css/components/buttons.css: {}
- css/components/colors.css: {}
css/components/messages.css: {}
css/components/dropbutton.component.css: {}
css/components/entity-meta.css: {}
@@ -33,6 +32,8 @@ global-styling:
css/components/system-status-counter.css: {}
css/components/tabs.css: {}
css/components/views-ui.css: {}
+ theme:
+ css/theme/colors.css: {}
layout:
css/layout/layout.css: {}
dependencies:
diff --git a/core/themes/stable/templates/admin/admin-block.html.twig b/core/themes/stable/templates/admin/admin-block.html.twig
index 9464d40..7401695 100644
--- a/core/themes/stable/templates/admin/admin-block.html.twig
+++ b/core/themes/stable/templates/admin/admin-block.html.twig
@@ -10,9 +10,15 @@
* - content: (optional) The content of the block.
* - description: (optional) A description of the block.
* (Description should only be output if content is not available).
+ * - attributes: HTML attributes for the containing div element.
*/
#}
-
+{%
+ set classes = [
+ 'panel',
+ ]
+%}
+
{% if block.title %}
{{ block.title }}
{% endif %}