WebformSourceEntityAccessTest.php in Webform 6.x
File
tests/src/Unit/Access/WebformSourceEntityAccessTest.php
View source
<?php
namespace Drupal\Tests\webform\Unit\Access;
use Drupal\Core\Access\AccessResult;
use Drupal\webform\Access\WebformSourceEntityAccess;
class WebformSourceEntityAccessTest extends WebformAccessTestBase {
public function testWebformSourceEntityAccess() {
$anonymous_account = $this
->mockAccount();
$submission_account = $this
->mockAccount([
'access webform overview' => TRUE,
'view any webform submission' => TRUE,
]);
$node = $this
->getMockBuilder('Drupal\\node\\NodeInterface')
->disableOriginalConstructor()
->getMock();
$node
->expects($this
->any())
->method('access')
->willReturn(AccessResult::neutral());
$webform = $this
->createMock('Drupal\\webform\\WebformInterface');
$webform_node = $this
->getMockBuilder('Drupal\\node\\NodeInterface')
->disableOriginalConstructor()
->getMock();
$webform_node
->expects($this
->any())
->method('access')
->willReturn(AccessResult::allowed());
$entity_reference_manager = $this
->getMockBuilder('Drupal\\webform\\WebformEntityReferenceManagerInterface')
->disableOriginalConstructor()
->getMock();
$entity_reference_manager
->expects($this
->any())
->method('getWebform')
->will($this
->returnValueMap([
[
$node,
NULL,
],
[
$webform_node,
$webform,
],
]));
$this->container
->set('webform.entity_reference_manager', $entity_reference_manager);
$this
->assertEquals(AccessResult::neutral(), WebformSourceEntityAccess::checkEntityResultsAccess($node, $anonymous_account));
$this
->assertEquals(AccessResult::allowed(), WebformSourceEntityAccess::checkEntityResultsAccess($webform_node, $submission_account));
}
}