You are here

public function EmailedExportTest::testIncludeAttachedFilesWithNativeFile in Webform Scheduled Tasks 8.2

Test exporting archived files with a format that is a file.

File

tests/src/Kernel/EmailedExportTest.php, line 312

Class

EmailedExportTest
Test the email export plugin.

Namespace

Drupal\Tests\webform_scheduled_tasks\Kernel

Code

public function testIncludeAttachedFilesWithNativeFile() {
  $task = $this
    ->createTestTask([
    'email_addresses' => 'foo@example.com, bar@example.com',
    'storage_type' => EmailedExport::STORAGE_TYPE_FILESYSTEM,
    'exporter' => 'delimited_text',
    'exporter_settings' => [
      'delimiter' => '|',
      'excel' => TRUE,
    ],
    'delete_submissions' => TRUE,
    'include_attachments' => TRUE,
  ]);
  $this
    ->createTestSubmissions();
  webform_scheduled_tasks_cron();
  $this
    ->assertFalse($task
    ->isHalted());
  $this
    ->assertCount(2, $this
    ->getMails());

  // Ensure we get an archive containing the delimited export plus the two
  // test files for each submission.
  $archive = new ArchiveTar('private://scheduled-exports/foo.webform_scheduled_task.foo.tar.gz');
  $contents = $archive
    ->listContent();
  $this
    ->assertCount(3, $contents);
  $this
    ->assertEquals('submission-1/test.pdf', $contents[0]['filename']);
  $this
    ->assertEquals('submission-2/test.pdf', $contents[1]['filename']);
  $this
    ->assertEquals('foo.webform_scheduled_task.foo/foo.webform_scheduled_task.foo.csv', $contents[2]['filename']);
  $this
    ->assertStringContainsString('FOO SUBMISSION CONTENT', $archive
    ->extractInString('foo.webform_scheduled_task.foo/foo.webform_scheduled_task.foo.csv'));
  $this
    ->assertStringContainsString('BAR SUBMISSION CONTENT', $archive
    ->extractInString('foo.webform_scheduled_task.foo/foo.webform_scheduled_task.foo.csv'));
}