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