public function EntityEmbedFilterTest::testAccessUnpublished in Entity Embed 8
Tests that entity access is respected by embedding an unpublished entity.
@dataProvider providerAccessUnpublished
File
- tests/
src/ Kernel/ EntityEmbedFilterTest.php, line 173
Class
- EntityEmbedFilterTest
- @coversDefaultClass \Drupal\entity_embed\Plugin\Filter\EntityEmbedFilter @group entity_embed
Namespace
Drupal\Tests\entity_embed\KernelCode
public function testAccessUnpublished($allowed_to_view_unpublished, $expected_rendered, CacheableMetadata $expected_cacheability, array $expected_attachments) {
// 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')
->addRole($this
->drupalCreateRole([
'view own unpublished content',
]));
}
$content = $this
->createEmbedCode([
'data-entity-type' => 'node',
'data-entity-uuid' => static::EMBEDDED_ENTITY_UUID,
'data-view-mode' => 'teaser',
]);
$result = $this
->applyFilter($content);
if (!$expected_rendered) {
$this
->assertEmpty($this
->getRawContent());
}
else {
$this
->assertCount(1, $this
->cssSelect('div.embedded-entity > [data-entity-embed-test-view-mode="teaser"]'));
}
// Expected bubbleable metadata.
$this
->assertSame($expected_cacheability
->getCacheTags(), $result
->getCacheTags());
$this
->assertSame($expected_cacheability
->getCacheContexts(), $result
->getCacheContexts());
$this
->assertSame($expected_cacheability
->getCacheMaxAge(), $result
->getCacheMaxAge());
$this
->assertSame($expected_attachments, $result
->getAttachments());
}