You are here

public function FileTest::test in Feeds 8.3

Tests importing several files.

File

tests/src/Functional/Feeds/Target/FileTest.php, line 42

Class

FileTest
@coversDefaultClass \Drupal\feeds\Feeds\Target\File @group feeds

Namespace

Drupal\Tests\feeds\Functional\Feeds\Target

Code

public function test() {

  // Create a feed type for importing nodes with files.
  $feed_type = $this
    ->createFeedTypeForCsv([
    'title' => 'title',
    'timestamp' => 'timestamp',
    'file' => 'file',
  ], [
    'fetcher' => 'http',
    'fetcher_configuration' => [],
    'mappings' => [
      [
        'target' => 'title',
        'map' => [
          'value' => 'title',
        ],
      ],
      [
        'target' => 'field_file',
        'map' => [
          'target_id' => 'file',
        ],
        'settings' => [
          'reference_by' => 'filename',
          'existing' => '2',
          'autocreate' => FALSE,
        ],
      ],
    ],
  ]);

  // Create a feed and import.
  $feed = $this
    ->createFeed($feed_type
    ->id(), [
    'source' => \Drupal::request()
      ->getSchemeAndHttpHost() . '/testing/feeds/files.csv',
  ]);
  $feed
    ->import();

  // Assert that all files were imported.
  foreach ($this
    ->getListOfTestFiles() as $file) {
    $file_path = $this->container
      ->get('file_system')
      ->realpath('public://' . date('Y-m') . '/' . $file);
    $this
      ->assertFileExists($file_path);
  }
}