View source
<?php
namespace Drupal\site_settings_type_permissions\Tests;
use Drupal\Tests\field_ui\Traits\FieldUiTestTrait;
use Drupal\Tests\BrowserTestBase;
class SiteSettingTypePermissionsUiTest extends BrowserTestBase {
use FieldUiTestTrait;
protected $defaultTheme = 'stark';
public static $modules = [
'site_settings',
'site_settings_sample_data',
'site_settings_type_permissions',
'field_ui',
'user',
];
public function testSiteSettingsTypePermissions() {
$editor = $this
->createUser([
'administer site configuration',
'access site settings overview',
'view published test_multiple_entries_and_fields site setting entities',
'view unpublished test_multiple_entries_and_fields site setting entities',
'create test_multiple_entries_and_fields site setting',
'edit test_multiple_entries_and_fields site setting',
'delete test_multiple_entries_and_fields site setting',
'view published test_plain_text site setting entities',
'view unpublished test_plain_text site setting entities',
'create test_plain_text site setting',
'edit test_plain_text site setting',
'delete test_plain_text site setting',
]);
$this
->drupalLogin($editor);
$this
->drupalGet('admin/content/site-settings');
$this
->assertRaw('<strong>Other</strong>');
$this
->assertNoRaw('<strong>Images</strong>');
$this
->assertText('Test plain text');
$this
->assertText('Test multiple entries and fields name 1');
$this
->assertText('Test multiple entries and fields name 2');
$this
->drupalLogout();
$edit_only = $this
->drupalCreateUser([
'administer site configuration',
'access site settings overview',
'edit test_multiple_entries_and_fields site setting',
'edit test_plain_text site setting',
]);
$this
->drupalLogin($edit_only);
$this
->drupalGet('admin/content/site-settings');
$this
->assertRaw('<strong>Other</strong>');
$this
->assertNoRaw('<strong>Images</strong>');
$this
->assertText('Test plain text');
$this
->assertText('Test multiple entries and fields name 1');
$this
->assertText('Test multiple entries and fields name 2');
$this
->clickLink('Edit', 0);
$this
->assertText('Edit Test plain text name');
$this
->drupalGet('admin/content/site-settings');
$this
->clickLink('Edit', 1);
$this
->assertText('Edit Test multiple entries and fields name 1');
$this
->drupalLogout();
$creator = $this
->drupalCreateUser([
'administer site configuration',
'access site settings overview',
'create test_multiple_entries_and_fields site setting',
'create test_plain_text site setting',
]);
$this
->drupalLogin($creator);
$this
->drupalGet('admin/content/site-settings');
$this
->assertNoText('Test plain text');
$this
->assertText('Test multiple entries and fields');
$this
->clickLink('Create setting', 0);
$this
->assertText('Test multiple entries and fields');
$this
->drupalGet('admin/structure/site_setting_entity/add/test_plain_text');
$this
->assertText('Access denied');
$this
->drupalLogout();
$remover = $this
->drupalCreateUser([
'administer site configuration',
'access site settings overview',
'view published test_multiple_entries_and_fields site setting entities',
'view unpublished test_multiple_entries_and_fields site setting entities',
'view published test_plain_text site setting entities',
'view unpublished test_plain_text site setting entities',
'delete test_multiple_entries_and_fields site setting',
'delete test_plain_text site setting',
]);
$this
->drupalLogin($remover);
$this
->drupalGet('admin/content/site-settings');
$this
->assertText('Test plain text');
$this
->assertText('Test multiple entries and fields');
$this
->clickLink('Delete', 0);
$this
->assertText('This action cannot be undone.');
$this
->drupalPostForm($this
->getUrl(), [], 'Delete');
$this
->assertNoText('Test plain text value');
$this
->drupalLogout();
$this
->drupalLogin($creator);
$this
->drupalGet('admin/content/site-settings');
$this
->assertText('Test plain text');
}
}