public function FileFieldSourcesTestBase::enableSources in FileField Sources 8
Enable file field sources.
Parameters
array $sources: List of sources to enable or disable. e.g array( 'upload' => FALSE, 'remote' => TRUE, ).
11 calls to FileFieldSourcesTestBase::enableSources()
- AttachSourceTest::testCopyFileFromAbsolutePath in tests/
src/ Functional/ AttachSourceTest.php - Tests copy file from absolute path.
- AttachSourceTest::testMoveFilesFromRelativePath in tests/
src/ Functional/ AttachSourceTest.php - Tests move relative files with different names.
- ClipboardSourceTest::testClipboardSourceEnabled in tests/
src/ Functional/ ClipboardSourceTest.php - Tests clipboard source enabled.
- EmptyValuesTest::testAllSourcesEnabled in tests/
src/ Functional/ EmptyValuesTest.php - Tests all sources enabled.
- ImceSourceTest::testImceSourceEnabled in tests/
src/ Functional/ ImceSourceTest.php - Tests imce source enabled.
File
- tests/
src/ Functional/ FileFieldSourcesTestBase.php, line 85
Class
- FileFieldSourcesTestBase
- Base class for File Field Sources test cases.
Namespace
Drupal\Tests\filefield_sources\FunctionalCode
public function enableSources($sources = []) {
$sources += [
'upload' => TRUE,
];
$map = [
'upload' => 'Upload',
'remote' => 'Remote URL',
'clipboard' => 'Clipboard',
'reference' => 'Reference existing',
'attach' => 'File attach',
'imce' => 'File browser',
];
$sources = array_intersect_key($sources, $map);
ksort($sources);
// Upload source enabled by default.
$manage_display = 'admin/structure/types/manage/' . $this->typeName . '/form-display';
$this
->drupalGet($manage_display);
$this
->assertSession()
->responseContains("File field sources: upload");
// Click on the widget settings button to open the widget settings form.
$this
->drupalPostForm(NULL, [], $this->fieldName . "_settings_edit");
// Enable sources.
$prefix = 'fields[' . $this->fieldName . '][settings_edit_form][third_party_settings][filefield_sources][filefield_sources][sources]';
$edit = [];
foreach ($sources as $source => $enabled) {
$edit[$prefix . '[' . $source . ']'] = $enabled ? TRUE : FALSE;
}
$this
->drupalPostForm(NULL, $edit, $this->fieldName . '_plugin_settings_update');
$this
->assertSession()
->responseContains("File field sources: " . implode(', ', array_keys($sources)));
// Save the form to save the third party settings.
$this
->drupalPostForm(NULL, [], t('Save'));
$add_node = 'node/add/' . $this->typeName;
$this
->drupalGet($add_node);
if (count($sources) > 1) {
// We can switch between sources.
foreach ($sources as $source => $enabled) {
$label = $map[$source];
$this
->assertSession()
->linkExists($label);
}
}
else {
foreach ($map as $source => $label) {
$this
->assertSession()
->linkNotExists($label);
}
}
}