Updated all the contrib modules to their latest versions.
[yaffs-website] / web / modules / contrib / token / tests / src / Kernel / FileTest.php
1 <?php
2
3 namespace Drupal\Tests\token\Kernel;
4
5 use Drupal\file\Entity\File;
6 /**
7  * Tests file tokens.
8  *
9  * @group token
10  */
11 class FileTest extends KernelTestBase {
12
13   /**
14    * Modules to enable.
15    *
16    * @var array
17    */
18   public static $modules = ['file'];
19
20   /**
21    * {@inheritdoc}
22    */
23   public function setUp() {
24     parent::setUp();
25     $this->installEntitySchema('file');
26   }
27
28   function testFileTokens() {
29     // Create a test file object.
30     $file = File::create([
31       'fid' => 1,
32       'filename' => 'test.png',
33       'filesize' => 100,
34       'uri' => 'public://images/test.png',
35       'filemime' => 'image/png',
36     ]);
37
38     $tokens = [
39       'basename' => 'test.png',
40       'extension' => 'png',
41       'size-raw' => 100,
42     ];
43     $this->assertTokens('file', ['file' => $file], $tokens);
44
45     // Test a file with no extension and a fake name.
46     $file->filename = 'Test PNG image';
47     $file->uri = 'public://images/test';
48
49     $tokens = [
50       'basename' => 'test',
51       'extension' => '',
52       'size-raw' => 100,
53     ];
54     $this->assertTokens('file', ['file' => $file], $tokens);
55   }
56
57 }