539cb5d41f460b3762820421609856ff04e2618d
[yaffs-website] / web / core / modules / file / tests / src / Kernel / Views / FileViewsFieldAccessTest.php
1 <?php
2
3 namespace Drupal\Tests\file\Kernel\Views;
4
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;
9
10 /**
11  * Tests base field access in Views for the file entity.
12  *
13  * @group File
14  */
15 class FileViewsFieldAccessTest extends FieldFieldAccessTestBase {
16
17   /**
18    * {@inheritdoc}
19    */
20   public static $modules = ['file', 'entity_test', 'language', 'user'];
21
22   /**
23    * {@inheritdoc}
24    */
25   protected function setUp($import_test_views = TRUE) {
26     parent::setUp($import_test_views);
27
28     $this->installEntitySchema('file');
29   }
30
31   /**
32    * Check access for file fields.
33    */
34   public function testFileFields() {
35     ConfigurableLanguage::create([
36       'id' => 'fr',
37       'name' => 'French',
38     ])->save();
39
40     $user = User::create([
41       'name' => 'test user',
42     ]);
43     $user->save();
44
45     file_put_contents('public://test.txt', 'test');
46     $file = File::create([
47       'filename' => 'test.txt',
48       'uri' => 'public://test.txt',
49       'status' => TRUE,
50       'langcode' => 'fr',
51       'uid' => $user->id(),
52     ]);
53     $file->save();
54
55     // @todo Expand the test coverage in https://www.drupal.org/node/2464635
56
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));
68   }
69
70 }