View source
<?php
declare (strict_types=1);
namespace Drupal\Tests\animated_gif\Functional;
use Drupal\Core\File\FileSystemInterface;
use Drupal\field\Entity\FieldConfig;
use Drupal\field\Entity\FieldStorageConfig;
use Drupal\file\FileInterface;
use Drupal\Tests\BrowserTestBase;
abstract class AnimatedGifFunctionalTestBase extends BrowserTestBase {
protected $defaultTheme = 'stark';
protected static $modules = [
'animated_gif',
'node',
'file',
'image',
'field_ui',
];
protected $fileSystem;
protected $entityTypeManager;
protected $displayRepository;
protected $adminUser;
protected function setUp() : void {
parent::setUp();
$this->displayRepository = $this->container
->get('entity_display.repository');
$this->fileSystem = $this->container
->get('file_system');
$this->entityTypeManager = $this->container
->get('entity_type.manager');
$this->adminUser = $this
->drupalCreateUser([
'access content',
'access administration pages',
'administer content types',
'administer node fields',
'administer node display',
'administer nodes',
'bypass node access',
]);
$this
->drupalCreateContentType([
'type' => 'article',
'name' => 'Article',
]);
}
protected function getTestFile(string $fileName, string $fileUri) : FileInterface {
$source = drupal_get_path('module', 'animated_gif');
$source .= '/tests/images/' . $fileName;
$this->fileSystem
->copy($source, $fileUri, FileSystemInterface::EXISTS_REPLACE);
$file = $this->entityTypeManager
->getStorage('file')
->create([
'filename' => $fileName,
'filemime' => 'image/gif',
'uri' => $fileUri,
]);
return $file;
}
protected function createFileField(string $entityType, string $bundle, string $fieldName) : void {
if (!FieldStorageConfig::loadByName($entityType, $fieldName)) {
FieldStorageConfig::create([
'field_name' => $fieldName,
'entity_type' => $entityType,
'type' => 'image',
'settings' => [
'alt_field_required' => 0,
],
'cardinality' => 1,
])
->save();
}
if (!FieldConfig::loadByName($entityType, $bundle, $fieldName)) {
FieldConfig::create([
'field_name' => $fieldName,
'entity_type' => $entityType,
'bundle' => $bundle,
'label' => $fieldName,
])
->save();
}
}
}