function MediaEmbedFilterTest::testRecursionProtection

Same name and namespace in other branches
  1. 9 core/modules/media/tests/src/Kernel/MediaEmbedFilterTest.php \Drupal\Tests\media\Kernel\MediaEmbedFilterTest::testRecursionProtection()
  2. 8.9.x core/modules/media/tests/src/Kernel/MediaEmbedFilterTest.php \Drupal\Tests\media\Kernel\MediaEmbedFilterTest::testRecursionProtection()
  3. 10 core/modules/media/tests/src/Kernel/MediaEmbedFilterTest.php \Drupal\Tests\media\Kernel\MediaEmbedFilterTest::testRecursionProtection()

Tests recursive rendering protection.

File

core/modules/media/tests/src/Kernel/MediaEmbedFilterTest.php, line 378

Class

MediaEmbedFilterTest
@coversDefaultClass <a href="/api/drupal/core%21modules%21media%21src%21Plugin%21Filter%21MediaEmbed.php/class/MediaEmbed/11.x" title="Provides a filter to embed media items using a custom tag." class="local">\Drupal\media\Plugin\Filter\MediaEmbed</a> @group media

Namespace

Drupal\Tests\media\Kernel

Code

public function testRecursionProtection() : void {
    $text = $this->createEmbedCode([
        'data-entity-type' => 'media',
        'data-entity-uuid' => static::EMBEDDED_ENTITY_UUID,
    ]);
    // Render and verify the presence of the embedded entity 20 times.
    for ($i = 0; $i < 20; $i++) {
        $this->applyFilter($text);
        $this->assertCount(1, $this->cssSelect('div[data-media-embed-test-view-mode="default"]'));
    }
    // Render a 21st time, this is exceeding the recursion limit. The entity
    // embed markup will be stripped.
    $this->applyFilter($text);
    $this->assertEmpty($this->getRawContent());
}

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