You are here

protected function BlazyCreationTestTrait::setUpContentTypeTest in Blazy 8

Same name and namespace in other branches
  1. 8.2 tests/src/Traits/BlazyCreationTestTrait.php \Drupal\Tests\blazy\Traits\BlazyCreationTestTrait::setUpContentTypeTest()

Build dummy content types.

Parameters

string $bundle: The bundle name.

array $settings: (Optional) configurable settings.

6 calls to BlazyCreationTestTrait::setUpContentTypeTest()
BlazyCreationTestTrait::setUpContentWithEntityReference in tests/src/Traits/BlazyCreationTestTrait.php
Build dummy contents with entity references.
BlazyFormatterTest::setUp in tests/src/Kernel/BlazyFormatterTest.php
Set the default field storage backend for fields created during tests.
BlazyJavaScriptTest::testFormatterDisplay in tests/src/FunctionalJavascript/BlazyJavaScriptTest.php
Test the Blazy element from loading to loaded states.
BlazyManagerTest::setUp in tests/src/Kernel/BlazyManagerTest.php
Set the default field storage backend for fields created during tests.
BlazyViewsFileTest::buildContents in tests/src/Kernel/Views/BlazyViewsFileTest.php
Build contents.

... See full list

File

tests/src/Traits/BlazyCreationTestTrait.php, line 166

Class

BlazyCreationTestTrait
A Trait common for Blazy tests.

Namespace

Drupal\Tests\blazy\Traits

Code

protected function setUpContentTypeTest($bundle = '', array $settings = []) {
  $node_type = NodeType::load($bundle);
  $restricted_html = $this->blazyManager
    ->entityLoad('restricted_html', 'filter_format');
  if (empty($node_type)) {
    $node_type = NodeType::create([
      'type' => $bundle,
      'name' => $bundle,
    ]);
    $node_type
      ->save();
  }
  if (!$restricted_html) {
    FilterFormat::create([
      'format' => 'restricted_html',
      'name' => 'Basic HML',
      'weight' => 2,
      'filters' => [],
    ])
      ->save();
  }
  node_add_body_field($node_type);
  if (!empty($this->testFieldName)) {
    $settings['fields'][$this->testFieldName] = empty($this->testFieldType) ? 'image' : $this->testFieldType;
  }
  if (!empty($settings['field_name']) && !empty($settings['field_type'])) {
    $settings['fields'][$settings['field_name']] = $settings['field_type'];
  }
  $data = [];
  if (!empty($settings['fields'])) {
    foreach ($settings['fields'] as $field_name => $field_type) {
      $data['field_name'] = $field_name;
      $data['field_type'] = $field_type;
      $this
        ->setUpFieldConfig($bundle, $data);
    }
  }
  $node_type
    ->save();
  return $node_type;
}