function WidgetOverflowTest::uploadFiles

Same name in other branches
  1. 11.x core/modules/media_library/tests/src/FunctionalJavascript/WidgetOverflowTest.php \Drupal\Tests\media_library\FunctionalJavascript\WidgetOverflowTest::uploadFiles()

Uploads multiple test images into the media library.

Parameters

int $number: The number of images to upload.

2 calls to WidgetOverflowTest::uploadFiles()
WidgetOverflowTest::testUnlimitedCardinality in core/modules/media_library/tests/src/FunctionalJavascript/WidgetOverflowTest.php
Tests that unlimited fields' selection count is not constrained.
WidgetOverflowTest::testWidgetOverflow in core/modules/media_library/tests/src/FunctionalJavascript/WidgetOverflowTest.php
Tests that the Media Library constrains the number of selected items.

File

core/modules/media_library/tests/src/FunctionalJavascript/WidgetOverflowTest.php, line 63

Class

WidgetOverflowTest
Tests that uploads in the 'media_library_widget' works as expected.

Namespace

Drupal\Tests\media_library\FunctionalJavascript

Code

private function uploadFiles(int $number) : void {
    
    /** @var \Drupal\Core\File\FileSystemInterface $file_system */
    $file_system = $this->container
        ->get('file_system');
    // Create a list of new files to upload.
    $filenames = $remote_paths = [];
    for ($i = 0; $i < $number; $i++) {
        $path = $file_system->copy($this->image->uri, 'public://');
        $path = $file_system->realpath($path);
        $this->assertNotEmpty($path);
        $this->assertFileExists($path);
        $filenames[] = $file_system->basename($path);
        $remote_paths[] = $this->getSession()
            ->getDriver()
            ->uploadFileAndGetRemoteFilePath($path);
    }
    $page = $this->getSession()
        ->getPage();
    $page->fillField('Add files', implode("\n", $remote_paths));
    $this->assertMediaAdded();
    $assert_session = $this->assertSession();
    foreach ($filenames as $i => $filename) {
        $assert_session->fieldValueEquals("media[{$i}][fields][name][0][value]", $filename);
        $page->fillField("media[{$i}][fields][field_media_test_image][0][alt]", $filename);
    }
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.