View source
<?php
namespace Drupal\Tests\user\Kernel\Views;
use Drupal\language\Entity\ConfigurableLanguage;
use Drupal\user\Entity\User;
use Drupal\Tests\views\Kernel\Handler\FieldFieldAccessTestBase;
class UserViewsFieldAccessTest extends FieldFieldAccessTestBase {
protected static $modules = [
'user',
'entity_test',
'language',
];
protected function setUp($import_test_views = TRUE) : void {
parent::setUp($import_test_views);
$this
->installEntitySchema('user');
}
public function testUserFields() {
ConfigurableLanguage::create([
'id' => 'es',
'name' => 'Spanish',
])
->save();
ConfigurableLanguage::create([
'id' => 'fr',
'name' => 'French',
])
->save();
$user = User::create([
'name' => 'test user',
'mail' => 'druplicon@drop.org',
'status' => 1,
'preferred_langcode' => 'es',
'preferred_admin_langcode' => 'fr',
'timezone' => 'ut1',
'created' => 123456,
]);
$user
->save();
$this
->assertFieldAccess('user', 'uid', $user
->id());
$this
->assertFieldAccess('user', 'uuid', $user
->uuid());
$this
->assertFieldAccess('user', 'langcode', $user
->language()
->getName());
$this
->assertFieldAccess('user', 'preferred_langcode', 'Spanish');
$this
->assertFieldAccess('user', 'preferred_admin_langcode', 'French');
$this
->assertFieldAccess('user', 'name', 'test user');
$this
->assertFieldAccess('user', 'timezone', 'ut1');
$this
->assertFieldAccess('user', 'status', 'On');
}
}