Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save suresh-kumara-gist/af860c64dff68fe9b7ca45f39c9ed7bd to your computer and use it in GitHub Desktop.
Save suresh-kumara-gist/af860c64dff68fe9b7ca45f39c9ed7bd to your computer and use it in GitHub Desktop.
Rendarable array to html string
$entity = EntityTest::create();
$entity->field_datasheet->target_id = $this->file->id();
$entity->save();
$output = $this->renderTestEntity($entity->id());
$expected_link = Link::fromTextAndUrl($this->field_label, Url::fromUri(file_create_url($this->file->getFileUri())));
$expected_link = $expected_link->toRenderable();
$expected_link['#attributes'] = [
'target' => '_blank',
];
$expected_link = \Drupal::service('renderer')->renderRoot($expected_link);
$this->assertContains($expected_link->__toString(), $output);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment