function ContentTypeCreationTrait::createContentType

Same name and namespace in other branches
  1. 8.9.x core/modules/node/tests/src/Traits/ContentTypeCreationTrait.php \Drupal\Tests\node\Traits\ContentTypeCreationTrait::createContentType()
  2. 10 core/modules/node/tests/src/Traits/ContentTypeCreationTrait.php \Drupal\Tests\node\Traits\ContentTypeCreationTrait::createContentType()
  3. 11.x 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.

305 calls to ContentTypeCreationTrait::createContentType()
AddedStylesheetsTest::setUp in core/modules/ckeditor5/tests/src/Functional/AddedStylesheetsTest.php
AggregatorTestBase::setUp in core/modules/aggregator/tests/src/Functional/AggregatorTestBase.php
BasicTest::testViewsWizardAndListing in core/modules/views/tests/src/Functional/Wizard/BasicTest.php
BigPipeRegressionTest::testCommentForm_2698811 in core/modules/ckeditor/tests/src/FunctionalJavascript/BigPipeRegressionTest.php
Ensure comment form works with history and big_pipe modules.
BlockExposedFilterAJAXTest::setUp in core/modules/views/tests/src/FunctionalJavascript/BlockExposedFilterAJAXTest.php

... See full list

1 method overrides ContentTypeCreationTrait::createContentType()
WorkspacesContentModerationStateTest::createContentType in core/modules/content_moderation/tests/src/Kernel/WorkspacesContentModerationStateTest.php
Creates a custom content type based on default settings.

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;
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.