protected function setUp() { parent::setUp(); // Create a 'test_field' field and storage for validation. entity_create('field_storage_config', array('field_name' => $this->field_name, 'entity_type' => 'entity_test', 'type' => 'test_field'))->save(); entity_create('field_config', array('entity_type' => 'entity_test', 'field_name' => $this->field_name, 'bundle' => 'entity_test'))->save(); }
/** * {@inheritdoc} */ protected function setUp() { parent::setUp(); $this->installEntitySchema('entity_test_rev'); $this->storage = \Drupal::entityManager()->getStorage('entity_test'); $this->storage_rev = \Drupal::entityManager()->getStorage('entity_test_rev'); }
protected function setUp() { parent::setUp(); // Create a telephone field storage and field for validation. entity_create('field_storage_config', array('field_name' => 'field_test', 'entity_type' => 'entity_test', 'type' => 'telephone'))->save(); entity_create('field_config', array('entity_type' => 'entity_test', 'field_name' => 'field_test', 'bundle' => 'entity_test'))->save(); }
/** * {@inheritdoc} * * This sets up the entity_test and user types to use our example * field plugins. */ protected function setUp() { array_unshift(self::$modules, 'field_permission_example'); parent::setUp(); // Tests for SimpleTest cannot usefully implement // ContainerInjectionInterface the way PHPUnit tests do. // We instead use KernelTest class' supplied container // to get services we require. $type_manager = $this->container->get('entity_type.manager'); // Set up our entity_type and user type for our new field: $type_manager->getStorage('field_storage_config')->create(['field_name' => 'field_fieldnote', 'entity_type' => 'entity_test', 'type' => 'field_permission_example_fieldnote'])->save(); $type_manager->getStorage('field_config')->create(['entity_type' => 'entity_test', 'field_name' => 'field_fieldnote', 'bundle' => 'entity_test'])->save(); // Create a form display for the default form mode, and // add our field type. $type_manager->getStorage('entity_form_display')->create(['targetEntityType' => 'entity_test', 'bundle' => 'entity_test', 'mode' => 'default', 'status' => TRUE])->setComponent('field_fieldnote', ['type' => 'field_permission_example_widget'])->save(); // Now do this for the user type. $type_manager->getStorage('field_storage_config')->create(['field_name' => 'user_fieldnote', 'entity_type' => 'user', 'type' => 'field_permission_example_fieldnote'])->save(); $type_manager->getStorage('field_config')->create(['entity_type' => 'user', 'field_name' => 'user_fieldnote', 'bundle' => 'user'])->save(); // Fetch a form display for a user. Most likely, this will already // exist, so check as Core does. // @see https://api.drupal.org/api/drupal/core%21includes%21entity.inc/function/entity_get_form_display/8 $entity_form_display = $type_manager->getStorage('entity_form_display')->load('user.user.default'); if (empty($entity_form_display)) { $entity_form_display = $type_manager->getStorage('entity_form_display')->create(['targetEntityType' => 'user', 'bundle' => 'user', 'mode' => 'default', 'status' => TRUE]); } // And add our fancy field to that display: $entity_form_display->setComponent('field_fieldnote', ['type' => 'field_permission_example_widget'])->save(); }
public function setUp() { parent::setUp(); // Create an link field and instance for validation. entity_create('field_storage_config', array('name' => 'field_test', 'entity_type' => 'entity_test', 'type' => 'link'))->save(); entity_create('field_instance_config', array('entity_type' => 'entity_test', 'field_name' => 'field_test', 'bundle' => 'entity_test'))->save(); }
protected function setUp() { parent::setUp(); $this->container->get('router.builder')->rebuild(); $this->installEntitySchema('entity_test_rev'); $this->createFieldWithStorage(); }
/** * Sets up the test. */ protected function setUp() { parent::setUp(); $this->installEntitySchema('entity_test_string_id'); $this->installEntitySchema('taxonomy_term'); $this->installEntitySchema('node'); $this->installEntitySchema('comment'); $this->installEntitySchema('file'); $this->installSchema('comment', ['comment_entity_statistics']); $this->installSchema('node', ['node_access']); $this->vocabulary = entity_create('taxonomy_vocabulary', array('name' => $this->randomMachineName(), 'vid' => Unicode::strtolower($this->randomMachineName()), 'langcode' => LanguageInterface::LANGCODE_NOT_SPECIFIED)); $this->vocabulary->save(); $this->term = entity_create('taxonomy_term', array('name' => $this->randomMachineName(), 'vid' => $this->vocabulary->id(), 'langcode' => LanguageInterface::LANGCODE_NOT_SPECIFIED)); $this->term->save(); $this->entityStringId = EntityTestStringId::create(['id' => $this->randomMachineName()]); $this->entityStringId->save(); // Use the util to create an instance. $this->createEntityReferenceField('entity_test', 'entity_test', 'field_test_taxonomy_term', 'Test content entity reference', 'taxonomy_term'); $this->createEntityReferenceField('entity_test', 'entity_test', 'field_test_entity_test_string_id', 'Test content entity reference with string ID', 'entity_test_string_id'); $this->createEntityReferenceField('entity_test', 'entity_test', 'field_test_taxonomy_vocabulary', 'Test config entity reference', 'taxonomy_vocabulary'); $this->createEntityReferenceField('entity_test', 'entity_test', 'field_test_node', 'Test node entity reference', 'node', 'default', [], FieldStorageDefinitionInterface::CARDINALITY_UNLIMITED); $this->createEntityReferenceField('entity_test', 'entity_test', 'field_test_user', 'Test user entity reference', 'user'); $this->createEntityReferenceField('entity_test', 'entity_test', 'field_test_comment', 'Test comment entity reference', 'comment'); $this->createEntityReferenceField('entity_test', 'entity_test', 'field_test_file', 'Test file entity reference', 'file'); }
function setUp() { parent::setUp(); $this->fieldStorageDefinition = array('field_name' => Unicode::strtolower($this->randomMachineName()), 'entity_type' => 'entity_test', 'type' => 'test_field'); $this->fieldStorage = entity_create('field_storage_config', $this->fieldStorageDefinition); $this->fieldStorage->save(); $this->fieldDefinition = array('field_name' => $this->fieldStorage->getName(), 'entity_type' => 'entity_test', 'bundle' => 'entity_test'); }
protected function setUp() { parent::setUp(); $this->installEntitySchema('entity_test_rev'); // Create the necessary formats. $this->installConfig(array('filter')); entity_create('filter_format', array('format' => 'no_filters', 'filters' => array()))->save(); }
public function setUp() { parent::setUp(); // Create number fields and instances for validation. foreach (array('integer', 'float', 'decimal') as $type) { entity_create('field_storage_config', array('name' => 'field_' . $type, 'entity_type' => 'entity_test', 'type' => $type))->save(); entity_create('field_instance_config', array('entity_type' => 'entity_test', 'field_name' => 'field_' . $type, 'bundle' => 'entity_test'))->save(); } }
public function setUp() { parent::setUp(); // Create a field with settings to validate. $field_storage = entity_create('field_storage_config', array('name' => 'field_datetime', 'type' => 'datetime', 'entity_type' => 'entity_test', 'settings' => array('datetime_type' => 'date'))); $field_storage->save(); $instance = entity_create('field_instance_config', array('field_storage' => $field_storage, 'bundle' => 'entity_test', 'settings' => array('default_value' => 'blank'))); $instance->save(); }
/** * {@inheritdoc} */ protected function setUp() { parent::setUp(); entity_create('field_storage_config', ['field_name' => 'field_test', 'entity_type' => 'entity_test', 'type' => 'video_embed_field'])->save(); entity_create('field_config', ['entity_type' => 'entity_test', 'field_name' => 'field_test', 'bundle' => 'entity_test'])->save(); // Fake colorbox being enabled for the purposes of testing. $module_handler = \Drupal::moduleHandler(); $module_handler->addModule('colorbox', NULL); }
/** * {@inheritdoc} */ protected function setUp() { parent::setUp(); // Create a boolean field and storage for validation. entity_create('field_storage_config', array('field_name' => 'field_boolean', 'entity_type' => 'entity_test', 'type' => 'boolean'))->save(); entity_create('field_config', array('entity_type' => 'entity_test', 'field_name' => 'field_boolean', 'bundle' => 'entity_test'))->save(); // Create a form display for the default form mode. entity_get_form_display('entity_test', 'entity_test', 'default')->setComponent('field_boolean', array('type' => 'boolean_checkbox'))->save(); }
public function setUp() { parent::setUp(); // Create an email field and instance for validation. entity_create('field_storage_config', array('name' => 'field_email', 'entity_type' => 'entity_test', 'type' => 'email'))->save(); entity_create('field_instance_config', array('entity_type' => 'entity_test', 'field_name' => 'field_email', 'bundle' => 'entity_test'))->save(); // Create a form display for the default form mode. entity_get_form_display('entity_test', 'entity_test', 'default')->setComponent('field_email', array('type' => 'email_default'))->save(); }
/** * {@inheritdoc} */ public function setUp() { parent::setUp(); $this->installSchema('system', array('router')); $this->fieldStorageDefinition = array('name' => $this->fieldName, 'entity_type' => 'entity_test', 'type' => 'list_integer', 'cardinality' => 1, 'settings' => array('allowed_values' => array(1 => 'One', 2 => 'Two', 3 => 'Three'))); $this->fieldStorage = entity_create('field_storage_config', $this->fieldStorageDefinition); $this->fieldStorage->save(); $this->instance = entity_create('field_instance_config', array('field_storage' => $this->fieldStorage, 'bundle' => 'entity_test')); $this->instance->save(); entity_get_form_display('entity_test', 'entity_test', 'default')->setComponent($this->fieldName, array('type' => 'options_buttons'))->save(); }
protected function setUp() { parent::setUp(); $this->installEntitySchema('file'); $this->installSchema('file', array('file_usage')); entity_create('field_storage_config', array('field_name' => 'file_test', 'entity_type' => 'entity_test', 'type' => 'file', 'cardinality' => FieldStorageDefinitionInterface::CARDINALITY_UNLIMITED))->save(); entity_create('field_config', array('entity_type' => 'entity_test', 'field_name' => 'file_test', 'bundle' => 'entity_test'))->save(); file_put_contents('public://example.txt', $this->randomMachineName()); $this->file = entity_create('file', array('uri' => 'public://example.txt')); $this->file->save(); }
/** * {@inheritdoc} */ protected function setUp() { parent::setUp(); $this->container->get('router.builder')->rebuild(); $this->fieldStorageDefinition = array('field_name' => $this->fieldName, 'entity_type' => 'entity_test', 'type' => 'list_integer', 'cardinality' => 1, 'settings' => array('allowed_values' => array(1 => 'One', 2 => 'Two', 3 => 'Three'))); $this->fieldStorage = entity_create('field_storage_config', $this->fieldStorageDefinition); $this->fieldStorage->save(); $this->field = entity_create('field_config', array('field_storage' => $this->fieldStorage, 'bundle' => 'entity_test')); $this->field->save(); entity_get_form_display('entity_test', 'entity_test', 'default')->setComponent($this->fieldName, array('type' => 'options_buttons'))->save(); }
protected function setUp() { parent::setUp(); $this->installEntitySchema('taxonomy_term'); $vocabulary = entity_create('taxonomy_vocabulary', array('name' => $this->randomMachineName(), 'vid' => Unicode::strtolower($this->randomMachineName()), 'langcode' => LanguageInterface::LANGCODE_NOT_SPECIFIED)); $vocabulary->save(); entity_create('field_storage_config', array('field_name' => 'field_test_taxonomy', 'entity_type' => 'entity_test', 'type' => 'taxonomy_term_reference', 'cardinality' => FieldStorageDefinitionInterface::CARDINALITY_UNLIMITED, 'settings' => array('allowed_values' => array(array('vocabulary' => $vocabulary->id(), 'parent' => 0)))))->save(); entity_create('field_config', array('entity_type' => 'entity_test', 'field_name' => 'field_test_taxonomy', 'bundle' => 'entity_test'))->save(); $this->term = entity_create('taxonomy_term', array('name' => $this->randomMachineName(), 'vid' => $vocabulary->id(), 'langcode' => LanguageInterface::LANGCODE_NOT_SPECIFIED)); $this->term->save(); }
protected function setUp() { parent::setUp(); // Create a generic, external, and internal link fields for validation. FieldStorageConfig::create(['field_name' => 'field_test', 'entity_type' => 'entity_test', 'type' => 'link'])->save(); FieldConfig::create(['entity_type' => 'entity_test', 'field_name' => 'field_test', 'bundle' => 'entity_test', 'settings' => ['link_type' => LinkItemInterface::LINK_GENERIC]])->save(); FieldStorageConfig::create(['field_name' => 'field_test_external', 'entity_type' => 'entity_test', 'type' => 'link'])->save(); FieldConfig::create(['entity_type' => 'entity_test', 'field_name' => 'field_test_external', 'bundle' => 'entity_test', 'settings' => ['link_type' => LinkItemInterface::LINK_EXTERNAL]])->save(); FieldStorageConfig::create(['field_name' => 'field_test_internal', 'entity_type' => 'entity_test', 'type' => 'link'])->save(); FieldConfig::create(['entity_type' => 'entity_test', 'field_name' => 'field_test_internal', 'bundle' => 'entity_test', 'settings' => ['link_type' => LinkItemInterface::LINK_INTERNAL]])->save(); }
public function setUp() { parent::setUp(); // Create a field and instance of type 'test_field', on the 'entity_test' // entity type. $this->entityType = 'entity_test'; $this->bundle = 'entity_test'; $this->createFieldWithInstance('', $this->entityType, $this->bundle); // Create an 'entity_test' entity. $this->entity = entity_create($this->entityType, array('type' => $this->bundle)); }
protected function setUp() { parent::setUp(); $this->installEntitySchema('file'); $this->installSchema('file', array('file_usage')); entity_create('field_storage_config', array('entity_type' => 'entity_test', 'field_name' => 'image_test', 'type' => 'image', 'cardinality' => FieldStorageDefinitionInterface::CARDINALITY_UNLIMITED))->save(); entity_create('field_config', array('entity_type' => 'entity_test', 'field_name' => 'image_test', 'bundle' => 'entity_test'))->save(); file_unmanaged_copy(\Drupal::root() . '/core/misc/druplicon.png', 'public://example.jpg'); $this->image = entity_create('file', array('uri' => 'public://example.jpg')); $this->image->save(); $this->imageFactory = $this->container->get('image.factory'); }
/** * {@inheritdoc} */ protected function setUp() { parent::setUp(); // Create a field and a storage of type 'test_field', on the 'entity_test' // entity type. $this->entityType = 'entity_test'; $this->bundle = 'entity_test'; $this->createFieldWithStorage('', $this->entityType, $this->bundle); $this->entityManager = $this->container->get('entity.manager'); // Create a second field on 'entity_test_rev'. $this->createFieldWithStorage('_rev', 'entity_test_rev', 'entity_test_rev'); }
/** * {@inheritdoc} */ public function setUp() { parent::setUp(); // Create a field and instance of type 'test_field', on the 'entity_test' // entity type. $this->entityType = 'entity_test'; $this->bundle = 'entity_test'; $this->createFieldWithInstance('', $this->entityType, $this->bundle); $this->entityManager = $this->container->get('entity.manager'); // Create a second instance on 'entity_test_rev'. $this->createFieldWithInstance('_rev', 'entity_test_rev', 'entity_test_rev'); }
/** * Sets up the test. */ protected function setUp() { parent::setUp(); $this->installEntitySchema('taxonomy_term'); $this->vocabulary = entity_create('taxonomy_vocabulary', array('name' => $this->randomMachineName(), 'vid' => Unicode::strtolower($this->randomMachineName()), 'langcode' => LanguageInterface::LANGCODE_NOT_SPECIFIED)); $this->vocabulary->save(); $this->term = entity_create('taxonomy_term', array('name' => $this->randomMachineName(), 'vid' => $this->vocabulary->id(), 'langcode' => LanguageInterface::LANGCODE_NOT_SPECIFIED)); $this->term->save(); // Use the util to create an instance. $this->createEntityReferenceField('entity_test', 'entity_test', 'field_test_taxonomy_term', 'Test content entity reference', 'taxonomy_term'); $this->createEntityReferenceField('entity_test', 'entity_test', 'field_test_taxonomy_vocabulary', 'Test config entity reference', 'taxonomy_vocabulary'); }
protected function setUp() { parent::setUp(); $this->installConfig(array('language')); $this->field_name = drupal_strtolower($this->randomMachineName()); $this->entity_type = 'entity_test'; $this->field_storage_definition = array('field_name' => $this->field_name, 'entity_type' => $this->entity_type, 'type' => 'test_field', 'cardinality' => 4, 'translatable' => TRUE); $this->fieldStorage = entity_create('field_storage_config', $this->field_storage_definition); $this->fieldStorage->save(); $this->field_definition = array('field_storage' => $this->fieldStorage, 'bundle' => 'entity_test'); $this->field = entity_create('field_config', $this->field_definition); $this->field->save(); for ($i = 0; $i < 3; ++$i) { ConfigurableLanguage::create(array('id' => 'l' . $i, 'label' => $this->randomString()))->save(); } }
function setUp() { parent::setUp(); $this->installConfig(array('language')); $this->field_name = drupal_strtolower($this->randomName()); $this->entity_type = 'entity_test'; $this->field_definition = array('name' => $this->field_name, 'entity_type' => $this->entity_type, 'type' => 'test_field', 'cardinality' => 4, 'translatable' => TRUE); $this->fieldStorage = entity_create('field_storage_config', $this->field_definition); $this->fieldStorage->save(); $this->instance_definition = array('field_storage' => $this->fieldStorage, 'bundle' => 'entity_test'); $this->instance = entity_create('field_instance_config', $this->instance_definition); $this->instance->save(); for ($i = 0; $i < 3; ++$i) { $language = new Language(array('id' => 'l' . $i, 'name' => $this->randomString())); language_save($language); } }
protected function setUp() { parent::setUp(); $this->fieldStorages = array(); $this->entities = array(); $this->entitiesByBundles = array(); // Create two bundles. $this->bundles = array('bb_1' => 'bb_1', 'bb_2' => 'bb_2'); foreach ($this->bundles as $name => $desc) { entity_test_create_bundle($name, $desc); } // Create two field storages. $field_storage = entity_create('field_storage_config', array('field_name' => 'bf_1', 'entity_type' => $this->entityTypeId, 'type' => 'test_field', 'cardinality' => 1)); $field_storage->save(); $this->fieldStorages[] = $field_storage; $field_storage = entity_create('field_storage_config', array('field_name' => 'bf_2', 'entity_type' => $this->entityTypeId, 'type' => 'test_field', 'cardinality' => 4)); $field_storage->save(); $this->fieldStorages[] = $field_storage; // For each bundle, create each field, and 10 entities with values for the // fields. foreach ($this->bundles as $bundle) { foreach ($this->fieldStorages as $field_storage) { entity_create('field_config', array('field_storage' => $field_storage, 'bundle' => $bundle))->save(); } for ($i = 0; $i < 10; $i++) { $entity = entity_create($this->entityTypeId, array('type' => $bundle)); foreach ($this->fieldStorages as $field_storage) { $entity->{$field_storage->getName()}->setValue($this->_generateTestFieldValues($field_storage->getCardinality())); } $entity->save(); } } $this->entities = entity_load_multiple($this->entityTypeId); 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 // now, so that they are always loaded. $entity->bf_1->value; // Also keep track of the entities per bundle. $this->entitiesByBundles[$entity->bundle()][$entity->id()] = $entity; } }
protected function setUp() { parent::setUp(); $this->fieldStorages = array(); $this->entities = array(); $this->entities_by_bundles = array(); // Create two bundles. $this->bundles = array('bb_1' => 'bb_1', 'bb_2' => 'bb_2'); foreach ($this->bundles as $name => $desc) { entity_test_create_bundle($name, $desc); } // Create two field storages. $field_storage = entity_create('field_storage_config', array('field_name' => 'bf_1', 'entity_type' => $this->entity_type, 'type' => 'test_field', 'cardinality' => 1)); $field_storage->save(); $this->fieldStorages[] = $field_storage; $field_storage = entity_create('field_storage_config', array('field_name' => 'bf_2', 'entity_type' => $this->entity_type, 'type' => 'test_field', 'cardinality' => 4)); $field_storage->save(); $this->fieldStorages[] = $field_storage; // For each bundle, create each field, and 10 entities with values for the // fields. foreach ($this->bundles as $bundle) { foreach ($this->fieldStorages as $field_storage) { entity_create('field_config', array('field_storage' => $field_storage, 'bundle' => $bundle))->save(); } for ($i = 0; $i < 10; $i++) { $entity = entity_create($this->entity_type, array('type' => $bundle)); foreach ($this->fieldStorages as $field_storage) { $entity->{$field_storage->getName()}->setValue($this->_generateTestFieldValues($field_storage->getCardinality())); } $entity->save(); } } $this->entities = entity_load_multiple($this->entity_type); foreach ($this->entities as $entity) { // Also keep track of the entities per bundle. $this->entities_by_bundles[$entity->bundle()][$entity->id()] = $entity; } }
function setUp() { parent::setUp(); // Create a field and instance. $this->field_name = 'test_field'; $this->label = $this->randomName(); $this->cardinality = 4; $field_storage = array('name' => $this->field_name, 'entity_type' => 'entity_test', 'type' => 'test_field', 'cardinality' => $this->cardinality); $instance = array('field_name' => $this->field_name, 'entity_type' => 'entity_test', 'bundle' => 'entity_test', 'label' => $this->label); $this->display_options = array('default' => array('type' => 'field_test_default', 'settings' => array('test_formatter_setting' => $this->randomName())), 'teaser' => array('type' => 'field_test_default', 'settings' => array('test_formatter_setting' => $this->randomName()))); entity_create('field_storage_config', $field_storage)->save(); entity_create('field_instance_config', $instance)->save(); // Create a display for the default view mode. entity_get_display($instance['entity_type'], $instance['bundle'], 'default')->setComponent($this->field_name, $this->display_options['default'])->save(); // Create a display for the teaser view mode. entity_create('view_mode', array('id' => 'entity_test.teaser', 'targetEntityType' => 'entity_test'))->save(); entity_get_display($instance['entity_type'], $instance['bundle'], 'teaser')->setComponent($this->field_name, $this->display_options['teaser'])->save(); // Create an entity with values. $this->values = $this->_generateTestFieldValues($this->cardinality); $this->entity = entity_create('entity_test'); $this->entity->{$this->field_name}->setValue($this->values); $this->entity->save(); }
/** * {@inheritdoc} */ protected function setUp() { parent::setUp(); \Drupal::service('router.builder')->rebuild(); }