本文整理汇总了PHP中user_role_grant_permissions函数的典型用法代码示例。如果您正苦于以下问题:PHP user_role_grant_permissions函数的具体用法?PHP user_role_grant_permissions怎么用?PHP user_role_grant_permissions使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了user_role_grant_permissions函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: setUp
protected function setUp()
{
parent::setUp();
// Enable anonymous and authenticated user comments.
user_role_grant_permissions(RoleInterface::ANONYMOUS_ID, array('access comments', 'post comments', 'skip comment approval'));
user_role_grant_permissions(RoleInterface::AUTHENTICATED_ID, array('access comments', 'post comments', 'skip comment approval'));
}
示例2: testUserRegisterForm
/**
* Test user registration integration.
*/
public function testUserRegisterForm()
{
$id = $this->type->id();
$field_name = $this->field->getName();
$this->field->setRequired(TRUE);
$this->field->save();
// Allow registration without administrative approval and log in user
// directly after registering.
\Drupal::configFactory()->getEditable('user.settings')->set('register', USER_REGISTER_VISITORS)->set('verify_mail', 0)->save();
user_role_grant_permissions(AccountInterface::AUTHENTICATED_ROLE, ['view own test profile']);
// Verify that the additional profile field is attached and required.
$name = $this->randomMachineName();
$pass_raw = $this->randomMachineName();
$edit = ['name' => $name, 'mail' => $this->randomMachineName() . '@example.com', 'pass[pass1]' => $pass_raw, 'pass[pass2]' => $pass_raw];
$this->drupalPostForm('user/register', $edit, t('Create new account'));
$this->assertRaw(new FormattableMarkup('@name field is required.', ['@name' => $this->field->getLabel()]));
// Verify that we can register.
$edit["entity_" . $id . "[{$field_name}][0][value]"] = $this->randomMachineName();
$this->drupalPostForm(NULL, $edit, t('Create new account'));
$this->assertText(new FormattableMarkup('Registration successful. You are now logged in.', []));
$new_user = user_load_by_name($name);
$this->assertTrue($new_user->isActive(), 'New account is active after registration.');
// Verify that a new profile was created for the new user ID.
$profile = \Drupal::entityTypeManager()->getStorage('profile')->loadByUser($new_user, $this->type->id());
$this->assertEqual($profile->get($field_name)->value, $edit["entity_" . $id . "[{$field_name}][0][value]"], 'Field value found in loaded profile.');
// Verify that the profile field value appears on the user account page.
$this->drupalGet('user');
$this->assertText($edit["entity_" . $id . "[{$field_name}][0][value]"], 'Field value found on user account page.');
}
示例3: testCommentFieldName
/**
* Test comment field name.
*/
public function testCommentFieldName()
{
/** @var \Drupal\Core\Render\RendererInterface $renderer */
$renderer = \Drupal::service('renderer');
$view = Views::getView('test_comment_field_name');
$this->executeView($view);
$expected_result = [['cid' => $this->comment->id(), 'field_name' => $this->comment->getFieldName()], ['cid' => $this->customComment->id(), 'field_name' => $this->customComment->getFieldName()]];
$column_map = ['cid' => 'cid', 'comment_field_data_field_name' => 'field_name'];
$this->assertIdenticalResultset($view, $expected_result, $column_map);
// Test that no data can be rendered.
$this->assertIdentical(FALSE, isset($view->field['field_name']));
// Grant permission to properly check view access on render.
user_role_grant_permissions(RoleInterface::ANONYMOUS_ID, ['access comments']);
$this->container->get('account_switcher')->switchTo(new AnonymousUserSession());
$view = Views::getView('test_comment_field_name');
$this->executeView($view);
// Test that data rendered.
$output = $renderer->executeInRenderContext(new RenderContext(), function () use($view) {
return $view->field['field_name']->advancedRender($view->result[0]);
});
$this->assertIdentical($this->comment->getFieldName(), $output);
$output = $renderer->executeInRenderContext(new RenderContext(), function () use($view) {
return $view->field['field_name']->advancedRender($view->result[1]);
});
$this->assertIdentical($this->customComment->getFieldName(), $output);
}
示例4: setUp
function setUp()
{
parent::setUp();
// Enable anonymous and authenticated user comments.
user_role_grant_permissions(DRUPAL_ANONYMOUS_RID, array('access comments', 'post comments', 'skip comment approval'));
user_role_grant_permissions(DRUPAL_AUTHENTICATED_RID, array('access comments', 'post comments', 'skip comment approval'));
}
示例5: testConfigChangePageCache
/**
* Tests that configuration changes also clear the page cache.
*/
public function testConfigChangePageCache()
{
$this->enableService('entity:entity_test', 'GET');
// Allow anonymous users to issue GET requests.
$permissions = $this->entityPermissions('entity_test', 'view');
$permissions[] = 'restful get entity:entity_test';
user_role_grant_permissions('anonymous', $permissions);
// Create an entity programmatically.
$entity = $this->entityCreate('entity_test');
$entity->set('field_test_text', 'custom cache tag value');
$entity->save();
// Read it over the REST API.
$this->httpRequest($entity->urlInfo()->setRouteParameter('_format', $this->defaultFormat), 'GET', NULL, $this->defaultMimeType);
$this->assertResponse(200, 'HTTP response code is correct.');
$this->assertHeader('x-drupal-cache', 'MISS');
$this->assertCacheTag('config:rest.settings');
$this->assertCacheTag('entity_test:1');
$this->assertCacheTag('entity_test_access:field_test_text');
// Read it again, should be page-cached now.
$this->httpRequest($entity->urlInfo()->setRouteParameter('_format', $this->defaultFormat), 'GET', NULL, $this->defaultMimeType);
$this->assertResponse(200, 'HTTP response code is correct.');
$this->assertHeader('x-drupal-cache', 'HIT');
$this->assertCacheTag('config:rest.settings');
$this->assertCacheTag('entity_test:1');
$this->assertCacheTag('entity_test_access:field_test_text');
// Trigger a config save which should clear the page cache, so we should get
// a cache miss now for the same request.
$this->config('rest.settings')->save();
$this->httpRequest($entity->urlInfo()->setRouteParameter('_format', $this->defaultFormat), 'GET', NULL, $this->defaultMimeType);
$this->assertResponse(200, 'HTTP response code is correct.');
$this->assertHeader('x-drupal-cache', 'MISS');
$this->assertCacheTag('config:rest.settings');
$this->assertCacheTag('entity_test:1');
$this->assertCacheTag('entity_test_access:field_test_text');
}
示例6: setupPermissionTestData
/**
* Set some test data for permission related tests.
*/
protected function setupPermissionTestData()
{
// Setup a role without any permission.
$this->roleStorage->create(array('id' => 'authenticated'))->save();
$this->roleStorage->create(array('id' => 'no_permission'))->save();
// Setup a role with just one permission.
$this->roleStorage->create(array('id' => 'one_permission'))->save();
user_role_grant_permissions('one_permission', array('administer permissions'));
// Setup a role with multiple permissions.
$this->roleStorage->create(array('id' => 'multiple_permissions'))->save();
user_role_grant_permissions('multiple_permissions', array('administer permissions', 'administer users', 'access user profiles'));
// Setup a user without an extra role.
$this->users[] = $account = $this->userStorage->create(['name' => $this->randomString()]);
$account->save();
// Setup a user with just the first role (so no permission beside the
// ones from the authenticated role).
$this->users[] = $account = $this->userStorage->create(array('name' => 'first_role'));
$account->addRole('no_permission');
$account->save();
// Setup a user with just the second role (so one additional permission).
$this->users[] = $account = $this->userStorage->create(array('name' => 'second_role'));
$account->addRole('one_permission');
$account->save();
// Setup a user with both the second and the third role.
$this->users[] = $account = $this->userStorage->create(array('name' => 'second_third_role'));
$account->addRole('one_permission');
$account->addRole('multiple_permissions');
$account->save();
}
示例7: setUp
protected function setUp()
{
parent::setUp();
// Enable user signatures.
\Drupal::config('user.settings')->set('signatures', 1)->save();
// Create Basic page node type.
$this->drupalCreateContentType(array('type' => 'page', 'name' => 'Basic page'));
// Add a comment field with commenting enabled by default.
$this->container->get('comment.manager')->addDefaultField('node', 'page');
// Prefetch and create text formats.
$this->filtered_html_format = entity_create('filter_format', array('format' => 'filtered_html_format', 'name' => 'Filtered HTML', 'weight' => -1, 'filters' => array('filter_html' => array('module' => 'filter', 'status' => TRUE, 'settings' => array('allowed_html' => '<a> <em> <strong>')))));
$this->filtered_html_format->save();
$this->full_html_format = entity_create('filter_format', array('format' => 'full_html', 'name' => 'Full HTML'));
$this->full_html_format->save();
user_role_grant_permissions(DRUPAL_AUTHENTICATED_RID, array($this->filtered_html_format->getPermissionName()));
// Create regular and administrative users.
$this->web_user = $this->drupalCreateUser(array('post comments'));
$admin_permissions = array('post comments', 'administer comments', 'administer user form display', 'administer account settings');
foreach (filter_formats() as $format) {
if ($permission = $format->getPermissionName()) {
$admin_permissions[] = $permission;
}
}
$this->admin_user = $this->drupalCreateUser($admin_permissions);
}
示例8: testInactiveDomain
public function testInactiveDomain()
{
// Create three new domains programmatically.
$this->domainCreateTestDomains(3);
$domains = \Drupal::service('domain.loader')->loadMultiple();
// Grab the last domain for testing.
$domain = end($domains);
$this->drupalGet($domain->getPath());
$this->assertTrue($domain->status(), 'Tested domain is set to active.');
$this->assertTrue($domain->getPath() == $this->getUrl(), 'Loaded the active domain.');
// Disable the domain and test for redirect.
$domain->disable();
$default = \Drupal::service('domain.loader')->loadDefaultDomain();
// Must flush cache.
drupal_flush_all_caches();
$this->drupalGet($domain->getPath());
$this->assertFalse($domain->status(), 'Tested domain is set to inactive.');
$this->assertTrue($default->getPath() == $this->getUrl(), 'Redirected an inactive domain to the default domain.');
// Try to access with the proper permission.
user_role_grant_permissions(DRUPAL_ANONYMOUS_RID, array('access inactive domains'));
$this->assertFalse($domain->status(), 'Tested domain is set to inactive.');
// Must flush cache.
drupal_flush_all_caches();
$this->drupalGet($domain->getPath());
$this->assertTrue($domain->getPath() == $this->getUrl(), 'Loaded the inactive domain with permission.');
}
示例9: testContactStorage
/**
* Tests configuration options and the site-wide contact form.
*/
public function testContactStorage()
{
// Create and login administrative user.
$admin_user = $this->drupalCreateUser(array('access site-wide contact form', 'administer contact forms', 'administer users', 'administer account settings', 'administer contact_message fields'));
$this->drupalLogin($admin_user);
// Create first valid contact form.
$mail = 'simpletest@example.com';
$this->addContactForm($id = Unicode::strtolower($this->randomMachineName(16)), $label = $this->randomMachineName(16), implode(',', array($mail)), '', TRUE, ['send_a_pony' => 1]);
$this->assertRaw(t('Contact form %label has been added.', array('%label' => $label)));
// Ensure that anonymous can submit site-wide contact form.
user_role_grant_permissions(RoleInterface::ANONYMOUS_ID, array('access site-wide contact form'));
$this->drupalLogout();
$this->drupalGet('contact');
$this->assertText(t('Your email address'));
$this->assertNoText(t('Form'));
$this->submitContact($name = $this->randomMachineName(16), $mail, $subject = $this->randomMachineName(16), $id, $message = $this->randomMachineName(64));
$this->assertText(t('Your message has been sent.'));
$messages = Message::loadMultiple();
/** @var \Drupal\contact\Entity\Message $message */
$message = reset($messages);
$this->assertEqual($message->getContactForm()->id(), $id);
$this->assertTrue($message->getContactForm()->getThirdPartySetting('contact_storage_test', 'send_a_pony', FALSE));
$this->assertEqual($message->getSenderName(), $name);
$this->assertEqual($message->getSubject(), $subject);
$this->assertEqual($message->getSenderMail(), $mail);
$config = $this->config("contact.form.{$id}");
$this->assertEqual($config->get('id'), $id);
}
示例10: setUp
/**
* {@inheritdoc}
*/
protected function setUp()
{
parent::setUp();
$this->drupalPlaceBlock('local_tasks_block');
$this->drupalPlaceBlock('local_actions_block');
$this->drupalPlaceBlock('page_title_block');
$this->type = $this->createProfileType('test', 'Test profile', TRUE);
$id = $this->type->id();
$field_storage = FieldStorageConfig::create(['field_name' => 'profile_fullname', 'entity_type' => 'profile', 'type' => 'text']);
$field_storage->save();
$this->field = FieldConfig::create(['field_storage' => $field_storage, 'bundle' => $this->type->id(), 'label' => 'Full name']);
$this->field->save();
// Configure the default display.
$this->display = EntityViewDisplay::load("profile.{$this->type->id()}.default");
if (!$this->display) {
$this->display = EntityViewDisplay::create(['targetEntityType' => 'profile', 'bundle' => $this->type->id(), 'mode' => 'default', 'status' => TRUE]);
$this->display->save();
}
$this->display->setComponent($this->field->getName(), ['type' => 'string'])->save();
// Configure rhe default form.
$this->form = EntityFormDisplay::load("profile.{$this->type->id()}.default");
if (!$this->form) {
$this->form = EntityFormDisplay::create(['targetEntityType' => 'profile', 'bundle' => $this->type->id(), 'mode' => 'default', 'status' => TRUE]);
$this->form->save();
}
$this->form->setComponent($this->field->getName(), ['type' => 'string_textfield'])->save();
$this->checkPermissions(['administer profile types', "view own {$id} profile", "view any {$id} profile", "add own {$id} profile", "add any {$id} profile", "edit own {$id} profile", "edit any {$id} profile", "delete own {$id} profile", "delete any {$id} profile"]);
user_role_grant_permissions(AccountInterface::AUTHENTICATED_ROLE, ['access user profiles']);
$this->adminUser = $this->drupalCreateUser(['administer profile types', "view any {$id} profile", "add any {$id} profile", "edit any {$id} profile", "delete any {$id} profile"]);
}
示例11: testContactStorage
/**
* Tests configuration options and the site-wide contact form.
*/
public function testContactStorage()
{
// Create and login administrative user.
$admin_user = $this->drupalCreateUser(array('access site-wide contact form', 'administer contact forms', 'administer users', 'administer account settings', 'administer contact_message fields'));
$this->drupalLogin($admin_user);
// Create first valid category.
$mail = 'simpletest@example.com';
$this->addCategory($id = drupal_strtolower($this->randomName(16)), $label = $this->randomName(16), implode(',', array($mail)), '', TRUE);
$this->assertRaw(t('Category %label has been added.', array('%label' => $label)));
// Ensure that anonymous can submit site-wide contact form.
user_role_grant_permissions(DRUPAL_ANONYMOUS_RID, array('access site-wide contact form'));
$this->drupalLogout();
$this->drupalGet('contact');
$this->assertText(t('Your email address'));
$this->assertNoText(t('Category'));
$this->submitContact($name = $this->randomName(16), $mail, $subject = $this->randomName(16), $id, $message = $this->randomName(64));
$this->assertText(t('Your message has been sent.'));
$messages = Message::loadMultiple();
/** @var \Drupal\contact\Entity\Message $message */
$message = reset($messages);
$this->assertEqual($message->getCategory()->id(), $id);
$this->assertEqual($message->getSenderName(), $name);
$this->assertEqual($message->getSubject(), $subject);
$this->assertEqual($message->getSenderMail(), $mail);
}
示例12: setUp
function setUp()
{
parent::setUp();
// Create an administrative user.
$this->admin_user = $this->drupalCreateUser(array('administer site configuration'));
user_role_grant_permissions(DRUPAL_ANONYMOUS_RID, array('access user profiles'));
user_role_grant_permissions(DRUPAL_AUTHENTICATED_RID, array('access user profiles'));
}
示例13: setUp
protected function setUp()
{
parent::setUp();
// Create an administrative user.
$this->adminUser = $this->drupalCreateUser(array('administer site configuration', 'link to any page'));
user_role_grant_permissions(RoleInterface::ANONYMOUS_ID, array('access user profiles'));
user_role_grant_permissions(RoleInterface::AUTHENTICATED_ID, array('access user profiles'));
}
示例14: setUp
protected function setUp()
{
parent::setUp();
$filtered_html_format = entity_create('filter_format', array('format' => 'filtered_html', 'name' => 'Filtered HTML'));
$filtered_html_format->save();
$filtered_html_permission = $filtered_html_format->getPermissionName();
user_role_grant_permissions(RoleInterface::ANONYMOUS_ID, array($filtered_html_permission));
}
示例15: setUp
protected function setUp()
{
parent::setUp();
$this->drupalCreateContentType(array('type' => 'page', 'name' => 'Basic page'));
$permissions = array('access comments', 'create page content', 'post comments', 'skip comment approval');
$this->user = $this->drupalCreateUser($permissions);
$this->otherUser = $this->drupalCreateUser($permissions);
$this->addDefaultCommentField('node', 'page');
user_role_grant_permissions(AccountInterface::ANONYMOUS_ROLE, array('access content', 'access user profiles'));
}