X-Git-Url: http://www.aleph1.co.uk/gitweb/?p=yaffs-website;a=blobdiff_plain;f=web%2Fcore%2Fmodules%2Ffile%2Ftests%2Fsrc%2FFunctional%2FFormatter%2FFileMediaFormatterTestBase.php;fp=web%2Fcore%2Fmodules%2Ffile%2Ftests%2Fsrc%2FFunctional%2FFormatter%2FFileMediaFormatterTestBase.php;h=5ff99f4b05ee27408a022050d0da0bb95abb1cc3;hp=0000000000000000000000000000000000000000;hb=af6d1fb995500ae68849458ee10d66abbdcfb252;hpb=680c79a86e3ed402f263faeac92e89fb6d9edcc0 diff --git a/web/core/modules/file/tests/src/Functional/Formatter/FileMediaFormatterTestBase.php b/web/core/modules/file/tests/src/Functional/Formatter/FileMediaFormatterTestBase.php new file mode 100644 index 000000000..5ff99f4b0 --- /dev/null +++ b/web/core/modules/file/tests/src/Functional/Formatter/FileMediaFormatterTestBase.php @@ -0,0 +1,93 @@ +drupalLogin($this->drupalCreateUser(['view test entity'])); + } + + /** + * Creates a file field and set's the correct formatter. + * + * @param string $formatter + * The formatter ID. + * @param string $file_extensions + * The file extensions of the new field. + * @param array $formatter_settings + * Settings for the formatter. + * + * @return \Drupal\field\Entity\FieldConfig + * Newly created file field. + */ + protected function createMediaField($formatter, $file_extensions, array $formatter_settings = []) { + $entity_type = $bundle = 'entity_test'; + $field_name = Unicode::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(); + + $display = entity_get_display('entity_test', 'entity_test', 'full'); + $display->setComponent($field_name, [ + 'type' => $formatter, + 'settings' => $formatter_settings, + ])->save(); + + return $field_config; + } + + /** + * Data provider for testRender. + * + * @return array + * An array of data arrays. + * The data array contains: + * - The number of expected HTML tags. + * - An array of settings for the field formatter. + */ + public function dataProvider() { + return [ + [2, []], + [1, ['multiple_file_display_type' => 'sources']], + ]; + } + +}