You are here

protected function FieldCollectionTestTrait::createNodeWithFieldCollection 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::createNodeWithFieldCollection()

Helper for creating a new node with a field collection item.

3 calls to FieldCollectionTestTrait::createNodeWithFieldCollection()
FieldCollectionBasicTestCase::testCRUD in tests/src/Functional/FieldCollectionBasicTestCase.php
Tests CRUD.
FieldCollectionBasicTestCase::testFieldDeletion in tests/src/Functional/FieldCollectionBasicTestCase.php
Test deleting the field corresponding to a field collection.
FieldCollectionRESTTest::testRead in src/Tests/FieldCollectionRESTTest.php
Tests read requests on host entities.

File

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

Class

FieldCollectionTestTrait
Provides helper properties and functions for field collection tests.

Namespace

Drupal\Tests\field_collection\Functional

Code

protected function createNodeWithFieldCollection($content_type) {
  $node = $this
    ->drupalCreateNode([
    'type' => $content_type,
  ]);

  // Manually create a field_collection.
  $entity = FieldCollectionItem::create([
    'field_name' => $this->field_collection_name,
  ]);
  $entity->{$this->inner_field_name}
    ->setValue(1);
  $entity
    ->setHostEntity($node);
  $entity
    ->save();
  return [
    $node,
    $entity,
  ];
}