FileTest.php in Token 8
File
tests/src/Kernel/FileTest.php
View source
<?php
namespace Drupal\Tests\token\Kernel;
use Drupal\file\Entity\File;
class FileTest extends KernelTestBase {
public static $modules = [
'file',
];
public function setUp() {
parent::setUp();
$this
->installEntitySchema('file');
}
function testFileTokens() {
$file = File::create([
'fid' => 1,
'filename' => 'test.png',
'filesize' => 100,
'uri' => 'public://images/test.png',
'filemime' => 'image/png',
]);
$tokens = [
'basename' => 'test.png',
'extension' => 'png',
'size-raw' => 100,
];
$this
->assertTokens('file', [
'file' => $file,
], $tokens);
$file->filename = 'Test PNG image';
$file->uri = 'public://images/test';
$tokens = [
'basename' => 'test',
'extension' => '',
'size-raw' => 100,
];
$this
->assertTokens('file', [
'file' => $file,
], $tokens);
}
}