// Assert the existing items are remembered when adding and removing media.
$checkbox =
$page->
findField("Select
$existing_media_name"
);
$checkbox->
click();
// Assert we can add multiple files.
$this->
assertTrue($assert_session->
fieldExists('Add files'
)->
hasAttribute('multiple'
));
// Create a list of new files to upload.
$filenames =
[];
$remote_paths =
[];
foreach (range(1, 4
) as $i) { $path =
$file_system->
copy($png_image->uri, 'public://'
);
$filenames[] =
$file_system->
basename($path);
$remote_paths[] =
$driver->
uploadFileAndGetRemoteFilePath($file_system->
realpath($path));
} $page->
findField('Add files'
)->
setValue(implode("\n",
$remote_paths));
// Assert the media item fields are shown and the vertical tabs are no
// longer shown.
$this->
assertMediaAdded();
// Assert all files have been added.
$assert_session->
fieldValueEquals('media[0][fields][name][0][value]',
$filenames[0
]);
$assert_session->
fieldValueEquals('media[1][fields][name][0][value]',
$filenames[1
]);
$assert_session->
fieldValueEquals('media[2][fields][name][0][value]',
$filenames[2
]);
$assert_session->
fieldValueEquals('media[3][fields][name][0][value]',
$filenames[3
]);
// Set alt texts for items 1 and 2, leave the alt text empty for items 3