View source
<?php
namespace Drupal\Tests\preview_link\Kernel;
use Drupal\preview_link\Entity\PreviewLink;
class PreviewLinkAccessTest extends PreviewLinkBase {
protected $node;
protected $previewLink;
public function setUp() {
parent::setUp();
$this->node = $this
->createNode();
$this->previewLink = PreviewLink::create([
'entity_type_id' => 'node',
'entity_id' => $this->node
->id(),
]);
$this->previewLink
->save();
}
public function testPreviewAccessDenied($entity_type_id, $entity_id, $token, $expected_result) {
$entity = $this->container
->get('entity_type.manager')
->getStorage($entity_type_id)
->load($entity_id);
$access = $this->container
->get('access_check.preview_link')
->access($entity, $token);
$this
->assertEquals($expected_result, $access
->isAllowed());
}
public function previewAccessDeniedDataProvider() {
return [
'empty token' => [
'node',
1,
'',
FALSE,
],
'invalid token' => [
'node',
1,
'invalid 123',
FALSE,
],
'invalid entity id' => [
'node',
99,
'correct-token',
FALSE,
],
];
}
public function testPreviewAccessAllowed() {
$access = $this->container
->get('access_check.preview_link')
->access($this->node, $this->previewLink
->getToken());
$this
->assertEquals(TRUE, $access
->isAllowed());
}
}