You are here

private function FieldCollectionTestTrait::setUpFieldCollectionTest in Field collection 8

Same name and namespace in other branches
  1. 8.3 tests/src/Functional/FieldCollectionTestTrait.php \Drupal\Tests\field_collection\Functional\FieldCollectionTestTrait::setUpFieldCollectionTest()

Sets up the data structures for the tests.

3 calls to FieldCollectionTestTrait::setUpFieldCollectionTest()
FieldCollectionAJAXTest::setUp in tests/src/FunctionalJavascript/FieldCollectionAjaxTest.php
Sets up the data structures for the tests.
FieldCollectionBasicTestCase::setUp in tests/src/Functional/FieldCollectionBasicTestCase.php
Sets up the data structures for the tests.
FieldCollectionRESTTest::setUp in src/Tests/FieldCollectionRESTTest.php
Sets up the data structures for the tests.

File

tests/src/Functional/FieldCollectionTestTrait.php, line 59

Class

FieldCollectionTestTrait
Provides helper properties and functions for field collection tests.

Namespace

Drupal\Tests\field_collection\Functional

Code

private function setUpFieldCollectionTest() {
  $this->nodeStorage = \Drupal::entityTypeManager()
    ->getStorage('node');

  // Create Article node type.
  if ($this->profile != 'standard') {
    $this
      ->drupalCreateContentType([
      'type' => 'article',
      'name' => 'Article',
    ]);
  }

  // Create a field_collection field to use for the tests.
  $this->field_collection_name = 'field_test_collection';
  $this->field_collection_field_storage = FieldStorageConfig::create([
    'field_name' => $this->field_collection_name,
    'entity_type' => 'node',
    'type' => 'field_collection',
    'cardinality' => 4,
  ]);
  $this->field_collection_field_storage
    ->save();
  $this->field_collection_field = $this
    ->addFieldCollectionFieldToContentType('article');

  // Create an integer field inside the field_collection.
  $this->inner_field_name = 'field_inner';
  $inner_field_storage = FieldStorageConfig::create([
    'field_name' => $this->inner_field_name,
    'entity_type' => 'field_collection_item',
    'type' => 'integer',
  ]);
  $inner_field_storage
    ->save();
  $this->inner_field_definition = [
    'field_name' => $this->inner_field_name,
    'entity_type' => 'field_collection_item',
    'bundle' => $this->field_collection_name,
    'field_storage' => $inner_field_storage,
    'label' => $this
      ->randomMachineName() . '_label',
    'description' => $this
      ->randomMachineName() . '_description',
    'settings' => [],
  ];
  $inner_field = FieldConfig::create($this->inner_field_definition);
  $inner_field
    ->save();
  entity_get_form_display('field_collection_item', $this->field_collection_name, 'default')
    ->setComponent($this->inner_field_name, [
    'type' => 'number',
  ])
    ->save();
  entity_get_display('field_collection_item', $this->field_collection_name, 'default')
    ->setComponent($this->inner_field_name, [
    'type' => 'number_decimal',
  ])
    ->save();
}