You are here

protected function AuditFilesUsedNotManagedTest::setUp in Audit Files 8.3

Same name and namespace in other branches
  1. 8.2 tests/src/Functional/AuditFilesUsedNotManagedTest.php \Drupal\Tests\auditfiles\Functional\AuditFilesUsedNotManagedTest::setUp()

Overrides BrowserTestBase::setUp

File

tests/src/Functional/AuditFilesUsedNotManagedTest.php, line 47

Class

AuditFilesUsedNotManagedTest
Tests that the "Used not managed" report is reachable with no errors.

Namespace

Drupal\Tests\auditfiles\Functional

Code

protected function setUp() : void {
  parent::setUp();

  // Create user with permissions to manage site configuration and access
  // audit files reports.
  $this->user = $this
    ->drupalCreateUser([
    'access audit files reports',
  ]);
  $all_rids = $this->user
    ->getRoles();
  unset($all_rids[array_search(RoleInterface::AUTHENTICATED_ID, $all_rids)]);

  // Save role IDs.
  $this->rid = reset($all_rids);

  // Create File Entities.
  $values = [
    [
      1,
      'file',
      'media',
      1,
      1,
    ],
    [
      2,
      'file',
      'media',
      3,
      1,
    ],
    [
      3,
      'file',
      'media',
      5,
      1,
    ],
  ];
  foreach ($values as $value) {
    \Drupal::database()
      ->insert('file_usage')
      ->fields([
      'fid' => $value[0],
      'module' => $value[1],
      'type' => $value[2],
      'id' => $value[3],
      'count' => $value[4],
    ])
      ->execute();
  }
}