addMediaFileToField example

$file_system = $this->container->get('file_system');

    // Add to the twin media field.     $this->openMediaLibraryForField('field_twin_media');

    // Assert the upload form is now visible for default tab type_three.     $assert_session->elementExists('css', '.js-media-library-add-form');
    $assert_session->fieldExists('Add files');

    // Assert we can upload a file to the default tab type_three.     $assert_session->elementNotExists('css', '.js-media-library-add-form[data-input]');
    $this->addMediaFileToField('Add files', $this->container->get('file_system')->realpath($png_image->uri));
    $this->assertMediaAdded();
    $assert_session->elementExists('css', '.js-media-library-add-form[data-input]');
    // We do not have pre-selected items, so the container should not be added     // to the form.     $assert_session->pageTextNotContains('Additional selected media');
    // Files are temporary until the form is saved.     $files = $file_storage->loadMultiple();
    $file = array_pop($files);
    $this->assertSame('public://type-three-dir', $file_system->dirname($file->getFileUri()));
    $this->assertTrue($file->isTemporary());
    // Assert the revision_log_message field is not shown.
Home | Imprint | This part of the site doesn't use cookies.