EmptyValuesTest.php in FileField Sources 8
File
tests/src/Functional/EmptyValuesTest.php
View source
<?php
namespace Drupal\Tests\filefield_sources\Functional;
use Drupal\Component\Render\FormattableMarkup;
use Drupal\Core\Field\FieldStorageDefinitionInterface;
use Drupal\Tests\BrowserTestBase;
class EmptyValuesTest extends FileFieldSourcesTestBase {
public static $modules = [
'imce',
];
protected function setUp() {
parent::setUp();
$this
->setUpImce();
}
public function testAllSourcesEnabled() {
$this
->drupalPostForm('admin/structure/types/manage/' . $this->typeName . '/fields/node.' . $this->typeName . '.' . $this->fieldName . '/storage', [
'cardinality' => FieldStorageDefinitionInterface::CARDINALITY_UNLIMITED,
], t('Save field settings'));
$this
->enableSources([
'upload' => TRUE,
'remote' => TRUE,
'clipboard' => TRUE,
'reference' => TRUE,
'attach' => TRUE,
'imce' => TRUE,
]);
$this
->uploadFileByRemoteSource();
$this
->uploadFileByReferenceSource();
$this
->uploadFileByClipboardSource();
$this
->uploadFileByAttachSource();
$this
->uploadFileByUploadSource('', '', 0, TRUE);
$this
->uploadFileByImceSource();
$this
->assertUniqueSubmitButtons();
}
protected function assertUniqueSubmitButtons() {
$buttons = [
$this->fieldName . '_0_attach' => t('Attach'),
$this->fieldName . '_0_clipboard_upload_button' => t('Upload'),
$this->fieldName . '_0_autocomplete_select' => t('Select'),
$this->fieldName . '_0_transfer' => t('Transfer'),
$this->fieldName . '_0_upload_button' => t('Upload'),
$this->fieldName . '_0_imce_select' => t('Select'),
];
foreach ($buttons as $button_name => $button_label) {
$buttons = $this
->xpath('//input[@name="' . $button_name . '" and @value="' . $button_label . '"]');
$this
->assertEquals(count($buttons), 1, new FormattableMarkup('There is only one button with name %name and label %label', [
'%name' => $button_name,
'%label' => $button_label,
]));
}
}
}