You are here

public function FieldCreateTest::testValidFields in Organic groups 8

Testing field creation.

File

tests/src/Kernel/Entity/FieldCreateTest.php, line 69

Class

FieldCreateTest
Testing field definition overrides.

Namespace

Drupal\Tests\og\Kernel\Entity

Code

public function testValidFields() {

  // Simple create, for all the fields defined by OG core.
  $field_names = [
    OgGroupAudienceHelperInterface::DEFAULT_FIELD,
    AccessField::DEFAULT_FIELD,
  ];
  foreach ($field_names as $field_name) {
    $bundle = $this->bundles[0];
    Og::CreateField($field_name, 'node', $bundle);
    $this
      ->assertNotNull(FieldConfig::loadByName('node', $bundle, $field_name));
  }

  // Override the field config.
  $bundle = $this->bundles[1];
  Og::CreateField(OgGroupAudienceHelperInterface::DEFAULT_FIELD, 'node', $bundle, [
    'field_config' => [
      'label' => 'Other groups dummy',
    ],
  ]);
  $this
    ->assertEquals(FieldConfig::loadByName('node', $bundle, OgGroupAudienceHelperInterface::DEFAULT_FIELD)
    ->label(), 'Other groups dummy');

  // Override the field storage config.
  $bundle = $this->bundles[2];
  Og::CreateField(OgGroupAudienceHelperInterface::DEFAULT_FIELD, 'node', $bundle, [
    'field_name' => 'override_name',
  ]);
  $this
    ->assertNotNull(FieldConfig::loadByName('node', $bundle, 'override_name')
    ->id());

  // Field that can be added only to certain entities.
  $bundle = $this->bundles[3];
  Og::CreateField('entity_restricted', 'node', $bundle);
  $this
    ->assertNotNull(FieldConfig::loadByName('node', $bundle, 'entity_restricted')
    ->id());
}