3 namespace Drupal\Tests\Core\Render;
5 use Drupal\Component\Utility\Html;
8 * @coversDefaultClass \Drupal\Core\Render\PlaceholderGenerator
11 class PlaceholderGeneratorTest extends RendererTestBase {
14 * The tested placeholder generator.
16 * @var \Drupal\Core\Render\PlaceholderGenerator
18 protected $placeholderGenerator;
21 * @covers ::createPlaceholder
22 * @dataProvider providerCreatePlaceholderGeneratesValidHtmlMarkup
24 * Ensure that the generated placeholder markup is valid. If it is not, then
25 * simply using DOMDocument on HTML that contains placeholders may modify the
26 * placeholders' markup, which would make it impossible to replace the
27 * placeholders: the placeholder markup in #attached versus that in the HTML
28 * processed by DOMDocument would no longer match.
30 public function testCreatePlaceholderGeneratesValidHtmlMarkup(array $element) {
31 $build = $this->placeholderGenerator->createPlaceholder($element);
33 $original_placeholder_markup = (string)$build['#markup'];
34 $processed_placeholder_markup = Html::serialize(Html::load($build['#markup']));
36 $this->assertEquals($original_placeholder_markup, $processed_placeholder_markup);
42 public function providerCreatePlaceholderGeneratesValidHtmlMarkup() {
44 'multiple-arguments' => [['#lazy_builder' => ['Drupal\Tests\Core\Render\PlaceholdersTest::callback', ['foo', 'bar']]]],
45 'special-character-&' => [['#lazy_builder' => ['Drupal\Tests\Core\Render\PlaceholdersTest::callback', ['foo&bar']]]],
46 'special-character-"' => [['#lazy_builder' => ['Drupal\Tests\Core\Render\PlaceholdersTest::callback', ['foo"bar']]]],
47 'special-character-<' => [['#lazy_builder' => ['Drupal\Tests\Core\Render\PlaceholdersTest::callback', ['foo<bar']]]],
48 'special-character->' => [['#lazy_builder' => ['Drupal\Tests\Core\Render\PlaceholdersTest::callback', ['foo>bar']]]],