You are here

public function S3FileOriginLocatorTest::testNoRecordLocally in Acquia Content Hub 8.2

@covers ::getS3FileSource

File

modules/acquia_contenthub_s3/tests/src/Kernel/S3FileOriginLocatorTest.php, line 106

Class

S3FileOriginLocatorTest
Tests the S3FileOriginLocator.

Namespace

Drupal\Tests\acquia_contenthub_s3\Kernel

Code

public function testNoRecordLocally() : void {

  // The mocking process below represents a file on Content Hub.
  $this
    ->setS3fsConfig('pub-bucket', 'pub-root');
  OverwriteContentHubAdminSettings::overwrite(new Settings('test-client', 'a76696bf-be45-4d42-b5c3-08cebee93798', 'api-key', 'secret-key', 'http://example.com'));
  $file = $this
    ->createFileEntity('test.png', 's3');

  // Same uri, pretend they are in different buckets.
  $this
    ->createFileEntity('test.png', 's3');
  $this
    ->createFileEntity('test.png', 's3');
  $cdf_doc = $this->container
    ->get('acquia_contenthub_common_actions')
    ->getLocalCdfDocument($file);
  $cdf = $cdf_doc
    ->getCdfEntity($file
    ->uuid());

  // Clear s3 file map table. getLocalCdfDocument call will populate the file
  // map table.
  $this
    ->truncateS3FileMap();
  $uuid = $file
    ->uuid();
  $common = $this
    ->prophesize(ContentHubCommonActions::class);
  $common
    ->getRemoteEntity(Argument::type('string'))
    ->will(function ($args) use ($uuid, $cdf) {
    return current($args) === $uuid ? $cdf : NULL;
  });
  $this->container
    ->set('acquia_contenthub_common_actions', $common
    ->reveal());

  // This is the subscriber side.
  $this
    ->setS3fsConfig('sub-bucket', 'sub-root');

  // Make sure the table is empty.
  $this
    ->assertCount(0, $this
    ->fetchAllData());

  // Make the remote call.
  $source = $this
    ->constructS3Locator()
    ->getS3FileSource($file
    ->getFileUri());
  $expected = [
    'bucket' => 'pub-bucket',
    'root_folder' => 'pub-root',
  ];
  $this
    ->assertEqual($source, $expected);
}