Skip to content

Instantly share code, notes, and snippets.

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