3 namespace Drupal\Tests\file\Kernel\Views;
5 use Drupal\file\Entity\File;
6 use Drupal\language\Entity\ConfigurableLanguage;
7 use Drupal\user\Entity\User;
8 use Drupal\Tests\views\Kernel\Handler\FieldFieldAccessTestBase;
11 * Tests base field access in Views for the file entity.
15 class FileViewsFieldAccessTest extends FieldFieldAccessTestBase {
20 public static $modules = ['file', 'entity_test', 'language', 'user'];
25 protected function setUp($import_test_views = TRUE) {
26 parent::setUp($import_test_views);
28 $this->installEntitySchema('file');
32 * Check access for file fields.
34 public function testFileFields() {
35 ConfigurableLanguage::create([
40 $user = User::create([
41 'name' => 'test user',
45 file_put_contents('public://test.txt', 'test');
46 $file = File::create([
47 'filename' => 'test.txt',
48 'uri' => 'public://test.txt',
55 // @todo Expand the test coverage in https://www.drupal.org/node/2464635
57 $this->assertFieldAccess('file', 'fid', $file->id());
58 $this->assertFieldAccess('file', 'uuid', $file->uuid());
59 $this->assertFieldAccess('file', 'langcode', $file->language()->getName());
60 $this->assertFieldAccess('file', 'uid', 'test user');
61 $this->assertFieldAccess('file', 'filename', $file->getFilename());
62 $this->assertFieldAccess('file', 'uri', $file->getFileUri());
63 $this->assertFieldAccess('file', 'filemime', $file->filemime->value);
64 $this->assertFieldAccess('file', 'filesize', '4 bytes');
65 $this->assertFieldAccess('file', 'status', t('Permanent'));
66 // $this->assertFieldAccess('file', 'created', \Drupal::service('date.formatter')->format(123456));
67 // $this->assertFieldAccess('file', 'changed', \Drupal::service('date.formatter')->format(REQUEST_TIME));