You are here

protected function EmbeddedImagesCollectorTest::uploadAndAttachFileToNode in Dependency Calculation 8

Simulates file attachment process to node via editor.

Parameters

string $uuid: File UUID.

string $usages: File usages count.

\Drupal\node\NodeInterface $node: Node.

Throws

\Drupal\Core\Entity\EntityStorageException

2 calls to EmbeddedImagesCollectorTest::uploadAndAttachFileToNode()
EmbeddedImagesCollectorTest::testDependenciesCalculation in tests/src/Kernel/EventSubscriber/DependencyCollector/EmbeddedImagesCollectorTest.php
Tests dependency calculation.
EmbeddedImagesCollectorTest::testDependenciesCalculationWithoutImagesCollector in tests/src/Kernel/EventSubscriber/DependencyCollector/EmbeddedImagesCollectorTest.php
Checks EmbeddedImagesCollector absence.

File

tests/src/Kernel/EventSubscriber/DependencyCollector/EmbeddedImagesCollectorTest.php, line 181

Class

EmbeddedImagesCollectorTest
Class EmbeddedImagesCollectorTest.

Namespace

Drupal\Tests\depcalc\Kernel\EventSubscriber\DependencyCollector

Code

protected function uploadAndAttachFileToNode($uuid, $usages, NodeInterface $node) {
  $uri = sprintf('public://file-%s.png', $this
    ->randomMachineName());
  file_put_contents($uri, '');
  $file = File::create([
    'uri' => $uri,
    'filename' => 'file.png',
    'uuid' => $uuid,
  ]);
  $file
    ->save();
  while ($usages--) {
    self::fileUsage()
      ->add($file, 'editor', 'node', $node
      ->id());
  }
}