You are here

protected function ContentTypeCreationTrait::createContentType in Drupal 10

Same name and namespace in other branches
  1. 8 core/modules/node/tests/src/Traits/ContentTypeCreationTrait.php \Drupal\Tests\node\Traits\ContentTypeCreationTrait::createContentType()
  2. 9 core/modules/node/tests/src/Traits/ContentTypeCreationTrait.php \Drupal\Tests\node\Traits\ContentTypeCreationTrait::createContentType()

Creates a custom content type based on default settings.

Parameters

array $values: An array of settings to change from the defaults. Example: 'type' => 'foo'.

Return value

\Drupal\node\Entity\NodeType Created content type.

62 calls to ContentTypeCreationTrait::createContentType()
BasicTest::testViewsWizardAndListing in core/modules/views/tests/src/Functional/Wizard/BasicTest.php
BooleanFormatterSettingsTest::setUp in core/modules/field/tests/src/Functional/Boolean/BooleanFormatterSettingsTest.php
BooleanFormatterSettingsTest::setUp in core/modules/field/tests/src/FunctionalJavascript/Boolean/BooleanFormatterSettingsTest.php
BreadcrumbFrontCacheContextsTest::setUp in core/modules/system/tests/src/Functional/Menu/BreadcrumbFrontCacheContextsTest.php
BulkFormAccessTest::setUp in core/modules/node/tests/src/Functional/Views/BulkFormAccessTest.php

... See full list

File

core/modules/node/tests/src/Traits/ContentTypeCreationTrait.php, line 26

Class

ContentTypeCreationTrait
Provides methods to create content type from given values.

Namespace

Drupal\Tests\node\Traits

Code

protected function createContentType(array $values = []) {

  // Find a non-existent random type name.
  if (!isset($values['type'])) {
    do {
      $id = strtolower($this
        ->randomMachineName(8));
    } while (NodeType::load($id));
  }
  else {
    $id = $values['type'];
  }
  $values += [
    'type' => $id,
    'name' => $id,
  ];
  $type = NodeType::create($values);
  $status = $type
    ->save();
  node_add_body_field($type);
  if ($this instanceof TestCase) {
    $this
      ->assertSame($status, SAVED_NEW, (new FormattableMarkup('Created content type %type.', [
      '%type' => $type
        ->id(),
    ]))
      ->__toString());
  }
  else {
    $this
      ->assertEquals(SAVED_NEW, $status, (new FormattableMarkup('Created content type %type.', [
      '%type' => $type
        ->id(),
    ]))
      ->__toString());
  }
  return $type;
}