You are here

public function EmailedExportTest::testSubmissionsExceedingBatchLimit in Webform Scheduled Tasks 8.2

Test exporting submissions exceeding the batch limit.

File

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

Class

EmailedExportTest
Test the email export plugin.

Namespace

Drupal\Tests\webform_scheduled_tasks\Kernel

Code

public function testSubmissionsExceedingBatchLimit() {

  // Set a low batch limit. This currently only affects a UI decision the user
  // must make, so the exporter that runs with chunked submission loads on a
  // long-running cron run shouldn't run into the same limitations.
  $this->container
    ->get('config.factory')
    ->getEditable('webform.settings')
    ->set('batch.default_batch_export_size', 2);
  $this
    ->createTestTask([
    'email_addresses' => 'foo@example.com, bar@example.com',
    'storage_type' => EmailedExport::STORAGE_TYPE_FILESYSTEM,
    'exporter' => 'json',
    'exporter_settings' => [
      'file_name' => 'submission-[webform_submission:serial]',
    ],
    'delete_submissions' => TRUE,
    'include_attachments' => FALSE,
  ]);
  $this
    ->createTestSubmissions();
  $this
    ->createTestSubmissions();
  webform_scheduled_tasks_cron();

  // 4 files will exist from the 4 submissions, the 5th will be the export.
  $file = File::load(5);
  $this
    ->assertEquals('private://scheduled-exports/foo.webform_scheduled_task.foo.tar.gz', $file
    ->getFileUri());
  $archive = new ArchiveTar('private://scheduled-exports/foo.webform_scheduled_task.foo.tar.gz');
  $this
    ->assertCount(4, $archive
    ->listContent());
  $this
    ->assertStringContainsString('FOO SUBMISSION CONTENT', $archive
    ->extractInString('submission-1.json'));
  $this
    ->assertStringContainsString('BAR SUBMISSION CONTENT', $archive
    ->extractInString('submission-2.json'));
  $this
    ->assertStringContainsString('FOO SUBMISSION CONTENT', $archive
    ->extractInString('submission-3.json'));
  $this
    ->assertStringContainsString('BAR SUBMISSION CONTENT', $archive
    ->extractInString('submission-4.json'));
}