You are here

protected function FieldOutputTest::getPreparedFieldOutput in Video Embed Field 8

Same name and namespace in other branches
  1. 8.2 tests/src/Kernel/FieldOutputTest.php \Drupal\Tests\video_embed_field\Kernel\FieldOutputTest::getPreparedFieldOutput()

Get and prepare the output of a field.

Parameters

string $url: The video URL.

array $settings: An array of formatter settings.

Return value

array The rendered prepared field output.

1 call to FieldOutputTest::getPreparedFieldOutput()
FieldOutputTest::testEmbedField in tests/src/Kernel/FieldOutputTest.php
Test the embed field.

File

tests/src/Kernel/FieldOutputTest.php, line 583

Class

FieldOutputTest
Test the embed field formatters are functioning.

Namespace

Drupal\Tests\video_embed_field\Kernel

Code

protected function getPreparedFieldOutput($url, $settings) {
  $entity = EntityTest::create();
  $entity->{$this->fieldName}->value = $url;
  $entity
    ->save();
  $field_output = $this->container
    ->get('renderer')
    ->executeInRenderContext(new RenderContext(), function () use ($entity, $settings) {
    return $entity->{$this->fieldName}
      ->view($settings);
  });

  // Prepare the field output to make it easier to compare our test data
  // values against.
  array_walk_recursive($field_output[0], function (&$value) {

    // Prevent circular references with comparing field output that
    // contains url objects.
    if ($value instanceof Url) {
      $value = $value
        ->isRouted() ? $value
        ->getRouteName() : $value
        ->getUri();
    }

    // Trim to prevent stray whitespace for the colorbox formatters with
    // early rendering.
    $value = $this
      ->stripWhitespace($value);
  });
  return $field_output;
}