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

This commit is contained in:
Pantheon Automation 2016-10-06 15:16:20 -07:00 committed by Greg Anderson
parent 2f563ab520
commit f1c8716f57
1732 changed files with 52334 additions and 11780 deletions

View file

@ -1,4 +1,5 @@
<?php
/**
* @file
* Attach custom data fields to Drupal entities.

View file

@ -21,9 +21,9 @@ use Drupal\field\FieldConfigInterface;
*
* When a single entity is deleted, the Entity storage performs the
* following operations:
* - Invoking the FieldItemListInterface delete() method for each field on the
* entity. A file field type might use this method to delete uploaded files
* from the filesystem.
* - Invoking the method \Drupal\Core\Field\FieldItemListInterface::delete() for
* each field on the entity. A file field type might use this method to delete
* uploaded files from the filesystem.
* - Removing the data from storage.
* - Invoking the global hook_entity_delete() for all modules that implement it.
* Each hook implementation receives the entity being deleted and can operate

View file

@ -64,7 +64,7 @@ class FieldStorageConfigStorage extends ConfigEntityStorage {
* The module handler.
* @param \Drupal\Core\State\StateInterface $state
* The state key value store.
* @param \Drupal\Component\Plugin\PluginManagerInterface\FieldTypePluginManagerInterface
* @param \Drupal\Component\Plugin\PluginManagerInterface\FieldTypePluginManagerInterface $field_type_manager
* The field type plugin manager.
*/
public function __construct(EntityTypeInterface $entity_type, ConfigFactoryInterface $config_factory, UuidInterface $uuid_service, LanguageManagerInterface $language_manager, EntityManagerInterface $entity_manager, ModuleHandlerInterface $module_handler, StateInterface $state, FieldTypePluginManagerInterface $field_type_manager) {

View file

@ -59,11 +59,11 @@ class FieldInstancePerViewMode extends ViewModeBase {
'label',
'display_settings',
'widget_settings',
))
->fields('cnf', array(
))
->fields('cnf', array(
'type',
'module',
));
));
$query->join('content_node_field', 'cnf', 'cnfi.field_name = cnf.field_name');
$query->orderBy('cnfi.weight');

View file

@ -3,6 +3,7 @@
namespace Drupal\field\Tests\Boolean;
use Drupal\Component\Utility\Unicode;
use Drupal\entity_test\Entity\EntityTest;
use Drupal\field\Entity\FieldStorageConfig;
use Drupal\field\Entity\FieldConfig;
use Drupal\simpletest\WebTestBase;
@ -94,7 +95,8 @@ class BooleanFieldTest extends WebTestBase {
// Display creation form.
$this->drupalGet('entity_test/add');
$this->assertFieldByName("{$field_name}[value]", '', 'Widget found.');
$this->assertRaw($on);
$this->assertText($this->field->label(), 'Uses field label by default.');
$this->assertNoRaw($on, 'Does not use the "On" label.');
// Submit and ensure it is accepted.
$edit = array(
@ -106,12 +108,27 @@ class BooleanFieldTest extends WebTestBase {
$this->assertText(t('entity_test @id has been created.', array('@id' => $id)));
// Verify that boolean value is displayed.
$entity = entity_load('entity_test', $id);
$entity = EntityTest::load($id);
$display = entity_get_display($entity->getEntityTypeId(), $entity->bundle(), 'full');
$content = $display->build($entity);
$this->setRawContent(\Drupal::service('renderer')->renderRoot($content));
$this->assertRaw('<div class="field__item">' . $on . '</div>');
// Test with "On" label option.
entity_get_form_display('entity_test', 'entity_test', 'default')
->setComponent($field_name, array(
'type' => 'boolean_checkbox',
'settings' => array(
'display_label' => FALSE,
)
))
->save();
$this->drupalGet('entity_test/add');
$this->assertFieldByName("{$field_name}[value]", '', 'Widget found.');
$this->assertRaw($on);
$this->assertNoText($this->field->label());
// Test if we can change the on label.
$on = $this->randomMachineName();
$edit = array(
@ -122,21 +139,6 @@ class BooleanFieldTest extends WebTestBase {
$this->drupalGet('entity_test/add');
$this->assertRaw($on);
// Test the display_label option.
entity_get_form_display('entity_test', 'entity_test', 'default')
->setComponent($field_name, array(
'type' => 'boolean_checkbox',
'settings' => array(
'display_label' => TRUE,
)
))
->save();
$this->drupalGet('entity_test/add');
$this->assertFieldByName("{$field_name}[value]", '', 'Widget found.');
$this->assertNoRaw($on);
$this->assertText($this->field->label());
// Go to the form display page and check if the default settings works as
// expected.
$fieldEditUrl = 'entity_test/structure/entity_test/form-display';

View file

@ -3,6 +3,7 @@
namespace Drupal\field\Tests\Email;
use Drupal\Component\Utility\Unicode;
use Drupal\entity_test\Entity\EntityTest;
use Drupal\field\Entity\FieldConfig;
use Drupal\simpletest\WebTestBase;
use Drupal\field\Entity\FieldStorageConfig;
@ -96,7 +97,7 @@ class EmailFieldTest extends WebTestBase {
$this->assertRaw($value);
// Verify that a mailto link is displayed.
$entity = entity_load('entity_test', $id);
$entity = EntityTest::load($id);
$display = entity_get_display($entity->getEntityTypeId(), $entity->bundle(), 'full');
$content = $display->build($entity);
$this->setRawContent(\Drupal::service('renderer')->renderRoot($content));

View file

@ -94,7 +94,7 @@ class EntityReferenceAdminTest extends WebTestBase {
// The base handler settings should be displayed.
$entity_type_id = 'node';
$bundles = entity_get_bundles($entity_type_id);
$bundles = $this->container->get('entity_type.bundle.info')->getBundleInfo($entity_type_id);
foreach ($bundles as $bundle_name => $bundle_info) {
$this->assertFieldByName('settings[handler_settings][target_bundles][' . $bundle_name . ']');
}

View file

@ -223,7 +223,7 @@ class EntityReferenceFieldTranslatedReferenceViewTest extends WebTestBase {
'bundle' => $this->referrerType->id(),
'entity_type' => $this->testEntityTypeName,
])
->save();
->save();
entity_get_form_display($this->testEntityTypeName, $this->referrerType->id(), 'default')
->setComponent($this->referenceFieldName, array(
'type' => 'entity_reference_autocomplete',

View file

@ -82,7 +82,9 @@ class EntityReferenceIntegrationTest extends WebTestBase {
// Try to post the form again with no modification and check if the field
// values remain the same.
$entity = current(entity_load_multiple_by_properties($this->entityType, array('name' => $entity_name)));
/** @var \Drupal\Core\Entity\EntityStorageInterface $storage */
$storage = $this->container->get('entity_type.manager')->getStorage($this->entityType);
$entity = current($storage->loadByProperties(['name' => $entity_name]));
$this->drupalGet($this->entityType . '/manage/' . $entity->id() . '/edit');
$this->assertFieldByName($this->fieldName . '[0][target_id]', $referenced_entities[0]->label() . ' (' . $referenced_entities[0]->id() . ')');
$this->assertFieldByName($this->fieldName . '[1][target_id]', $referenced_entities[1]->label() . ' (' . $referenced_entities[1]->id() . ')');
@ -108,7 +110,7 @@ class EntityReferenceIntegrationTest extends WebTestBase {
// Try to post the form again with no modification and check if the field
// values remain the same.
$entity = current(entity_load_multiple_by_properties($this->entityType, array('name' => $entity_name)));
$entity = current($storage->loadByProperties(['name' => $entity_name]));
$this->drupalGet($this->entityType . '/manage/' . $entity->id() . '/edit');
$this->assertFieldByName($this->fieldName . '[target_id]', $target_id . ' (' . $referenced_entities[1]->id() . ')');
@ -119,7 +121,7 @@ class EntityReferenceIntegrationTest extends WebTestBase {
// Since we don't know the form structure for these widgets, just test
// that editing and saving an already created entity works.
$exclude = array('entity_reference_autocomplete', 'entity_reference_autocomplete_tags');
$entity = current(entity_load_multiple_by_properties($this->entityType, array('name' => $entity_name)));
$entity = current($storage->loadByProperties(['name' => $entity_name]));
$supported_widgets = \Drupal::service('plugin.manager.field.widget')->getOptions('entity_reference');
$supported_widget_types = array_diff(array_keys($supported_widgets), $exclude);
@ -173,7 +175,8 @@ class EntityReferenceIntegrationTest extends WebTestBase {
* An array of referenced entities.
*/
protected function assertFieldValues($entity_name, $referenced_entities) {
$entity = current(entity_load_multiple_by_properties($this->entityType, array('name' => $entity_name)));
$entity = current($this->container->get('entity_type.manager')->getStorage(
$this->entityType)->loadByProperties(['name' => $entity_name]));
$this->assertTrue($entity, format_string('%entity_type: Entity found in the database.', array('%entity_type' => $this->entityType)));

View file

@ -73,7 +73,7 @@ class FieldImportDeleteUninstallUiTest extends FieldTestBase {
// Verify entity has been created properly.
$id = $entity->id();
$entity = entity_load('entity_test', $id);
$entity = EntityTest::load($id);
$this->assertEqual($entity->field_tel->value, $value);
$this->assertEqual($entity->field_tel[0]->value, $value);

View file

@ -47,8 +47,11 @@ abstract class FieldTestBase extends WebTestBase {
*/
function assertFieldValues(EntityInterface $entity, $field_name, $expected_values, $langcode = LanguageInterface::LANGCODE_DEFAULT, $column = 'value') {
// Re-load the entity to make sure we have the latest changes.
\Drupal::entityManager()->getStorage($entity->getEntityTypeId())->resetCache(array($entity->id()));
$e = entity_load($entity->getEntityTypeId(), $entity->id());
$storage = $this->container->get('entity_type.manager')
->getStorage($entity->getEntityTypeId());
$storage->resetCache([$entity->id()]);
$e = $storage->load($entity->id());
$field = $values = $e->getTranslation($langcode)->$field_name;
// Filter out empty values so that they don't mess with the assertions.
$field->filterEmptyItems();

View file

@ -1,204 +0,0 @@
<?php
namespace Drupal\field\Tests;
use Drupal\Component\Utility\Unicode;
use Drupal\Core\Entity\EntityInterface;
use Drupal\Core\Language\LanguageInterface;
use Drupal\field\Entity\FieldConfig;
use Drupal\field\Entity\FieldStorageConfig;
use Drupal\simpletest\KernelTestBase;
/**
* Parent class for Field API unit tests.
*
* @deprecated in Drupal 8.1.x, will be removed before Drupal 8.2.x. Use
* \Drupal\Tests\field\Kernel\FieldKernelTestBase instead.
*/
abstract class FieldUnitTestBase extends KernelTestBase {
/**
* Modules to enable.
*
* @var array
*/
public static $modules = ['user', 'system', 'field', 'text', 'entity_test', 'field_test'];
/**
* Bag of created field storages and fields.
*
* Allows easy access to test field storage/field names/IDs/objects via:
* - $this->fieldTestData->field_name[suffix]
* - $this->fieldTestData->field_storage[suffix]
* - $this->fieldTestData->field_storage_uuid[suffix]
* - $this->fieldTestData->field[suffix]
* - $this->fieldTestData->field_definition[suffix]
*
* @see \Drupal\field\Tests\FieldUnitTestBase::createFieldWithStorage()
*
* @var \ArrayObject
*/
protected $fieldTestData;
/**
* Set the default field storage backend for fields created during tests.
*/
protected function setUp() {
parent::setUp();
$this->fieldTestData = new \ArrayObject(array(), \ArrayObject::ARRAY_AS_PROPS);
$this->installEntitySchema('entity_test');
$this->installEntitySchema('user');
$this->installSchema('system', ['sequences', 'key_value']);
// Set default storage backend and configure the theme system.
$this->installConfig(array('field', 'system'));
// Create user 1.
$storage = \Drupal::entityManager()->getStorage('user');
$storage
->create(array(
'uid' => 1,
'name' => 'entity-test',
'mail' => 'entity@localhost',
'status' => TRUE,
))
->save();
}
/**
* Create a field and an associated field storage.
*
* @param string $suffix
* (optional) A string that should only contain characters that are valid in
* PHP variable names as well.
* @param string $entity_type
* (optional) The entity type on which the field should be created.
* Defaults to "entity_test".
* @param string $bundle
* (optional) The entity type on which the field should be created.
* Defaults to the default bundle of the entity type.
*/
protected function createFieldWithStorage($suffix = '', $entity_type = 'entity_test', $bundle = NULL) {
if (empty($bundle)) {
$bundle = $entity_type;
}
$field_name = 'field_name' . $suffix;
$field_storage = 'field_storage' . $suffix;
$field_storage_uuid = 'field_storage_uuid' . $suffix;
$field = 'field' . $suffix;
$field_definition = 'field_definition' . $suffix;
$this->fieldTestData->$field_name = Unicode::strtolower($this->randomMachineName() . '_field_name' . $suffix);
$this->fieldTestData->$field_storage = FieldStorageConfig::create(array(
'field_name' => $this->fieldTestData->$field_name,
'entity_type' => $entity_type,
'type' => 'test_field',
'cardinality' => 4,
));
$this->fieldTestData->$field_storage->save();
$this->fieldTestData->$field_storage_uuid = $this->fieldTestData->$field_storage->uuid();
$this->fieldTestData->$field_definition = array(
'field_storage' => $this->fieldTestData->$field_storage,
'bundle' => $bundle,
'label' => $this->randomMachineName() . '_label',
'description' => $this->randomMachineName() . '_description',
'settings' => array(
'test_field_setting' => $this->randomMachineName(),
),
);
$this->fieldTestData->$field = FieldConfig::create($this->fieldTestData->$field_definition);
$this->fieldTestData->$field->save();
entity_get_form_display($entity_type, $bundle, 'default')
->setComponent($this->fieldTestData->$field_name, array(
'type' => 'test_field_widget',
'settings' => array(
'test_widget_setting' => $this->randomMachineName(),
)
))
->save();
}
/**
* Saves and reloads an entity.
*
* @param \Drupal\Core\Entity\EntityInterface $entity
* The entity to save.
*
* @return \Drupal\Core\Entity\EntityInterface
* The entity, freshly reloaded from storage.
*/
protected function entitySaveReload(EntityInterface $entity) {
$entity->save();
$controller = $this->container->get('entity.manager')->getStorage($entity->getEntityTypeId());
$controller->resetCache();
return $controller->load($entity->id());
}
/**
* Validate and save entity. Fail if violations are found.
*
* @param \Drupal\Core\Entity\EntityInterface $entity
* The entity to save.
*/
protected function entityValidateAndSave(EntityInterface $entity) {
$violations = $entity->validate();
if ($violations->count()) {
$this->fail($violations);
}
else {
$entity->save();
}
}
/**
* Generate random values for a field_test field.
*
* @param $cardinality
* Number of values to generate.
* @return
* An array of random values, in the format expected for field values.
*/
protected function _generateTestFieldValues($cardinality) {
$values = array();
for ($i = 0; $i < $cardinality; $i++) {
// field_test fields treat 0 as 'empty value'.
$values[$i]['value'] = mt_rand(1, 127);
}
return $values;
}
/**
* Assert that a field has the expected values in an entity.
*
* This function only checks a single column in the field values.
*
* @param EntityInterface $entity
* The entity to test.
* @param $field_name
* The name of the field to test
* @param $expected_values
* The array of expected values.
* @param $langcode
* (Optional) The language code for the values. Defaults to
* \Drupal\Core\Language\LanguageInterface::LANGCODE_NOT_SPECIFIED.
* @param $column
* (Optional) The name of the column to check. Defaults to 'value'.
*/
protected function assertFieldValues(EntityInterface $entity, $field_name, $expected_values, $langcode = LanguageInterface::LANGCODE_NOT_SPECIFIED, $column = 'value') {
// Re-load the entity to make sure we have the latest changes.
\Drupal::entityManager()->getStorage($entity->getEntityTypeId())->resetCache(array($entity->id()));
$e = entity_load($entity->getEntityTypeId(), $entity->id());
$field = $values = $e->getTranslation($langcode)->$field_name;
// Filter out empty values so that they don't mess with the assertions.
$field->filterEmptyItems();
$values = $field->getValue();
$this->assertEqual(count($values), count($expected_values), 'Expected number of values were saved.');
foreach ($expected_values as $key => $value) {
$this->assertEqual($values[$key][$column], $value, format_string('Value @value was saved correctly.', array('@value' => $value)));
}
}
}

View file

@ -6,6 +6,7 @@ use Drupal\Component\Utility\Html;
use Drupal\Core\Entity\Entity\EntityFormDisplay;
use Drupal\Core\Field\FieldStorageDefinitionInterface;
use Drupal\Core\Form\FormState;
use Drupal\entity_test\Entity\EntityTest;
use Drupal\entity_test\Entity\EntityTestBaseFieldDisplay;
use Drupal\field\Entity\FieldConfig;
use Drupal\field\Entity\FieldStorageConfig;
@ -130,7 +131,7 @@ class FormTest extends FieldTestBase {
preg_match('|entity_test/manage/(\d+)|', $this->url, $match);
$id = $match[1];
$this->assertText(t('entity_test @id has been created.', array('@id' => $id)), 'Entity was created');
$entity = entity_load('entity_test', $id);
$entity = EntityTest::load($id);
$this->assertEqual($entity->{$field_name}->value, $value, 'Field value was saved');
// Display edit form.
@ -146,7 +147,7 @@ class FormTest extends FieldTestBase {
$this->drupalPostForm(NULL, $edit, t('Save'));
$this->assertText(t('entity_test @id has been updated.', array('@id' => $id)), 'Entity was updated');
$this->container->get('entity.manager')->getStorage('entity_test')->resetCache(array($id));
$entity = entity_load('entity_test', $id);
$entity = EntityTest::load($id);
$this->assertEqual($entity->{$field_name}->value, $value, 'Field value was updated');
// Empty the field.
@ -157,7 +158,7 @@ class FormTest extends FieldTestBase {
$this->drupalPostForm('entity_test/manage/' . $id . '/edit', $edit, t('Save'));
$this->assertText(t('entity_test @id has been updated.', array('@id' => $id)), 'Entity was updated');
$this->container->get('entity.manager')->getStorage('entity_test')->resetCache(array($id));
$entity = entity_load('entity_test', $id);
$entity = EntityTest::load($id);
$this->assertTrue($entity->{$field_name}->isEmpty(), 'Field was emptied');
}
@ -189,7 +190,7 @@ class FormTest extends FieldTestBase {
preg_match('|entity_test/manage/(\d+)|', $this->url, $match);
$id = $match[1];
$this->assertText(t('entity_test @id has been created.', array('@id' => $id)), 'Entity was created.');
$entity = entity_load('entity_test', $id);
$entity = EntityTest::load($id);
$this->assertTrue($entity->{$field_name}->isEmpty(), 'Field is now empty.');
}
@ -218,7 +219,7 @@ class FormTest extends FieldTestBase {
preg_match('|entity_test/manage/(\d+)|', $this->url, $match);
$id = $match[1];
$this->assertText(t('entity_test @id has been created.', array('@id' => $id)), 'Entity was created');
$entity = entity_load('entity_test', $id);
$entity = EntityTest::load($id);
$this->assertEqual($entity->{$field_name}->value, $value, 'Field value was saved');
// Edit with missing required value.
@ -299,7 +300,7 @@ class FormTest extends FieldTestBase {
preg_match('|entity_test/manage/(\d+)|', $this->url, $match);
$id = $match[1];
$this->assertText(t('entity_test @id has been created.', array('@id' => $id)), 'Entity was created');
$entity = entity_load('entity_test', $id);
$entity = EntityTest::load($id);
ksort($field_values);
$field_values = array_values($field_values);
$this->assertIdentical($entity->{$field_name}->getValue(), $field_values, 'Field values were saved in the correct order');
@ -333,7 +334,7 @@ class FormTest extends FieldTestBase {
$this->assertTrue(isset($element[0]), 'Required symbol added field label.');
// Check that the label of the field input is visually hidden and contains
// the field title and an indication of the delta for a11y.
$element = $this->xpath('//label[@for=:for and contains(@class, "js-form-required") and contains(text(), :value)]', array(':for' => 'edit-field-unlimited-0-value', ':value' => $this->field['label'] . ' (value 1)'));
$element = $this->xpath('//label[@for=:for and contains(@class, "visually-hidden") and contains(text(), :value)]', array(':for' => 'edit-field-unlimited-0-value', ':value' => $this->field['label'] . ' (value 1)'));
$this->assertTrue(isset($element[0]), 'Required symbol not added for field input.');
}
@ -474,7 +475,7 @@ class FormTest extends FieldTestBase {
$id = $match[1];
// Check that the values were saved.
$entity_init = entity_load('entity_test', $id);
$entity_init = EntityTest::load($id);
$this->assertFieldValues($entity_init, $field_name, array(1, 2, 3));
// Display the form, check that the values are correctly filled in.
@ -554,7 +555,9 @@ class FormTest extends FieldTestBase {
$id = $match[1];
// Check that the default value was saved.
$entity = entity_load($entity_type, $id);
$storage = $this->container->get('entity_type.manager')
->getStorage($entity_type);
$entity = $storage->load($id);
$this->assertEqual($entity->$field_name_no_access->value, 99, 'Default value was saved for the field with no edit access.');
$this->assertEqual($entity->$field_name->value, 1, 'Entered value vas saved for the field with edit access.');
@ -566,13 +569,13 @@ class FormTest extends FieldTestBase {
$this->drupalPostForm($entity_type . '/manage/' . $id . '/edit', $edit, t('Save'));
// Check that the new revision has the expected values.
$this->container->get('entity.manager')->getStorage($entity_type)->resetCache(array($id));
$entity = entity_load($entity_type, $id);
$storage->resetCache([$id]);
$entity = $storage->load($id);
$this->assertEqual($entity->$field_name_no_access->value, 99, 'New revision has the expected value for the field with no edit access.');
$this->assertEqual($entity->$field_name->value, 2, 'New revision has the expected value for the field with edit access.');
// Check that the revision is also saved in the revisions table.
// $entity = entity_revision_load($entity_type, $entity->getRevisionId());
// $entity = entity_revision_load($entity_type, $entity->getRevisionId());
$this->assertEqual($entity->$field_name_no_access->value, 99, 'New revision has the expected value for the field with no edit access.');
$this->assertEqual($entity->$field_name->value, 2, 'New revision has the expected value for the field with edit access.');
}
@ -605,7 +608,10 @@ class FormTest extends FieldTestBase {
preg_match('|' . $entity_type . '/manage/(\d+)|', $this->url, $match);
$id = $match[1];
$this->assertText(t('entity_test_rev @id has been created.', array('@id' => $id)), 'Entity was created');
$entity = entity_load($entity_type, $id);
$storage = $this->container->get('entity_type.manager')
->getStorage($entity_type);
$entity = $storage->load($id);
$this->assertEqual($entity->{$field_name}->value, 99, 'Default value was saved');
// Update the field to remove the default value, and switch to the default
@ -627,8 +633,8 @@ class FormTest extends FieldTestBase {
$edit = array("{$field_name}[0][value]" => $value);
$this->drupalPostForm(NULL, $edit, t('Save'));
$this->assertText(t('entity_test_rev @id has been updated.', array('@id' => $id)), 'Entity was updated');
\Drupal::entityManager()->getStorage($entity_type)->resetCache(array($id));
$entity = entity_load($entity_type, $id);
$storage->resetCache([$id]);
$entity = $storage->load($id);
$this->assertEqual($entity->{$field_name}->value, $value, 'Field value was updated');
// Set the field back to hidden.
@ -641,8 +647,8 @@ class FormTest extends FieldTestBase {
$this->drupalPostForm($entity_type . '/manage/' . $id . '/edit', $edit, t('Save'));
// Check that the expected value has been carried over to the new revision.
\Drupal::entityManager()->getStorage($entity_type)->resetCache(array($id));
$entity = entity_load($entity_type, $id);
$storage->resetCache(array($id));
$entity = $storage->load($id);
$this->assertEqual($entity->{$field_name}->value, $value, 'New revision has the expected value for the field with the Hidden widget');
}

View file

@ -71,17 +71,16 @@ class NestedFormTest extends FieldTestBase {
// Create two entities.
$entity_type = 'entity_test';
$entity_1 = $this->container->get('entity_type.manager')
->getStorage($entity_type)
->create(array('id' => 1));
$storage = $this->container->get('entity_type.manager')
->getStorage($entity_type);
$entity_1 = $storage->create(['id' => 1]);
$entity_1->enforceIsNew();
$entity_1->field_single->value = 0;
$entity_1->field_unlimited->value = 1;
$entity_1->save();
$entity_2 = $this->container->get('entity_type.manager')
->getStorage($entity_type)
->create(array('id' => 2));
$entity_2 = $storage->create(array('id' => 2));
$entity_2->enforceIsNew();
$entity_2->field_single->value = 10;
$entity_2->field_unlimited->value = 11;
@ -104,8 +103,8 @@ class NestedFormTest extends FieldTestBase {
'entity_2[field_unlimited][1][value]' => 13,
);
$this->drupalPostForm(NULL, $edit, t('Save'));
$entity_1 = entity_load($entity_type, 1);
$entity_2 = entity_load($entity_type, 2);
$entity_1 = $storage->load(1);
$entity_2 = $storage->load(2);
$this->assertFieldValues($entity_1, 'field_single', array(1));
$this->assertFieldValues($entity_1, 'field_unlimited', array(2, 3));
$this->assertFieldValues($entity_2, 'field_single', array(11));

View file

@ -3,6 +3,7 @@
namespace Drupal\field\Tests\String;
use Drupal\Component\Utility\Unicode;
use Drupal\entity_test\Entity\EntityTest;
use Drupal\field\Entity\FieldConfig;
use Drupal\simpletest\WebTestBase;
use Drupal\field\Entity\FieldStorageConfig;
@ -91,7 +92,7 @@ class StringFieldTest extends WebTestBase {
$this->assertText(t('entity_test @id has been created.', array('@id' => $id)), 'Entity was created');
// Display the entity.
$entity = entity_load('entity_test', $id);
$entity = EntityTest::load($id);
$display = entity_get_display($entity->getEntityTypeId(), $entity->bundle(), 'full');
$content = $display->build($entity);
$this->setRawContent(\Drupal::service('renderer')->renderRoot($content));

View file

@ -146,6 +146,16 @@ class FieldUITest extends FieldTestBase {
$this->assertEqual(t('True'), (string) $option[0]);
$option = $this->xpath('//label[@for="edit-options-value-0"]');
$this->assertEqual(t('False'), (string) $option[0]);
// Expose the filter and see if the 'Any' option is added and if we can save
// it.
$this->drupalPostForm(NULL, [], 'Expose filter');
$option = $this->xpath('//label[@for="edit-options-value-all"]');
$this->assertEqual(t('- Any -'), (string) $option[0]);
$this->drupalPostForm(NULL, ['options[value]' => 'All', 'options[expose][required]' => FALSE], 'Apply');
$this->drupalPostForm(NULL, [], 'Save');
$this->drupalGet('/admin/structure/views/nojs/handler/test_view_fieldapi/default/filter/field_boolean_value');
$this->assertFieldChecked('edit-options-value-all');
}
}

View file

@ -7,7 +7,7 @@
*/
use Drupal\Core\Database\Database;
use Drupal\Component\Serialization\Yaml;
use Drupal\Core\Serialization\Yaml;
use Drupal\field\Entity\FieldStorageConfig;
$connection = Database::getConnection();

View file

@ -55,7 +55,7 @@ class BooleanItemTest extends FieldKernelTestBase {
// Verify entity has been created properly.
$id = $entity->id();
$entity = entity_load('entity_test', $id);
$entity = EntityTest::load($id);
$this->assertTrue($entity->field_boolean instanceof FieldItemListInterface, 'Field implements interface.');
$this->assertTrue($entity->field_boolean[0] instanceof FieldItemInterface, 'Field item implements interface.');
$this->assertEqual($entity->field_boolean->value, $value);
@ -68,7 +68,7 @@ class BooleanItemTest extends FieldKernelTestBase {
// Read changed entity and assert changed values.
$entity->save();
$entity = entity_load('entity_test', $id);
$entity = EntityTest::load($id);
$this->assertEqual($entity->field_boolean->value, $new_value);
// Test sample item generation.

View file

@ -137,7 +137,8 @@ class BulkDeleteTest extends FieldKernelTestBase {
$entity->save();
}
}
$this->entities = entity_load_multiple($this->entityTypeId);
$this->entities = $this->container->get('entity_type.manager')
->getStorage($this->entityTypeId)->loadMultiple();
foreach ($this->entities as $entity) {
// This test relies on the entities having stale field definitions
// so that the deleted field can be accessed on them. Access the field

View file

@ -52,7 +52,7 @@ class EmailItemTest extends FieldKernelTestBase {
// Verify entity has been created properly.
$id = $entity->id();
$entity = entity_load('entity_test', $id);
$entity = EntityTest::load($id);
$this->assertTrue($entity->field_email instanceof FieldItemListInterface, 'Field implements interface.');
$this->assertTrue($entity->field_email[0] instanceof FieldItemInterface, 'Field item implements interface.');
$this->assertEqual($entity->field_email->value, $value);
@ -65,7 +65,7 @@ class EmailItemTest extends FieldKernelTestBase {
// Read changed entity and assert changed values.
$entity->save();
$entity = entity_load('entity_test', $id);
$entity = EntityTest::load($id);
$this->assertEqual($entity->field_email->value, $new_value);
// Test sample item generation.

View file

@ -116,7 +116,7 @@ class EntityReferenceItemTest extends FieldKernelTestBase {
$entity->name->value = $this->randomMachineName();
$entity->save();
$entity = entity_load('entity_test', $entity->id());
$entity = EntityTest::load($entity->id());
$this->assertTrue($entity->field_test_taxonomy_term instanceof FieldItemListInterface, 'Field implements interface.');
$this->assertTrue($entity->field_test_taxonomy_term[0] instanceof FieldItemInterface, 'Field item implements interface.');
$this->assertEqual($entity->field_test_taxonomy_term->target_id, $tid);
@ -212,7 +212,7 @@ class EntityReferenceItemTest extends FieldKernelTestBase {
$entity->name->value = $this->randomMachineName();
$entity->save();
$entity = entity_load('entity_test', $entity->id());
$entity = EntityTest::load($entity->id());
$this->assertTrue($entity->field_test_taxonomy_vocabulary instanceof FieldItemListInterface, 'Field implements interface.');
$this->assertTrue($entity->field_test_taxonomy_vocabulary[0] instanceof FieldItemInterface, 'Field item implements interface.');
$this->assertEqual($entity->field_test_taxonomy_vocabulary->target_id, $referenced_entity_id);

View file

@ -70,7 +70,7 @@ class FieldImportDeleteUninstallTest extends FieldKernelTestBase {
// Verify entity has been created properly.
$id = $entity->id();
$entity = entity_load('entity_test', $id);
$entity = EntityTest::load($id);
$this->assertEqual($entity->field_test->value, $value);
$this->assertEqual($entity->field_test[0]->value, $value);
$this->assertEqual($entity->field_int->value, '99');
@ -134,7 +134,7 @@ class FieldImportDeleteUninstallTest extends FieldKernelTestBase {
// Verify entity has been created properly.
$id = $entity->id();
$entity = entity_load('entity_test', $id);
$entity = EntityTest::load($id);
$this->assertEqual($entity->field_test->value, $value);
}

View file

@ -186,8 +186,11 @@ abstract class FieldKernelTestBase extends KernelTestBase {
*/
protected function assertFieldValues(EntityInterface $entity, $field_name, $expected_values, $langcode = LanguageInterface::LANGCODE_NOT_SPECIFIED, $column = 'value') {
// Re-load the entity to make sure we have the latest changes.
\Drupal::entityManager()->getStorage($entity->getEntityTypeId())->resetCache(array($entity->id()));
$e = entity_load($entity->getEntityTypeId(), $entity->id());
$storage = $this->container->get('entity_type.manager')
->getStorage($entity->getEntityTypeId());
$storage->resetCache([$entity->id()]);
$e = $storage->load($this->entityId);
$field = $values = $e->getTranslation($langcode)->$field_name;
// Filter out empty values so that they don't mess with the assertions.
$field->filterEmptyItems();

View file

@ -61,7 +61,7 @@ class NumberItemTest extends FieldKernelTestBase {
// Verify entity has been created properly.
$id = $entity->id();
$entity = entity_load('entity_test', $id);
$entity = EntityTest::load($id);
$this->assertTrue($entity->field_integer instanceof FieldItemListInterface, 'Field implements interface.');
$this->assertTrue($entity->field_integer[0] instanceof FieldItemInterface, 'Field item implements interface.');
$this->assertEqual($entity->field_integer->value, $integer);
@ -88,7 +88,7 @@ class NumberItemTest extends FieldKernelTestBase {
// Read changed entity and assert changed values.
$entity->save();
$entity = entity_load('entity_test', $id);
$entity = EntityTest::load($id);
$this->assertEqual($entity->field_integer->value, $new_integer);
$this->assertEqual($entity->field_float->value, $new_float);
$this->assertEqual($entity->field_decimal->value, $new_decimal);

View file

@ -60,7 +60,7 @@ class ShapeItemTest extends FieldKernelTestBase {
// Verify entity has been created properly.
$id = $entity->id();
$entity = entity_load('entity_test', $id);
$entity = EntityTest::load($id);
$this->assertTrue($entity->{$this->fieldName} instanceof FieldItemListInterface, 'Field implements interface.');
$this->assertTrue($entity->{$this->fieldName}[0] instanceof FieldItemInterface, 'Field item implements interface.');
$this->assertEqual($entity->{$this->fieldName}->shape, $shape);
@ -78,7 +78,7 @@ class ShapeItemTest extends FieldKernelTestBase {
// Read changed entity and assert changed values.
$entity->save();
$entity = entity_load('entity_test', $id);
$entity = EntityTest::load($id);
$this->assertEqual($entity->{$this->fieldName}->shape, $new_shape);
$this->assertEqual($entity->{$this->fieldName}->color, $new_color);
}

View file

@ -59,7 +59,7 @@ class TestItemTest extends FieldKernelTestBase {
// Verify entity has been created properly.
$id = $entity->id();
$entity = entity_load('entity_test', $id);
$entity = EntityTest::load($id);
$this->assertTrue($entity->{$this->fieldName} instanceof FieldItemListInterface, 'Field implements interface.');
$this->assertTrue($entity->{$this->fieldName}[0] instanceof FieldItemInterface, 'Field item implements interface.');
$this->assertEqual($entity->{$this->fieldName}->value, $value);
@ -72,7 +72,7 @@ class TestItemTest extends FieldKernelTestBase {
// Read changed entity and assert changed values.
$entity->save();
$entity = entity_load('entity_test', $id);
$entity = EntityTest::load($id);
$this->assertEqual($entity->{$this->fieldName}->value, $new_value);
// Test the schema for this field type.