WebformAccessEntityRestTest.php in Webform 6.x
File
tests/src/Functional/Access/WebformAccessEntityRestTest.php
View source
<?php
namespace Drupal\Tests\webform\Functional\Access;
use Drupal\webform\Entity\Webform;
use Drupal\Tests\webform\Functional\WebformBrowserTestBase;
class WebformAccessEntityRestTest extends WebformBrowserTestBase {
public static $modules = [
'webform',
'webform_test_rest',
];
public function testRestAccess() {
$webform = Webform::load('contact');
$account = $this
->drupalCreateUser();
$configuration_account = $this
->drupalCreateUser([
'access any webform configuration',
]);
$this
->drupalGet('/webform/contact', [
'query' => [
'_format' => 'hal_json',
],
]);
$this
->assertRaw('{"message":"Access to webform configuration is required."}');
$this
->drupalLogin($account);
$this
->drupalGet('/webform/contact');
$this
->assertFieldByName('subject');
$this
->drupalGet('/webform/contact', [
'query' => [
'_format' => 'hal_json',
],
]);
$this
->assertRaw('{"message":"Access to webform configuration is required."}');
$this
->drupalLogin($configuration_account);
$this
->drupalGet('/webform/contact', [
'query' => [
'_format' => 'hal_json',
],
]);
$this
->assertNoRaw('{"message":"Access to webform configuration is required."}');
$this
->assertRaw('"id":"contact","title":"Contact"');
$access_rules = $webform
->getAccessRules();
$access_rules['configuration']['roles'] = [
'anonymous',
'authenticated',
];
$webform
->setAccessRules($access_rules);
$webform
->save();
$this
->drupalLogout();
$this
->drupalGet('/webform/contact', [
'query' => [
'_format' => 'hal_json',
],
]);
$this
->assertNoRaw('{"message":"Access to webform configuration is required."}');
$this
->drupalLogin($account);
$this
->drupalGet('/webform/contact', [
'query' => [
'_format' => 'hal_json',
],
]);
$this
->assertNoRaw('{"message":"Access to webform configuration is required."}');
}
}