/**
  * Tests migration of user profile fields.
  */
 public function testUserProfileFields()
 {
     // Migrated a text field.
     $field = FieldConfig::load('user.user.profile_color');
     $this->assertIdentical('Favorite color', $field->label());
     $this->assertIdentical('List your favorite color', $field->getDescription());
     // Migrated a textarea.
     $field = FieldConfig::load('user.user.profile_biography');
     $this->assertIdentical('Biography', $field->label());
     $this->assertIdentical('Tell people a little bit about yourself', $field->getDescription());
     // Migrated checkbox field.
     $field = FieldConfig::load('user.user.profile_sell_address');
     $this->assertIdentical('Sell your email address?', $field->label());
     $this->assertIdentical("If you check this box, we'll sell your address to spammers to help line the pockets of our shareholders. Thanks!", $field->getDescription());
     // Migrated selection field.
     $field = FieldConfig::load('user.user.profile_sold_to');
     $this->assertIdentical('Sales Category', $field->label());
     $this->assertIdentical("Select the sales categories to which this user's address was sold.", $field->getDescription());
     // Migrated list field.
     $field = FieldConfig::load('user.user.profile_bands');
     $this->assertIdentical('Favorite bands', $field->label());
     $this->assertIdentical("Enter your favorite bands. When you've saved your profile, you'll be able to find other people with the same favorites.", $field->getDescription());
     // Migrated URL field.
     $field = FieldConfig::load('user.user.profile_blog');
     $this->assertIdentical('Blog', $field->label());
     $this->assertIdentical("Paste the full URL, including http://, of your personal blog.", $field->getDescription());
     // Migrated date field.
     $field = FieldConfig::load('user.user.profile_birthdate');
     $this->assertIdentical('Birthdate', $field->label());
     $this->assertIdentical("Enter your birth date and we'll send you a coupon.", $field->getDescription());
     // Another migrated checkbox field, with a different source visibility setting.
     $field = FieldConfig::load('user.user.profile_love_migrations');
     $this->assertIdentical('I love migrations', $field->label());
     $this->assertIdentical("If you check this box, you love migrations.", $field->getDescription());
 }
예제 #2
0
 /**
  * Tests that the default 'comment_body' field is correctly added.
  */
 function testCommentDefaultFields()
 {
     // Do not make assumptions on default node types created by the test
     // installation profile, and create our own.
     $this->drupalCreateContentType(array('type' => 'test_node_type'));
     $this->addDefaultCommentField('node', 'test_node_type');
     // Check that the 'comment_body' field is present on the comment bundle.
     $field = FieldConfig::loadByName('comment', 'comment', 'comment_body');
     $this->assertTrue(!empty($field), 'The comment_body field is added when a comment bundle is created');
     $field->delete();
     // Check that the 'comment_body' field is not deleted since it is persisted
     // even if it has no fields.
     $field_storage = FieldStorageConfig::loadByName('comment', 'comment_body');
     $this->assertTrue($field_storage, 'The comment_body field storage was not deleted');
     // Create a new content type.
     $type_name = 'test_node_type_2';
     $this->drupalCreateContentType(array('type' => $type_name));
     $this->addDefaultCommentField('node', $type_name);
     // Check that the 'comment_body' field exists and has an instance on the
     // new comment bundle.
     $field_storage = FieldStorageConfig::loadByName('comment', 'comment_body');
     $this->assertTrue($field_storage, 'The comment_body field exists');
     $field = FieldConfig::loadByName('comment', 'comment', 'comment_body');
     $this->assertTrue(isset($field), format_string('The comment_body field is present for comments on type @type', array('@type' => $type_name)));
     // Test adding a field that defaults to CommentItemInterface::CLOSED.
     $this->addDefaultCommentField('node', 'test_node_type', 'who_likes_ponies', CommentItemInterface::CLOSED, 'who_likes_ponies');
     $field = FieldConfig::load('node.test_node_type.who_likes_ponies');
     $this->assertEqual($field->getDefaultValueLiteral()[0]['status'], CommentItemInterface::CLOSED);
 }
 /**
  * Tests the widget.
  */
 protected function testWidget()
 {
     $user = $this->drupalCreateUser(['administer user fields']);
     $this->drupalLogin($user);
     // Test the widget when setting a default field value.
     $field_name = strtolower($this->randomMachineName());
     $selectable_plugin_type_id = 'block';
     $field_type = 'plugin:' . $selectable_plugin_type_id;
     $default_selected_plugin_id = 'broken';
     $this->drupalPostForm('admin/config/people/accounts/fields/add-field', ['label' => $this->randomString(), 'field_name' => $field_name, 'new_storage_type' => $field_type], t('Save and continue'));
     $this->drupalPostForm(NULL, [], t('Save field settings'));
     $this->drupalPostForm(NULL, [sprintf('default_value_input[field_%s][0][plugin_selector][container][select][container][plugin_id]', $field_name) => $default_selected_plugin_id], t('Choose'));
     $this->drupalPostForm(NULL, [], t('Save settings'));
     \Drupal::entityManager()->clearCachedFieldDefinitions();
     // Get all plugin fields.
     $field_storage_id = 'user.field_' . $field_name;
     $field_storage = FieldStorageConfig::load($field_storage_id);
     $this->assertNotNull($field_storage);
     $field_id = 'user.user.field_' . $field_name;
     /** @var \Drupal\field\FieldConfigInterface $field */
     $field = FieldConfig::load($field_id);
     $this->assertNotNull($field);
     $this->assertEqual($field->getDefaultValueLiteral()[0]['plugin_type_id'], $selectable_plugin_type_id);
     $this->assertEqual($field->getDefaultValueLiteral()[0]['plugin_id'], $default_selected_plugin_id);
     $this->assertTrue(is_array($field->getDefaultValueLiteral()[0]['plugin_configuration']));
     // Test the widget when creating an entity.
     $entity_selected_plugin_id = 'system_breadcrumb_block';
     $this->drupalPostForm('user/' . $user->id() . '/edit', [sprintf('field_%s[0][plugin_selector][container][select][container][plugin_id]', $field_name) => $entity_selected_plugin_id], t('Choose'));
     $this->drupalPostForm(NULL, [], t('Save'));
     // Test whether the widget displays field values.
     /** @var \Drupal\Core\Entity\ContentEntityInterface $user */
     $user = entity_load_unchanged('user', $user->id());
     $this->assertEqual($user->get('field_' . $field_name)->get(0)->get('plugin_type_id')->getValue(), $selectable_plugin_type_id);
     $this->assertEqual($user->get('field_' . $field_name)->get(0)->get('plugin_id')->getValue(), $entity_selected_plugin_id);
 }
 /**
  * Test the user picture field migration.
  */
 public function testUserPictureField()
 {
     /** @var \Drupal\field\FieldConfigInterface $field */
     $field = FieldConfig::load('user.user.user_picture');
     $this->assertTrue($field instanceof FieldConfigInterface);
     $this->assertIdentical('user', $field->getTargetEntityTypeId());
     $this->assertIdentical('user', $field->getTargetBundle());
     $this->assertIdentical('user_picture', $field->getName());
 }
예제 #5
0
 /**
  * Tests using entity fields of the file field type.
  */
 public function testFileItem()
 {
     // Check that the selection handler was automatically assigned to
     // 'default:file'.
     $field_definition = FieldConfig::load('entity_test.entity_test.file_test');
     $handler_id = $field_definition->getSetting('handler');
     $this->assertEqual($handler_id, 'default:file');
     // Create a test entity with the
     $entity = EntityTest::create();
     $entity->file_test->target_id = $this->file->id();
     $entity->file_test->display = 1;
     $entity->file_test->description = $description = $this->randomMachineName();
     $entity->name->value = $this->randomMachineName();
     $entity->save();
     $entity = EntityTest::load($entity->id());
     $this->assertTrue($entity->file_test instanceof FieldItemListInterface, 'Field implements interface.');
     $this->assertTrue($entity->file_test[0] instanceof FieldItemInterface, 'Field item implements interface.');
     $this->assertEqual($entity->file_test->target_id, $this->file->id());
     $this->assertEqual($entity->file_test->display, 1);
     $this->assertEqual($entity->file_test->description, $description);
     $this->assertEqual($entity->file_test->entity->getFileUri(), $this->file->getFileUri());
     $this->assertEqual($entity->file_test->entity->url(), $url = file_create_url($this->file->getFileUri()));
     $this->assertEqual($entity->file_test->entity->id(), $this->file->id());
     $this->assertEqual($entity->file_test->entity->uuid(), $this->file->uuid());
     // Make sure the computed files reflects updates to the file.
     file_put_contents('public://example-2.txt', $this->randomMachineName());
     $file2 = File::create(['uri' => 'public://example-2.txt']);
     $file2->save();
     $entity->file_test->target_id = $file2->id();
     $this->assertEqual($entity->file_test->entity->id(), $file2->id());
     $this->assertEqual($entity->file_test->entity->getFileUri(), $file2->getFileUri());
     // Test the deletion of an entity having an entity reference field targeting
     // a non-existing entity.
     $file2->delete();
     $entity->delete();
     // Test the generateSampleValue() method.
     $entity = EntityTest::create();
     $entity->file_test->generateSampleItems();
     $this->entityValidateAndSave($entity);
     // Verify that the sample file was stored in the correct directory.
     $uri = $entity->file_test->entity->getFileUri();
     $this->assertEqual($this->directory, dirname(file_uri_target($uri)));
     // Make sure the computed files reflects updates to the file.
     file_put_contents('public://example-3.txt', $this->randomMachineName());
     // Test unsaved file entity.
     $file3 = File::create(['uri' => 'public://example-3.txt']);
     $display = entity_get_display('entity_test', 'entity_test', 'default');
     $display->setComponent('file_test', ['label' => 'above', 'type' => 'file_default', 'weight' => 1])->save();
     $entity = EntityTest::create();
     $entity->file_test = array('entity' => $file3);
     $uri = $file3->getFileUri();
     $output = entity_view($entity, 'default');
     \Drupal::service('renderer')->renderRoot($output);
     $this->assertTrue(!empty($entity->file_test->entity));
     $this->assertEqual($entity->file_test->entity->getFileUri(), $uri);
 }
 /**
  * {@inheritdoc}
  *
  * @param string $field_config
  *   The ID of the field config whose field storage config is being edited.
  */
 public function buildForm(array $form, FormStateInterface $form_state, $field_config = NULL)
 {
     if ($field_config) {
         $field = FieldConfig::load($field_config);
         $form_state->set('field_config', $field);
         $form_state->set('entity_type_id', $field->getTargetEntityTypeId());
         $form_state->set('bundle', $field->getTargetBundle());
     }
     return parent::buildForm($form, $form_state);
 }
예제 #7
0
 /**
  * Tests migrating fields into non-existent content types.
  */
 public function testMigrateFieldIntoUnknownNodeType()
 {
     $this->sourceDatabase->delete('node_type')->condition('type', 'test_planet')->execute();
     // The field migrations use the migration plugin to ensure that the node
     // types exist, so this should produce no failures...
     $this->migrateFields();
     // ...and the field instances should not have been migrated.
     $this->assertNull(FieldConfig::load('node.test_planet.field_multivalue'));
     $this->assertNull(FieldConfig::load('node.test_planet.field_test_text_single_checkbox'));
 }
 /**
  * Tests the Drupal 6 user picture to Drupal 8 picture field instance migration.
  */
 public function testUserPictureFieldInstance()
 {
     $field = FieldConfig::load('user.user.user_picture');
     $settings = $field->getSettings();
     $this->assertIdentical('png gif jpg jpeg', $settings['file_extensions']);
     $this->assertIdentical('pictures', $settings['file_directory']);
     $this->assertIdentical('30KB', $settings['max_filesize']);
     $this->assertIdentical('85x85', $settings['max_resolution']);
     $this->assertIdentical(array('user', 'user', 'user_picture'), entity_load('migration', 'd6_user_picture_field_instance')->getIdMap()->lookupDestinationID(array('')));
 }
 /**
  * Tests the Drupal 6 vocabulary-node type association to Drupal 8 migration.
  */
 public function testVocabularyFieldInstance()
 {
     // Test that the field exists.
     $field_id = 'node.article.tags';
     $field = FieldConfig::load($field_id);
     $this->assertIdentical($field_id, $field->id(), 'Field instance exists on article bundle.');
     // Test the page bundle as well.
     $field_id = 'node.page.tags';
     $field = FieldConfig::load($field_id);
     $this->assertIdentical($field_id, $field->id(), 'Field instance exists on page bundle.');
     $this->assertIdentical(array('node', 'article', 'tags'), entity_load('migration', 'd6_vocabulary_field_instance')->getIdMap()->lookupDestinationID(array(4, 'article')));
 }
 /**
  * Tests migrating D7 fields to field_storage_config entities, then rolling back.
  */
 public function testFieldInstances()
 {
     // Test that the field instances have migrated (prior to rollback).
     parent::testFieldInstances();
     $this->executeRollback('d7_field_instance');
     $this->executeRollback('d7_field');
     // Check that field instances have been rolled back.
     $field_instance_ids = ['comment.comment_node_page.comment_body', 'node.page.body', 'comment.comment_node_article.comment_body', 'node.article.body', 'node.article.field_tags', 'node.article.field_image', 'comment.comment_node_blog.comment_body', 'node.blog.body', 'comment.comment_node_book.comment_body', 'node.book.body', 'node.forum.taxonomy_forums', 'comment.comment_node_forum.comment_body', 'node.forum.body', 'comment.comment_node_test_content_type.comment_body', 'node.test_content_type.field_boolean', 'node.test_content_type.field_email', 'node.test_content_type.field_phone', 'node.test_content_type.field_date', 'node.test_content_type.field_date_with_end_time', 'node.test_content_type.field_file', 'node.test_content_type.field_float', 'node.test_content_type.field_images', 'node.test_content_type.field_integer', 'node.test_content_type.field_link', 'node.test_content_type.field_text_list', 'node.test_content_type.field_integer_list', 'node.test_content_type.field_long_text', 'node.test_content_type.field_term_reference', 'node.test_content_type.field_text', 'comment.comment_node_test_content_type.field_integer', 'user.user.field_file'];
     foreach ($field_instance_ids as $field_instance_id) {
         $this->assertNull(FieldConfig::load($field_instance_id));
     }
 }
 /**
  * Asserts various aspects of a field config entity.
  *
  * @param string $id
  *   The entity ID in the form ENTITY_TYPE.BUNDLE.FIELD_NAME.
  * @param string $expected_label
  *   The expected field label.
  * @param string $expected_field_type
  *   The expected field type.
  * @param boolean $is_required
  *   Whether or not the field is required.
  */
 protected function assertEntity($id, $expected_label, $expected_field_type, $is_required)
 {
     list($expected_entity_type, $expected_bundle, $expected_name) = explode('.', $id);
     /** @var \Drupal\field\FieldConfigInterface $field */
     $field = FieldConfig::load($id);
     $this->assertTrue($field instanceof FieldConfigInterface);
     $this->assertIdentical($expected_label, $field->label());
     $this->assertIdentical($expected_field_type, $field->getType());
     $this->assertIdentical($expected_entity_type, $field->getTargetEntityTypeId());
     $this->assertIdentical($expected_bundle, $field->getTargetBundle());
     $this->assertIdentical($expected_name, $field->getName());
     $this->assertEqual($is_required, $field->isRequired());
     $this->assertIdentical($expected_entity_type . '.' . $expected_name, $field->getFieldStorageDefinition()->id());
 }
예제 #12
0
 protected function setUp()
 {
     parent::setUp();
     $this->fieldName = Unicode::strtolower($this->randomMachineName() . '_field_name');
     $field_storage = array('field_name' => $this->fieldName, 'entity_type' => $this->entityTypeId, 'type' => 'test_field', 'cardinality' => 4);
     entity_create('field_storage_config', $field_storage)->save();
     $this->fieldStorage = FieldStorageConfig::load($this->entityTypeId . '.' . $this->fieldName);
     $field = array('field_storage' => $this->fieldStorage, 'bundle' => $this->entityTypeId);
     entity_create('field_config', $field)->save();
     $this->field = FieldConfig::load($this->entityTypeId . '.' . $field['bundle'] . '.' . $this->fieldName);
     entity_get_form_display($this->entityTypeId, $this->entityTypeId, 'default')->setComponent($this->fieldName)->save();
     for ($i = 0; $i < 3; ++$i) {
         ConfigurableLanguage::create(array('id' => 'l' . $i, 'label' => $this->randomString()))->save();
     }
 }
 /**
  * Tests the Drupal 6 upload settings to Drupal 8 field instance migration.
  */
 public function testUploadFieldInstance()
 {
     $field = FieldConfig::load('node.page.upload');
     $settings = $field->getSettings();
     $this->assertIdentical('node.page.upload', $field->id());
     $this->assertIdentical('jpg jpeg gif png txt doc xls pdf ppt pps odt ods odp', $settings['file_extensions']);
     $this->assertIdentical('1MB', $settings['max_filesize']);
     $this->assertIdentical(TRUE, $settings['description_field']);
     $field = FieldConfig::load('node.story.upload');
     $this->assertIdentical('node.story.upload', $field->id());
     // Shouldn't exist.
     $field = FieldConfig::load('node.article.upload');
     $this->assertTrue(is_null($field));
     $this->assertIdentical(array('node', 'page', 'upload'), Migration::load('d6_upload_field_instance')->getIdMap()->lookupDestinationID(array('page')));
 }
 /**
  * Tests the block content body field migration.
  */
 public function testBlockContentBodyFieldMigration()
 {
     /** @var \Drupal\field\FieldStorageConfigInterface $storage */
     $storage = FieldStorageConfig::load('block_content.body');
     $this->assertTrue($storage instanceof FieldStorageConfigInterface);
     $this->assertIdentical('block_content', $storage->getTargetEntityTypeId());
     $this->assertIdentical(['basic'], array_values($storage->getBundles()));
     $this->assertIdentical('body', $storage->getName());
     /** @var \Drupal\field\FieldConfigInterface $field */
     $field = FieldConfig::load('block_content.basic.body');
     $this->assertTrue($field instanceof FieldConfigInterface);
     $this->assertIdentical('block_content', $field->getTargetEntityTypeId());
     $this->assertIdentical('basic', $field->getTargetBundle());
     $this->assertIdentical('body', $field->getName());
     $this->assertIdentical('Body', $field->getLabel());
 }
예제 #15
0
 /**
  * Tests that comments are deleted with the node.
  */
 function testNodeDeletion()
 {
     $this->drupalLogin($this->webUser);
     $comment = $this->postComment($this->node, $this->randomMachineName(), $this->randomMachineName());
     $this->assertTrue($comment->id(), 'The comment could be loaded.');
     $this->node->delete();
     $this->assertFalse(Comment::load($comment->id()), 'The comment could not be loaded after the node was deleted.');
     // Make sure the comment field storage and all its fields are deleted when
     // the node type is deleted.
     $this->assertNotNull(FieldStorageConfig::load('node.comment'), 'Comment field storage exists');
     $this->assertNotNull(FieldConfig::load('node.article.comment'), 'Comment field exists');
     // Delete the node type.
     entity_delete_multiple('node_type', array($this->node->bundle()));
     $this->assertNull(FieldStorageConfig::load('node.comment'), 'Comment field storage deleted');
     $this->assertNull(FieldConfig::load('node.article.comment'), 'Comment field deleted');
 }
 /**
  * Tests the Drupal 6 vocabulary-node type association to Drupal 8 migration.
  */
 public function testVocabularyFieldInstance()
 {
     // Test that the field exists.
     $field_id = 'node.article.tags';
     $field = FieldConfig::load($field_id);
     $this->assertIdentical($field_id, $field->id(), 'Field instance exists on article bundle.');
     // Test the page bundle as well.
     $field_id = 'node.page.tags';
     $field = FieldConfig::load($field_id);
     $this->assertIdentical($field_id, $field->id(), 'Field instance exists on page bundle.');
     $settings = $field->getSettings();
     $this->assertIdentical('default:taxonomy_term', $settings['handler'], 'The handler plugin ID is correct.');
     $this->assertIdentical(['tags'], $settings['handler_settings']['target_bundles'], 'The target_bundle handler setting is correct.');
     $this->assertIdentical(TRUE, $settings['handler_settings']['auto_create'], 'The "auto_create" setting is correct.');
     $this->assertIdentical(array('node', 'article', 'tags'), entity_load('migration', 'd6_vocabulary_field_instance')->getIdMap()->lookupDestinationID(array(4, 'article')));
 }
 /**
  * Tests a single node type.
  *
  * @dataProvider testNodeTypeDataProvider
  *
  * @param string $id
  *   The node type ID.
  * @param string $label
  *   The expected label.
  * @param string $description
  *   The expected node type description.
  * @param string $help
  *   The expected help text.
  */
 protected function assertEntity($id, $label, $description, $help, $display_submitted, $new_revision, $body_label = NULL)
 {
     /** @var \Drupal\node\NodeTypeInterface $entity */
     $entity = NodeType::load($id);
     $this->assertTrue($entity instanceof NodeTypeInterface);
     $this->assertIdentical($label, $entity->label());
     $this->assertIdentical($description, $entity->getDescription());
     $this->assertIdentical($help, $entity->getHelp());
     $this->assertIdentical($display_submitted, $entity->displaySubmitted(), 'Submission info is displayed');
     $this->assertIdentical($new_revision, $entity->isNewRevision(), 'Is a new revision');
     if ($body_label) {
         /** @var \Drupal\field\FieldConfigInterface $body */
         $body = FieldConfig::load('node.' . $id . '.body');
         $this->assertTrue($body instanceof FieldConfigInterface);
         $this->assertIdentical($body_label, $body->label());
     }
 }
 /**
  * Asserts a comment field entity.
  *
  * @param string $id
  *   The entity ID.
  * @param string $field_name
  *   The field name.
  * @param string $bundle
  *   The bundle ID.
  * @param int $default_mode
  *   The field's default_mode setting.
  * @param int $per_page
  *   The field's per_page setting.
  * @param bool $anonymous
  *   The field's anonymous setting.
  * @param int $form_location
  *   The field's form_location setting.
  * @param bool $preview
  *   The field's preview setting.
  */
 protected function assertEntity($id, $field_name, $bundle, $default_mode, $per_page, $anonymous, $form_location, $preview)
 {
     $entity = FieldConfig::load($id);
     $this->assertTrue($entity instanceof FieldConfigInterface);
     /** @var \Drupal\field\FieldConfigInterface $entity */
     $this->assertIdentical('node', $entity->getTargetEntityTypeId());
     $this->assertIdentical('Comments', $entity->label());
     $this->assertTrue($entity->isRequired());
     $this->assertIdentical($field_name, $entity->getFieldStorageDefinition()->getName());
     $this->assertIdentical($bundle, $entity->getTargetBundle());
     $this->assertTrue($entity->get('default_value')[0]['status']);
     $this->assertEqual($default_mode, $entity->getSetting('default_mode'));
     $this->assertIdentical($per_page, $entity->getSetting('per_page'));
     $this->assertEqual($anonymous, $entity->getSetting('anonymous'));
     // This assertion fails because 1 !== TRUE. It's extremely strange that
     // the form_location setting is returning a boolean, but this appears to
     // be a problem with the entity, not with the migration.
     // $this->asserIdentical($form_location, $entity->getSetting('form_location'));
     $this->assertEqual($preview, $entity->getSetting('preview'));
 }
 /**
  * Tests importing an updated field.
  */
 function testImportChange()
 {
     $this->installConfig(['field_test_config']);
     $field_storage_id = 'field_test_import';
     $field_id = "entity_test.entity_test.{$field_storage_id}";
     $field_config_name = "field.field.{$field_id}";
     $active = $this->container->get('config.storage');
     $sync = $this->container->get('config.storage.sync');
     $this->copyConfig($active, $sync);
     // Save as files in the sync directory.
     $field = $active->read($field_config_name);
     $new_label = 'Test update import field';
     $field['label'] = $new_label;
     $sync->write($field_config_name, $field);
     // Import the content of the sync directory.
     $this->configImporter()->import();
     // Check that the updated config was correctly imported.
     $field = FieldConfig::load($field_id);
     $this->assertEqual($field->getLabel(), $new_label, 'field label updated');
 }
예제 #20
0
 /**
  * Tests migration of file variables to file.settings.yml.
  */
 public function testFieldInstanceSettings()
 {
     $entity = entity_create('node', array('type' => 'story'));
     // Test a text field.
     $field = FieldConfig::load('node.story.field_test');
     $this->assertIdentical('Text Field', $field->label());
     $expected = array('max_length' => 255);
     $this->assertIdentical($expected, $field->getSettings());
     $this->assertIdentical('text for default value', $entity->field_test->value);
     // Test a number field.
     $field = FieldConfig::load('node.story.field_test_two');
     $this->assertIdentical('Integer Field', $field->label());
     $expected = array('min' => 10, 'max' => 100, 'prefix' => 'pref', 'suffix' => 'suf', 'unsigned' => FALSE, 'size' => 'normal');
     $this->assertIdentical($expected, $field->getSettings());
     $field = FieldConfig::load('node.story.field_test_four');
     $this->assertIdentical('Float Field', $field->label());
     $expected = array('min' => 100.0, 'max' => 200.0, 'prefix' => 'id-', 'suffix' => '');
     $this->assertIdentical($expected, $field->getSettings());
     // Test email field.
     $field = FieldConfig::load('node.story.field_test_email');
     $this->assertIdentical('Email Field', $field->label());
     $this->assertIdentical('*****@*****.**', $entity->field_test_email->value);
     // Test a filefield.
     $field = FieldConfig::load('node.story.field_test_filefield');
     $this->assertIdentical('File Field', $field->label());
     $expected = array('file_extensions' => 'txt pdf doc', 'file_directory' => 'images', 'description_field' => TRUE, 'max_filesize' => '200KB', 'target_type' => 'file', 'display_field' => FALSE, 'display_default' => FALSE, 'uri_scheme' => 'public', 'handler' => 'default:node', 'handler_settings' => array(), 'target_bundle' => NULL);
     $field_settings = $field->getSettings();
     ksort($expected);
     ksort($field_settings);
     // This is the only way to compare arrays.
     $this->assertIdentical($expected, $field_settings);
     // Test a link field.
     $field = FieldConfig::load('node.story.field_test_link');
     $this->assertIdentical('Link Field', $field->label());
     $expected = array('title' => 2, 'link_type' => LinkItemInterface::LINK_GENERIC);
     $this->assertIdentical($expected, $field->getSettings());
     $this->assertIdentical('default link title', $entity->field_test_link->title, 'Field field_test_link default title is correct.');
     $this->assertIdentical('http://drupal.org', $entity->field_test_link->url, 'Field field_test_link default title is correct.');
     $this->assertIdentical([], $entity->field_test_link->options['attributes']);
 }
예제 #21
0
 protected function setUp()
 {
     parent::setUp();
     $this->languageManager = $this->container->get('language_manager');
     foreach (entity_test_entity_types() as $entity_type_id) {
         // The entity_test schema is installed by the parent.
         if ($entity_type_id != 'entity_test') {
             $this->installEntitySchema($entity_type_id);
         }
     }
     $this->installConfig(array('language'));
     // Create the test field.
     module_load_install('entity_test');
     entity_test_install();
     // Enable translations for the test entity type.
     $this->state->set('entity_test.translation', TRUE);
     // Create a translatable test field.
     $this->fieldName = Unicode::strtolower($this->randomMachineName() . '_field_name');
     // Create an untranslatable test field.
     $this->untranslatableFieldName = Unicode::strtolower($this->randomMachineName() . '_field_name');
     // Create field fields in all entity variations.
     foreach (entity_test_entity_types() as $entity_type) {
         entity_create('field_storage_config', array('field_name' => $this->fieldName, 'entity_type' => $entity_type, 'type' => 'text', 'cardinality' => 4))->save();
         entity_create('field_config', array('field_name' => $this->fieldName, 'entity_type' => $entity_type, 'bundle' => $entity_type, 'translatable' => TRUE))->save();
         $this->field[$entity_type] = FieldConfig::load($entity_type . '.' . $entity_type . '.' . $this->fieldName);
         entity_create('field_storage_config', array('field_name' => $this->untranslatableFieldName, 'entity_type' => $entity_type, 'type' => 'text', 'cardinality' => 4))->save();
         entity_create('field_config', array('field_name' => $this->untranslatableFieldName, 'entity_type' => $entity_type, 'bundle' => $entity_type, 'translatable' => FALSE))->save();
     }
     // Create the default languages.
     $this->installConfig(array('language'));
     // Create test languages.
     $this->langcodes = array();
     for ($i = 0; $i < 3; ++$i) {
         $language = ConfigurableLanguage::create(array('id' => 'l' . $i, 'label' => $this->randomString(), 'weight' => $i));
         $this->langcodes[$i] = $language->getId();
         $language->save();
     }
 }
 /**
  * Test the deletion of a field.
  */
 function testDeleteField()
 {
     // TODO: Test deletion of the data stored in the field also.
     // Need to check that data for a 'deleted' field / storage doesn't get loaded
     // Need to check data marked deleted is cleaned on cron (not implemented yet...)
     // Create two fields for the same field storage so we can test that only one
     // is deleted.
     FieldConfig::create($this->fieldDefinition)->save();
     $another_field_definition = $this->fieldDefinition;
     $another_field_definition['bundle'] .= '_another_bundle';
     entity_test_create_bundle($another_field_definition['bundle']);
     FieldConfig::create($another_field_definition)->save();
     // Test that the first field is not deleted, and then delete it.
     $field = current(entity_load_multiple_by_properties('field_config', array('entity_type' => 'entity_test', 'field_name' => $this->fieldDefinition['field_name'], 'bundle' => $this->fieldDefinition['bundle'], 'include_deleted' => TRUE)));
     $this->assertTrue(!empty($field) && empty($field->deleted), 'A new field is not marked for deletion.');
     $field->delete();
     // Make sure the field is marked as deleted when it is specifically loaded.
     $field = current(entity_load_multiple_by_properties('field_config', array('entity_type' => 'entity_test', 'field_name' => $this->fieldDefinition['field_name'], 'bundle' => $this->fieldDefinition['bundle'], 'include_deleted' => TRUE)));
     $this->assertTrue($field->isDeleted(), 'A deleted field is marked for deletion.');
     // Try to load the field normally and make sure it does not show up.
     $field = FieldConfig::load('entity_test.' . '.' . $this->fieldDefinition['bundle'] . '.' . $this->fieldDefinition['field_name']);
     $this->assertTrue(empty($field), 'A deleted field is not loaded by default.');
     // Make sure the other field is not deleted.
     $another_field = FieldConfig::load('entity_test.' . $another_field_definition['bundle'] . '.' . $another_field_definition['field_name']);
     $this->assertTrue(!empty($another_field) && empty($another_field->deleted), 'A non-deleted field is not marked for deletion.');
 }
예제 #23
0
 /**
  * Tests that the 'handler' field setting stores the proper plugin ID.
  */
 public function testSelectionHandlerSettings()
 {
     $field_name = Unicode::strtolower($this->randomMachineName());
     $field_storage = FieldStorageConfig::create(array('field_name' => $field_name, 'entity_type' => 'entity_test', 'type' => 'entity_reference', 'settings' => array('target_type' => 'entity_test')));
     $field_storage->save();
     // Do not specify any value for the 'handler' setting in order to verify
     // that the default handler with the correct derivative is used.
     $field = FieldConfig::create(array('field_storage' => $field_storage, 'bundle' => 'entity_test'));
     $field->save();
     $field = FieldConfig::load($field->id());
     $this->assertEqual($field->getSetting('handler'), 'default:entity_test');
     // Change the target_type in the field storage, and check that the handler
     // was correctly reassigned in the field.
     $field_storage->setSetting('target_type', 'entity_test_rev');
     $field_storage->save();
     $field = FieldConfig::load($field->id());
     $this->assertEqual($field->getSetting('handler'), 'default:entity_test_rev');
     // Change the handler to another, non-derivative plugin.
     $field->setSetting('handler', 'views');
     $field->save();
     $field = FieldConfig::load($field->id());
     $this->assertEqual($field->getSetting('handler'), 'views');
     // Change the target_type in the field storage again, and check that the
     // non-derivative handler was unchanged.
     $field_storage->setSetting('target_type', 'entity_test_rev');
     $field_storage->save();
     $field = FieldConfig::load($field->id());
     $this->assertEqual($field->getSetting('handler'), 'views');
 }
예제 #24
0
 /**
  * Test the deletion of a field storage.
  */
 function testDelete()
 {
     // TODO: Also test deletion of the data stored in the field ?
     // Create two fields (so we can test that only one is deleted).
     $field_storage_definition = array('field_name' => 'field_1', 'type' => 'test_field', 'entity_type' => 'entity_test');
     FieldStorageConfig::create($field_storage_definition)->save();
     $another_field_storage_definition = array('field_name' => 'field_2', 'type' => 'test_field', 'entity_type' => 'entity_test');
     FieldStorageConfig::create($another_field_storage_definition)->save();
     // Create fields for each.
     $field_definition = array('field_name' => $field_storage_definition['field_name'], 'entity_type' => 'entity_test', 'bundle' => 'entity_test');
     FieldConfig::create($field_definition)->save();
     $another_field_definition = $field_definition;
     $another_field_definition['field_name'] = $another_field_storage_definition['field_name'];
     FieldConfig::create($another_field_definition)->save();
     // Test that the first field is not deleted, and then delete it.
     $field_storage = current(entity_load_multiple_by_properties('field_storage_config', array('field_name' => $field_storage_definition['field_name'], 'include_deleted' => TRUE)));
     $this->assertTrue(!empty($field_storage) && !$field_storage->isDeleted(), 'A new storage is not marked for deletion.');
     FieldStorageConfig::loadByName('entity_test', $field_storage_definition['field_name'])->delete();
     // Make sure that the field is marked as deleted when it is specifically
     // loaded.
     $field_storage = current(entity_load_multiple_by_properties('field_storage_config', array('field_name' => $field_storage_definition['field_name'], 'include_deleted' => TRUE)));
     $this->assertTrue($field_storage->isDeleted(), 'A deleted storage is marked for deletion.');
     // Make sure that this field is marked as deleted when it is
     // specifically loaded.
     $field = current(entity_load_multiple_by_properties('field_config', array('entity_type' => 'entity_test', 'field_name' => $field_definition['field_name'], 'bundle' => $field_definition['bundle'], 'include_deleted' => TRUE)));
     $this->assertTrue($field->isDeleted(), 'A field whose storage was deleted is marked for deletion.');
     // Try to load the storage normally and make sure it does not show up.
     $field_storage = FieldStorageConfig::load('entity_test.' . $field_storage_definition['field_name']);
     $this->assertTrue(empty($field_storage), 'A deleted storage is not loaded by default.');
     // Try to load the field normally and make sure it does not show up.
     $field = FieldConfig::load('entity_test.' . '.' . $field_definition['bundle'] . '.' . $field_definition['field_name']);
     $this->assertTrue(empty($field), 'A field whose storage was deleted is not loaded by default.');
     // Make sure the other field and its storage are not deleted.
     $another_field_storage = FieldStorageConfig::load('entity_test.' . $another_field_storage_definition['field_name']);
     $this->assertTrue(!empty($another_field_storage) && !$another_field_storage->isDeleted(), 'A non-deleted storage is not marked for deletion.');
     $another_field = FieldConfig::load('entity_test.' . $another_field_definition['bundle'] . '.' . $another_field_definition['field_name']);
     $this->assertTrue(!empty($another_field) && !$another_field->isDeleted(), 'A field whose storage was not deleted is not marked for deletion.');
     // Try to create a new field the same name as a deleted field and
     // write data into it.
     FieldStorageConfig::create($field_storage_definition)->save();
     FieldConfig::create($field_definition)->save();
     $field_storage = FieldStorageConfig::load('entity_test.' . $field_storage_definition['field_name']);
     $this->assertTrue(!empty($field_storage) && !$field_storage->isDeleted(), 'A new storage with a previously used name is created.');
     $field = FieldConfig::load('entity_test.' . $field_definition['bundle'] . '.' . $field_definition['field_name']);
     $this->assertTrue(!empty($field) && !$field->isDeleted(), 'A new field for a previously used field name is created.');
     // Save an entity with data for the field
     $entity = EntityTest::create();
     $values[0]['value'] = mt_rand(1, 127);
     $entity->{$field_storage->getName()}->value = $values[0]['value'];
     $entity = $this->entitySaveReload($entity);
     // Verify the field is present on load
     $this->assertIdentical(count($entity->{$field_storage->getName()}), count($values), "Data in previously deleted field saves and loads correctly");
     foreach ($values as $delta => $value) {
         $this->assertEqual($entity->{$field_storage->getName()}[$delta]->value, $values[$delta]['value'], "Data in previously deleted field saves and loads correctly");
     }
 }
 /**
  * Tests deleting field storages and fields as part of config import.
  */
 public function testImportDelete()
 {
     $this->installConfig(['field_test_config']);
     // At this point there are 5 field configuration objects in the active
     // storage.
     // - field.storage.entity_test.field_test_import
     // - field.storage.entity_test.field_test_import_2
     // - field.field.entity_test.entity_test.field_test_import
     // - field.field.entity_test.entity_test.field_test_import_2
     // - field.field.entity_test.test_bundle.field_test_import_2
     $field_name = 'field_test_import';
     $field_storage_id = "entity_test.{$field_name}";
     $field_name_2 = 'field_test_import_2';
     $field_storage_id_2 = "entity_test.{$field_name_2}";
     $field_id = "entity_test.entity_test.{$field_name}";
     $field_id_2a = "entity_test.entity_test.{$field_name_2}";
     $field_id_2b = "entity_test.test_bundle.{$field_name_2}";
     $field_storage_config_name = "field.storage.{$field_storage_id}";
     $field_storage_config_name_2 = "field.storage.{$field_storage_id_2}";
     $field_config_name = "field.field.{$field_id}";
     $field_config_name_2a = "field.field.{$field_id_2a}";
     $field_config_name_2b = "field.field.{$field_id_2b}";
     // Create a second bundle for the 'Entity test' entity type.
     entity_test_create_bundle('test_bundle');
     // Get the uuid's for the field storages.
     $field_storage_uuid = FieldStorageConfig::load($field_storage_id)->uuid();
     $field_storage_uuid_2 = FieldStorageConfig::load($field_storage_id_2)->uuid();
     $active = $this->container->get('config.storage');
     $staging = $this->container->get('config.storage.staging');
     $this->copyConfig($active, $staging);
     $this->assertTrue($staging->delete($field_storage_config_name), String::format('Deleted field storage: !field_storage', array('!field_storage' => $field_storage_config_name)));
     $this->assertTrue($staging->delete($field_storage_config_name_2), String::format('Deleted field storage: !field_storage', array('!field_storage' => $field_storage_config_name_2)));
     $this->assertTrue($staging->delete($field_config_name), String::format('Deleted field: !field', array('!field' => $field_config_name)));
     $this->assertTrue($staging->delete($field_config_name_2a), String::format('Deleted field: !field', array('!field' => $field_config_name_2a)));
     $this->assertTrue($staging->delete($field_config_name_2b), String::format('Deleted field: !field', array('!field' => $field_config_name_2b)));
     $deletes = $this->configImporter()->getUnprocessedConfiguration('delete');
     $this->assertEqual(count($deletes), 5, 'Importing configuration will delete 3 fields and 2 field storages.');
     // Import the content of the staging directory.
     $this->configImporter()->import();
     // Check that the field storages and fields are gone.
     \Drupal::entityManager()->getStorage('field_storage_config')->resetCache(array($field_storage_id));
     $field_storage = FieldStorageConfig::load($field_storage_id);
     $this->assertFalse($field_storage, 'The field storage was deleted.');
     \Drupal::entityManager()->getStorage('field_storage_config')->resetCache(array($field_storage_id_2));
     $field_storage_2 = FieldStorageConfig::load($field_storage_id_2);
     $this->assertFalse($field_storage_2, 'The second field storage was deleted.');
     \Drupal::entityManager()->getStorage('field_config')->resetCache(array($field_id));
     $field = FieldConfig::load($field_id);
     $this->assertFalse($field, 'The field was deleted.');
     \Drupal::entityManager()->getStorage('field_config')->resetCache(array($field_id_2a));
     $field_2a = FieldConfig::load($field_id_2a);
     $this->assertFalse($field_2a, 'The second field on test bundle was deleted.');
     \Drupal::entityManager()->getStorage('field_config')->resetCache(array($field_id_2b));
     $field_2b = FieldConfig::load($field_id_2b);
     $this->assertFalse($field_2b, 'The second field on test bundle 2 was deleted.');
     // Check that all config files are gone.
     $active = $this->container->get('config.storage');
     $this->assertIdentical($active->listAll($field_storage_config_name), array());
     $this->assertIdentical($active->listAll($field_storage_config_name_2), array());
     $this->assertIdentical($active->listAll($field_config_name), array());
     $this->assertIdentical($active->listAll($field_config_name_2a), array());
     $this->assertIdentical($active->listAll($field_config_name_2b), array());
     // Check that the storage definition is preserved in state.
     $deleted_storages = \Drupal::state()->get('field.storage.deleted') ?: array();
     $this->assertTrue(isset($deleted_storages[$field_storage_uuid]));
     $this->assertTrue(isset($deleted_storages[$field_storage_uuid_2]));
     // Purge field data, and check that the storage definition has been
     // completely removed once the data is purged.
     field_purge_batch(10);
     $deleted_storages = \Drupal::state()->get('field.storage.deleted') ?: array();
     $this->assertTrue(empty($deleted_storages), 'Fields are deleted');
 }
예제 #26
0
 /**
  * Tests field_update_8002().
  *
  * @see field_update_8002()
  */
 public function testFieldUpdate8002()
 {
     // Check that 'entity_reference' is the provider and a dependency of the
     // test field storage .
     $field_storage = $this->configFactory->get('field.storage.node.field_ref_views_select_2429191');
     $this->assertIdentical($field_storage->get('module'), 'entity_reference');
     $this->assertEntityRefDependency($field_storage, TRUE);
     // Check that 'entity_reference' is a dependency of the test field.
     $field = $this->configFactory->get('field.field.node.article.field_ref_views_select_2429191');
     $this->assertEntityRefDependency($field, TRUE);
     // Check that 'entity_reference' is a dependency of the test view.
     $view = $this->configFactory->get('views.view.entity_reference_plugins_2429191');
     $this->assertEntityRefDependency($view, TRUE);
     // Run updates.
     $this->runUpdates();
     // Check that 'entity_reference' is no longer a dependency of the test field
     // and view.
     $field_storage = $this->configFactory->get('field.storage.node.field_ref_views_select_2429191');
     $this->assertIdentical($field_storage->get('module'), 'core');
     $this->assertEntityRefDependency($field_storage, FALSE);
     $field = $this->configFactory->get('field.field.node.article.field_ref_views_select_2429191');
     $this->assertEntityRefDependency($field, FALSE);
     $view = $this->configFactory->get('views.view.entity_reference_plugins_2429191');
     $this->assertEntityRefDependency($view, FALSE);
     // Check that field selection, based on the view, still works. It only
     // selects nodes whose title contains 'foo'.
     $node_1 = Node::create(['type' => 'article', 'title' => 'foobar']);
     $node_1->save();
     $node_2 = Node::create(['type' => 'article', 'title' => 'barbaz']);
     $node_2->save();
     $field = FieldConfig::load('node.article.field_ref_views_select_2429191');
     $selection = \Drupal::service('plugin.manager.entity_reference_selection')->getSelectionHandler($field);
     $referencable = $selection->getReferenceableEntities();
     $this->assertEqual(array_keys($referencable['article']), [$node_1->id()]);
 }
예제 #27
0
 /**
  * Test entity_bundle_delete().
  */
 function testEntityDeleteBundle()
 {
     $entity_type = 'entity_test_rev';
     $this->createFieldWithStorage('', $entity_type);
     // Create a new bundle.
     $new_bundle = 'test_bundle_' . Unicode::strtolower($this->randomMachineName());
     entity_test_create_bundle($new_bundle, NULL, $entity_type);
     // Add a field to that bundle.
     $this->fieldTestData->field_definition['bundle'] = $new_bundle;
     entity_create('field_config', $this->fieldTestData->field_definition)->save();
     // Create a second field for the test bundle
     $field_name = Unicode::strtolower($this->randomMachineName() . '_field_name');
     $field_storage = array('field_name' => $field_name, 'entity_type' => $entity_type, 'type' => 'test_field', 'cardinality' => 1);
     entity_create('field_storage_config', $field_storage)->save();
     $field = array('field_name' => $field_name, 'entity_type' => $entity_type, 'bundle' => $this->fieldTestData->field->getTargetBundle(), 'label' => $this->randomMachineName() . '_label', 'description' => $this->randomMachineName() . '_description', 'weight' => mt_rand(0, 127));
     entity_create('field_config', $field)->save();
     // Save an entity with data for both fields
     $entity = entity_create($entity_type, array('type' => $this->fieldTestData->field->getTargetBundle()));
     $values = $this->_generateTestFieldValues($this->fieldTestData->field_storage->getCardinality());
     $entity->{$this->fieldTestData->field_name} = $values;
     $entity->{$field_name} = $this->_generateTestFieldValues(1);
     $entity = $this->entitySaveReload($entity);
     // Verify the fields are present on load
     $this->assertEqual(count($entity->{$this->fieldTestData->field_name}), 4, 'First field got loaded');
     $this->assertEqual(count($entity->{$field_name}), 1, 'Second field got loaded');
     // Delete the bundle.
     entity_test_delete_bundle($this->fieldTestData->field->getTargetBundle(), $entity_type);
     // Verify no data gets loaded
     $controller = $this->container->get('entity.manager')->getStorage($entity->getEntityTypeId());
     $controller->resetCache();
     $entity = $controller->load($entity->id());
     $this->assertTrue(empty($entity->{$this->fieldTestData->field_name}), 'No data for first field');
     $this->assertTrue(empty($entity->{$field_name}), 'No data for second field');
     // Verify that the fields are gone.
     $this->assertFalse(FieldConfig::load('entity_test.' . $this->fieldTestData->field->getTargetBundle() . '.' . $this->fieldTestData->field_name), "First field is deleted");
     $this->assertFalse(FieldConfig::load('entity_test.' . $field['bundle'] . '.' . $field_name), "Second field is deleted");
 }
 /**
  * Tests cache tags presence and invalidation of the entity at its URI.
  *
  * Tests the following cache tags:
  * - "<entity type>_view"
  * - "<entity_type>:<entity ID>"
  */
 public function testEntityUri()
 {
     $entity_url = $this->entity->urlInfo();
     $entity_type = $this->entity->getEntityTypeId();
     // Selects the view mode that will be used.
     $view_mode = $this->selectViewMode($entity_type);
     // The default cache contexts for rendered entities.
     $entity_cache_contexts = ['languages:' . LanguageInterface::TYPE_INTERFACE, 'theme', 'user.permissions'];
     // Generate the standardized entity cache tags.
     $cache_tag = $this->entity->getCacheTags();
     $view_cache_tag = \Drupal::entityManager()->getViewBuilder($entity_type)->getCacheTags();
     $render_cache_tag = 'rendered';
     $this->pass("Test entity.", 'Debug');
     $this->verifyPageCache($entity_url, 'MISS');
     // Verify a cache hit, but also the presence of the correct cache tags.
     $this->verifyPageCache($entity_url, 'HIT');
     // Also verify the existence of an entity render cache entry, if this entity
     // type supports render caching.
     if (\Drupal::entityManager()->getDefinition($entity_type)->isRenderCacheable()) {
         $cache_keys = ['entity_view', $entity_type, $this->entity->id(), $view_mode];
         $cid = $this->createCacheId($cache_keys, $entity_cache_contexts);
         $redirected_cid = NULL;
         $additional_cache_contexts = $this->getAdditionalCacheContextsForEntity($this->entity);
         if (count($additional_cache_contexts)) {
             $redirected_cid = $this->createCacheId($cache_keys, Cache::mergeContexts($entity_cache_contexts, $additional_cache_contexts));
         }
         $expected_cache_tags = Cache::mergeTags($cache_tag, $view_cache_tag);
         $expected_cache_tags = Cache::mergeTags($expected_cache_tags, $this->getAdditionalCacheTagsForEntity($this->entity));
         $expected_cache_tags = Cache::mergeTags($expected_cache_tags, array($render_cache_tag));
         $this->verifyRenderCache($cid, $expected_cache_tags, $redirected_cid);
     }
     // Verify that after modifying the entity, there is a cache miss.
     $this->pass("Test modification of entity.", 'Debug');
     $this->entity->save();
     $this->verifyPageCache($entity_url, 'MISS');
     // Verify a cache hit.
     $this->verifyPageCache($entity_url, 'HIT');
     // Verify that after modifying the entity's display, there is a cache miss.
     $this->pass("Test modification of entity's '{$view_mode}' display.", 'Debug');
     $entity_display = entity_get_display($entity_type, $this->entity->bundle(), $view_mode);
     $entity_display->save();
     $this->verifyPageCache($entity_url, 'MISS');
     // Verify a cache hit.
     $this->verifyPageCache($entity_url, 'HIT');
     if ($bundle_entity_type_id = $this->entity->getEntityType()->getBundleEntityType()) {
         // Verify that after modifying the corresponding bundle entity, there is a
         // cache miss.
         $this->pass("Test modification of entity's bundle entity.", 'Debug');
         $bundle_entity = entity_load($bundle_entity_type_id, $this->entity->bundle());
         $bundle_entity->save();
         $this->verifyPageCache($entity_url, 'MISS');
         // Verify a cache hit.
         $this->verifyPageCache($entity_url, 'HIT');
     }
     if ($this->entity->getEntityType()->get('field_ui_base_route')) {
         // Verify that after modifying a configurable field on the entity, there
         // is a cache miss.
         $this->pass("Test modification of entity's configurable field.", 'Debug');
         $field_storage_name = $this->entity->getEntityTypeId() . '.configurable_field';
         $field_storage = FieldStorageConfig::load($field_storage_name);
         $field_storage->save();
         $this->verifyPageCache($entity_url, 'MISS');
         // Verify a cache hit.
         $this->verifyPageCache($entity_url, 'HIT');
         // Verify that after modifying a configurable field on the entity, there
         // is a cache miss.
         $this->pass("Test modification of entity's configurable field.", 'Debug');
         $field_name = $this->entity->getEntityTypeId() . '.' . $this->entity->bundle() . '.configurable_field';
         $field = FieldConfig::load($field_name);
         $field->save();
         $this->verifyPageCache($entity_url, 'MISS');
         // Verify a cache hit.
         $this->verifyPageCache($entity_url, 'HIT');
     }
     // Verify that after invalidating the entity's cache tag directly, there is
     // a cache miss.
     $this->pass("Test invalidation of entity's cache tag.", 'Debug');
     Cache::invalidateTags($this->entity->getCacheTagsToInvalidate());
     $this->verifyPageCache($entity_url, 'MISS');
     // Verify a cache hit.
     $this->verifyPageCache($entity_url, 'HIT');
     // Verify that after invalidating the generic entity type's view cache tag
     // directly, there is a cache miss.
     $this->pass("Test invalidation of entity's 'view' cache tag.", 'Debug');
     Cache::invalidateTags($view_cache_tag);
     $this->verifyPageCache($entity_url, 'MISS');
     // Verify a cache hit.
     $this->verifyPageCache($entity_url, 'HIT');
     // Verify that after deleting the entity, there is a cache miss.
     $this->pass('Test deletion of entity.', 'Debug');
     $this->entity->delete();
     $this->verifyPageCache($entity_url, 'MISS');
     $this->assertResponse(404);
 }
 /**
  * Tests that the 'handler' field setting stores the proper plugin ID.
  */
 public function testSelectionHandlerSettings()
 {
     $field_name = Unicode::strtolower($this->randomMachineName());
     $field_storage = FieldStorageConfig::create(array('field_name' => $field_name, 'entity_type' => 'entity_test', 'type' => 'entity_reference', 'settings' => array('target_type' => 'entity_test')));
     $field_storage->save();
     // Do not specify any value for the 'handler' setting in order to verify
     // that the default value is properly used.
     $field = FieldConfig::create(array('field_storage' => $field_storage, 'bundle' => 'entity_test'));
     $field->save();
     $field = FieldConfig::load($field->id());
     $this->assertTrue($field->getSetting('handler') == 'default:entity_test');
     $field->settings['handler'] = 'views';
     $field->save();
     $field = FieldConfig::load($field->id());
     $this->assertTrue($field->getSetting('handler') == 'views');
 }
 /**
  * Tests creating field storages and fields during config import.
  */
 function testImportCreate()
 {
     // A field storage with one single field.
     $field_name = 'field_test_import_sync';
     $field_storage_id = "entity_test.{$field_name}";
     $field_id = "entity_test.entity_test.{$field_name}";
     $field_storage_config_name = "field.storage.{$field_storage_id}";
     $field_config_name = "field.field.{$field_id}";
     // A field storage with two fields.
     $field_name_2 = 'field_test_import_sync_2';
     $field_storage_id_2 = "entity_test.{$field_name_2}";
     $field_id_2a = "entity_test.test_bundle.{$field_name_2}";
     $field_id_2b = "entity_test.test_bundle_2.{$field_name_2}";
     $field_storage_config_name_2 = "field.storage.{$field_storage_id_2}";
     $field_config_name_2a = "field.field.{$field_id_2a}";
     $field_config_name_2b = "field.field.{$field_id_2b}";
     $active = $this->container->get('config.storage');
     $sync = $this->container->get('config.storage.sync');
     $this->copyConfig($active, $sync);
     // Add the new files to the sync directory.
     $src_dir = __DIR__ . '/../../modules/field_test_config/sync';
     $target_dir = config_get_config_directory(CONFIG_SYNC_DIRECTORY);
     $this->assertTrue(file_unmanaged_copy("{$src_dir}/{$field_storage_config_name}.yml", "{$target_dir}/{$field_storage_config_name}.yml"));
     $this->assertTrue(file_unmanaged_copy("{$src_dir}/{$field_config_name}.yml", "{$target_dir}/{$field_config_name}.yml"));
     $this->assertTrue(file_unmanaged_copy("{$src_dir}/{$field_storage_config_name_2}.yml", "{$target_dir}/{$field_storage_config_name_2}.yml"));
     $this->assertTrue(file_unmanaged_copy("{$src_dir}/{$field_config_name_2a}.yml", "{$target_dir}/{$field_config_name_2a}.yml"));
     $this->assertTrue(file_unmanaged_copy("{$src_dir}/{$field_config_name_2b}.yml", "{$target_dir}/{$field_config_name_2b}.yml"));
     // Import the content of the sync directory.
     $this->configImporter()->import();
     // Check that the field and storage were created.
     $field_storage = FieldStorageConfig::load($field_storage_id);
     $this->assertTrue($field_storage, 'Test import storage field from sync exists');
     $field = FieldConfig::load($field_id);
     $this->assertTrue($field, 'Test import field  from sync exists');
     $field_storage = FieldStorageConfig::load($field_storage_id_2);
     $this->assertTrue($field_storage, 'Test import storage field 2 from sync exists');
     $field = FieldConfig::load($field_id_2a);
     $this->assertTrue($field, 'Test import field 2a from sync exists');
     $field = FieldConfig::load($field_id_2b);
     $this->assertTrue($field, 'Test import field 2b from sync exists');
 }