YamlFormElementAccessTest.php in YAML Form 8
File
src/Tests/YamlFormElementAccessTest.php
View source
<?php
namespace Drupal\yamlform\Tests;
use Drupal\yamlform\Entity\YamlForm;
use Drupal\yamlform\Entity\YamlFormSubmission;
class YamlFormElementAccessTest extends YamlFormTestBase {
protected static $modules = [
'yamlform',
'yamlform_ui',
'yamlform_test',
];
public function testElementAccess() {
$yamlform = YamlForm::load('test_element_access');
$elements = $yamlform
->get('elements');
$elements = str_replace(' - 1', ' - ' . $this->adminSubmissionUser
->id(), $elements);
$elements = str_replace('USER:1', 'USER:' . $this->adminSubmissionUser
->id(), $elements);
$yamlform
->set('elements', $elements);
$yamlform
->save();
$this
->drupalLogin($this->normalUser);
$sid = $this
->postSubmission($yamlform);
$yamlform_submission = YamlFormSubmission::load($sid);
$this
->drupalLogin($this->normalUser);
$this
->drupalGet('yamlform/test_element_access');
$this
->assertNoFieldByName('private', '');
$this
->drupalLogin($this->adminFormUser);
$this
->drupalGet('yamlform/test_element_access');
$this
->assertFieldByName('private', '');
$this
->drupalLogin($this->adminFormUser);
$this
->drupalGet('admin/structure/yamlform/manage/test_element_access/element/access_create_roles_anonymous/edit');
$this
->assertFieldById('edit-properties-access-create-roles-anonymous');
$this
->drupalLogin($this->ownFormUser);
$this
->drupalGet('admin/structure/yamlform/manage/test_element_access/element/access_create_roles_anonymous/edit');
$this
->assertNoFieldById('edit-properties-access-create-roles-anonymous');
$this
->drupalLogout();
$this
->drupalGet('yamlform/test_element_access');
$this
->assertFieldByName('access_create_roles_anonymous');
$this
->assertNoFieldByName('access_create_roles_authenticated');
$this
->assertNoFieldByName('access_create_users');
$this
->drupalLogin($this->normalUser);
$this
->drupalGet('yamlform/test_element_access');
$this
->assertNoFieldByName('access_create_roles_anonymous');
$this
->assertFieldByName('access_create_roles_authenticated');
$this
->assertNoFieldByName('access_create_users');
$this
->drupalLogin($this->adminSubmissionUser);
$this
->drupalGet('yamlform/test_element_access');
$this
->assertNoFieldByName('access_create_roles_anonymous');
$this
->assertFieldByName('access_create_roles_authenticated');
$this
->assertFieldByName('access_create_users');
$this
->drupalLogout();
$this
->drupalGet($yamlform_submission
->getTokenUrl());
$this
->assertFieldByName('access_update_roles_anonymous');
$this
->assertNoFieldByName('access_update_roles_authenticated');
$this
->assertNoFieldByName('access_update_users');
$this
->drupalLogin($this->normalUser);
$this
->drupalGet("/yamlform/test_element_access/submissions/{$sid}/edit");
$this
->assertNoFieldByName('access_update_roles_anonymous');
$this
->assertFieldByName('access_update_roles_authenticated');
$this
->assertNoFieldByName('access_update_users');
$this
->drupalLogin($this->adminSubmissionUser);
$this
->drupalGet("/admin/structure/yamlform/manage/test_element_access/submission/{$sid}/edit");
$this
->assertNoFieldByName('access_update_roles_anonymous');
$this
->assertFieldByName('access_update_roles_authenticated');
$this
->assertFieldByName('access_update_users');
$this
->drupalLogin($this->adminFormUser);
$this
->drupalGet("/admin/structure/yamlform/manage/test_element_access/submission/{$sid}");
$this
->assertNoRaw('access_view_roles (anonymous)');
$this
->assertRaw('access_view_roles (authenticated)');
$this
->assertNoRaw('access_view_users (USER:' . $this->adminSubmissionUser
->id() . ')');
$this
->drupalLogin($this->adminSubmissionUser);
$this
->drupalGet("/admin/structure/yamlform/manage/test_element_access/submission/{$sid}");
$this
->assertNoRaw('access_view_roles (anonymous)');
$this
->assertRaw('access_view_roles (authenticated)');
$this
->assertRaw('access_view_users (USER:' . $this->adminSubmissionUser
->id() . ')');
}
}