function DownloadTest::doTransform

Same name and namespace in other branches
  1. 9 core/modules/migrate/tests/src/Kernel/process/DownloadTest.php \Drupal\Tests\migrate\Kernel\process\DownloadTest::doTransform()
  2. 8.9.x core/modules/migrate/tests/src/Kernel/process/DownloadTest.php \Drupal\Tests\migrate\Kernel\process\DownloadTest::doTransform()
  3. 11.x core/modules/migrate/tests/src/Kernel/process/DownloadTest.php \Drupal\Tests\migrate\Kernel\process\DownloadTest::doTransform()

Runs an input value through the download plugin.

Parameters

string $destination_uri: The destination URI to download to.

array $configuration: (optional) Configuration for the download plugin.

Return value

string The local URI of the downloaded file.

3 calls to DownloadTest::doTransform()
DownloadTest::testNonDestructiveDownload in core/modules/migrate/tests/src/Kernel/process/DownloadTest.php
Tests a download that renames the downloaded file if there's a collision.
DownloadTest::testOverwritingDownload in core/modules/migrate/tests/src/Kernel/process/DownloadTest.php
Tests a download that overwrites an existing local file.
DownloadTest::testWriteProtectedDestination in core/modules/migrate/tests/src/Kernel/process/DownloadTest.php
Tests that an exception is thrown if the destination URI is not writable.

File

core/modules/migrate/tests/src/Kernel/process/DownloadTest.php, line 103

Class

DownloadTest
Tests the download process plugin.

Namespace

Drupal\Tests\migrate\Kernel\process

Code

protected function doTransform($destination_uri, $configuration = []) {
    // Prepare a mock HTTP client.
    $this->container
        ->set('http_client', $this->createMock(Client::class));
    // Instantiate the plugin statically so it can pull dependencies out of
    // the container.
    $plugin = Download::create($this->container, $configuration, 'download', []);
    // Execute the transformation.
    $executable = $this->createMock(MigrateExecutableInterface::class);
    $row = new Row([], []);
    // Return the downloaded file's local URI.
    $value = [
        'http://drupal.org/favicon.ico',
        $destination_uri,
    ];
    // Assert that number of stream resources in use is the same before and
    // after the download.
    $initial_count = count(get_resources('stream'));
    $return = $plugin->transform($value, $executable, $row, 'foo');
    $this->assertCount($initial_count, get_resources('stream'));
    return $return;
}

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