FileDownloadUrlTest.php in JSON:API 8
File
tests/src/Kernel/Field/FileDownloadUrlTest.php
View source
<?php
namespace Drupal\Tests\jsonapi\Kernel\Field;
use Drupal\file\Entity\File;
use Drupal\KernelTests\KernelTestBase;
class FileDownloadUrlTest extends KernelTestBase {
public static $modules = [
'jsonapi',
'file',
'serialization',
'text',
'user',
];
protected $file;
protected $filename = 'druplicon.txt';
protected function setUp() {
parent::setUp();
$this
->installEntitySchema('file');
$this
->installSchema('file', [
'file_usage',
]);
$this->file = File::create([
'filename' => $this->filename,
'uri' => sprintf('public://%s', $this->filename),
'filemime' => 'text/plain',
'status' => FILE_STATUS_PERMANENT,
]);
$this->file
->save();
}
public function testUrlField() {
$url_field = $this->file
->get('url');
$values = [
$url_field->value,
$url_field
->getValue()[0]['value'],
$url_field
->get(0)
->toArray()['value'],
$url_field
->first()
->getValue()['value'],
];
array_walk($values, function ($value) {
$this
->assertContains('simpletest', $value);
$this
->assertContains($this->filename, $value);
});
$violationList = $this->file
->validate();
$this
->assertEquals(0, $violationList
->count());
}
}