You are here

protected function SimplenewsSynchronizeFieldsTest::addField in Simplenews 8

Same name and namespace in other branches
  1. 8.2 tests/src/Kernel/SimplenewsSynchronizeFieldsTest.php \Drupal\Tests\simplenews\Kernel\SimplenewsSynchronizeFieldsTest::addField()
  2. 3.x tests/src/Kernel/SimplenewsSynchronizeFieldsTest.php \Drupal\Tests\simplenews\Kernel\SimplenewsSynchronizeFieldsTest::addField()

Creates and saves a field storage and instance.

Parameters

string $type: The field type.

string $field_name: The name of the new field.

string $entity_type: The ID of the entity type to attach the field instance to.

string $bundle: (optional) The entity bundle. Defaults to same as $entity_type.

3 calls to SimplenewsSynchronizeFieldsTest::addField()
SimplenewsSynchronizeFieldsTest::testDisableSync in tests/src/Kernel/SimplenewsSynchronizeFieldsTest.php
Unsets the sync setting and asserts that fields are not synced.
SimplenewsSynchronizeFieldsTest::testSetSharedFieldAutomatically in tests/src/Kernel/SimplenewsSynchronizeFieldsTest.php
Tests that new entities copy values from corresponding user/subscriber.
SimplenewsSynchronizeFieldsTest::testSynchronizeConfigurableFields in tests/src/Kernel/SimplenewsSynchronizeFieldsTest.php
Tests that shared fields are synchronized.

File

tests/src/Kernel/SimplenewsSynchronizeFieldsTest.php, line 308

Class

SimplenewsSynchronizeFieldsTest
Tests that fields shared by user account and subscribers are synchronized.

Namespace

Drupal\Tests\simplenews\Kernel

Code

protected function addField($type, $field_name, $entity_type, $bundle = NULL) {
  if (!isset($bundle)) {
    $bundle = $entity_type;
  }
  FieldStorageConfig::create(array(
    'field_name' => $field_name,
    'entity_type' => $entity_type,
    'type' => $type,
  ))
    ->save();
  FieldConfig::create(array(
    'field_name' => $field_name,
    'entity_type' => $entity_type,
    'bundle' => $bundle,
  ))
    ->save();
}