You are here

protected function ContentHubSubscriberTestBase::configEntityValues in Acquia Content Hub 8

Provides an array of suitable property values for a config entity type.

Config entities have some common keys that need to be created. Required properties differ among config entity types, so we keep a minimum mapping here.

Parameters

string $entity_type_id: The ID of the type of entity that should be created.

\Drupal\Core\Session\AccountInterface $account: The account that will own this entity.

Return value

array An array of values keyed by property name.

2 calls to ContentHubSubscriberTestBase::configEntityValues()
ContentHubSubscriberTestBase::entityCreate in acquia_contenthub_subscriber/tests/src/Functional/ContentHubSubscriberTestBase.php
Creates entity objects based on their types.
ContentHubSubscriberTestBase::entityValues in acquia_contenthub_subscriber/tests/src/Functional/ContentHubSubscriberTestBase.php
Provides an array of suitable property values for an entity type.

File

acquia_contenthub_subscriber/tests/src/Functional/ContentHubSubscriberTestBase.php, line 356

Class

ContentHubSubscriberTestBase
Provides the base class for web tests for Content Hub Subscribers.

Namespace

Drupal\Tests\acquia_contenthub_subscriber\Functional

Code

protected function configEntityValues($entity_type_id, AccountInterface $account = NULL) {
  $entity_type = \Drupal::entityTypeManager()
    ->getDefinition($entity_type_id);
  $keys = $entity_type
    ->getKeys();
  $values = [];

  // Fill out known key values that are shared across entity types.
  foreach ($keys as $key) {
    if ($key === 'id' || $key === 'label') {
      $values[$key] = $this
        ->randomMachineName();
    }
  }

  // Add extra values for particular entity types.
  switch ($entity_type_id) {
    case 'contenthub_filter':
      $publish_settings = [
        'none',
        'import',
        'publish',
      ];
      $values['name'] = 'Name for ' . $values['id'];
      $values['publish_setting'] = $publish_settings[random_int(0, 2)];
      $values['search_term'] = $this
        ->randomMachineName();
      $author = $account !== NULL ? $account
        ->id() : $this->adminUser
        ->id();
      $values['author'] = intval($author);
      $values['entity_types'] = [
        'node',
      ];
      $values['bundles'] = [
        'article',
        'page',
      ];
      break;
  }
  return $values;
}