X-Git-Url: http://aleph1.co.uk/gitweb/?a=blobdiff_plain;f=web%2Fcore%2Fmodules%2Ffile%2Ftests%2Fsrc%2FFunctional%2FFileFieldTestBase.php;h=16733144e31e792063bfa434ccf09770cc055e50;hb=9917807b03b64faf00f6a1f29dcb6eafc454efa5;hp=9ed447aaf25e969eee31621e04e7f588791f8ed0;hpb=a2bd1bf0c2c1f1a17d188f4dc0726a45494cefae;p=yaffs-website diff --git a/web/core/modules/file/tests/src/Functional/FileFieldTestBase.php b/web/core/modules/file/tests/src/Functional/FileFieldTestBase.php index 9ed447aaf..16733144e 100644 --- a/web/core/modules/file/tests/src/Functional/FileFieldTestBase.php +++ b/web/core/modules/file/tests/src/Functional/FileFieldTestBase.php @@ -13,6 +13,8 @@ use Drupal\file\Entity\File; */ abstract class FileFieldTestBase extends BrowserTestBase { + use FileFieldCreationTrait; + /** * Modules to enable. * @@ -57,76 +59,6 @@ abstract class FileFieldTestBase extends BrowserTestBase { return (int) db_query('SELECT MAX(fid) FROM {file_managed}')->fetchField(); } - /** - * Creates a new file field. - * - * @param string $name - * The name of the new field (all lowercase), exclude the "field_" prefix. - * @param string $entity_type - * The entity type. - * @param string $bundle - * The bundle that this field will be added to. - * @param array $storage_settings - * A list of field storage settings that will be added to the defaults. - * @param array $field_settings - * A list of instance settings that will be added to the instance defaults. - * @param array $widget_settings - * A list of widget settings that will be added to the widget defaults. - */ - public function createFileField($name, $entity_type, $bundle, $storage_settings = [], $field_settings = [], $widget_settings = []) { - $field_storage = FieldStorageConfig::create([ - 'entity_type' => $entity_type, - 'field_name' => $name, - 'type' => 'file', - 'settings' => $storage_settings, - 'cardinality' => !empty($storage_settings['cardinality']) ? $storage_settings['cardinality'] : 1, - ]); - $field_storage->save(); - - $this->attachFileField($name, $entity_type, $bundle, $field_settings, $widget_settings); - return $field_storage; - } - - /** - * Attaches a file field to an entity. - * - * @param string $name - * The name of the new field (all lowercase), exclude the "field_" prefix. - * @param string $entity_type - * The entity type this field will be added to. - * @param string $bundle - * The bundle this field will be added to. - * @param array $field_settings - * A list of field settings that will be added to the defaults. - * @param array $widget_settings - * A list of widget settings that will be added to the widget defaults. - */ - public function attachFileField($name, $entity_type, $bundle, $field_settings = [], $widget_settings = []) { - $field = [ - 'field_name' => $name, - 'label' => $name, - 'entity_type' => $entity_type, - 'bundle' => $bundle, - 'required' => !empty($field_settings['required']), - 'settings' => $field_settings, - ]; - FieldConfig::create($field)->save(); - - entity_get_form_display($entity_type, $bundle, 'default') - ->setComponent($name, [ - 'type' => 'file_generic', - 'settings' => $widget_settings, - ]) - ->save(); - // Assign display settings. - entity_get_display($entity_type, $bundle, 'default') - ->setComponent($name, [ - 'label' => 'hidden', - 'type' => 'file_default', - ]) - ->save(); - } - /** * Updates an existing file field with new settings. */ @@ -259,7 +191,7 @@ abstract class FileFieldTestBase extends BrowserTestBase { /** * Asserts that a file exists physically on disk. * - * Overrides PHPUnit_Framework_Assert::assertFileExists() to also work with + * Overrides PHPUnit\Framework\Assert::assertFileExists() to also work with * file entities. * * @param \Drupal\File\FileInterface|string $file @@ -286,7 +218,7 @@ abstract class FileFieldTestBase extends BrowserTestBase { /** * Asserts that a file does not exist on disk. * - * Overrides PHPUnit_Framework_Assert::assertFileExists() to also work with + * Overrides PHPUnit\Framework\Assert::assertFileExists() to also work with * file entities. * * @param \Drupal\File\FileInterface|string $file