executeInRenderContext(new RenderContext(), function () use ($url) { return \Drupal::l(['#markup' => 'link with markup'], $url); }); $this->setRawContent($link); $this->assertTrue($link instanceof MarkupInterface, 'The output of link generation is marked safe as it is a link.'); // Ensure the content of the link is not escaped. $this->assertRaw('link with markup'); // Test just adding text to an already safe string. \Drupal::state()->set('link_generation_test_link_alter', TRUE); $link = $renderer->executeInRenderContext(new RenderContext(), function () use ($url) { return \Drupal::l(['#markup' => 'link with markup'], $url); }); $this->setRawContent($link); $this->assertTrue($link instanceof MarkupInterface, 'The output of link generation is marked safe as it is a link.'); // Ensure the content of the link is escaped. $this->assertEscaped('link with markup Test!'); // Test passing a safe string to t(). \Drupal::state()->set('link_generation_test_link_alter_safe', TRUE); $link = $renderer->executeInRenderContext(new RenderContext(), function () use ($url) { return \Drupal::l(['#markup' => 'link with markup'], $url); }); $this->setRawContent($link); $this->assertTrue($link instanceof MarkupInterface, 'The output of link generation is marked safe as it is a link.'); // Ensure the content of the link is escaped. $this->assertRaw('link with markup Test!'); // Test passing an unsafe string to t(). $link = $renderer->executeInRenderContext(new RenderContext(), function () use ($url) { return \Drupal::l('link with markup', $url); }); $this->setRawContent($link); $this->assertTrue($link instanceof MarkupInterface, 'The output of link generation is marked safe as it is a link.'); // Ensure the content of the link is escaped. $this->assertEscaped('link with markup'); $this->assertRaw('Test!'); } }