You are here

public function AcquiaContentHubSerializerTestBase::createContentType in Acquia Content Hub 8.2

Create content type.

Parameters

string $field_name: Field name.

string $field_type: Field type.

Throws

\Drupal\Core\Entity\EntityStorageException

3 calls to AcquiaContentHubSerializerTestBase::createContentType()
CreateNewRevisionTest::testNewRevision in tests/src/Kernel/EventSubscriber/PreEntitySave/CreateNewRevisionTest.php
Tests CreateNewRevision event subscriber.
EntitySubqueuePreSaveTest::testNewRevision in tests/src/Kernel/EventSubscriber/PreEntitySave/EntitySubqueuePreSaveTest.php
Tests CreateNewRevision event subscriber.
MetatagFieldSerializerTest::setUp in modules/acquia_contenthub_metatag/tests/src/Kernel/EventSubscriber/SerializeContentField/MetatagFieldSerializerTest.php

File

tests/src/Kernel/AcquiaContentHubSerializerTestBase.php, line 132

Class

AcquiaContentHubSerializerTestBase
Base class for testing serialization.

Namespace

Drupal\Tests\acquia_contenthub\Kernel

Code

public function createContentType(string $field_name = '', string $field_type = '') {

  // Create a content type.
  NodeType::create([
    'type' => self::BUNDLE,
    'name' => self::BUNDLE,
  ])
    ->save();
  if ($field_name && $field_type) {

    // Add a field to the content type.
    FieldStorageConfig::create([
      'field_name' => $field_name,
      'entity_type' => self::ENTITY_TYPE,
      'type' => $field_type,
      'cardinality' => 1,
    ])
      ->save();
    FieldConfig::create([
      'entity_type' => self::ENTITY_TYPE,
      'field_name' => $field_name,
      'bundle' => self::BUNDLE,
      'label' => $this
        ->randomMachineName(),
    ])
      ->save();
  }
}