public function UserNameFormatterTest::testFormatter in Zircon Profile 8
Same name and namespace in other branches
- 8.0 core/modules/user/src/Tests/Field/UserNameFormatterTest.php \Drupal\user\Tests\Field\UserNameFormatterTest::testFormatter()
Tests the formatter output.
File
- core/
modules/ user/ src/ Tests/ Field/ UserNameFormatterTest.php, line 79 - Contains \Drupal\user\Tests\Field\UserNameFormatterTest.
Class
- UserNameFormatterTest
- Tests the user_name formatter.
Namespace
Drupal\user\Tests\FieldCode
public function testFormatter() {
$user = User::create([
'name' => 'test name',
]);
$user
->save();
$result = $user->{$this->fieldName}
->view([
'type' => 'user_name',
]);
$this
->assertEqual('username', $result[0]['#theme']);
$this
->assertEqual(spl_object_hash($user), spl_object_hash($result[0]['#account']));
$result = $user->{$this->fieldName}
->view([
'type' => 'user_name',
'settings' => [
'link_to_entity' => FALSE,
],
]);
$this
->assertEqual($user
->getDisplayName(), $result[0]['#markup']);
$user = User::getAnonymousUser();
$result = $user->{$this->fieldName}
->view([
'type' => 'user_name',
]);
$this
->assertEqual('username', $result[0]['#theme']);
$this
->assertEqual(spl_object_hash($user), spl_object_hash($result[0]['#account']));
$result = $user->{$this->fieldName}
->view([
'type' => 'user_name',
'settings' => [
'link_to_entity' => FALSE,
],
]);
$this
->assertEqual($user
->getDisplayName(), $result[0]['#markup']);
$this
->assertEqual($this
->config('user.settings')
->get('anonymous'), $result[0]['#markup']);
}