• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

PHP Entity\User类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

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



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

示例1: content

 public function content()
 {
     $user = \Drupal\user\Entity\User::load(\Drupal::currentUser()->id());
     $userId = $user->get('uid')->value;
     $data = array(array('job_title' => '', 'job_path' => '', 'company_name' => '', 'application_date' => ''));
     $appliedJobs = db_select('user_job_application', 'uja')->condition('uja.user_id', $userId, '=')->fields('uja', array('job_id', 'date'))->orderBy('uja.date', 'DESC')->execute()->fetchAll();
     if ($appliedJobs) {
         $x = 0;
         foreach ($appliedJobs as $appliedJob) {
             $jobNode = \Drupal\node\Entity\Node::load($appliedJob->job_id);
             $jobTitle = $jobNode->getTitle();
             $jobPathAlias = \Drupal::service('path.alias_manager')->getAliasByPath('/node/' . $appliedJob->job_id);
             $companyNodeEntity = $jobNode->get('field_company');
             $companyNode = \Drupal\node\Entity\Node::load($companyNodeEntity->entity->id());
             $companyName = $companyNode->getTitle();
             $data[$x]['job_title'] = $jobTitle;
             $data[$x]['job_path'] = $jobPathAlias;
             $data[$x]['company_name'] = $companyName;
             $data[$x]['application_date'] = $appliedJob->date;
             $x++;
         }
     }
     $markUp = $this->createMarkUp($data);
     return array('#type' => 'markup', '#markup' => $markUp);
 }
开发者ID:augustpascual-mse,项目名称:job-searching-network,代码行数:25,代码来源:JobHistoryController.php


示例2: setUp

 /**
  * {@inheritdoc}
  */
 protected function setUp()
 {
     parent::setUp();
     $this->installSchema('system', 'sequences');
     $this->installEntitySchema('user');
     $this->manager = $this->container->get('plugin.manager.condition');
     // Set up the authenticated and anonymous roles.
     Role::create(array('id' => DRUPAL_ANONYMOUS_RID, 'label' => 'Anonymous user'))->save();
     Role::create(array('id' => DRUPAL_AUTHENTICATED_RID, 'label' => 'Authenticated user'))->save();
     // Create new role.
     $rid = strtolower($this->randomMachineName(8));
     $label = $this->randomString(8);
     $role = Role::create(array('id' => $rid, 'label' => $label));
     $role->save();
     $this->role = $role;
     // Setup an anonymous user for our tests.
     $this->anonymous = User::create(array('uid' => 0));
     $this->anonymous->save();
     // Loading the anonymous user adds the correct role.
     $this->anonymous = User::load($this->anonymous->id());
     // Setup an authenticated user for our tests.
     $this->authenticated = User::create(array('name' => $this->randomMachineName()));
     $this->authenticated->save();
     // Add the custom role.
     $this->authenticated->addRole($this->role->id());
 }
开发者ID:davidsoloman,项目名称:drupalconsole.com,代码行数:29,代码来源:UserRoleConditionTest.php


示例3: createUserProfile

 /**
  * Helper function, which creates node of type person
  *
  * @param \Drupal\user\Entity\User $user
  * @param bool $isIndividualSponsor
  */
 public function createUserProfile(User $user, $isIndividualSponsor = FALSE)
 {
     $values = ['type' => 'person', 'title' => $user->getUsername(), 'uid' => 1, 'field_referenced_user' => ['target_id' => $user->id()]];
     if ($isIndividualSponsor) {
         $values['field_person_type'] = ['target_id' => 8];
     }
     $node = entity_create('node', $values);
     $node->save();
 }
开发者ID:slovak-drupal-association,项目名称:dccs,代码行数:15,代码来源:EventbriteSync.php


示例4: setUpFixtures

 /**
  * {@inheritdoc}
  */
 protected function setUpFixtures()
 {
     $this->installEntitySchema('user');
     $this->installConfig(array('user'));
     parent::setUpFixtures();
     // Create a record for uid 1.
     $this->rootUser = User::create(['name' => $this->randomMachineName()]);
     $this->rootUser->save();
     Views::viewsData()->clear();
 }
开发者ID:eigentor,项目名称:tommiblog,代码行数:13,代码来源:RelationshipJoinTestBase.php


示例5: testBasicAuth

 /**
  * Tests that CSRF check is not triggered for Basic Auth requests.
  */
 public function testBasicAuth()
 {
     $curl_options = $this->getCurlOptions();
     $curl_options[CURLOPT_HTTPAUTH] = CURLAUTH_BASIC;
     $curl_options[CURLOPT_USERPWD] = $this->account->getUsername() . ':' . $this->account->pass_raw;
     $this->curlExec($curl_options);
     $this->assertResponse(201);
     // Ensure that the entity was created.
     $loaded_entity = $this->loadEntityFromLocationHeader($this->drupalGetHeader('location'));
     $this->assertTrue($loaded_entity, 'An entity was created in the database');
 }
开发者ID:eigentor,项目名称:tommiblog,代码行数:14,代码来源:CsrfTest.php


示例6: tokenList

 /**
  * Provide a list of tokens.
  */
 public function tokenList(User $user)
 {
     $entity_type = 'access_token';
     $storage = $this->entityManager()->getStorage($entity_type);
     $ids = $storage->getQuery()->condition('auth_user_id', $user->id())->execute();
     if (empty($ids)) {
         return ['#markup' => $this->t('There are no tokens for this user.')];
     }
     $view_controller = $this->entityManager()->getViewBuilder($entity_type);
     $tokens = $storage->loadMultiple($ids);
     return $view_controller->viewMultiple($tokens);
 }
开发者ID:mosswoodcreative,项目名称:d8-api-test,代码行数:15,代码来源:AccessTokenUserList.php


示例7: syncSmfPassword

 /**
  * Sets new hash password in smf
  *
  * @param \Drupal\User\Entity\User $drupalUser
  * @param \stdClass $smfMember
  */
 protected function syncSmfPassword(\Drupal\User\Entity\User $drupalUser, \stdClass $smfMember)
 {
     /**
      * @var \Drupal\Core\Database\Connection $this ->smfConnection
      */
     $hashedPasswd = sha1($drupalUser->getPassword());
     $id_member = $this->smfConnection->select('members', 'm')->fields('m', ['id_member'])->condition('m.member_name', $drupalUser->getUsername())->condition('m.passwd', $hashedPasswd)->execute()->fetchField();
     if (!$id_member) {
         $updateResult = $this->smfConnection->update('members')->fields(['passwd' => $hashedPasswd, 'password_salt' => ''])->condition('member_name', $drupalUser->getUsername())->execute();
         if ($updateResult) {
             $smfMember->passwd = $hashedPasswd;
         }
     }
 }
开发者ID:DimDev,项目名称:smfbridge,代码行数:20,代码来源:Member.php


示例8: createTestEntity

 /**
  * Creates a test entity.
  *
  * @param string $entity_type
  *   An entity type.
  *
  * @return \Drupal\Core\Entity\EntityInterface
  *   The created test entity.
  */
 protected function createTestEntity($entity_type)
 {
     $this->entity_name = $this->randomMachineName();
     $this->entity_user = $this->createUser();
     $this->entity_field_text = $this->randomMachineName();
     // Pass in the value of the name field when creating. With the user
     // field we test setting a field after creation.
     $entity = entity_create($entity_type);
     $entity->user_id->target_id = $this->entity_user->id();
     $entity->name->value = $this->entity_name;
     // Set a value for the test field.
     $entity->field_test_text->value = $this->entity_field_text;
     return $entity;
 }
开发者ID:Nikola-xiii,项目名称:d8intranet,代码行数:23,代码来源:EntityValidationTest.php


示例9: setUp

 /**
  * {@inheritdoc}
  */
 protected function setUp($import_test_views = TRUE)
 {
     parent::setUp($import_test_views);
     $this->installEntitySchema('user');
     $this->installEntitySchema('comment');
     // Create the anonymous role.
     $this->installConfig(['user']);
     // Create an anonymous user.
     $storage = \Drupal::entityManager()->getStorage('user');
     // Insert a row for the anonymous user.
     $storage->create(array('uid' => 0, 'name' => '', 'status' => 0))->save();
     $admin_role = Role::create(['id' => 'admin', 'permissions' => ['administer comments', 'access user profiles']]);
     $admin_role->save();
     /* @var \Drupal\user\RoleInterface $anonymous_role */
     $anonymous_role = Role::load(Role::ANONYMOUS_ID);
     $anonymous_role->grantPermission('access comments');
     $anonymous_role->save();
     $this->adminUser = User::create(['name' => $this->randomMachineName(), 'roles' => [$admin_role->id()]]);
     $this->adminUser->save();
     // Create some comments.
     $comment = Comment::create(['subject' => 'My comment title', 'uid' => $this->adminUser->id(), 'name' => $this->adminUser->label(), 'entity_type' => 'entity_test', 'comment_type' => 'entity_test', 'status' => 1]);
     $comment->save();
     $comment_anonymous = Comment::create(['subject' => 'Anonymous comment title', 'uid' => 0, 'name' => 'barry', 'mail' => '[email protected]', 'homepage' => 'https://example.com', 'entity_type' => 'entity_test', 'comment_type' => 'entity_test', 'created' => 123456, 'status' => 1]);
     $comment_anonymous->save();
 }
开发者ID:aWEBoLabs,项目名称:taxi,代码行数:28,代码来源:CommentUserNameTest.php


示例10: setUp

 /**
  * {@inheritdoc}
  */
 protected function setUp()
 {
     parent::setUp();
     $config = $this->config('system.theme');
     $config->set('default', 'bartik');
     $config->set('admin', 'seven');
     $config->save();
     foreach (static::$modules as $module) {
         $function = $module . '_schema';
         module_load_install($module);
         if (function_exists($function)) {
             $schema = $function();
             $this->installSchema($module, array_keys($schema));
         }
     }
     $this->installEntitySchema('aggregator_feed');
     $this->installEntitySchema('aggregator_item');
     $this->installEntitySchema('block_content');
     $this->installEntitySchema('comment');
     $this->installEntitySchema('file');
     $this->installEntitySchema('node');
     $this->installEntitySchema('menu_link_content');
     $this->installEntitySchema('taxonomy_term');
     $this->installEntitySchema('user');
     $this->installConfig(['block_content', 'comment', 'file', 'node', 'simpletest']);
     // Install one of D8's test themes.
     \Drupal::service('theme_handler')->install(array('test_theme'));
     // Create a new user which needs to have UID 1, because that is expected by
     // the assertions from
     // \Drupal\migrate_drupal\Tests\d6\MigrateNodeRevisionTest.
     User::create(['uid' => 1, 'name' => $this->randomMachineName(), 'status' => 1])->enforceIsNew(TRUE)->save();
     $this->installMigrations('Drupal 6');
 }
开发者ID:scratch,项目名称:gai,代码行数:36,代码来源:MigrateDrupal6Test.php


示例11: checkAccess

 /**
  * {@inheritdoc}
  *
  * When the $operation is 'add' then the $entity is of type 'profile_type',
  * otherwise $entity is of type 'profile'.
  */
 protected function checkAccess(EntityInterface $entity, $operation, AccountInterface $account)
 {
     $account = $this->prepareUser($account);
     $user_page = \Drupal::request()->attributes->get('user');
     // Some times, operation edit is called update.
     // Use edit in any case.
     if ($operation == 'update') {
         $operation = 'edit';
     }
     // Check that if profile type has require roles, the user the profile is
     // being added to has any of the required roles.
     if ($entity->getEntityTypeId() == 'profile') {
         $profile_roles = ProfileType::load($entity->bundle())->getRoles();
         $user_roles = $entity->getOwner()->getRoles(TRUE);
         if (!empty(array_filter($profile_roles)) && !array_intersect($user_roles, $profile_roles)) {
             return AccessResult::forbidden();
         }
     } elseif ($entity->getEntityTypeId() == 'profile_type') {
         $profile_roles = $entity->getRoles();
         $user_roles = User::load($user_page->id())->getRoles(TRUE);
         if (!empty(array_filter($profile_roles)) && !array_intersect($user_roles, $profile_roles)) {
             return AccessResult::forbidden();
         }
     }
     if ($account->hasPermission('bypass profile access')) {
         return AccessResult::allowed()->cachePerPermissions();
     } elseif ($operation == 'add' && ($user_page->id() == $account->id() && $account->hasPermission($operation . ' own ' . $entity->id() . ' profile') || $account->hasPermission($operation . ' any ' . $entity->id() . ' profile')) || $operation != 'add' && ($entity->getOwnerId() == $account->id() && $account->hasPermission($operation . ' own ' . $entity->getType() . ' profile') || $account->hasPermission($operation . ' any ' . $entity->getType() . ' profile'))) {
         return AccessResult::allowed()->cachePerPermissions();
     } else {
         return AccessResult::forbidden()->cachePerPermissions();
     }
 }
开发者ID:augustpascual-mse,项目名称:job-searching-network,代码行数:38,代码来源:ProfileAccessControlHandler.php


示例12: testShortcutSetUsersMigration

 /**
  * Test the shortcut set migration.
  */
 public function testShortcutSetUsersMigration() {
   // Check if migrated user has correct migrated shortcut set assigned.
   $account = User::load(2);
   $shortcut_set = shortcut_current_displayed_set($account);
   /** @var \Drupal\shortcut\ShortcutSetInterface $shortcut_set */
   $this->assertIdentical('shortcut_set_2', $shortcut_set->id());
 }
开发者ID:Greg-Boggs,项目名称:electric-dev,代码行数:10,代码来源:MigrateShortcutSetUsersTest.php


示例13: execute

 /**
  * {@inheritdoc}
  */
 protected function execute(InputInterface $input, OutputInterface $output)
 {
     $io = new DrupalStyle($input, $output);
     $uid = $input->getArgument('uid');
     $account = User::load($uid);
     if (!$account) {
         // Error loading User entity.
         $io->error(sprintf($this->trans('commands.user.login.clear.attempts.errors.invalid-user'), $uid));
         return 1;
     }
     // Define event name and identifier.
     $event = 'user.failed_login_user';
     // Identifier is created by uid and IP address,
     // Then we defined a generic identifier.
     $identifier = "{$account->id()}-";
     // Retrieve current database connection.
     $database = $this->getDrupalService('database');
     $schema = $database->schema();
     $flood = $schema->findTables('flood');
     if (!$flood) {
         $io->error($this->trans('commands.user.login.clear.attempts.errors.no-flood'));
         return 1;
     }
     // Clear login attempts.
     $database->delete('flood')->condition('event', $event)->condition('identifier', $database->escapeLike($identifier) . '%', 'LIKE')->execute();
     // Command executed successful.
     $io->success(sprintf($this->trans('commands.user.login.clear.attempts.messages.successful'), $uid));
 }
开发者ID:mnico,项目名称:DrupalConsole,代码行数:31,代码来源:LoginCleanAttemptsCommand.php


示例14: testRoleDeleteUserRoleReferenceDelete

 /**
  * Tests removal of role references on role entity delete.
  *
  * @see user_user_role_delete()
  */
 public function testRoleDeleteUserRoleReferenceDelete()
 {
     // Create two test roles.
     $role_storage = $this->container->get('entity.manager')->getStorage('user_role');
     $role_storage->create(array('id' => 'test_role_one'))->save();
     $role_storage->create(array('id' => 'test_role_two'))->save();
     // Create user and assign both test roles.
     $values = array('uid' => 1, 'name' => $this->randomString(), 'roles' => array('test_role_one', 'test_role_two'));
     $user = User::create($values);
     $user->save();
     // Check that user has both roles.
     $this->assertTrue($user->hasRole('test_role_one'));
     $this->assertTrue($user->hasRole('test_role_two'));
     // Delete test role one.
     $test_role_one = $role_storage->load('test_role_one');
     $test_role_one->delete();
     // Load user again from the database.
     $user = User::load($user->id());
     // Check that user does not have role one anymore, still has role two.
     $this->assertFalse($user->hasRole('test_role_one'));
     $this->assertTrue($user->hasRole('test_role_two'));
     // Create new role with same name.
     $role_storage->create(array('id' => 'test_role_one'))->save();
     // Load user again from the database.
     $user = User::load($user->id());
     // Check that user does not have role one.
     $this->assertFalse($user->hasRole('test_role_one'));
     $this->assertTrue($user->hasRole('test_role_two'));
 }
开发者ID:ddrozdik,项目名称:dmaps,代码行数:34,代码来源:UserRoleDeleteTest.php


示例15: setUp

 /**
  * {@inheritdoc}
  */
 protected function setUp()
 {
     parent::setUp();
     $this->installEntitySchema('node');
     $this->installConfig(['node']);
     $this->installSchema('node', ['node_access']);
     $this->installSchema('system', ['sequences']);
     // Create a new user which needs to have UID 1, because that is expected by
     // the assertions from
     // \Drupal\migrate_drupal\Tests\d6\MigrateNodeRevisionTest.
     User::create(['uid' => 1, 'name' => $this->randomMachineName(), 'status' => 1])->enforceIsNew(TRUE)->save();
     $node_type = entity_create('node_type', array('type' => 'test_planet'));
     $node_type->save();
     node_add_body_field($node_type);
     $node_type = entity_create('node_type', array('type' => 'story'));
     $node_type->save();
     node_add_body_field($node_type);
     $id_mappings = array('d6_node_type' => array(array(array('test_story'), array('story'))), 'd6_filter_format' => array(array(array(1), array('filtered_html')), array(array(2), array('full_html'))), 'd6_user' => array(array(array(1), array(1)), array(array(2), array(2))), 'd6_field_instance_widget_settings' => array(array(array('page', 'field_test'), array('node', 'page', 'default', 'test'))), 'd6_field_formatter_settings' => array(array(array('page', 'default', 'node', 'field_test'), array('node', 'page', 'default', 'field_test'))));
     $this->prepareMigrations($id_mappings);
     $migration = entity_load('migration', 'd6_node_settings');
     $migration->setMigrationResult(MigrationInterface::RESULT_COMPLETED);
     // Create a test node.
     $node = entity_create('node', array('type' => 'story', 'nid' => 1, 'vid' => 1, 'revision_log' => '', 'title' => $this->randomString()));
     $node->enforceIsNew();
     $node->save();
     $node = entity_create('node', array('type' => 'test_planet', 'nid' => 3, 'vid' => 4, 'revision_log' => '', 'title' => $this->randomString()));
     $node->enforceIsNew();
     $node->save();
 }
开发者ID:ravindrasingh22,项目名称:Drupal-8-rc,代码行数:32,代码来源:MigrateNodeTestBase.php


示例16: testSubscriberFormFieldSync

 /**
  * Tests that fields are synchronized using the Subscriber form.
  */
 public function testSubscriberFormFieldSync()
 {
     // Create a subscriber for the user.
     $subscriber = Subscriber::create(array('uid' => $this->user->id(), 'mail' => '[email protected]'));
     $subscriber->save();
     // Edit subscriber field and assert user field is changed accordingly.
     $this->drupalLogin($this->user);
     $this->drupalGet('admin/people/simplenews/edit/' . $subscriber->id());
     $this->assertField('field_shared[0][value]');
     $this->assertRaw($this->user->field_shared->value);
     $new_value = $this->randomMachineName();
     $this->drupalPostForm(NULL, array('field_shared[0][value]' => $new_value), t('Save'));
     $this->drupalGet('admin/people/simplenews/edit/' . $subscriber->id());
     $this->assertRaw($new_value);
     $this->user = User::load($this->user->id());
     $this->assertEqual($this->user->field_shared->value, $new_value);
     // Unset the sync setting and assert field is not synced.
     $this->drupalPostForm('admin/config/people/simplenews/settings/subscriber', array('simplenews_sync_fields' => FALSE), t('Save configuration'));
     $unsynced_value = $this->randomMachineName();
     $this->drupalPostForm('admin/people/simplenews/edit/' . $subscriber->id(), array('field_shared[0][value]' => $unsynced_value), t('Save'));
     $this->drupalGet('admin/people/simplenews/edit/' . $subscriber->id());
     $this->assertRaw($unsynced_value);
     $this->user = User::load($this->user->id());
     $this->assertEqual($this->user->field_shared->value, $new_value);
     $this->assertNotEqual($this->user->field_shared->value, $unsynced_value);
 }
开发者ID:aritnath1990,项目名称:simplenewslatest,代码行数:29,代码来源:SimplenewsSynchronizeFieldsFormTest.php


示例17: create

 /**
  * {@inheritdoc}
  */
 public function create(array $values = array())
 {
     $store_config = \Drupal::config('uc_store.settings');
     // Set the primary email address.
     if (empty($values['primary_email']) && !empty($values['uid'])) {
         if ($account = User::load($values['uid'])) {
             $values['primary_email'] = $account->mail;
         }
     }
     // Set the default order status.
     if (empty($values['order_status'])) {
         $values['order_status'] = uc_order_state_default('in_checkout');
     }
     // Set the default currency.
     if (empty($values['currency'])) {
         $values['currency'] = $store_config->get('currency.code');
     }
     // Set the default country codes.
     if (empty($values['billing_country'])) {
         $values['billing_country'] = $store_config->get('address.country');
     }
     if (empty($values['delivery_country'])) {
         $values['delivery_country'] = $store_config->get('address.country');
     }
     // Set the created time to now.
     if (empty($values['created'])) {
         $values['created'] = REQUEST_TIME;
     }
     return parent::create($values);
 }
开发者ID:pedrocones,项目名称:hydrotools,代码行数:33,代码来源:OrderStorage.php


示例18: testUserProfileValues

    /**
     * Tests Drupal 6 profile values to Drupal 8 migration.
     */
    public function testUserProfileValues()
    {
        $user = User::load(2);
        $this->assertFalse(is_null($user));
        $this->assertIdentical('red', $user->profile_color->value);
        $expected = <<<EOT
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nam nulla sapien, congue nec risus ut, adipiscing aliquet felis. Maecenas quis justo vel nulla varius euismod. Quisque metus metus, cursus sit amet sem non, bibendum vehicula elit. Cras dui nisl, eleifend at iaculis vitae, lacinia ut felis. Nullam aliquam ligula volutpat nulla consectetur accumsan. Maecenas tincidunt molestie diam, a accumsan enim fringilla sit amet. Morbi a tincidunt tellus. Donec imperdiet scelerisque porta. Sed quis sem bibendum eros congue sodales. Vivamus vel fermentum est, at rutrum orci. Nunc consectetur purus ut dolor pulvinar, ut volutpat felis congue. Cras tincidunt odio sed neque sollicitudin, vehicula tempor metus scelerisque.
EOT;
        $this->assertIdentical($expected, $user->profile_biography->value);
        $this->assertIdentical('1', $user->profile_sell_address->value);
        $this->assertIdentical('Back\\slash', $user->profile_sold_to->value);
        $this->assertIdentical('AC/DC', $user->profile_bands[0]->value);
        $this->assertIdentical('Eagles', $user->profile_bands[1]->value);
        $this->assertIdentical('Elton John', $user->profile_bands[2]->value);
        $this->assertIdentical('Lemonheads', $user->profile_bands[3]->value);
        $this->assertIdentical('Rolling Stones', $user->profile_bands[4]->value);
        $this->assertIdentical('Queen', $user->profile_bands[5]->value);
        $this->assertIdentical('The White Stripes', $user->profile_bands[6]->value);
        $this->assertIdentical('1974-06-02', $user->profile_birthdate->value);
        $this->assertIdentical('http://example.com/blog', $user->profile_blog->uri);
        $this->assertNull($user->profile_blog->title);
        $this->assertIdentical([], $user->profile_blog->options);
        $this->assertIdentical('http://example.com/blog', $user->profile_blog->uri);
        $this->assertNull($user->profile_love_migrations->value);
        $user = User::load(8);
        $this->assertIdentical('Forward/slash', $user->profile_sold_to->value);
        $user = User::load(15);
        $this->assertIdentical('Dot.in.the.middle', $user->profile_sold_to->value);
    }
开发者ID:aWEBoLabs,项目名称:taxi,代码行数:32,代码来源:MigrateUserProfileValuesTest.php


示例19: testContactLink

 /**
  * Tests contact link.
  */
 public function testContactLink()
 {
     $accounts = array();
     $accounts['root'] = User::load(1);
     // Create an account with access to all contact pages.
     $admin_account = $this->drupalCreateUser(array('administer users'));
     $accounts['admin'] = $admin_account;
     // Create an account with no access to contact pages.
     $no_contact_account = $this->drupalCreateUser();
     $accounts['no_contact'] = $no_contact_account;
     // Create an account with access to contact pages.
     $contact_account = $this->drupalCreateUser(array('access user contact forms'));
     $accounts['contact'] = $contact_account;
     $this->drupalLogin($admin_account);
     $this->drupalGet('test-contact-link');
     // The admin user has access to all contact links beside his own.
     $this->assertContactLinks($accounts, array('root', 'no_contact', 'contact'));
     $this->drupalLogin($no_contact_account);
     $this->drupalGet('test-contact-link');
     // Ensure that the user without the permission doesn't see any link.
     $this->assertContactLinks($accounts, array());
     $this->drupalLogin($contact_account);
     $this->drupalGet('test-contact-link');
     $this->assertContactLinks($accounts, array('root', 'admin', 'no_contact'));
     // Disable contact link for no_contact.
     $this->userData->set('contact', $no_contact_account->id(), 'enabled', FALSE);
     // @todo Remove cache invalidation in https://www.drupal.org/node/2477903.
     Cache::invalidateTags($no_contact_account->getCacheTagsToInvalidate());
     $this->drupalGet('test-contact-link');
     $this->assertContactLinks($accounts, array('root', 'admin'));
 }
开发者ID:ddrozdik,项目名称:dmaps,代码行数:34,代码来源:ContactLinkTest.php


示例20: testUserMethods

 /**
  * Tests some of the methods.
  *
  * @see \Drupal\user\Entity\User::getRoles()
  * @see \Drupal\user\Entity\User::addRole()
  * @see \Drupal\user\Entity\User::removeRole()
  */
 public function testUserMethods()
 {
     $role_storage = $this->container->get('entity.manager')->getStorage('user_role');
     $role_storage->create(array('id' => 'test_role_one'))->save();
     $role_storage->create(array('id' => 'test_role_two'))->save();
     $role_storage->create(array('id' => 'test_role_three'))->save();
     $values = array('uid' => 1, 'roles' => array('test_role_one'));
     $user = User::create($values);
     $this->assertTrue($user->hasRole('test_role_one'));
     $this->assertFalse($user->hasRole('test_role_two'));
     $this->assertEqual(array(RoleInterface::AUTHENTICATED_ID, 'test_role_one'), $user->getRoles());
     $user->addRole('test_role_one');
     $this->assertTrue($user->hasRole('test_role_one'));
     $this->assertFalse($user->hasRole('test_role_two'));
     $this->assertEqual(array(RoleInterface::AUTHENTICATED_ID, 'test_role_one'), $user->getRoles());
     $user->addRole('test_role_two');
     $this->assertTrue($user->hasRole('test_role_one'));
     $this->assertTrue($user->hasRole('test_role_two'));
     $this->assertEqual(array(RoleInterface::AUTHENTICATED_ID, 'test_role_one', 'test_role_two'), $user->getRoles());
     $user->removeRole('test_role_three');
     $this->assertTrue($user->hasRole('test_role_one'));
     $this->assertTrue($user->hasRole('test_role_two'));
     $this->assertEqual(array(RoleInterface::AUTHENTICATED_ID, 'test_role_one', 'test_role_two'), $user->getRoles());
     $user->removeRole('test_role_one');
     $this->assertFalse($user->hasRole('test_role_one'));
     $this->assertTrue($user->hasRole('test_role_two'));
     $this->assertEqual(array(RoleInterface::AUTHENTICATED_ID, 'test_role_two'), $user->getRoles());
 }
开发者ID:aWEBoLabs,项目名称:taxi,代码行数:35,代码来源:UserEntityTest.php



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
PHP views\EntityViewsData类代码示例发布时间:2022-05-23
下一篇:
PHP Entity\Role类代码示例发布时间:2022-05-23
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap