You are here

public function UploadFetcherFeedFormTest::testFeedForm in Feeds 8.3

Tests the feed form.

@covers ::buildConfigurationForm @covers ::validateConfigurationForm @covers ::submitConfigurationForm

File

tests/src/Unit/Feeds/Fetcher/Form/UploadFetcherFeedFormTest.php, line 30

Class

UploadFetcherFeedFormTest
@coversDefaultClass \Drupal\feeds\Feeds\Fetcher\Form\UploadFetcherFeedForm @group feeds

Namespace

Drupal\Tests\feeds\Unit\Feeds\Fetcher\Form

Code

public function testFeedForm() {
  $file = $this
    ->prophesize(FileInterface::class);
  $file_storage = $this
    ->prophesize(FileStorageInterface::class);
  $file_storage
    ->load(1)
    ->willReturn($file
    ->reveal());
  $entity_manager = $this
    ->prophesize(EntityTypeManagerInterface::class);
  $entity_manager
    ->getStorage('file')
    ->willReturn($file_storage
    ->reveal());
  $file_usage = $this
    ->prophesize(FileUsageInterface::class);
  $uuid = $this
    ->prophesize(UuidInterface::class);
  $container = new ContainerBuilder();
  $container
    ->set('entity_type.manager', $entity_manager
    ->reveal());
  $container
    ->set('file.usage', $file_usage
    ->reveal());
  $container
    ->set('uuid', $uuid
    ->reveal());
  $plugin = $this
    ->prophesize(FeedsPluginInterface::class);
  $plugin
    ->getConfiguration('allowed_extensions')
    ->willReturn('foo');
  $plugin
    ->getConfiguration('directory')
    ->willReturn('foodir');
  $form_object = UploadFetcherFeedForm::create($container);
  $form_object
    ->setStringTranslation($this
    ->getStringTranslationStub());
  $form_object
    ->setPlugin($plugin
    ->reveal());
  $form_state = new FormState();
  $feed = $this
    ->prophesize(FeedInterface::class);
  $feed
    ->getConfigurationFor($plugin
    ->reveal())
    ->willReturn([
    'fid' => 1,
    'usage_id' => 'foo',
  ]);
  $feed
    ->setConfigurationFor($plugin
    ->reveal(), [
    'fid' => 1,
    'usage_id' => 'foo',
  ])
    ->shouldBeCalled();
  $form = $form_object
    ->buildConfigurationForm([], $form_state, $feed
    ->reveal());
  $this
    ->assertIsArray($form);
  $form_object
    ->validateConfigurationForm($form, $form_state, $feed
    ->reveal());
  $form_state
    ->setValue('source', [
    1,
  ]);
  $form_object
    ->submitConfigurationForm($form, $form_state, $feed
    ->reveal());
}