View source
<?php
namespace Drupal\file\Tests\Views;
use Drupal\file\Entity\File;
use Drupal\language\Entity\ConfigurableLanguage;
use Drupal\user\Entity\User;
use Drupal\views\Tests\Handler\FieldFieldAccessTestBase;
class FileViewsFieldAccessTest extends FieldFieldAccessTestBase {
public static $modules = [
'file',
'entity_test',
'language',
'user',
];
protected function setUp($import_test_views = TRUE) {
parent::setUp($import_test_views);
$this
->installEntitySchema('file');
}
public function testFileFields() {
ConfigurableLanguage::create([
'id' => 'fr',
'name' => 'French',
])
->save();
$user = User::create([
'name' => 'test user',
]);
$user
->save();
file_put_contents('public://test.txt', 'test');
$file = File::create([
'filename' => 'test.txt',
'uri' => 'public://test.txt',
'status' => TRUE,
'langcode' => 'fr',
'uid' => $user
->id(),
]);
$file
->save();
$this
->assertFieldAccess('file', 'fid', $file
->id());
$this
->assertFieldAccess('file', 'uuid', $file
->uuid());
$this
->assertFieldAccess('file', 'langcode', $file
->language()
->getName());
$this
->assertFieldAccess('file', 'uid', 'test user');
$this
->assertFieldAccess('file', 'filename', $file
->getFilename());
$this
->assertFieldAccess('file', 'uri', $file
->getFileUri());
$this
->assertFieldAccess('file', 'filemime', $file->filemime->value);
$this
->assertFieldAccess('file', 'filesize', '4 bytes');
$this
->assertFieldAccess('file', 'status', t('Permanent'));
}
}