当前位置: 首页>>代码示例>>PHP>>正文


PHP user_load_by_name函数代码示例

本文整理汇总了PHP中user_load_by_name函数的典型用法代码示例。如果您正苦于以下问题:PHP user_load_by_name函数的具体用法?PHP user_load_by_name怎么用?PHP user_load_by_name使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了user_load_by_name函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: addGroupMemberships

 /**
  * Creates multiple group memberships.
  *
  * Provide group membership data in the following format:
  *
  * | user  | group     | role on group        | membership status |
  * | Foo   | The Group | administrator member | Active            |
  *
  * @Given group memberships:
  */
 public function addGroupMemberships(TableNode $groupMembershipsTable)
 {
     foreach ($groupMembershipsTable->getHash() as $groupMembershipHash) {
         if (isset($groupMembershipHash['group']) && isset($groupMembershipHash['user'])) {
             $group = $this->getGroupByName($groupMembershipHash['group']);
             $user = user_load_by_name($groupMembershipHash['user']);
             // Add user to group with the proper group permissions and status
             if ($group && $user) {
                 // Add the user to the group
                 og_group("node", $group->nid->value(), array("entity type" => "user", "entity" => $user, "membership type" => OG_MEMBERSHIP_TYPE_DEFAULT, "state" => $this->getMembershipStatusByName($groupMembershipHash['membership status'])));
                 // Grant user roles
                 $group_role = $this->getGroupRoleByName($groupMembershipHash['role on group']);
                 og_role_grant("node", $group->nid->value(), $user->uid, $group_role);
             } else {
                 if (!$group) {
                     throw new \Exception(sprintf("No group was found with name %s.", $groupMembershipHash['group']));
                 }
                 if (!$user) {
                     throw new \Exception(sprintf("No user was found with name %s.", $groupMembershipHash['user']));
                 }
             }
         } else {
             throw new \Exception(sprintf("The group and user information is required."));
         }
     }
 }
开发者ID:nucivic,项目名称:dkanextension,代码行数:36,代码来源:GroupContext.php

示例2: nodeCreate

 /**
  * {@inheritdoc}
  */
 public function nodeCreate($node)
 {
     // Throw an exception if the node type is missing or does not exist.
     if (!isset($node->type) || !$node->type) {
         throw new \Exception("Cannot create content because it is missing the required property 'type'.");
     }
     $bundles = \Drupal::entityManager()->getBundleInfo('node');
     if (!in_array($node->type, array_keys($bundles))) {
         throw new \Exception("Cannot create content because provided content type '{$node->type}' does not exist.");
     }
     // Default status to 1 if not set.
     if (!isset($node->status)) {
         $node->status = 1;
     }
     // If 'author' is set, remap it to 'uid'.
     if (isset($node->author)) {
         $user = user_load_by_name($node->author);
         if ($user) {
             $node->uid = $user->id();
         }
     }
     $this->expandEntityFields('node', $node);
     $entity = entity_create('node', (array) $node);
     $entity->save();
     $node->nid = $entity->id();
     return $node;
 }
开发者ID:shrimala,项目名称:DrupalDriver,代码行数:30,代码来源:Drupal8.php

示例3: transitionModerationState

 /**
  * @Given I update the moderation state of :named_entity to :state
  * @Given I update the moderation state of :named_entity to :state on date :date
  * @Given :workflow_user updates the moderation state of :named_entity to :state
  * @Given :workflow_user updates the moderation state of :named_entity to :state on date :date
  *
  * Transition a Moderated Node from one state to another.
  *
  * @param String|null $user The string of the username.
  * @param String $named_entity A named entity stored in the entity store.
  * @param String $state The state that you want to transition to.
  * @param String|null $date A valid php datetime string. Supports relative dates.
  * @throws \Exception
  */
 public function transitionModerationState($workflow_user = null, $named_entity, $state, $date = null)
 {
     global $user;
     // Save the original user to set it back later
     $global_user = $user;
     $node = $this->getModerationNode($named_entity);
     $possible_states = workbench_moderation_state_labels();
     $state_key = array_search($state, $possible_states);
     if (!$state_key) {
         $possible_states = implode(", ", $possible_states);
         throw new \Exception("State '{$state}' is not available. All possible states are [{$possible_states}].");
     }
     $current_user = $workflow_user ? user_load_by_name($workflow_user) : $this->getCurrentUser();
     if (!$current_user) {
         throw new \Exception("No user is logged in.");
     }
     $my_revision = $node->workbench_moderation['my_revision'];
     $state_machine_name = array_search($state, $possible_states);
     // If node is moderated to the same state but with different time, then the moderation isn't performed but the time is updated.
     if ($my_revision->state != $state_machine_name) {
         $next_states = workbench_moderation_states_next($my_revision->state, $current_user, $node);
         if (empty($next_states)) {
             $next_states = array();
         }
         if (!isset($next_states[$state_key])) {
             $next_states = implode(", ", $next_states);
             throw new \Exception("State '{$possible_states[$state_key]}' is not available to transition to. Transitions available to user '{$current_user->name}' are [{$next_states}]");
         }
         // Change global user to the current user in order to allow
         // workflow moderation to get the right user.
         $user = $current_user;
         // This function actually updates the transition.
         workbench_moderation_moderate($node, $state_key);
         // the workbench_moderation_moderate defer some status updates on the
         // node (currently the "Publish" status) to the process shutdown. Which
         // does not work well on Behat since scenarios are run on a single drupal
         // bootstrap.
         // To work around this setup. After calling the
         // `workbench_moderation_moderate` callback we check if a call to the
         // `workbench_moderation_store` function is part of the shutdown
         // execution and run it.
         $callbacks =& drupal_register_shutdown_function();
         while (list($key, $callback) = each($callbacks)) {
             if ($callback['callback'] == 'workbench_moderation_store') {
                 call_user_func_array($callback['callback'], $callback['arguments']);
                 unset($callbacks[$key]);
             }
         }
         // Back global user to the original user. Probably an anonymous.
         $user = $global_user;
     }
     // If a specific date is requested, then updated it after the fact.
     if (isset($date)) {
         $timestamp = strtotime($date, REQUEST_TIME);
         if (!$timestamp) {
             throw new \Exception("Error creating datetime from string '{$date}'");
         }
         db_update('workbench_moderation_node_history')->fields(array('stamp' => $timestamp))->condition('nid', $node->nid, '=')->condition('vid', $node->vid, '=')->execute();
     }
 }
开发者ID:nucivic,项目名称:dkanextension,代码行数:74,代码来源:WorkflowContext.php

示例4: updateProfile

 /**
  * Update profile
  * FIXME
  *
  * @return void
  */
 protected function updateProfile()
 {
     if ($this->isCreateProfile()) {
         $error = user_validate_name(\XLite\Core\Request::getInstance()->username);
         if ($error) {
             // Username validation error
             $this->valid = false;
             \XLite\Core\Event::invalidElement('username', $error);
         } elseif (user_load_by_name(\XLite\Core\Request::getInstance()->username)) {
             // Username is already exists
             $this->valid = false;
             $label = static::t('This user name is used for an existing account. Enter another user name or sign in', array('URL' => $this->getLoginURL()));
             \XLite\Core\Event::invalidElement('username', $label);
         } elseif (\XLite\Core\Request::getInstance()->email && user_load_multiple(array(), array('mail' => \XLite\Core\Request::getInstance()->email))) {
             // E-mail is already exists in Drupal DB
             $this->valid = false;
             $label = static::t('This email address is used for an existing account. Enter another user name or sign in', array('URL' => $this->getLoginURL()));
             \XLite\Core\Event::invalidElement('email', $label);
         }
     }
     parent::updateProfile();
     if ($this->isCreateProfile() && $this->valid) {
         // Save username is session (temporary, wait place order procedure)
         \XLite\Core\Session::getInstance()->order_username = \XLite\Core\Request::getInstance()->create_profile ? \XLite\Core\Request::getInstance()->username : false;
     }
 }
开发者ID:kingsj,项目名称:core,代码行数:32,代码来源:Checkout.php

示例5: testModerateToBeApproved

 /**
  * Test node creation by editor.
  *
  * 1. Editor creates Draft node
  * 2. Editor set status from Draft to Final Draft
  * 3. The node appears in the users's overview screen.
  */
 public function testModerateToBeApproved()
 {
     $this->loginAs('editor1');
     $node = $this->drupalCreateNode(array('language' => 'en', 'title' => $this->nodeTitle1, 'type' => 'news', 'workbench_access' => 1007));
     workbench_moderation_moderate($node, 'final_draft');
     $this->loginAs('review_manager1');
     // Set node status To Be Reviewed.
     $options = array('title_field[en][0][value]' => $this->nodeTitle1, 'workbench_moderation_state_new' => 'needs_review');
     $this->drupalPost("node/{$node->nid}/edit", $options, t('Save'));
     entity_get_controller('node')->resetCache(array($node->nid));
     $node = node_load($node->nid);
     $this->assertEquals('needs_review', $node->workbench_moderation['current']->state);
     // Set the reviewer to project_manager1
     $pm1 = user_load_by_name('project_manager1');
     $options = array('project_manager' => $pm1->uid);
     $this->drupalPost("node/{$node->nid}/review", $options, t('Change'));
     $this->drupalGet("node/{$node->nid}/review");
     $this->assertText('project_manager1');
     // Define the list of approvers.
     // Cannot use drupalPost here.
     $ap1 = user_load_by_name('approver1');
     $ap2 = user_load_by_name('approver2 ');
     $form_state = array('node' => $node, 'values' => array('rows' => array($ap1->uid => array('weight' => -10), $ap2->uid => array('weight' => -11))));
     module_load_include('inc', 'osha_workflow', 'osha_workflow.admin');
     drupal_form_submit('osha_workflow_node_approval_form', $form_state, $node);
     $this->drupalGet("node/{$node->nid}/approve");
     $this->assertText($ap1->name);
     $this->assertText($ap2->name);
     $this->loginAs('project_manager1');
     $options = array('workbench_moderation_state_new' => 'to_be_approved');
     $this->drupalPost("node/{$node->nid}/edit", $options, t('Save'));
     entity_get_controller('node')->resetCache(array($node->nid));
     $node = node_load($node->nid);
     $this->assertEquals('to_be_approved', $node->workbench_moderation['current']->state);
 }
开发者ID:enriquesanchezhernandez,项目名称:campaigns,代码行数:42,代码来源:WorkflowPublicationProjectManagerTest.php

示例6: 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.');
 }
开发者ID:darrylri,项目名称:protovbmwmo,代码行数:32,代码来源:ProfileAttachTest.php

示例7: loginAs

 /**
  * Login as custom account.
  *
  * @param string $username
  *   Username to login with
  * @param string $password
  *   Password. By default all dev instance are set to 'password'.
  */
 public function loginAs($username, $password = 'password')
 {
     global $user;
     $user = user_load_by_name($username);
     $this->assertNotNull($user, "Could not login {$username}");
     $user->pass_raw = $password;
     $this->drupalLogin($user);
 }
开发者ID:enriquesanchezhernandez,项目名称:campaigns,代码行数:16,代码来源:osha-bootstrap.php

示例8: validateConfigurationForm

 public function validateConfigurationForm(array &$form, array &$form_state)
 {
     $values =& $form_state['values']['processor']['configuration'];
     if ($author = user_load_by_name($values['author'])) {
         $values['author'] = $author->id();
     } else {
         $values['author'] = 0;
     }
 }
开发者ID:alnutile,项目名称:drunatra,代码行数:9,代码来源:NodeHandler.php

示例9: restLogin

 /**
  * Login via rest to get the user's access token.
  *
  * @param $user
  *   The user name.
  *
  * @return string
  *   The user access token.
  */
 private function restLogin($user)
 {
     if (isset($this->accessToken[$user])) {
         return $this->accessToken[$user]['access_token'];
     }
     $handler = new RestfulAccessTokenAuthentication(['entity_type' => 'restful_token_auth', 'bundle' => 'access_token']);
     $handler->setAccount(user_load_by_name($user));
     $data = $handler->getOrCreateToken();
     $this->accessToken[$user] = $data;
     return $data['access_token'];
 }
开发者ID:aleph-n,项目名称:opencholar,代码行数:20,代码来源:RestfulTrait.php

示例10: test_osha_workflow_get_set_project_manager

 public function test_osha_workflow_get_set_project_manager()
 {
     $this->assertNull(osha_workflow_get_project_manager(-1));
     $node = $this->createNodeNews();
     $pm3 = user_load_by_name('project_manager3');
     osha_workflow_set_project_manager($node->nid, $pm3->uid);
     $pm = osha_workflow_get_project_manager($node->nid);
     $this->assertEquals($pm3->uid, $pm->uid);
     $this->assertFalse(osha_workflow_is_assigned_project_manager($node->nid));
     $this->loginAs('project_manager3');
     $this->assertTrue(osha_workflow_is_assigned_project_manager($node->nid));
     node_delete($node->nid);
 }
开发者ID:enriquesanchezhernandez,项目名称:campaigns,代码行数:13,代码来源:WorkflowPublicationTest.php

示例11: testUserAdd

 /**
  * Create a user through the administration interface and ensure that it
  * displays in the user list.
  */
 public function testUserAdd()
 {
     $user = $this->drupalCreateUser(array('administer users'));
     $this->drupalLogin($user);
     $this->assertEqual($user->getCreatedTime(), REQUEST_TIME, 'Creating a user sets default "created" timestamp.');
     $this->assertEqual($user->getChangedTime(), REQUEST_TIME, 'Creating a user sets default "changed" timestamp.');
     // Create a field.
     $field_name = 'test_field';
     FieldStorageConfig::create(array('field_name' => $field_name, 'entity_type' => 'user', 'module' => 'image', 'type' => 'image', 'cardinality' => 1, 'locked' => FALSE, 'indexes' => array('target_id' => array('target_id')), 'settings' => array('uri_scheme' => 'public')))->save();
     FieldConfig::create(['field_name' => $field_name, 'entity_type' => 'user', 'label' => 'Picture', 'bundle' => 'user', 'description' => t('Your virtual face or picture.'), 'required' => FALSE, 'settings' => array('file_extensions' => 'png gif jpg jpeg', 'file_directory' => 'pictures', 'max_filesize' => '30 KB', 'alt_field' => 0, 'title_field' => 0, 'max_resolution' => '85x85', 'min_resolution' => '')])->save();
     // Test user creation page for valid fields.
     $this->drupalGet('admin/people/create');
     $this->assertFieldbyId('edit-status-0', 0, 'The user status option Blocked exists.', 'User login');
     $this->assertFieldbyId('edit-status-1', 1, 'The user status option Active exists.', 'User login');
     $this->assertFieldByXPath('//input[@type="radio" and @id="edit-status-1" and @checked="checked"]', NULL, 'Default setting for user status is active.');
     // Test that browser autocomplete behavior does not occur.
     $this->assertNoRaw('data-user-info-from-browser', 'Ensure form attribute, data-user-info-from-browser, does not exist.');
     // Test that the password strength indicator displays.
     $config = $this->config('user.settings');
     $config->set('password_strength', TRUE)->save();
     $this->drupalGet('admin/people/create');
     $this->assertRaw(t('Password strength:'), 'The password strength indicator is displayed.');
     $config->set('password_strength', FALSE)->save();
     $this->drupalGet('admin/people/create');
     $this->assertNoRaw(t('Password strength:'), 'The password strength indicator is not displayed.');
     // We create two users, notifying one and not notifying the other, to
     // ensure that the tests work in both cases.
     foreach (array(FALSE, TRUE) as $notify) {
         $name = $this->randomMachineName();
         $edit = array('name' => $name, 'mail' => $this->randomMachineName() . '@example.com', 'pass[pass1]' => $pass = $this->randomString(), 'pass[pass2]' => $pass, 'notify' => $notify);
         $this->drupalPostForm('admin/people/create', $edit, t('Create new account'));
         if ($notify) {
             $this->assertText(t('A welcome message with further instructions has been emailed to the new user @name.', array('@name' => $edit['name'])), 'User created');
             $this->assertEqual(count($this->drupalGetMails()), 1, 'Notification email sent');
         } else {
             $this->assertText(t('Created a new user account for @name. No email has been sent.', array('@name' => $edit['name'])), 'User created');
             $this->assertEqual(count($this->drupalGetMails()), 0, 'Notification email not sent');
         }
         $this->drupalGet('admin/people');
         $this->assertText($edit['name'], 'User found in list of users');
         $user = user_load_by_name($name);
         $this->assertEqual($user->isActive(), 'User is not blocked');
     }
     // Test that the password '0' is considered a password.
     // @see https://www.drupal.org/node/2563751.
     $name = $this->randomMachineName();
     $edit = array('name' => $name, 'mail' => $this->randomMachineName() . '@example.com', 'pass[pass1]' => 0, 'pass[pass2]' => 0, 'notify' => FALSE);
     $this->drupalPostForm('admin/people/create', $edit, t('Create new account'));
     $this->assertText("Created a new user account for {$name}. No email has been sent");
     $this->assertNoText('Password field is required');
 }
开发者ID:sojo,项目名称:d8_friendsofsilence,代码行数:55,代码来源:UserCreateTest.php

示例12: cosign_user_status

 /**
  * Check whether user is loggedin to cosign, is a drupal user, and is logged into drupal
  *
  * @return
  *   User object
  */
 public static function cosign_user_status($cosign_username)
 {
     $user = \Drupal::currentUser();
     $uname = $user->getAccountName();
     $drupal_user = user_load_by_name($cosign_username);
     if (!empty($uname)) {
         //youre already logged in
         //make sure you are the cosign user. if not log out. This is unlikely
         if ($cosign_username != $uname) {
             user_logout();
             return null;
         }
     }
     if (!empty($cosign_username)) {
         $is_friend_account = CosignSharedFunctions::cosign_is_friend_account($cosign_username);
         // If friend accounts are not allowed, log them out
         if (\Drupal::config('cosign.settings')->get('cosign_allow_friend_accounts') == 0 && $is_friend_account) {
             CosignSharedFunctions::cosign_friend_not_allowed();
             if (\Drupal::config('cosign.settings')->get('cosign_allow_anons_on_https') == 1) {
                 return user_load(0);
             } else {
                 return null;
             }
         }
     }
     if (!empty($cosign_username) && !empty($drupal_user) && empty($uname)) {
         //login the cosign user
         CosignSharedFunctions::cosign_login_user($drupal_user);
     } elseif (!empty($cosign_username) && empty($drupal_user)) {
         //cosign user doesn't have a drupal account
         if (\Drupal::config('cosign.settings')->get('cosign_autocreate') == 1) {
             $new_user = CosignSharedFunctions::cosign_create_new_user($cosign_username);
             user_load($new_user->id(), TRUE);
         } else {
             //drupal_set_message(t('This site does not auto create users from cosign. Please contact the <a href="mailto:'. \Drupal::config("system.site")->get("mail").'">site administrator</a> to have an account created.'), 'warning');
             user_load(0);
         }
     } elseif (empty($cosign_username) && \Drupal::config('cosign.settings')->get('cosign_allow_anons_on_https') == 0) {
         //no cosign account found
         user_logout();
         return null;
     }
     $user = \Drupal::currentUser();
     if (!$user) {
         $user = user_load(0);
     }
     if ($user->id() == 0 && \Drupal::config('cosign.settings')->get('cosign_allow_anons_on_https') == 1) {
         //drupal_set_message(t('You do not have a valid cosign username. Browsing as anonymous user over https.'));
     }
     return $user;
 }
开发者ID:bertrama,项目名称:cosign-drupal8,代码行数:57,代码来源:CosignSharedFunctions.php

示例13: testLocalUserCreation

 /**
  * Functional test for language handling during user creation.
  */
 function testLocalUserCreation()
 {
     // User to add and remove language and create new users.
     $admin_user = $this->drupalCreateUser(array('administer languages', 'access administration pages', 'administer users'));
     $this->drupalLogin($admin_user);
     // Add predefined language.
     $langcode = 'fr';
     $language = new Language(array('id' => $langcode));
     language_save($language);
     // Set language negotiation.
     $edit = array('language_interface[enabled][language-url]' => TRUE);
     $this->drupalPostForm('admin/config/regional/language/detection', $edit, t('Save settings'));
     $this->assertText(t('Language negotiation configuration saved.'), 'Set language negotiation.');
     // Check if the language selector is available on admin/people/create and
     // set to the currently active language.
     $this->drupalGet($langcode . '/admin/people/create');
     $this->assertOptionSelected("edit-preferred-langcode", $langcode, 'Global language set in the language selector.');
     // Create a user with the admin/people/create form and check if the correct
     // language is set.
     $username = $this->randomName(10);
     $edit = array('name' => $username, 'mail' => $this->randomName(4) . '@example.com', 'pass[pass1]' => $username, 'pass[pass2]' => $username);
     $this->drupalPostForm($langcode . '/admin/people/create', $edit, t('Create new account'));
     $user = user_load_by_name($username);
     $this->assertEqual($user->getPreferredLangcode(), $langcode, 'New user has correct preferred language set.');
     $this->assertEqual($user->language()->id, $langcode, 'New user has correct profile language set.');
     // Register a new user and check if the language selector is hidden.
     $this->drupalLogout();
     $this->drupalGet($langcode . '/user/register');
     $this->assertNoFieldByName('language[fr]', 'Language selector is not accessible.');
     $username = $this->randomName(10);
     $edit = array('name' => $username, 'mail' => $this->randomName(4) . '@example.com');
     $this->drupalPostForm($langcode . '/user/register', $edit, t('Create new account'));
     $user = user_load_by_name($username);
     $this->assertEqual($user->getPreferredLangcode(), $langcode, 'New user has correct preferred language set.');
     $this->assertEqual($user->language()->id, $langcode, 'New user has correct profile language set.');
     // Test if the admin can use the language selector and if the
     // correct language is was saved.
     $user_edit = $langcode . '/user/' . $user->id() . '/edit';
     $this->drupalLogin($admin_user);
     $this->drupalGet($user_edit);
     $this->assertOptionSelected("edit-preferred-langcode", $langcode, 'Language selector is accessible and correct language is selected.');
     // Set pass_raw so we can login the new user.
     $user->pass_raw = $this->randomName(10);
     $edit = array('pass[pass1]' => $user->pass_raw, 'pass[pass2]' => $user->pass_raw);
     $this->drupalPostForm($user_edit, $edit, t('Save'));
     $this->drupalLogin($user);
     $this->drupalGet($user_edit);
     $this->assertOptionSelected("edit-preferred-langcode", $langcode, 'Language selector is accessible and correct language is selected.');
 }
开发者ID:alnutile,项目名称:drunatra,代码行数:52,代码来源:UserLanguageCreationTest.php

示例14: testCasAutoAssignedRoles

 /**
  * Tests Standard installation profile.
  */
 public function testCasAutoAssignedRoles()
 {
     $role_id = $this->drupalCreateRole([]);
     $role_id_2 = $this->drupalCreateRole([]);
     $edit = ['user_accounts[auto_register]' => TRUE, 'user_accounts[auto_assigned_roles_enable]' => TRUE, 'user_accounts[auto_assigned_roles][]' => [$role_id, $role_id_2]];
     $this->drupalPostForm('/admin/config/people/cas', $edit, 'Save configuration');
     $this->assertEquals([$role_id, $role_id_2], $this->config('cas.settings')->get('user_accounts.auto_assigned_roles'));
     $cas_property_bag = new CasPropertyBag('test_cas_user_name');
     \Drupal::service('cas.login')->loginToDrupal($cas_property_bag, 'fake_ticket_string');
     $user = user_load_by_name('test_cas_user_name');
     $this->assertTrue($user->hasRole($role_id), 'The user has the auto assigned role: ' . $role_id);
     $this->assertTrue($user->hasRole($role_id_2), 'The user has the auto assigned role: ' . $role_id_2);
     Role::load($role_id_2)->delete();
     $this->assertEquals([$role_id], $this->config('cas.settings')->get('user_accounts.auto_assigned_roles'));
 }
开发者ID:pulibrary,项目名称:recap,代码行数:18,代码来源:CasAdminSettingsTest.php

示例15: processInbound

 /**
  * {@inheritdoc}
  */
 public function processInbound($path, Request $request)
 {
     if (preg_match('!^/user/([^/]+)(/.*)?!', $path, $matches)) {
         if ($account = user_load_by_name($matches[1])) {
             $matches += array(2 => '');
             $path = '/user/' . $account->id() . $matches[2];
         }
     }
     // Rewrite community/ to forum/.
     $path = preg_replace('@^/community(.*)@', '/forum$1', $path);
     if ($path == '/url-alter-test/bar') {
         $path = '/url-alter-test/foo';
     }
     return $path;
 }
开发者ID:318io,项目名称:318-io,代码行数:18,代码来源:PathProcessor.php


注:本文中的user_load_by_name函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。