You are here

protected function FeedsParaMapperWebTestCase::createContentType in Feeds Paragraphs 7

Utility function to create a content type.

Parameters

string $name: The content type name.

string $paragraph_field: The paragraph field name to add to the content type.

array $allowed_bundles: The allowed bundles for the paragraph field.

1 call to FeedsParaMapperWebTestCase::createContentType()
FeedsParaMapperWebTestCase::setUp in tests/FeedsParaMapperWebTestCase.test
Prepares the test environment.

File

tests/FeedsParaMapperWebTestCase.test, line 191
Common functionality for all Paragraphs Mapper tests.

Class

FeedsParaMapperWebTestCase
Test basic functionality via DrupalWebTestCase.

Code

protected function createContentType($name, $paragraph_field, array $allowed_bundles) {
  $this
    ->drupalGet('admin/structure/types/add');
  $edit = array(
    'name' => $name,
    'type' => $name,
  );
  $this
    ->drupalPost(NULL, $edit, t('Save and add fields'));
  $text = t('The content type @name has been added.', array(
    '@name' => $name,
  ));
  $this
    ->assertText($text, NULL, "Setup");
  $fields = array();
  $cardinality = $this->multiValuedParagraph ? -1 : 1;
  $fields[$paragraph_field] = array(
    'type' => "paragraphs",
    'widget' => 'paragraphs_embed',
    'cardinality' => $cardinality,
    'bundles' => $allowed_bundles,
  );
  foreach ($fields as $field_name => $details) {
    $this
      ->createField($field_name, $details['cardinality'], $details['type'], $details['widget'], $details['bundles']);
  }

  // Somehow clicking "save" isn't enough, and we have to do a
  // node_types_rebuild().
  node_types_rebuild();
  menu_rebuild();
  $type_exists = db_query('SELECT 1 FROM {node_type} WHERE type = :type', array(
    ':type' => $name,
  ))
    ->fetchField();
  $this
    ->assertTrue($type_exists, "The new content type has been created in the database", "Setup");
}