View source
<?php
namespace Drupal\Tests\file\Functional\Formatter;
use Drupal\Core\Field\FieldStorageDefinitionInterface;
use Drupal\field\Entity\FieldConfig;
use Drupal\field\Entity\FieldStorageConfig;
use Drupal\Tests\BrowserTestBase;
abstract class FileMediaFormatterTestBase extends BrowserTestBase {
protected static $modules = [
'entity_test',
'field',
'file',
'user',
'system',
];
protected function setUp() {
parent::setUp();
$this
->drupalLogin($this
->drupalCreateUser([
'view test entity',
]));
}
protected function createMediaField($formatter, $file_extensions, array $formatter_settings = []) {
$entity_type = $bundle = 'entity_test';
$field_name = mb_strtolower($this
->randomMachineName());
FieldStorageConfig::create([
'entity_type' => $entity_type,
'field_name' => $field_name,
'type' => 'file',
'cardinality' => FieldStorageDefinitionInterface::CARDINALITY_UNLIMITED,
])
->save();
$field_config = FieldConfig::create([
'entity_type' => $entity_type,
'field_name' => $field_name,
'bundle' => $bundle,
'settings' => [
'file_extensions' => trim($file_extensions),
],
]);
$field_config
->save();
$this->container
->get('entity_display.repository')
->getViewDisplay('entity_test', 'entity_test', 'full')
->setComponent($field_name, [
'type' => $formatter,
'settings' => $formatter_settings,
])
->save();
return $field_config;
}
public function dataProvider() {
return [
[
2,
[],
],
[
1,
[
'multiple_file_display_type' => 'sources',
],
],
];
}
}