AuditFilesNotOnServerTest.php in Audit Files 4.x
File
tests/src/FunctionalJavascript/AuditFilesNotOnServerTest.php
View source
<?php
namespace Drupal\Tests\auditfiles\FunctionalJavascript;
use Drupal\FunctionalJavascriptTests\WebDriverTestBase;
use Drupal\user\RoleInterface;
use Drupal\Core\Url;
use Drupal\file\Entity\File;
class AuditFilesNotOnServerTest extends WebDriverTestBase {
protected static $modules = [
'node',
'file',
'user',
'auditfiles',
];
protected $user;
protected $rid;
protected $defaultTheme = 'stark';
protected function setUp() {
parent::setUp();
$this->user = $this
->drupalCreateUser([
'access audit files reports',
]);
$all_rids = $this->user
->getRoles();
unset($all_rids[array_search(RoleInterface::AUTHENTICATED_ID, $all_rids)]);
$this->rid = reset($all_rids);
for ($i = 0; $i < 3; $i++) {
$path = "public://example_{$i}.png";
$image = File::create([
'uri' => $path,
'status' => TRUE,
]);
$image
->save();
}
}
public function testReportPage() {
$path = URL::fromRoute('auditfiles.audit_files_notonserver');
$session = $this
->assertSession();
$this
->drupalGet($path);
$session
->pageTextContains('Access denied');
$this
->drupalLogin($this->user);
$this
->drupalGet($path);
$session
->pageTextContains('Not on server');
}
public function testFileEntityCanBeDeleted() {
$path = URL::fromRoute('auditfiles.audit_files_notonserver');
$session = $this
->assertSession();
$this
->drupalLogin($this->user);
$this
->drupalGet($path);
$session
->pageTextContains("Not on server");
$edit = [
'edit-files-1' => TRUE,
];
$this
->submitForm($edit, 'Delete selected items from the database');
$session
->pageTextContains("Delete these items from the database?");
$edit = [];
$this
->submitForm($edit, 'Confirm');
$session
->pageTextContains("Not on server");
$session
->pageTextContains("Sucessfully deleted File ID : 1 from the file_managed table.");
}
}