Updated to Drupal 8.5. Core Media not yet in use.
[yaffs-website] / web / core / tests / Drupal / Tests / Core / Render / PlaceholderGeneratorTest.php
1 <?php
2
3 namespace Drupal\Tests\Core\Render;
4
5 use Drupal\Component\Utility\Html;
6
7 /**
8  * @coversDefaultClass \Drupal\Core\Render\PlaceholderGenerator
9  * @group Render
10  */
11 class PlaceholderGeneratorTest extends RendererTestBase {
12
13   /**
14    * The tested placeholder generator.
15    *
16    * @var \Drupal\Core\Render\PlaceholderGenerator
17    */
18   protected $placeholderGenerator;
19
20   /**
21    * @covers ::createPlaceholder
22    * @dataProvider providerCreatePlaceholderGeneratesValidHtmlMarkup
23    *
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.
29    */
30   public function testCreatePlaceholderGeneratesValidHtmlMarkup(array $element) {
31     $build = $this->placeholderGenerator->createPlaceholder($element);
32
33     $original_placeholder_markup = (string) $build['#markup'];
34     $processed_placeholder_markup = Html::serialize(Html::load($build['#markup']));
35
36     $this->assertEquals($original_placeholder_markup, $processed_placeholder_markup);
37   }
38
39   /**
40    * @return array
41    */
42   public function providerCreatePlaceholderGeneratesValidHtmlMarkup() {
43     return [
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']]]],
49     ];
50
51   }
52
53 }