本文整理汇总了PHP中Drupal\user\Entity\User::set方法的典型用法代码示例。如果您正苦于以下问题:PHP User::set方法的具体用法?PHP User::set怎么用?PHP User::set使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Drupal\user\Entity\User
的用法示例。
在下文中一共展示了User::set方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: testSwitchUserListItems
/**
* Test the user list items.
*/
public function testSwitchUserListItems()
{
$anonymous = \Drupal::config('user.settings')->get('anonymous');
$this->setBlockConfiguration('list_size', 2);
// Login as web user so we are sure that this account is prioritized
// in the list if not enougth user with 'switch users' permission are
// present.
$this->drupalLogin($this->webUser);
$this->drupalLogin($this->develUser);
$this->drupalGet('');
// Ensure that user with 'switch users' permission are prioritized.
$this->assertSwitchUserListCount(2);
$this->assertSwitchUserListContainsUser($this->develUser->getUsername());
$this->assertSwitchUserListContainsUser($this->switchUser->getUsername());
// Ensure that blocked users are not shown in the list.
$this->switchUser->set('status', 0)->save();
$this->drupalGet('');
$this->assertSwitchUserListCount(2);
$this->assertSwitchUserListContainsUser($this->develUser->getUsername());
$this->assertSwitchUserListContainsUser($this->webUser->getUsername());
$this->assertSwitchUserListNoContainsUser($this->switchUser->getUsername());
// Ensure that anonymous user are prioritized if include_anon is set to true.
$this->setBlockConfiguration('include_anon', TRUE);
$this->drupalGet('');
$this->assertSwitchUserListCount(2);
$this->assertSwitchUserListContainsUser($this->develUser->getUsername());
$this->assertSwitchUserListContainsUser($anonymous);
}
示例2: testSwitchUserListItems
/**
* Test the user list items.
*/
public function testSwitchUserListItems()
{
$anonymous = \Drupal::config('user.settings')->get('anonymous');
$this->setBlockConfiguration('list_size', 2);
// Login as web user so we are sure that this account is prioritized
// in the list if not enougth user with 'switch users' permission are
// present.
$this->drupalLogin($this->webUser);
$this->drupalLogin($this->develUser);
$this->drupalGet('');
// Ensure that user with 'switch users' permission are prioritized.
$this->assertSwitchUserListCount(2);
$this->assertSwitchUserListContainsUser($this->develUser->getUsername());
$this->assertSwitchUserListContainsUser($this->switchUser->getUsername());
// Ensure that blocked users are not shown in the list.
$this->switchUser->set('status', 0)->save();
$this->drupalGet('');
$this->assertSwitchUserListCount(2);
$this->assertSwitchUserListContainsUser($this->develUser->getUsername());
$this->assertSwitchUserListContainsUser($this->webUser->getUsername());
$this->assertSwitchUserListNoContainsUser($this->switchUser->getUsername());
// Ensure that anonymous user are prioritized if include_anon is set to true.
$this->setBlockConfiguration('include_anon', TRUE);
$this->drupalGet('');
$this->assertSwitchUserListCount(2);
$this->assertSwitchUserListContainsUser($this->develUser->getUsername());
$this->assertSwitchUserListContainsUser($anonymous);
// Ensure that the switch user block works properly even if no prioritized
// users are found (special handling for user 1).
$this->drupalLogout();
$this->develUser->delete();
$this->drupalLogin($this->rootUser);
$this->drupalGet('');
$this->assertSwitchUserListCount(2);
$this->assertSwitchUserListContainsUser($this->rootUser->getUsername());
$this->assertSwitchUserListContainsUser($anonymous);
// Ensure that the switch user block works properly even if no roles have
// the 'switch users' permission associated (special handling for user 1).
$roles = user_roles(TRUE, 'switch users');
\Drupal::entityTypeManager()->getStorage('user_role')->delete($roles);
$this->drupalGet('');
$this->assertSwitchUserListCount(2);
$this->assertSwitchUserListContainsUser($this->rootUser->getUsername());
$this->assertSwitchUserListContainsUser($anonymous);
}
示例3: testPluralEditDateFormatter
/**
* Tests plural editing of DateFormatter strings
*/
public function testPluralEditDateFormatter()
{
// Import some .po files with formulas to set up the environment.
// These will also add the languages to the system.
$this->importPoFile($this->getPoFileWithSimplePlural(), array('langcode' => 'fr'));
// Set French as the site default language.
$this->config('system.site')->set('default_langcode', 'fr')->save();
// Visit User Info page before updating translation strings. Change the
// created time to ensure that the we're dealing in seconds and it can't be
// exactly 1 minute.
$this->adminUser->set('created', time() - 1)->save();
$this->drupalGet('user');
// Member for time should be translated.
$this->assertText("seconde", "'Member for' text is translated.");
$path = 'admin/config/regional/translate/';
$search = array('langcode' => 'fr', 'translation' => 'translated');
$this->drupalPostForm($path, $search, t('Filter'));
// Plural values for the langcode fr.
$this->assertText('@count seconde');
$this->assertText('@count secondes');
// Inject a plural source string to the database. We need to use a specific
// langcode here because the language will be English by default and will
// not save our source string for performance optimization if we do not ask
// specifically for a language.
\Drupal::translation()->formatPlural(1, '1 second', '@count seconds', array(), array('langcode' => 'fr'))->render();
$lid = db_query("SELECT lid FROM {locales_source} WHERE source = :source AND context = ''", array(':source' => "1 second" . LOCALE_PLURAL_DELIMITER . "@count seconds"))->fetchField();
// Look up editing page for this plural string and check fields.
$search = array('string' => '1 second', 'langcode' => 'fr');
$this->drupalPostForm('admin/config/regional/translate', $search, t('Filter'));
// Save complete translations for the string in langcode fr.
$edit = array("strings[{$lid}][translations][0]" => '1 seconde updated', "strings[{$lid}][translations][1]" => '@count secondes updated');
$this->drupalPostForm($path, $edit, t('Save translations'));
// User interface input for translating seconds should not be duplicated
$this->assertUniqueText('@count seconds', 'Interface translation input for @count seconds only appears once.');
// Member for time should be translated. Change the created time to ensure
// that the we're dealing in multiple seconds and it can't be exactly 1
// second or minute.
$this->adminUser->set('created', time() - 2)->save();
$this->drupalGet('user');
$this->assertText("secondes updated", "'Member for' text is translated.");
}