UserEntityCallbacksTest.php in Zircon Profile 8
File
core/modules/user/src/Tests/UserEntityCallbacksTest.php
View source
<?php
namespace Drupal\user\Tests;
use Drupal\simpletest\WebTestBase;
class UserEntityCallbacksTest extends WebTestBase {
public static $modules = array(
'user',
'user_hooks_test',
);
protected $account;
protected $anonymous;
protected function setUp() {
parent::setUp();
$this->account = $this
->drupalCreateUser();
$this->anonymous = entity_create('user', array(
'uid' => 0,
));
}
function testLabelCallback() {
$this
->assertEqual($this->account
->label(), $this->account
->getUsername(), 'The username should be used as label');
$name = $this
->randomMachineName();
$this
->config('user.settings')
->set('anonymous', $name)
->save();
$this
->assertEqual($this->anonymous
->label(), $name, 'The variable anonymous should be used for name of uid 0');
$this
->assertEqual($this->anonymous
->getDisplayName(), $name, 'The variable anonymous should be used for display name of uid 0');
$this
->assertEqual($this->anonymous
->getUserName(), '', 'The raw anonymous user name should be empty string');
\Drupal::state()
->set('user_hooks_test_user_format_name_alter', TRUE);
$this
->assertEqual($this->account
->getDisplayName(), '<em>' . $this->account
->id() . '</em>', 'The user display name should be altered.');
$this
->assertEqual($this->account
->getUsername(), $this->account->name->value, 'The user name should not be altered.');
}
}