You are here

private function FieldApiTest::createTestNode in Field Formatter Filter 8

Same name and namespace in other branches
  1. 2.0.x tests/src/Kernel/FieldApiTest.php \Drupal\Tests\field_formatter_filter\Kernel\FieldApiTest::createTestNode()

Create a node with sample content.

Parameters

$bundle:

Return value

\Drupal\Core\Entity\EntityInterface

1 call to FieldApiTest::createTestNode()
FieldApiTest::testTeaserFilter in tests/src/Kernel/FieldApiTest.php
Test enabling the filter formatter. Check before, during and after.

File

tests/src/Kernel/FieldApiTest.php, line 202

Class

FieldApiTest
Tests applying the filter formatter to a node.

Namespace

Drupal\Tests\field_formatter_filter\Kernel

Code

private function createTestNode($bundle) {

  // Sample markup is in an external file - just to keep HTML out of code.
  $path = __DIR__ . '/../..';
  $body = file_get_contents($path . '/sample-markup.txt');
  $node = Node::create([
    'type' => $bundle,
    'title' => 'Test this is filtered',
    'uid' => 1,
    'body' => [
      'value' => $body,
      'format' => 'full_html',
    ],
  ]);
  $validated = $node
    ->validate();
  $saved = $node
    ->save();

  // It's now populated with expected values like date and nid, so should be
  // ready to render.
  return $node;
}