protected function AuditFilesReferencedNotUsedTest::setUp in Audit Files 4.x
Same name and namespace in other branches
- 8.3 tests/src/FunctionalJavascript/AuditFilesReferencedNotUsedTest.php \Drupal\Tests\auditfiles\FunctionalJavascript\AuditFilesReferencedNotUsedTest::setUp()
- 8.2 tests/src/FunctionalJavascript/AuditFilesReferencedNotUsedTest.php \Drupal\Tests\auditfiles\FunctionalJavascript\AuditFilesReferencedNotUsedTest::setUp()
Overrides BrowserTestBase::setUp
File
- tests/
src/ FunctionalJavascript/ AuditFilesReferencedNotUsedTest.php, line 50
Class
- AuditFilesReferencedNotUsedTest
- Tests that the "Referenced not used" report is reachable with no errors.
Namespace
Drupal\Tests\auditfiles\FunctionalJavascriptCode
protected function setUp() {
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);
// Array of data for file_usage, files_managed, and entity node creation.
$values = [
[
'file',
'node',
1,
1,
],
[
'file',
'node',
2,
1,
],
[
'file',
'node',
3,
1,
],
];
foreach ($values as $key => $value) {
// Create file_usage entry.
\Drupal::database()
->insert('file_usage')
->fields([
'fid' => $key + 1,
'module' => $value[0],
'type' => $value[1],
'id' => $value[2],
'count' => $value[3],
])
->execute();
// Create file_managed entry.
$fileno = $key + 1;
$path = "public://example_{$fileno}.png";
$image = File::create([
'uri' => $path,
'status' => TRUE,
]);
$image
->save();
$node = Node::create([
'type' => 'article',
'title' => 'Sample Node',
'field_image' => [
'target_id' => $key + 1,
'alt' => 'Sample',
'title' => 'Sample File',
],
]);
$node
->save();
}
}