function FileViewsFieldAccessTest::testFileFields
Same name in other branches
- 9 core/modules/file/tests/src/Kernel/Views/FileViewsFieldAccessTest.php \Drupal\Tests\file\Kernel\Views\FileViewsFieldAccessTest::testFileFields()
- 8.9.x core/modules/file/tests/src/Kernel/Views/FileViewsFieldAccessTest.php \Drupal\Tests\file\Kernel\Views\FileViewsFieldAccessTest::testFileFields()
- 11.x core/modules/file/tests/src/Kernel/Views/FileViewsFieldAccessTest.php \Drupal\Tests\file\Kernel\Views\FileViewsFieldAccessTest::testFileFields()
Check access for file fields.
File
-
core/
modules/ file/ tests/ src/ Kernel/ Views/ FileViewsFieldAccessTest.php, line 36
Class
- FileViewsFieldAccessTest
- Tests base field access in Views for the file entity.
Namespace
Drupal\Tests\file\Kernel\ViewsCode
public function testFileFields() : void {
ConfigurableLanguage::create([
'id' => 'fr',
'label' => '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();
// @todo Expand the test coverage in https://www.drupal.org/node/2464635
$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', 'Permanent');
// $this->assertFieldAccess('file', 'created', \Drupal::service('date.formatter')->format(123456));
// $this->assertFieldAccess('file', 'changed', \Drupal::service('date.formatter')->format(\Drupal::time()->getRequestTime()));
}
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.