You are here

protected function ExportTest::createNodeWithField in Acquia Content Hub 8.2

Creates a node with a field value.

Parameters

int $items_expected: Expected number of items in the queue.

array $cdf_expectations: The sets of expectation arguments for CDF object validation.

Return value

int Node id.

Throws

\Drupal\Core\Entity\EntityStorageException

See also

\Drupal\Tests\acquia_contenthub\Kernel\ExportTest::createFields()

2 calls to ExportTest::createNodeWithField()
ExportTest::testPublishing in tests/src/Kernel/ExportTest.php
Tests Acquia ContentHub content/configuration export.
ExportTest::testQueue in tests/src/Kernel/ExportTest.php
Tests Acquia ContentHub export queue.

File

tests/src/Kernel/ExportTest.php, line 1003

Class

ExportTest
Tests entity exports.

Namespace

Drupal\Tests\acquia_contenthub\Kernel

Code

protected function createNodeWithField(&$items_expected, array &$cdf_expectations = []) {
  $title = $this
    ->getRandomGenerator()
    ->word(32);
  $bundle = 'test_content_type';
  $field_value = $this
    ->getRandomGenerator()
    ->string(256);
  $values = [
    'title' => $title,
    'type' => $bundle,
    'status' => Node::PUBLISHED,
    'field_1' => [
      'value' => $field_value,
    ],
  ];
  $node = Node::create($values);
  $node
    ->save();
  $items_expected = 1;
  $field = [
    'field_1' => [
      'value' => [
        'en' => [
          'value' => $field_value,
        ],
      ],
    ],
    'field_term_reference' => [
      'value' => [
        'en' => [],
      ],
    ],
  ];
  $field_metadata = [
    'field_1' => [
      'type' => 'string_long',
    ],
    'field_term_reference' => [
      'type' => 'entity_reference',
      'target' => 'taxonomy_term',
    ],
  ];
  $cdf_expectations = [
    [
      $node
        ->id(),
      $title,
      $bundle,
      Node::PUBLISHED,
      $field,
      $field_metadata,
    ],
  ];
  return $node
    ->id();
}