function MediaEmbedFilterTest::testAccessUnpublished
Same name in other branches
- 9 core/modules/media/tests/src/Kernel/MediaEmbedFilterTest.php \Drupal\Tests\media\Kernel\MediaEmbedFilterTest::testAccessUnpublished()
- 8.9.x core/modules/media/tests/src/Kernel/MediaEmbedFilterTest.php \Drupal\Tests\media\Kernel\MediaEmbedFilterTest::testAccessUnpublished()
- 11.x core/modules/media/tests/src/Kernel/MediaEmbedFilterTest.php \Drupal\Tests\media\Kernel\MediaEmbedFilterTest::testAccessUnpublished()
Tests that entity access is respected by embedding an unpublished entity.
@dataProvider providerAccessUnpublished
File
-
core/
modules/ media/ tests/ src/ Kernel/ MediaEmbedFilterTest.php, line 135
Class
- MediaEmbedFilterTest
- @coversDefaultClass \Drupal\media\Plugin\Filter\MediaEmbed @group media @group #slow
Namespace
Drupal\Tests\media\KernelCode
public function testAccessUnpublished($allowed_to_view_unpublished, $expected_rendered, CacheableMetadata $expected_cacheability, array $expected_attachments) : void {
// Unpublish the embedded entity so we can test variations in behavior.
$this->embeddedEntity
->setUnpublished()
->save();
// Are we testing as a user who is allowed to view the embedded entity?
if ($allowed_to_view_unpublished) {
$this->container
->get('current_user')
->getAccount()
->addRole($this->drupalCreateRole([
'view own unpublished media',
]));
}
$content = $this->createEmbedCode([
'data-entity-type' => 'media',
'data-entity-uuid' => static::EMBEDDED_ENTITY_UUID,
]);
$result = $this->applyFilter($content);
if (!$expected_rendered) {
$this->assertEmpty($this->getRawContent());
}
else {
$this->assertCount(1, $this->cssSelect('div[data-media-embed-test-view-mode="default"]'));
}
$this->assertEqualsCanonicalizing($expected_cacheability->getCacheTags(), $result->getCacheTags());
$this->assertEqualsCanonicalizing($expected_cacheability->getCacheContexts(), $result->getCacheContexts());
$this->assertSame($expected_cacheability->getCacheMaxAge(), $result->getCacheMaxAge());
$this->assertSame($expected_attachments, $result->getAttachments());
}
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.