$edit =
['settings[file_extensions]' => 'jpg php'
];
$this->
submitForm($edit, 'Save settings'
);
$this->
assertSession()->
pageTextContains('Saved ' .
$field_name . ' configuration.'
);
// Check that a file extension with an underscore can be configured.
$edit =
[ 'settings[file_extensions]' => 'x_t x.t xt x_y_t',
];
$this->
drupalGet("admin/structure/types/manage/
$type_name/fields/
$field_id"
);
$this->
submitForm($edit, 'Save settings'
);
$field = FieldConfig::
loadByName('node',
$type_name,
$field_name);
$this->
assertEquals('x_t x.t xt x_y_t',
$field->
getSetting('file_extensions'
));
// Check that a file field with an invalid value in allowed extensions
// property throws an error message.
$invalid_extensions =
['x_.t', 'x._t', 'xt_', 'x__t', '_xt'
];
foreach ($invalid_extensions as $value) { $edit =
[ 'settings[file_extensions]' =>
$value,
];
$this->
drupalGet("admin/structure/types/manage/
$type_name/fields/
$field_id"
);
$this->
submitForm($edit, 'Save settings'
);
$this->
assertSession()->
pageTextContains("The list of allowed extensions is not valid. Allowed characters are a-z, 0-9, '.', and '_'. The first and last characters cannot be '.' or '_', and these two characters cannot appear next to each other. Separate extensions with a comma or space."
);
}