You are here

public function DownloadLoggerTest::testDownloadLog in Commerce File 8.2

Tests the download logger.

@covers ::clear @covers ::getDownloadCounts @covers ::log

File

tests/src/Kernel/DownloadLoggerTest.php, line 53

Class

DownloadLoggerTest
Tests the file download logger.

Namespace

Drupal\Tests\commerce_file\Kernel

Code

public function testDownloadLog() {
  $license = $this
    ->prophesize(LicenseInterface::class);
  $license
    ->id()
    ->willReturn(100);
  $license
    ->getCacheTagsToInvalidate()
    ->willReturn([]);
  $license
    ->getOwnerId()
    ->willReturn(2);
  $purchased_entity = $this
    ->prophesize(ProductVariationInterface::class);
  $purchased_entity
    ->hasField('commerce_file')
    ->willReturn(TRUE);
  $file_reference = $this
    ->prophesize(EntityReferenceItem::class);
  $file_reference
    ->isEmpty()
    ->willReturn(FALSE);
  $file_reference
    ->getValue()
    ->willReturn([
    [
      'target_id' => 10,
    ],
    [
      'target_id' => 15,
    ],
  ]);
  $file_reference
    ->reveal();
  $purchased_entity
    ->get('commerce_file')
    ->willReturn($file_reference);
  $purchased_entity
    ->reveal();
  $license
    ->getPurchasedEntity()
    ->willReturn($purchased_entity);
  $license = $license
    ->reveal();
  $file = $this
    ->prophesize(FileInterface::class);
  $file
    ->id()
    ->willReturn(10);
  $file = $file
    ->reveal();
  $this->downloadLogger
    ->log($license, $file);
  $this
    ->assertEquals([
    10 => 1,
    15 => 0,
  ], $this->downloadLogger
    ->getDownloadCounts($license));
  $this->downloadLogger
    ->log($license, $file);
  $this
    ->assertEquals([
    10 => 2,
    15 => 0,
  ], $this->downloadLogger
    ->getDownloadCounts($license));
  $this->downloadLogger
    ->clear($license);
  $this
    ->assertEquals([
    10 => 0,
    15 => 0,
  ], $this->downloadLogger
    ->getDownloadCounts($license));
}