You are here

public function ConfigFormTest::testSubmitForm in Flysystem 8

Same name and namespace in other branches
  1. 3.x tests/src/Unit/Form/ConfigFormTest.php \Drupal\Tests\flysystem\Unit\Form\ConfigFormTest::testSubmitForm()
  2. 2.0.x tests/src/Unit/Form/ConfigFormTest.php \Drupal\Tests\flysystem\Unit\Form\ConfigFormTest::testSubmitForm()
  3. 3.0.x tests/src/Unit/Form/ConfigFormTest.php \Drupal\Tests\flysystem\Unit\Form\ConfigFormTest::testSubmitForm()

@covers ::submitForm @covers ::getFileList

File

tests/src/Unit/Form/ConfigFormTest.php, line 116

Class

ConfigFormTest
@coversDefaultClass \Drupal\flysystem\Form\ConfigForm @group flysystem

Namespace

Drupal\Tests\flysystem\Unit\Form

Code

public function testSubmitForm() {
  $form_state = new FormState();
  $form = [];
  $form_state
    ->setValue('sync_from', 'from_empty');
  $form_state
    ->setValue('sync_to', 'to_empty');
  $this->form
    ->submitForm($form, $form_state);
  $batch = \Drupal\flysystem\Form\batch_set();
  $this
    ->assertSame(ConfigForm::class . '::finishBatch', $batch['finished']);
  $this
    ->assertSame(0, count($batch['operations']));

  // Test with existing source files.
  $from = new Filesystem(new MemoryAdapter());
  $from
    ->write('dir/test.txt', 'abcdefg');
  $from
    ->write('test.txt', 'abcdefg');
  $this->factory
    ->getFilesystem('from_files')
    ->willReturn($from);
  $form_state
    ->setValue('sync_from', 'from_files');
  $this->form
    ->submitForm($form, $form_state);
  $batch_files = array_map(function (array $operation) {
    return $operation[1][2];
  }, \Drupal\flysystem\Form\batch_set()['operations']);
  $this
    ->assertSame([
    'dir/test.txt',
    'test.txt',
  ], $batch_files);

  // Test with existing destination files, and force true.
  $form_state
    ->setValue('force', TRUE);
  $form_state
    ->setValue('sync_to', 'from_files');
  $this->form
    ->submitForm($form, $form_state);
  $batch_files = array_map(function (array $operation) {
    return $operation[1][2];
  }, \Drupal\flysystem\Form\batch_set()['operations']);
  $this
    ->assertSame([
    'dir/test.txt',
    'test.txt',
  ], $batch_files);
}