You are here

protected function FeedsParaMapperWebTestCase::createBundles in Feeds Paragraphs 7

Creates the needed Paragraphs bundles in a loop.

1- Create a bundle with a text field. 2- Create another bundle with a paragraph field, with the previous bundle as allowed.

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

File

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

Class

FeedsParaMapperWebTestCase
Test basic functionality via DrupalWebTestCase.

Code

protected function createBundles() {
  $counter = $this->nested ? 2 : 1;
  for ($i = 0; $i < $counter; $i++) {
    if ($i === 0) {
      $cardinality = $this->multiValued ? -1 : 1;
      $bundle = array(
        'name' => 'image_details_bundle',
        'fields' => array(
          array(
            'name' => 'description',
            'type' => "text",
            'widget' => 'text_textfield',
            'cardinality' => $cardinality,
            'mapping' => array(
              'text' => 'field_description',
            ),
            'mapping_multiple' => array(
              'text_multiple' => 'field_description',
            ),
          ),
          array(
            'name' => 'image',
            'type' => "image",
            'widget' => 'image_image',
            'cardinality' => $cardinality,
            'mapping' => array(
              'image_alt' => 'field_image:alt',
              'image_title' => 'field_image:title',
              'image_uri' => 'field_image:uri',
            ),
            'mapping_multiple' => array(
              'image_multi_alt' => 'field_image:alt',
              'image_multi_title' => 'field_image:title',
              'image_multi_uri' => 'field_image:uri',
            ),
          ),
        ),
      );
    }
    else {
      $isLast = $i + 1 === $counter;
      $cardinality = $this->multiValuedParagraph && $isLast ? -1 : 1;
      $bundle = array(
        'name' => 'image_bundle',
        'fields' => array(
          array(
            'name' => 'images',
            'type' => "paragraphs",
            'widget' => 'paragraphs_embed',
            'cardinality' => $cardinality,
            'allowed_bundles' => array(
              end($this->bundles)['name'],
            ),
          ),
        ),
      );
    }
    $this->bundles[] = $bundle;
    $this
      ->createBundle($bundle);
  }
}