You are here

protected function FunctionalTestBase::createEntityType in Entity Construction Kit (ECK) 8

Creates an entity type with a given label and/or enabled base fields.

Parameters

array $fields: The fields that should be enabled for this entity type.

string $label: The name of the entity type.

Return value

array Information about the created entity type.

  • id: the type's machine name
  • label: the type's label.

Throws

\Behat\Mink\Exception\ExpectationException

22 calls to FunctionalTestBase::createEntityType()
AccessTest::setUp in tests/src/Functional/AccessTest.php
BundleCRUDTest::identicallyNamedBundleCreation in tests/src/Functional/BundleCRUDTest.php
Tests identically named bundle creation.
BundleCRUDTest::multipleBundleCreation in tests/src/Functional/BundleCRUDTest.php
Tests multiple bundle creation.
BundleCRUDTest::singleBundleCreation in tests/src/Functional/BundleCRUDTest.php
Tests single bundle creation.
BundleCRUDTest::singleBundleCreationWithOverrides in tests/src/Functional/BundleCRUDTest.php
Tests single bundle creation with title overrides.

... See full list

File

tests/src/Functional/FunctionalTestBase.php, line 70

Class

FunctionalTestBase
Provides common functionality for ECK functional tests.

Namespace

Drupal\Tests\eck\Functional

Code

protected function createEntityType(array $fields = [], $label = '') {
  $label = empty($label) ? $this
    ->randomMachineName() : $label;
  $fields = empty($fields) ? $this
    ->getConfigurableBaseFields() : $fields;
  $edit = [
    'label' => $label,
    'id' => $id = strtolower($label),
  ];
  foreach ($fields as $field) {
    $edit[$field] = TRUE;
  }
  $this
    ->drupalGet(Url::fromRoute('eck.entity_type.add'));
  $this
    ->submitForm($edit, 'Create entity type');
  $this
    ->assertSession()
    ->statusCodeEquals(200);
  $this
    ->assertSession()
    ->responseContains("Entity type <em class=\"placeholder\">{$label}</em> has been added.");

  // Clear entity definitions cache to find definition of our new entity type.
  \Drupal::entityTypeManager()
    ->clearCachedDefinitions();
  return [
    'id' => $id,
    'label' => $label,
  ];
}