You are here

protected function DrupalTestBrowser::addPostFiles in Drupal 9

Adds files to the $multipart array.

Parameters

array $files: The files.

array $multipart: A reference to the multipart array to add the files to.

string $array_name: Internal parameter used by recursive calls.

1 call to DrupalTestBrowser::addPostFiles()
DrupalTestBrowser::doRequest in core/tests/Drupal/Tests/DrupalTestBrowser.php

File

core/tests/Drupal/Tests/DrupalTestBrowser.php, line 162

Class

DrupalTestBrowser
Enables a BrowserKitDriver mink driver to use a Guzzle client.

Namespace

Drupal\Tests

Code

protected function addPostFiles(array $files, array &$multipart, $array_name = '') {
  if (empty($files)) {
    return;
  }
  foreach ($files as $name => $info) {
    if (!empty($array_name)) {
      $name = $array_name . '[' . $name . ']';
    }
    $file = [
      'name' => $name,
    ];
    if (\is_array($info)) {
      if (isset($info['tmp_name'])) {
        if ($info['tmp_name'] !== '') {
          $file['contents'] = fopen($info['tmp_name'], 'r');
          if (isset($info['name'])) {
            $file['filename'] = $info['name'];
          }
        }
        else {
          continue;
        }
      }
      else {
        $this
          ->addPostFiles($info, $multipart, $name);
        continue;
      }
    }
    else {
      $file['contents'] = fopen($info, 'r');
    }
    $multipart[] = $file;
  }
}