You are here

public function LicenseFileManagerTest::testCanDownload in Commerce File 8.2

@covers ::canDownload

File

tests/src/Kernel/LicenseFileManagerTest.php, line 65

Class

LicenseFileManagerTest
Tests the license file manager.

Namespace

Drupal\Tests\commerce_file\Kernel

Code

public function testCanDownload() {
  $account = $this
    ->createUser([], [
    'bypass license control',
  ]);
  $this
    ->assertTrue($this->licenseFileManager
    ->canDownload($this->license, $this->file, $account));
  $account = $this
    ->createUser([], [
    'administer commerce_license',
  ]);
  $this
    ->assertTrue($this->licenseFileManager
    ->canDownload($this->license, $this->file, $account));
  $account = $this
    ->createUser();
  $this
    ->assertFalse($this->licenseFileManager
    ->canDownload($this->license, $this->file, $account));

  // Ensure the license owner can download its own license.
  $this
    ->assertTrue($this->licenseFileManager
    ->canDownload($this->license, $this->file));

  /** @var \Drupal\commerce_file\DownloadLoggerInterface $download_logger */
  $download_logger = $this->container
    ->get('commerce_file.download_logger');
  $download_logger
    ->log($this->license, $this->file);
  $this
    ->assertTrue($this->licenseFileManager
    ->canDownload($this->license, $this->file));
  $download_logger
    ->log($this->license, $this->file);
  $this
    ->assertFalse($this->licenseFileManager
    ->canDownload($this->license, $this->file));
}