You are here

public function FileTestBase::setUp in Feeds 8.3

Overrides FeedsKernelTestBase::setUp

File

tests/src/Kernel/Feeds/Target/FileTestBase.php, line 66

Class

FileTestBase
Base class for file field tests.

Namespace

Drupal\Tests\feeds\Kernel\Feeds\Target

Code

public function setUp() {
  parent::setUp();
  $this
    ->setUpFileFields();
  $this->entityTypeManager = $this
    ->prophesize(EntityTypeManagerInterface::class);
  $this->client = $this
    ->prophesize(ClientInterface::class);
  $this->token = $this
    ->prophesize(Token::class);
  $this->entityFieldManager = $this
    ->prophesize(EntityFieldManagerInterface::class);
  $this->entityFieldManager
    ->getFieldStorageDefinitions('file')
    ->willReturn([]);
  $this->entityFinder = $this
    ->prophesize(EntityFinderInterface::class);
  $this->entityFinder
    ->findEntities(Argument::cetera())
    ->willReturn([]);
  $this->fileSystem = $this
    ->prophesize(FileSystemInterface::class);

  // Made-up entity type that we are referencing to.
  $referenceable_entity_type = $this
    ->prophesize(EntityTypeInterface::class);
  $referenceable_entity_type
    ->getKey('label')
    ->willReturn('file label');
  $this->entityTypeManager
    ->getDefinition('file')
    ->willReturn($referenceable_entity_type)
    ->shouldBeCalled();
  $configuration = [
    'feed_type' => $this
      ->createMock(FeedTypeInterface::class),
    'target_definition' => $this
      ->getTargetDefinition(),
  ];
  $this->targetPlugin = $this
    ->getMockBuilder($this
    ->getTargetPluginClass())
    ->setMethods([
    'getDestinationDirectory',
  ])
    ->setConstructorArgs([
    $configuration,
    'file',
    [],
    $this->entityTypeManager
      ->reveal(),
    $this->client
      ->reveal(),
    $this->token
      ->reveal(),
    $this->entityFieldManager
      ->reveal(),
    $this->entityFinder
      ->reveal(),
    $this->fileSystem
      ->reveal(),
  ])
    ->getMock();
  $this->targetPlugin
    ->expects($this
    ->any())
    ->method('getDestinationDirectory')
    ->will($this
    ->returnValue('public:/'));

  // Role::load fails without installing the user config.
  $this
    ->installConfig([
    'user',
  ]);

  // Give anonymous users permission to access content, so that they can view
  // and download public files. Without this we get an access denied error
  // when trying to import public files.
  Role::load(Role::ANONYMOUS_ID)
    ->grantPermission('access content')
    ->save();
}