function ProcessedTextTestTrait::processText

Same name and namespace in other branches
  1. main core/modules/filter/tests/src/Traits/ProcessedTextTestTrait.php \Drupal\Tests\filter\Traits\ProcessedTextTestTrait::processText()

Processes a text using the renderer.

Important: This technique of rendering processed text is only permitted for testing isolated string cases. This is because flattening the render array leads to loss of cacheability metadata. In production code, use the render array directly.

Parameters

string $text: Text to process.

string|null $format: (optional) The format to use. Defaults to the fallback format.

string|null $langcode: (optional) The language code to use. Defaults to the current language.

array $filterTypesToSkip: (optional) An array of filter types to skip.

Return value

\Drupal\Component\Render\MarkupInterface The processed text.

6 calls to ProcessedTextTestTrait::processText()
AreaTextTest::testAreaText in core/modules/views/tests/src/Kernel/Handler/AreaTextTest.php
Tests the rendering of a text area.
AreaTextTokenTest::testAreaTextToken in core/modules/views/tests/src/Kernel/Handler/AreaTextTokenTest.php
Tests the token into text area plugin within header.
FilterAPITest::testFormatFilterOrder in core/modules/filter/tests/src/Kernel/FilterAPITest.php
Tests that the filter order is respected.
FilterAPITest::testFormatFilterSubset in core/modules/filter/tests/src/Kernel/FilterAPITest.php
Tests the ability to apply only a subset of filters.
FilterNoFormatTest::testProcessedTextNoFormat in core/modules/filter/tests/src/Kernel/FilterNoFormatTest.php
Tests text without format.

... See full list

File

core/modules/filter/tests/src/Traits/ProcessedTextTestTrait.php, line 34

Class

ProcessedTextTestTrait
Provides a trait for testing processed text.

Namespace

Drupal\Tests\filter\Traits

Code

protected function processText(string $text, ?string $format = NULL, ?string $langcode = NULL, array $filterTypesToSkip = []) : MarkupInterface {
  $build = [
    '#type' => 'processed_text',
    '#text' => $text,
    '#format' => $format,
    '#langcode' => $langcode,
    '#filter_types_to_skip' => $filterTypesToSkip,
  ];
  return \Drupal::service('renderer')->renderInIsolation($build);
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.